LR/GLR parser generator for Rust (currently only LR).
Status: In early phase. Fairly complete feature set for the initial release. Not yet optimized for speed so don't expect blazing performance.
Feedback is welcome!
Be sure to check the docs!
Both LR and GLR parsing from the same grammar
E.g. start with GLR for easier development and refactor to LR for performance, or start from LR and move to GLR if your language needs more than 1 token of lookahead or is inherently ambiguous.
Usability and error reporting
Rustemo should be easy to use with sane defaults. Each error should be caught and explained with sufficient details. The docs should always be up-to-date and all docs examples should be tested by CI.
Clean separation of CFG grammar and semantic actions written in Rust
So a regular editors can be used for editing Rust code to its full potential. At the same time the syntax of the language is kept clean and existing grammars can be easily ported to Rustemo.
Syntax sugar for common patterns
E.g. zero-or-more(*
), one-or-more (+
), optional(?
), groups (()
),
multiple match with a separator etc.
Clean separation between lexer, parser and builder
A parser asks a lexer for next tokens during parsing while telling the lexer what is expected due to the current parsing context. This avoids certain classes of lexical ambiguities. The parser calls builder to produce the result on each parser operation.
Flexibility
Default lexers and builders are provided/generated out-of-the box but the user can choose to write custom lexer and/or builder.
When a custom lexer/builder is provided Rustemo can be used to parse virtually any kind of sequence and also build any kind of output.
Inference of AST node types from the grammar
For the default built-in builder, AST node types and semantics actions should be inferred from the grammar and auto-generated, but the user can introduce manual changes.
Zero-copy by default
Built-in builders should by default produce outputs by borrowing from the input.
High test coverage
There are a reasonable number of tests. I usually write tests before implementing each new feature (TDD). Tests are a good source of info until the docs are improved.
rcomp
compiler CLI is available that can be called on
Rustemo grammars. Also an API enables integrating parser compiling into
Rust build.rs
scripts. See the calculator
example or integration tests.Licensed under either of
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Bootstrapping approach and the idea of macro for loading the generated code are based on the approach taken in the LALRPOP project.
The architecture and the general idea of Rustemo is loosely based on a similar project for Python, called parglare, I've started several years ago.
I have found a lot of inspiration and ideas in the following projects:
Rustemo is pronounced the same as Serbian word "растемо" which means "we grow". The name is a tribute to the awesome and ever growing Rust community.