DSL Archives

Creating a Simple DSL in Perl

Let's look at the XSPF playlist format. It's a pretty simple XML-based file format.

  <?xml version="1.0" encoding="UTF-8"?>
  <playlist version="1" xmlns="http://xspf.org/ns/0/">
    <title>80's Music</title>
        <title>Take On Me</title>
        <title>Tainted Love</title>
        <creator>Soft Cell</creator>
        <title>Livin' on a Prayer</title>
        <creator>Bon Jovi</creator>

The full specification has a lot more details, but for now, we'll just use those elements.

If we are building a Perl application that needs to allow less experienced users to write playlists in Perl, it might be useful to define a domain-specific dialect of Perl for writing playlists.

About Toby Inkster

user-pic I'm tobyink on CPAN, IRC and PerlMonks.