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

Stack overflow at ~20,000 characters #384

Open
rscarson opened this issue Mar 29, 2024 · 4 comments
Open

Stack overflow at ~20,000 characters #384

rscarson opened this issue Mar 29, 2024 · 4 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@rscarson
Copy link

rscarson commented Mar 29, 2024

I have a StringLiteral token with the following expressions on it:

    #[regex(r#"(?:/(?:\\.|[^\\/])+/[a-zA-Z]*)"#)] // Regex literal
    #[regex(r#"(?:"(?:(?:[^"\\])|(?:\\.))*")"#)] // " string literal "
    #[regex(r#"(?:'(?:(?:[^'\\])|(?:\\.))*')"#)] // ' string literal '

And encountering a string literal above ~20,000 characters stack overflows within logos generated code
Is there an error in one of these expressions?

@maciejhirsz
Copy link
Owner

maciejhirsz commented Mar 31, 2024

Groups are never capturing in logos so you don't need ?:, and you don't need groups around |, so string literal can be rewritten as #[regex(r#""([^"\\]|\\.)*""#)]. If that still overflows try #[regex(r#""([^"\\]+|\\.)*""#)]. I believe it loops internally by doing tail call recursion so the greedily looping all non-escaped non-quote characters inside the group could help (but I have not tested it).

This is one of those cases that really needs the codegen rewrite (#291) into a loop with enum branching working as faux-goto instead of function calls.

@rscarson
Copy link
Author

I had already rewritten it as #[regex(r#""([^"\\]|\\.)*""#)] with no luck but #[regex(r#""([^"\\]+|\\.)*""#)] did the trick!
Thanks!

@rscarson
Copy link
Author

rscarson commented Mar 31, 2024

it still overflows at some point though, at a larger number

Should I leave this issue open for tracking?

@maciejhirsz
Copy link
Owner

Should I leave this issue open for tracking?

Ye, let's do that.

@maciejhirsz maciejhirsz reopened this Mar 31, 2024
@jeertmans jeertmans added bug Something isn't working help wanted Extra attention is needed labels Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants