You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was trying to get C-style multiline comment working in logos, the state machine for it is quite simple but I can't seem to get it working in logos. This regex seemed to work but it causes a panic when parsing certain things.
The code for report:
use logos::Logos;#[derive(Logos,Debug,PartialEq)]#[logos(skip r"[ \t\n\f\r]+")]// Ignore this regex pattern between tokensenumToken{// Tokens can be literal strings, of any length.#[token("#define")]Define,#[token("macro")]Macro,#[regex("//[^\n]*\n?", logos::skip)]LineComment,#[regex("/\\*([^\\*]*(\\*[^/])?)*\\*/", logos::skip)]MultiLineComment,// Or regular expressions.#[regex("0x[0-9a-fA-F]+")]HexLiteral,#[regex("[a-zA-Z_]\\w*:")]Label,#[regex("[a-zA-Z_]\\w*")]Ident,}fnmain(){let src = "/*wow amazing!!!!!*** /* **/// wow very nice#define macro hi: very nice";letmut lexer = Token::lexer(src);whileletSome(token) = lexer.next(){println!("{:?} {}", token, lexer.slice());}}
The error I'm getting:
thread 'main' has overflowed its stack
fatal runtime error: stack overflow
[1] 5609 abort cargo run
The text was updated successfully, but these errors were encountered:
Philogy
changed the title
Runtime panic when parsing lexing
Runtime panic when lexing based on certain regex
Sep 22, 2024
Philogy
changed the title
Runtime panic when lexing based on certain regex
Runtime stack overflow when lexing certain strings
Sep 22, 2024
Hello @Philogy, I currently haven't much time to invest in this issue, but I would recommend to you the same thing as I do for all comment-style lexing: just create a token that matches the start of a comment, and then process the comment with a callback. This is usually much better, as comments can contain almost any characters, like escaped /, which makes it super hard to write a regex that handles all specific cases.
See #421 (comment) for an example on XML comments, which is very similar to multiline strings.
I was trying to get C-style multiline comment working in logos, the state machine for it is quite simple but I can't seem to get it working in logos. This regex seemed to work but it causes a panic when parsing certain things.
The code for report:
The error I'm getting:
The text was updated successfully, but these errors were encountered: