Skip to content

Add a flag for ignoring verbatim code - #677

Open
ratmice wants to merge 7 commits into
softdevteam:masterfrom
ratmice:ignore_verbatim
Open

ratmice wants to merge 7 commits into
softdevteam:masterfrom
ratmice:ignore_verbatim

Conversation

@ratmice

@ratmice ratmice commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

Here is a patch for #670

It doesn't quite do what the bug report asks for (ignoring comments or whitespace by default),
but allows a way to disable the error, and mentions that now in the error.

This can improve grammar source compatibility posix lex.
Other lex implementations still generally emit verbatim code in an unreachable area of the generated source. Meaning it is parsed, but not evaluated.

In that bug report we had also discussed a LexCompatibility enum, I hadn't implemented that yet.

This can improve grammar source compatibility posix lex.
Other lex implementations still generally emit verbatim code
in an unreachable area of the generated source. Meaning it is
parsed, but not evaluated.
grammar: |
%grmtools{
yacckind: Original(NoAction),
ignore_verbatim_code,

@ratmice ratmice Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely something to look into here,

This should be in the lexer, I don't understand yet why it isn't failing when in the grammar.
Alas it also doesn't yet work when moving it into the lexer.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partially fixed in 74552ee

I added a new ctfail for the false negative.
It'll be easier to wait until after #674 to fix that.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just moved that fix/test entirely to the other PR as it probably just belongs there.

@ratmice
ratmice marked this pull request as draft December 3, 2026 19:18
@ltratt

ltratt commented Dec 4, 2026

Copy link
Copy Markdown
Member

Possibly dumb question: what counts as verbatim code? Do we hardcode // etc inside action code?

@ratmice

ratmice commented Dec 4, 2026 •

Copy link
Copy Markdown
Collaborator Author

Possibly dumb question: what counts as verbatim code? Do we hardcode // etc inside action code?

The test for verbatim code is whether the line has any leading whitespace.
The entire test is actually visibile within the diff context, but it's pretty easily overlooked.

            let j = self.parse_ws(i)?;
            if j != i {
+                if let Some(false) = self.lex_flags.ignore_verbatim_code {

We don't parse any more than that, and we never write it into action code.
We either:

  1. Produce an error if the flag is not set.
  2. Ignore the entire line if the flag is set.

So there is no case in which we actually write the verbatim code snippets to action code or parse it beyond the leading space.

Start: 'ANY' | 'a' | 'NL';

lexer: |
%grmtools{!dot_matches_new_line, octal, size_limit: 1048576}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should probably remove some of the extra things in this test.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fixed in b222f6f & b292d43

@ratmice

ratmice commented Dec 4, 2026 •

Copy link
Copy Markdown
Collaborator Author

Still an issue with this, as it seems to work for CTLexerBuilder, but not yet for nimbleparse

Edit: Fixed by f842132

@ratmice
ratmice marked this pull request as ready for review December 4, 2026 13:09

This branch has not been deployed

No deployments
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