Sometimes the same literals are recognized in a number of different places. The most common example is the literals for fully expanded programs, which are used in many analysis and transformation tools. Specifying literals individually is burdensome and error-prone. As a remedy, syntax/parse offers literal sets. A literal set is defined via define-literal-set and used via the #:literal-set option of syntax-parse.
(define-literal-set id maybe-phase maybe-imports (literal ...))
literal = literal-id | (pattern-id literal-id) maybe-phase =
| #:for-template | #:for-syntax | #:for-label | #:phase phase-level maybe-imports =
| #:literal-sets (imported-litset-id ...)
The literals in a literal set always refer to the bindings at phase phase-level relative to the enclosing module. If the #:for-template option is given, phase-level is -1; #:for-syntax means 1, and #:for-label means #f. If no phase keyword option is given, then phase-level is 0.
In the literal set common-lits, the literal x always recognizes identifiers bound to the variable x defined in module 'common.
The following module defines an equivalent literal set, but imports the 'common module for-template instead:
When a literal set is used with the #:phase phase-expr option, the literals’ fixed bindings are compared against the binding of the input literal at the specified phase. Continuing the example:
The occurrence of x in the pattern matches any identifier whose binding at phase 1 is the x from module 'common.
(define-conventions name-id convention-rule ...)
convention-rule = (name-pattern syntax-class) name-pattern = exact-id | name-rx syntax-class = syntax-class-id | (syntax-class-id expr ...)
Local conventions, introduced with the #:local-conventions keyword argument of syntax-parse and syntax class definitions, may refer to local bindings: