2.1Specifying languagesπ i
This section describes the syntax of the syntax-spec metalanguage,
used to describe the grammar, binding structure, and host interface of a DSL.
Language specifications are made via the subforms of syntax-spec ,
which must be used at module-level.
spec-def = binding-class
| extension-class
| nonterminal
| host-interface
The following subsections address each kind of declaration allowed within the
syntax-spec form.
2.1.1Binding classesπ i
Binding classes distinguish types of binding. When a reference resolves to a
binder, it is an error if the binding class declared for the reference position
does not match the binding class of the binding position.
( binding-classidmaybe-descriptionmaybe-binding-space)
maybe-description = #:descriptionstring-literal
|
maybe-binding-space = #:binding-spacespace-symbol
|
The #:description option provides a user-friendly phrase describing the
kind of binding. This description is used in error messages.
The #:binding-space option specifies a binding space
to use for all bindings and references declared with this class.
Operationally, the binding space declaration causes the syntax-spec expander to
add the binding space scope to bindings and references.
The scope is added to the scope sets of all binding occurrences.
When parsing a reference position declared with a binding
class that has an associated binding space, the name that is looked up is
augmented with the binding class scope in order to give it access to bindings
defined in the space.
2.1.2Extension classesπ i
( extension-classidmaybe-descriptionmaybe-binding-space)
maybe-description = #:descriptionstring-literal
|
maybe-binding-space = #:binding-spacespace-symbol
|
2.1.3Nonterminalsπ i
( nonterminalidnonterminal-optionsproduction...)
( nonterminal/nestingid(nested-id)nonterminal-optionsproduction...)
( nonterminal/two-passidnonterminal-optionsproduction...)
2.1.3.1Nonterminal optionsπ i
nonterminal-options =
maybe-description
maybe-allow-extension
maybe-binding-space
maybe-description = #:descriptionstring-literal
|
maybe-allow-extension = #:allow-extensionextension-class-spec
|
extension-class-spec = extension-class-id
| (extension-class-id...)
maybe-binding-space = #:binding-spacespace-symbol
|
2.1.3.2Productionsπ i
production = rewrite-production
| form-production
| syntax-production
rewrite-production =
(~>syntax-pattern
pattern-directive...
body...+)
form-production = (form-id. syntax-spec)maybe-binding-spec
| form-id
syntax-production = syntax-specmaybe-binding-spec
maybe-binding-spec = #:bindingbinding-spec
|
2.1.4Syntax specsπ i
syntax-spec = ()
| keyword
| ...
| ...+
| (~literalidmaybe-space)
| (~datumid)
| (syntax-spec. syntax-spec)
| spec-variable-id:binding-class-id
| spec-variable-id:nonterminal-id
| spec-variable-id:extension-class-id
maybe-space = #:spacespace-name
|
2.1.5Binding specsπ i
binding-spec = spec-variable-id
| (bindspec-variable-id...+)
| {spec...}
| [spec...]
| (nestspec-variable-idbinding-spec)
| (nest-onespec-variable-idbinding-spec)
| (recursivespec-variable-id...+)
|
(export spec-variable-id...+) | (re-exportspec-variable-id...+)
2.1.6Defining host interface formsπ i
( host-interface/expression (id. syntax-spec)
maybe-binding-spec
pattern-directive...
body...+)
( host-interface/definition (id. syntax-spec)
maybe-binding-spec
#:lhs
[pattern-directive...
body...+]
#:rhs
[pattern-directive...
body...+])
( host-interface/definitions (id. syntax-spec)
maybe-binding-spec
pattern-directive...
body...+)
2.1.7Embedding Racket syntaxπ i