rusty_lr
GLR, LR(1) and LALR(1) parser generator for Rust.
Cargo Features
build
: Enable buildscript tools.fxhash
: In parser table, replacestd::collections::HashMap
withFxHashMap
fromrustc-hash
.tree
: Enable automatic syntax tree construction. This feature should be used on debug purpose only, since it will consume much more memory and time.
Features
- GLR, LR(1) and LALR(1) parser generator
- Provides procedural macros and buildscript tools
- readable error messages, for resolving conflicts in the grammar
- pretty-printed syntax tree
- compile-time DFA construction
- customizable reduce action
- resolving conflicts of ambiguous grammar
- regex patterns partially supported
Example
// this define `EParser` struct
// where `E` is the start symbol
lr1!
let parser = new; // generate `EParser`
let mut context = new; // create context
let mut userdata: i32 = 0; // define userdata
let input_sequence = "1 + 2 * ( 3 + 4 )";
// start feeding tokens
for token in input_sequence.chars
context.feed.unwrap; // feed `eof` token
let res = context.accept; // get the value of start symbol
println!;
println!;
Readable error messages (with codespan)
- This error message is generated by the buildscript tool, not the procedural macros.
Visualized syntax tree
- With
tree
feature enabled.
Syntax
See SYNTAX.md for details of grammar-definition syntax.
- Bootstrap is written in
rusty_lr
itself.
Executable
An executable version of buildscript tool is available rustylr.
cargo install rustylr
$ rustylr --help
Contribution
- Any contribution is welcome.
- Please feel free to open an issue or pull request.
License (Since 2.8.0)
Either of
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)