osa1 / lexgen

A fully-featured lexer generator, implemented as a proc macro
MIT License
63 stars 7 forks source link

Wrong lexing when rules share prefix #31

Closed osa1 closed 2 years ago

osa1 commented 2 years ago
use lexgen::lexer;
use lexgen_util::Loc;

lexer! {
    Lexer -> usize;

    "'" _ "'" = 1,
    "'" ['a'-'z']+ = 2,
}

#[test]
fn char_lit() {
    let input = "'a'";
    let mut lexer = Lexer::new(input);
    // Fails:
    assert_eq!(lexer.next(), Some(Ok((Loc { line: 0, col: 0, byte_idx: 0 }, 1, Loc { line: 0, col: 3, byte_idx: 3 }))));
    assert_eq!(lexer.next(), None);
}