Crates.io | jayce |
lib.rs | jayce |
version | 12.1.0 |
source | src |
created_at | 2022-03-26 16:47:16.613617 |
updated_at | 2024-03-12 10:13:45.418805 |
description | jayce is a tokenizer 🌌 |
homepage | |
repository | https://github.com/AuracleTech/jayce |
max_upload_size | |
id | 556807 |
size | 157,442 |
jayce is a tokenizer 🌌
use jayce::{Duo, Tokenizer};
use std::sync::OnceLock;
const SOURCE: &str = "Excalibur = 5000$; // Your own language!";
fn duos() -> &'static Vec<Duo<&'static str>> {
static DUOS: OnceLock<Vec<Duo<&'static str>>> = OnceLock::new();
DUOS.get_or_init(|| {
vec![
Duo::new("whitespace", r"^[^\S\n]+", false),
Duo::new("commentLine", r"^//(.*)", false),
Duo::new("commentBlock", r"^/\*(.|\n)*?\*/", false),
Duo::new("newline", r"^\n", false),
Duo::new("price", r"^[0-9]+\$", true),
Duo::new("semicolon", r"^;", true),
Duo::new("operator", r"^=", true),
Duo::new("name", r"^[a-zA-Z_]+", true),
]
})
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut tokenizer = Tokenizer::new(SOURCE, duos());
while let Some(token) = tokenizer.consume()? {
println!("{:?}", token);
}
Ok(())
}
Token { kind: "name", value: "Excalibur", pos: (1, 1) }
Token { kind: "operator", value: "=", pos: (1, 11) }
Token { kind: "price", value: "5000$", pos: (1, 13) }
Token { kind: "semicolon", value: ";", pos: (1, 18) }
Tokenizer::consume
returns Result Option Token
Ok Some
match foundOk None
end of sourceErr
an error occursTokenizer::consume_all
returns Result Vec Token
Ok Vec Token
tokens matchedErr
an error occursinitialization in ~3 nanoseconds
tokenization of Yuumi in ~4 milliseconds
generic-simd
runtime-dispatch-simd
default enabled, to disable modify Cargo.toml
as followsjayce = { version = "X.X.X", default-features = false }