justlex 0.1.0

Configurable lexer with no dependencies
Documentation
// SPDX-License-Identifier: MIT
// Author:  Giovanni Santini
// Mail:    giovanni.santini@proton.me
// Github:  @San7o
//
// basic usage
// ===========
//
// This example shows how to setup a defaultl exer to parse C code
// and print the tokens to the standard output.
//

use justlex::*;

use std::error::Error;

fn main() -> Result<(), Box<dyn Error>> {
    // 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;
        }
    }

    Ok(())
}

// 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)
// ...