Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Another example of regex stumping on tokens #383

Open
porkbrain opened this issue Mar 11, 2024 · 0 comments
Open

Another example of regex stumping on tokens #383

porkbrain opened this issue Mar 11, 2024 · 0 comments

Comments

@porkbrain
Copy link

porkbrain commented Mar 11, 2024

This is a dupe of #377, but I thought to post it nonetheless as an extra test case for #265.

    use logos::Logos;

    #[derive(Logos, Debug, PartialEq, Eq)]
    #[logos(skip r"[ \t\f]+")]
    enum FooToken {
        #[token("fast", priority = 999999)]
        SomeToken,
        #[regex(r#"[a-z0-9_/]+ = "#)]
        RegexThatShouldNotMatch,
    }

    #[test]
    fn it_does_not_ignore_token() {
        let mut lex = FooToken::lexer("[fast ");

        let _first_goes_the_bracket = lex.next().unwrap();
        assert_eq!("[", lex.slice());

        let second_match = lex.next().unwrap();

        assert_eq!("fast", lex.slice());
        assert_eq!(Ok(FooToken::SomeToken), second_match); // <--- incorrectly results in `Err(())`
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant