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

Skip linenum increment for indented code blocks #599

Merged
merged 4 commits into from
Dec 11, 2023

Conversation

taniwha
Copy link
Contributor

@taniwha taniwha commented Oct 19, 2023

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"); }

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
Copy link
Owner

westes commented Oct 20, 2023

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

@taniwha
Copy link
Contributor Author

taniwha commented Oct 20, 2023

Sure, I'll look into that.

This checks the line numbers in multiple places, so it should help keep
line numbers working in general.
@taniwha
Copy link
Contributor Author

taniwha commented Oct 20, 2023

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
Copy link
Owner

westes commented Nov 2, 2023

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
Copy link
Contributor Author

taniwha commented Nov 7, 2023

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

This makes the test much less fragile as now all that is need is for
@line@ and __LINE__ to be on the same line (the comment gets substituted
too, but it's a comment...)
@taniwha
Copy link
Contributor Author

taniwha commented Nov 16, 2023

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

I had forgotten about distcheck
@taniwha
Copy link
Contributor Author

taniwha commented Dec 11, 2023

@westes are there any further issues?

@westes
Copy link
Owner

westes commented Dec 11, 2023

This looks great; thank you!

@westes westes merged commit 1370faa into westes:master Dec 11, 2023
3 checks passed
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

Successfully merging this pull request may close these issues.

2 participants