Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alexknauth/syntax-class-or
Combining syntax classes together as multiple variants
https://github.com/alexknauth/syntax-class-or
Last synced: about 1 month ago
JSON representation
Combining syntax classes together as multiple variants
- Host: GitHub
- URL: https://github.com/alexknauth/syntax-class-or
- Owner: AlexKnauth
- License: mit
- Created: 2018-08-01T01:43:37.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2020-07-06T14:51:23.000Z (over 4 years ago)
- Last Synced: 2024-10-16T02:55:20.095Z (3 months ago)
- Language: Racket
- Size: 4.88 KB
- Stars: 1
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# syntax-class-or
Combining a list of variants into one syntax class.
Documentation: https://docs.racket-lang.org/syntax-class-or/index.html
```racket
(require syntax/parse/syntax-class-or)
``````racket
(define-syntax-class/or* head
#:attributes [attr-arity-decl ...]
reified-classes-expr)head = name-id
| (name-id parameters)
parameters = parameter ...
| parameter ... . rest-id
parameter = param-id
| [param-id default-expr]
| #:keyword param-id
| #:keyword [param-id default-expr]
```Normally, there needs to be one syntax-class containing
all the variants, in one centralized place. Even when you
divide the the work into helper syntax classes, you're
limited to the variants that were already written that
the parsing can depend on. The number of variants is
limited by the syntax at compile time.The syntax-parse reflection interface (`~reflect`) allows
you to fill in a syntax class at runtime, which lets you
leave a variant to be filled in from somewhere else.
However, the `~reflect` pattern only allows one syntax
class, and that syntax class must include all the
non-built-in variants, still limiting it to what some
centralized parser can depend on. And still the number of
new variants is limited to fixed number at compile time.The `define-syntax-class/or*` form allows you to define
a syntax class that combines a list of arbitrarily many
variants into one parser. The list of variants can be
computed at run time (relative to the parser) or can be
passed in as arguments.