Crates.io | lp-pack-scanner |
lib.rs | lp-pack-scanner |
version | 0.4.0 |
source | src |
created_at | 2024-05-12 09:19:58.731566 |
updated_at | 2024-05-16 05:27:35.533391 |
description | scanner library |
homepage | |
repository | |
max_upload_size | |
id | 1237320 |
size | 19,892 |
Language Pack - Scanner, is scanning/lexing Rust library, useful for interpreter/compiler applications. Library is intended to be highly customizable and easy to learn, it recognizes every character aviable on the keyboard and keywords you can configure, and returns an array of tokens, you can use for building AST.
Run the following Cargo command in your project directory:
cargo add lp-pack-scanner
Or add the following line to your Cargo.toml:
lp-pack-scanner = "0.4.0"
use std::collections::HashMap;
use lp_pack_scanner::{Config, Scanner, Token};
fn main() {
let tokens = Scanner::scan(Config {
input: "let x = 5".to_string(),
keywords: HashMap::from([("let", lp_pack_scanner::Token::Variable)]),
allow_unknown: Some(true),
errors: None,
comments: None,
benchmark: false,
});
println!("{:?}", tokens);
}
/*
[OutputToken { token: Variable, literal: None, lexeme: "let", line: 1 }, OutputToken { token: Identifier, literal: None, lexeme: "x", line: 1 }, OutputToken { token: Equal, literal: None, lexeme: "=", line: 1 }, OutputToken { token: Number, literal: Number(5.0), lexeme: "5", line: 1 }, OutputToken { token: EndOfFile, literal: None, lexeme: "", line: 1 }]
*/
soon