Trait lemon_tree::LemonTree[][src]

pub trait LemonTree {
    type Parser;
    type Token;
}

Parser "start symbol" can be represented as a struct or enum. You need to annotate it with #[derive(LemonTree)], and implementation of this trait will be generated.

The implementation contains 2 associated types:

  • Parser - the parser, that will accept tokens, and finally return the start symbol.
  • Token - enum with token names. All the terminal symbols (tokens) that appear in your grammar (in #[lem()] and #[lem_fn()] attributes) will become variants in this enum.

If you annotate a struct like this:

#[derive(LemonTree)]
struct Unit
{
}

And you have terminal symbols HELLO and WORLD, then you can:

let mut parser = Unit::get_parser(()); // where () is initializer for %extra_argument
// the type of parser is <Unit as LemonTree>::Parser
parser.add_token(<Unit as LemonTree>::Token::HELLO, ()).unwrap();
parser.add_token(<Unit as LemonTree>::Token::WORLD, ()).unwrap();
let resulting_unit = parser.end().unwrap(); // returns Unit

Associated Types

Loading content...

Implementors

Loading content...