1 stable release

1.0.0 Jun 6, 2024


Used in 3 crates (via wagon-parser)

Apache-2.0

67KB
1K SLoC

WAGon Lexer

Lexer for the WAGon DSL.


lib.rs:

WAGon Lexers

Provides lexers for the WAGon DSL, as well as helper iterators which can switch between lexers on the fly. Most likely, all you will care about are LexerBridge and Tokens.

Example

let s = r#"
meta: "data";
============
S -> A;
"#;
use wagon_lexer::{Tokens, LexerBridge, LexResult};
use wagon_ident::Ident;

let lexer = LexerBridge::new(s);
let tokens: Vec<LexResult> = lexer.collect();
assert_eq!(tokens, vec![
Ok(Tokens::MetadataToken(Metadata::Identifier("meta".into()))), 
Ok(Tokens::MetadataToken(Metadata::Colon)),
Ok(Tokens::MathToken(Math::LitString("data".to_string()))),
Ok(Tokens::MathToken(Math::Semi)),
Ok(Tokens::MetadataToken(Metadata::Delim)),
Ok(Tokens::ProductionToken(Productions::Identifier(Ident::Unknown("S".to_string())))),
Ok(Tokens::ProductionToken(Productions::Produce)),
Ok(Tokens::ProductionToken(Productions::Identifier(Ident::Unknown("A".to_string())))),
Ok(Tokens::ProductionToken(Productions::Semi))
])

Dependencies

~4.5MB
~82K SLoC