pub fn parse_spec(input: &str) -> Result<LexerSpec, Box<dyn Error>>Expand description
Parses a lexer specification file.
The input should be in the format:
(Rust code)
%%
(Lexer rules)
%%
(Rust code)Rules should be in the format: pattern -> TOKEN_NAME or just pattern.
§Arguments
input- The lexer specification file content
§Returns
A Result containing the parsed LexerSpec or an error.
§Examples
use klex::parse_spec;
let input = r#"
use std::collections::HashMap;
%%
[0-9]+ -> NUMBER
[a-zA-Z_][a-zA-Z0-9_]* -> IDENTIFIER
%%
// Generated code will be here
"#;
let spec = parse_spec(input).unwrap();
assert_eq!(spec.rules.len(), 2);