A proc_macro lexer generator. using enum
-like syntax.
```rust
use enumlexer::enumlexer;
enumlexer! {
#[derive(Debug, Eq, PartialEq)]
enum lexer {
Ident(String): {
r"[A-Za-z][A-Za-z0-9]*" => Ident(text),
}
LitInt(usize): {
r"[0-9][0-9]*" =>
LitInt(text.parse::
This will generate struct and enum like:
```rust mod lexer { #[derive(Debug, Eq, PartialEq)] pub struct Token { pub inner: TokenInner, pub span: Span, }
#[derive(Debug, Eq, PartialEq)]
pub enum TokenInner {
Ident(String),
LitInt(usize),
Op(char),
Def,
Let,
Group(Vec<Token>, char),
}
pub struct TokenIterator{...}
pub type LexError = Box<&dyn Error>;
pub fn parse_str(src: &str) -> Result<TokenIterator>;
} ```
```rust
let vec: lexer::Result
println!("{:?}", vec); ```
rust
enum_lexer! {
type LexError = MyError;
enum lexer {
LitStr: "\".*?\""
}
}
enum_lexer_test
will write generated DFA to a dfa.dot
file.