Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
GLL parsing framework
Usage
Easiest way to get started is through gll-macros
:
[]
= "0.0.1"
= "0.0.1"
extern crate gll;
extern crate 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:
let tokens = string.parse.unwrap;
parse_with;
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:
- grouping, using
{...}
- string literals, matching input characters / tokens exactly
- character ranges:
'a'..='d'
is equivalent to"a"|"b"|"c"|"d"
- only in scannerless mode
- builtin rules:
IDENT
,PUNCT
,LITERAL
,TOKEN_TREE
- only in proc macro mode
- named rules, referred to by their name
- concatenation:
A B
- "A
followed byB
" - alternation:
A | B
- "eitherA
orB
" - optionals:
A?
- "eitherA
or nothing" - lists:
A*
- "zero or moreA
s",A+
- "one or moreA
s"- optional separator:
A* % ","
- "comma-separatedA
s"
- optional separator:
Parts of a rule can be labeled with field names, to allow later access to them:
LetDecl = "let" pat:Pat { "=" init:Expr }? ";";
produces:
// Note: generic parameters omitted for brevity.
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
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
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.