As an example, this is what you might write for a JSON-like syntax,
that uses plain identifiers instead of string literals for field names,
and allows values to be parenthesized Rust expressions:
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in this crate by you, as defined in the Apache-2.0 license, shall
be dual licensed as above, without any additional terms or conditions.
GLL parsing framework
Usage
Easiest way to get started is through
gll-macros:As an example, this is what you might write for a JSON-like syntax, that uses plain identifiers instead of string literals for field names, and allows values to be parenthesized Rust expressions:
You can also use a build script to generate the parser (TODO: document).
To parse a string with that grammar:
Grammar
All grammars contain a set of named rules, with the syntax
Name = rule;. (the order between the rules doesn’t matter)Rules are made out of:
{...}'a'..='d'is equivalent to"a"|"b"|"c"|"d"IDENT,PUNCT,LITERAL,TOKEN_TREEA B- “Afollowed byB“A | B- “eitherAorB“A?- “eitherAor nothing”A*- “zero or moreAs”,A+- “one or moreAs”A* % ","- “comma-separatedAs”A* %% ","- “comma-separatedAs”, with an optional trailing commaParts of a rule can be labeled with field names, to allow later access to them:
LetDecl = "let" pat:Pat { "=" init:Expr }? ";";produces:One Rust-specific convention is that alternation fields are enum variants.
Expr = Lit:LITERAL | Add:{ a:Expr "+" b:Expr };produces:License
Licensed under either of
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.