Lexi-Matic
A proc-macro for lexers similar to logos. Uses regex-automata DFA under the hood.
# use Lexer;
// An iterator of Result<(usize, Token, usize), lexi_matic::Error>.
let tokens = lex;
for t in tokens
Token Disambiguation
There are only two simple rules:
- Longer matches always win.
- If multiple patterns are matched for the longest match, the first pattern wins.
So if you have keywords and identifiers, specify the keywords first:
# use Lexer;
So import would be Import but import1 would be Ident.
Custom Lexing
Sometimes the lexing grammar isn't regular or even context-free. You can use a callback for these:
# use Lexer;
// A `more` function should return how many more bytes to include in this token.
// We are trying to finish a raw string literal, so we search for the matching
// `"###`.
//
// If a `more` function returns `None`, it is considered a lexical error.