8. Origins: Minilanguages...
Source: The Art of Unix Programming:Taxonomy of languages: http://www.faqs.org/docs/artu/ch08s01.html
# Minilanguage taxonomy %!PS-Adobe-3.0
# Base ellipses %%Creator: groff version 1.20.1
define smallellipse {ellipse width 3.0 height 1.5} ...
M: ellipse width 3.0 height 1.8 fill 0.2 597.6 12 72 12 DL(increasing loopiness)297.71 8.2 Q(/etc/passwd)102.67
line from M.n to M.s dashed 94.6 Q(.ne)110.715 106.6 Q(wsrc)-.25 E(SNG)195.2 100.6 Q(re)243.8 94.6 Q
D: smallellipse() with .e at M.w + (0.8, 0) (ge)-.15 E(xps)-.15 E(Glade)247.26 106.6 Q(m4)306.81 58.6 Q -1(Ya)303.43
line from D.n to D.s dashed 70.6 S(cc)1 E(Le)305.5 82.6 Q(x)-.15 E(mak)302.42 94.6 Q(e)-.1 E(XSL)
I: smallellipse() with .w at M.e - (0.8, 0) 301.16 106.6 Q(T)-.92 E(pic)307.09 118.6 Q(tbl)307.92 130.6 Q(eqn)305.98
142.6 Q(fetchmail)344.715 82.6 Q -.15(aw)355.345 94.6 S(k).15 E(trof)
# Arrow headings 354.84 106.6 Q(f)-.25 E(Postscript)343.875 118.6 Q(dc)412.88 94.6 Q(bc)
arrow from D.w + (0.4, 0.8) to D.e + (-0.4, 0.8) 412.88 106.6 Q(Emacs Lisp)462.53 94.6 Q(Ja)465.395 106.6 Q -.25(va)-.2 G
"flat to structured" "" at last arrow.c (Script).25 E(sh)529.075 94.6 Q(tcl)528.52 106.6 Q(Perl)565.065 88.6 Q
... (Python)558.95 100.6 Q(Ja)564.46 112.6 Q -.25(va)-.2 G 0 Cg EP
# Interpreters %%Trailer
"Emacs Lisp" "JavaScript" at 0.25 between M.e and I.e end
"sh" "tcl" at 0.55 between M.e and I.e %%EOF
"Perl" "Python" "Java" at 0.8 between M.e and I.e
Input DSL: pic for above picture Output "DSL": Postscript for above picture DSLs 2010 - 8
9. ...Origins: Minilanguages...
import builder.PowerPointBuilder
def name = 'minilanguages'
assert new File("${name}.pic').exists()
"groff -e -p ${name}.pic > ${name}.ps".execute()
"gs -q -sDEVICE='ppmraw' -g2600x3500 -r300x300 -sOutputFile='-' -dBATCH ↵
–dNOPAUSE ${name}.ps | pnmcrop | ppmtogif > ${name}.gif".execute()
def builder = new PowerPointBuilder() // Adapted from Erik Pragt
builder.slideshow(filename: 'DSLsInGroovy_MiniLanguages.ppt') {
slide(title: 'Origins: Minilanguages...') {
image(
origin: [0, 15],
src: "${name}.gif",
caption: 'Source: The Art of Unix Programming:Taxonomy...' )
textbox(
origin: [5, 100],
text: new File("${name}.pic").text,
caption: 'Input DSL: pic for above picture' )
textbox(
origin: [115, 100],
text: new File("${name}.ps").text,
caption: 'Output "DSL": Postscript for above picture' )
}
}
PowerPoint DSL for previous slide DSLs 2010 - 9
10. ...Origins: Minilanguages
Glade XSLT
<?xml version="1.0"?> <?xml version="1.0"?>
<GTK-Interface> <xsl:stylesheetversion="1.0"
<widget> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<class>GtkWindow</class> <xsl:output method="xml"/>
<name>HelloWindow</name> <xsl:template match="*">
<border_width>5</border_width> <xsl:element name="{name()}">
<Signal> <xsl:for-each select="@*">
<name>destroy</name> <xsl:element name="{name()}">
<handler>gtk_main_quit</handler> <xsl:value-of select="."/>
</Signal> </xsl:element>
<title>Hello</title> </xsl:for-each>
<type>GTK_WINDOW_TOPLEVEL</type> <xsl:apply-templates select="*|text()"/>
<position>GTK_WIN_POS_NONE</position> </xsl:element>
<allow_shrink>True</allow_shrink> </xsl:template>
<allow_grow>True</allow_grow> </xsl:stylesheet>
<auto_shrink>False</auto_shrink> Regex
<widget>
<class>GtkButton</class> "x.z?z{1,3}y"
<name>Hello World</name>
<can_focus>True</can_focus> fetchmail
<label>Hello World</label>
</widget> # Poll this site first each cycle.
poll pop.provider.net proto pop3
</widget>
</GTK-Interface> user "jsmith" with pass "secret1" is "smith" here
user jones with pass "secret2" is "jjones" here with options keep
SQL # Poll this site second, unless Lord Voldemort zaps us first.
poll billywig.hogwarts.com with proto imap:
SELECT * FROM TABLE user harry_potter with pass "floo" is harry_potter here
WHERE NAME LIKE '%SMI' # Poll this site third in the cycle.
ORDER BY NAME # Password will be fetched from ~/.netrc
poll mailhost.net with proto imap:
user esr is esr here
Troff
cat thesis.ms | chem | tbl | refer | grap | pic | eqn | groff -Tps > thesis.ps
Source: Applying minilanguages: http://www.faqs.org/docs/artu/ch08s02.html DSLs 2010 - 10
11. And now? The twitterverse says...
DSLs 2010 - 11
14. "Is it a DSL or an API?" Checklist
• A ten-question test to help determine whether
a wad of code represents a DSL or an API:
1. Have you ever programmed in a language other than Ruby?
(PHP and HTML don‟t count.) If not, it‟s a DSL.
2. Is the defining syntactic feature that you’ve cleverly left the
parentheses off of a list of function arguments?
If so, it‟s a DSL.
3. Is the code primarily a list of key-value pairs?
Welcome to DSL Town, population you!
4. Does the code require the liberal use of eval() or equivalent?
DSL, yay!
5. Have you ever used the phrase “… and it reads just like
English!” in seriousness? You‟d better get to the hospital;
you‟re coming down with a case of the DSLs!
6. ...
Source: http://www.oreillynet.com/onlamp/blog/2007/05/the_is_it_a_dsl_or_an_api_ten.html DSLs 2010 - 14
93. ...GParsec
• satisfyC: combinator consumes a single input when its
predicate succeeds
• altC (alt3C, altCs): is the choice combinator. Given two
parsers it only looks at its second alternative if the first has
not consumed any input - regardless of the final value
• seqC (seq3C, seqCs): is the sequencing combinator. It runs
two parsers in succession and if successful, returns the result
of the two parsers
• noneOrMoreC, oneOrMoreC: applies a parser zero or more
times to an input stream. The result from each application of
the parser are returned in a list
• optionalC: The combinator optionalC may succeed in
parsing some input. It always returns success.
DSLs 2010 - 93