O'Reilly logo

Windows PowerShell for Developers by Douglas Finke

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 9. Writing Little Languages in PowerShell

The term little language was coined by Jon Bentley in a 1986 article he wrote for Communications of the ACM (http://bit.ly/akBpXr).[2] Little languages are also referred to as domain-specific languages, or DSLs.

Some little languages are intended to save development time and effort by allowing a developer to express his or her intentions at a much higher level of abstraction. This allows the developer’s programs to be much shorter than equivalent programs in other languages. The “little” part primarily refers to the scope of what the language tackles.

In this chapter, we will focus on using PowerShell as a better XML, building our own little language that can do more than just plain XML. Then, we’ll build another DSL to blend Graphviz, an open source graph visualization toolset, into the PowerShell ecosystem. This offers us a better way to manipulate abstractions when working with structural information like diagrams of abstract graphs and networks.

There are many examples of DSLs in the software industry—for example, MSBuild is a little language, to my way of thinking. While others may view MSBuild as a build system that reads a specific schema of XML as input, I see it as a domain-specific language in an XML format, specific to dealing with Visual Studio builds.

One of the challenges of using MSBuild with XML happens when we want to extend it. Adding a custom task to MSBuild requires dropping into C#, inheriting from some base classes, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required