rusty_lr
GLR, LR(1) and LALR(1) parser generator for Rust.
Please refer to docs.rs for detailed example and documentation.
Features
- GLR, LR(1) and LALR(1) parser generator
- Can handle every possible paths with GLR parser
- Procedural macros and buildscript tools
- Customizable reduce action
- Readable error messages, both for parsing and building grammar
Examples
Projects
- Simple Calculator
- lua 5.4 syntax parser
- Bootstrap: rusty_lr syntax parser is written in rusty_lr itself.
Quick Example
// this define `EParser` struct
// where `E` is the start symbol
lr1!
let parser = new; // generate `EParser`, this holds the parser table
let mut context = new; // create context, this holds current state of parser
let mut userdata: i32 = 0; // define userdata
let input_sequence = "1 + 2 * 3 + 4"; // input sequence
// 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 `E(f32)`
println!;
println!;
Readable error messages (with codespan)
-Reduce/Reduce conflicts

- Shift/Reduce conflicts

Visualized syntax tree
With tree feature enabled.
detailed ParseError message
With error feature enabled.
Cargo Features
build: Enable buildscript tools.fxhash: In parser table, replacestd::collections::HashMapwithFxHashMapfromrustc-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.error: Enable detailed parsing error messages, forDisplayandDebugtrait. This feature should be used on debug purpose only, since it will consume much more memory and time.
Syntax
See SYNTAX.md for details of grammar-definition syntax.
- Bootstrap: rusty_lr syntax is written in rusty_lr itself.
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)