Expand description
§justlex.rs
Configurable lexer with no dependencies.
The entire implementation lives in a single .rs file. This means
that you can copy-paste it in your project and modify it as you
like, keeping your dependency tree clean. You can easily add
custom Punctuation or Keywords by modifying the file
directly.
Check out the examples in the examples directory.
§Quickstart
use justlex::*;
// Some input string
let example_input = String::from(
"#include <stdio.h>
if (a == 17*2 + 35) { // single line comment
/* multi
* line
* comment
*/
return b;
}\n");
// Setup the lexer
let mut lexer = JustLex::default();
lexer.set_input(example_input);
// Iterate over the tokens
for token in lexer {
let token = token;
println!("Received token {:?}", token);
if token == Token::None {
break;
}
}§Credits
- Author: Giovanni Santini
- Mail: giovanni.santini@proton.me
- Github: @San7o
- License: MIT
Structs§
- JustLex
- You can set the keywords, punctuation and input to the lexer via
the functions
newandset_input. Then, you can keep callingnext_tokenornextto receive all the tokens.
Enums§
Functions§
- alphanumeric_
len - Returns the number of alphanumeric characters that occur from the
start of
input - is_
alpha - Returns true if
cis a letter of the alphabet (ASCII) - is_
alphanumeric - Returns true if
cis a letter or a digit - is_
numeric - Returns true if
cis a digit (0 to 9) - is_
space - Returns true if
cis considered a white-space character - numeric_
len - Returns the number of numeric characters that occur from the start
of
input