Ungrammar implementation and API in Go. Blog post for background.
Ungrammar is a DSL for concrete syntax trees (CST). This implementation is based on the original ungrammar crate, also borrowing some test files from it.
The syntax of Ungrammar files is very simple:
// -- comment
Name = -- non-terminal definition
'ident' -- token (terminal)
A B -- sequence
A | B -- alternation
A* -- repetition (zero or more)
A? -- optional (zero or one)
(A B) -- grouping elements for precedence control
label:A -- label hint for naming
For some concrete examples, look at files in the testdata
directory.
Usage example:
Lines 13 to 31 in 229d0dd
For somewhat more sophisticated usage, see the cmd/ungrammar2json
command.