8.16.0.1
2.1 Specifying languages🔗ℹ
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.
(syntax-spec spec-def ...)
|
|
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.1 Binding classes🔗ℹ
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-class id maybe-description maybe-binding-space)
|
|
maybe-description | | = | | #:description string-literal | | | | | | | | | | | | maybe-binding-space | | = | | #:binding-space space-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.2 Extension classes🔗ℹ
(extension-class id maybe-description maybe-binding-space)
|
|
maybe-description | | = | | #:description string-literal | | | | | | | | | | | | maybe-binding-space | | = | | #:binding-space space-symbol | | | | | | |
|
2.1.3 Nonterminals🔗ℹ
(nonterminal id nonterminal-options production ...)
|
(nonterminal/nesting id (nested-id) nonterminal-options production ...)
|
(nonterminal/two-pass id nonterminal-options production ...)
|
2.1.3.1 Nonterminal options🔗ℹ
nonterminal-options | | = | | maybe-description | maybe-allow-extension | maybe-binding-space |
|
| | | | |
maybe-description | | = | | #:description string-literal |
| | | | | |
| | | | |
maybe-allow-extension | | = | | #:allow-extension extension-class-spec |
| | | | | |
| | | | |
extension-class-spec | | = | | extension-class-id |
| | | | | (extension-class-id ...) |
| | | | |
maybe-binding-space | | = | | #:binding-space space-symbol |
| | | | | |
2.1.3.2 Productions🔗ℹ
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-spec maybe-binding-spec |
| | | | |
maybe-binding-spec | | = | | #:binding binding-spec |
| | | | | |
2.1.4 Syntax specs🔗ℹ
syntax-spec | | = | | () |
| | | | | keyword |
| | | | | ... |
| | | | | ...+ |
| | | | | (~literal id maybe-space) |
| | | | | (~datum id) |
| | | | | (syntax-spec . syntax-spec) |
| | | | | spec-variable-id:binding-class-id |
| | | | | spec-variable-id:nonterminal-id |
| | | | | spec-variable-id:extension-class-id |
| | | | |
maybe-space | | = | | #:space space-name |
| | | | | |
2.1.5 Binding specs🔗ℹ
binding-spec | | = | | spec-variable-id |
| | | | | (bind spec-variable-id ...+) |
| | | | | {spec ...} |
| | | | | [spec ...] |
| | | | | (nest spec-variable-id binding-spec) |
| | | | | (nest-one spec-variable-id binding-spec) |
| | | | | (recursive spec-variable-id ...+) |
| | | | | (export spec-variable-id ...+) |
| | | | | (re-export spec-variable-id ...+) |
2.1.6 Defining host interface forms🔗ℹ
(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.7 Embedding Racket syntax🔗ℹ