justlex 0.1.0

Configurable lexer with no dependencies
Documentation
  • Coverage
  • 19.35%
    12 out of 62 items documented1 out of 1 items with examples
  • Size
  • Source code size: 19.1 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 433.5 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 7s Average build duration of successful builds.
  • all releases: 7s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • San7o/justlex-rs
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • San7o

justlex-rs

Configurable lexer with no dependencies in Rust.

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.

Example

// 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;
    }
}

Will output:

Received token Punct(Hash)
Received token Symbol("include")
Received token Punct(Less)
Received token Symbol("stdio")
Received token Punct(Dot)
Received token Symbol("h")
Received token Punct(Greater)
...

Usage

Run an example:

cargo run --example basic_usage

Run the tests:

cargo test

Run lint:

cargo clippy