lexer-generator

Crates.iolexer-generator
lib.rslexer-generator
version0.1.4
sourcesrc
created_at2022-03-28 17:19:26.217839
updated_at2022-03-31 15:21:22.943645
descriptionLexer derived from Regex patterns with user customizeable tokens
homepage
repositoryhttps://github.com/lackingInGrav1tas/lexer-generator
max_upload_size
id558018
size15,932
(LackingInGrav1tas)

documentation

https://docs.rs/lexer-generator

README

lexer-generator

Lexer crate derived from Regex patterns with user customizeable tokens

Example: Basic Tokenizing

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)
Commit count: 17

cargo fmt