-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesc.scrbl
65 lines (56 loc) · 2.18 KB
/
esc.scrbl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#lang scribble/manual
@(require planet/scribble scribble/bnf (for-label racket))
@title{@exec{esc}: Extensible Syntax Compiler}
@author{@(author+email "Erik Silkensen" "[email protected]")}
@defmodule/this-package[main]
This is a project for an extensible parsing system that aims to provide a
user-friendly method for designing @emph{composable} DSLs.
Languages are defined in modules by CFGs written in standard BNF notation.
DSLs can be built on top of the Racket programming language by writing
@emph{type-oriented} grammar rules as function or macro signatures followed
by Racket code for their implementation.
For example, the rule
@verbatim[#:indent 4]{Integer ::= "|" s:Set "|" = (set-count s);}
defines syntax for set cardinality, which is implemented by Racket's
@racket[set-count] function.
@section{Installation}
To try out the tool, first download and install Racket from
@link["http://racket-lang.org/download"]{http://racket-lang.org}.
Then start the Racket interpreter, and enter
@racket[(require (planet esilkensen/esc))].
This installs an @tt{esc} command to the @tt{raco} program.
At the command line,
@verbatim[#:indent 4]{raco esc [<source-file>] ...}
will compile a sequence of extensible syntax files into Typed Racket code.
@section{Examples}
Included in the
@link["http://planet.racket-lang.org/package-source/esilkensen/esc.plt/1/1/examples"]{examples}
directory is a module for giving ML-like syntax to several Typed Racket forms
(@link["http://planet.racket-lang.org/package-source/esilkensen/esc.plt/1/1/examples/ML.es"]{ML.es}),
and another for basic set operations such as the one above
(@link["http://planet.racket-lang.org/package-source/esilkensen/esc.plt/1/1/examples/Sets.es"]{Sets.es}).
@filebox["abc.es"]{
@verbatim|{
import ML, Sets;
let A = {1, 2, 3} {
let B = {2, 3, 4} {
let C = {3, 4, 5} {
print |A & C|;
print A | B & C
}
}
}
}|
}
The above program
(@link["http://planet.racket-lang.org/package-source/esilkensen/esc.plt/1/1/examples/abc.es"]{abc.es})
can be compiled and run with the following commands:
@verbatim[#:indent 4]|{
raco esc abc.es
racket -I typed/racket abc.rkt
}|
The output of the program is
@verbatim[#:indent 4]|{
1
#<set: 1 2 3 4>
}|