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

"a|a*b" should match "aa" but it doesn't #456

Open
zeng-y-l opened this issue Dec 21, 2024 · 3 comments
Open

"a|a*b" should match "aa" but it doesn't #456

zeng-y-l opened this issue Dec 21, 2024 · 3 comments

Comments

@zeng-y-l
Copy link

Example:

use logos::Logos;

#[derive(Debug, PartialEq, Logos)]
enum Tok {
    #[regex("a|a*b")]
    T,
}

fn main() {
    let lex = Tok::lexer("aa");
    assert_eq!(lex.collect::<Vec<_>>(), [Ok(Tok::T), Ok(Tok::T)]); // [Err(())]
}

Maybe it's related to #160. Is this a bug? Thank you so much!

@jeertmans
Copy link
Collaborator

Hi @zeng-y-l, I didn’t verify but I think you need to quote your patterns around the or operator; otherwise you current pattern needs to match a « b » at the end.

@zeng-y-l
Copy link
Author

I want it to match a or a*b. I have tried a|(a*b), and the result is the same.

@zeng-y-l
Copy link
Author

Graph:

{
    1: ::T,
    3: b ⇒ 1,
    4: [
        a ⇒ 4,
        _ ⇒ 3,
    ],
    5: {
        a ⇒ 4,
        b ⇒ 1,
        _ ⇒ 1,
    },
    8: {
        a ⇒ 5,
        b ⇒ 1,
    },
}

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

2 participants