Crates.io | lexer-generator |
lib.rs | lexer-generator |
version | 0.1.4 |
source | src |
created_at | 2022-03-28 17:19:26.217839 |
updated_at | 2022-03-31 15:21:22.943645 |
description | Lexer derived from Regex patterns with user customizeable tokens |
homepage | |
repository | https://github.com/lackingInGrav1tas/lexer-generator |
max_upload_size | |
id | 558018 |
size | 15,932 |
Lexer crate derived from Regex patterns with user customizeable tokens
Potential code one might use to lex tokens for a calculator
key.json
:
{
"literals": {
"number": "[0-9]*(\\.[0-9]*){0, 1}",
"subtract": "-",
"add": "\\+",
"divide": "/",
"multiply": "\\*"
},
"whitespace": "\n| |\r|\t"
}
main.rs
:
let json: String = std::fs::read_to_string("key.json").unwrap();
let source: String = String::from("123 + 456 * 789");
let mut lexer = Lexer::from(json, source);
while !lexer.done() {
println!("{}", lexer.next_token().unwrap());
}
number(123)
add(+)
number(456)
multiply(*)
number(789)