westes / flex

The Fast Lexical Analyzer - scanner generator for lexing in C and C++
Other
3.55k stars 529 forks source link

Skip linenum increment for indented code blocks #599

Closed taniwha closed 9 months ago

taniwha commented 10 months ago

An indented code block would cause the subsequent all subsequent code block line numbers (including its own) to be out by one.

For example, the following would cause the line number for the BEGIN code block to have the line number for the warning code block. This would also affect the code in the final section after the second %%.

%%
            yyflexdebug = 0;
            grab_frame = GRAB_FRAME;
            grab_other = GRAB_OTHER;
            grab_write = GRAB_WRITE;
            yylval->pointer = 0;// ensure pointer vals are null

"/*"        { BEGIN (COMMENT); }
<COMMENT>"/*" { warning (0, "nested /* in comment"); }
westes commented 10 months ago

This should have a test case to detect regression in the future. Is that someting you're able to add?

taniwha commented 10 months ago

Sure, I'll look into that.

taniwha commented 10 months ago

Done. I covered as many places as I could think of, and I verified that it does catch the incorrect lines before the patch.

westes commented 10 months ago

What do you think about having the lexer be generated from something that e.g. grep -n 's the line numbers so that changing the source is less prone to break the test?

taniwha commented 10 months ago

Oh, hmm, I hadn't thought of that. Interesting idea. I'll see what I can come up with, but generation certainly makes sense.

taniwha commented 10 months ago

I came up with something that works nicely so long as the two (@LINE@ and __LINE__) are on the same line.

taniwha commented 9 months ago

@westes are there any further issues?

westes commented 9 months ago

This looks great; thank you!