A port of the Lemon Parser Generator to Rust.
This project is being deprecated in favor of pomelo, a reimplementation of this very same code as a Rust procedural macro. You should use that for any new code, and also consider porting your existing code.
From the original Lemon documentation:
Lemon is an LALR(1) parser generator for C or C++. It does the same job as "bison" and "yacc". But lemon is not another bison or yacc clone. It uses a different grammar syntax which is designed to reduce the number of coding errors. Lemon also uses a more sophisticated parsing engine that is faster than yacc and bison and which is both reentrant and thread-safe.
Change C or C++ to Rust and you will get also the well known benefits of this language.
My thanks and acknowledgement to D. Richard Hipp, the original creator of Lemon.
Lemon_Rust works basically the same as Lemon_C. The main difference is, obviously, that it generates Rust code instead of C code. However there are a few other differences, due to the differences in the generated languages.
In the grammar file there are basically the following differences:
- There is no
%name
or%token_prefix
directives. In C all the symbol names are global so this directive allows you to change the name of the generated symbols. In Rust, the generated file will be compiled as a crate and it will have its own namespace. So changing the names of the generated symbols is not needed. - There are no destructors (
%destructor
,%token_destructor
and%default_destructor
). If you need to write destructors, just implement theDrop
trait for the associated type. - There is no
%token_type
directive. In Lemon_C, all tokens must have the same type, while non-terminal symbols may have different types. In Lemon_Rust there is no such distinctions, so you can specify the type for each individual token with%type
. - There is a new
%derive_token
directive. It is used to add the#[derive()]
directive to the generatedToken
type.
In the invocation of the program:
- There is no
-m
option. That was for writing amakeheaders
file, but Rust does not need that. - The default template file is not
lempar.c
butlempar.rs
.
See the DOCUMENTATION.md
file included in the source tree.