softdevteam / grmtools

Rust grammar tool libraries and binaries
Other
507 stars 31 forks source link

Raise an error if rules start with whitespace. #411

Closed ratmice closed 1 year ago

ratmice commented 1 year ago

Here is a patch which turns rules with leading whitespace into errors as discussed.

Posix lex treats these as verbatim copied into the generated code BSD/System V lex copy these into unreachable areas of code. Which are still used as the primary mechanism for adding comments to lex files.

Before this patch we trimmed leading spaces, and parsed them as normal rules. Afterwords we now throw a VerbatimUnsupported error.

ratmice commented 1 year ago

One thing I should mention probably is this does allow entirely empty lines, that is \n\n\n is silently skipped, this is covered by the testcase exceed_tok_id_capacity, where the writeln ends up with double \ns at writeln!(src, "x 'x{}'\n", i).ok();

ltratt commented 1 year ago

This looks mostly good! Possibly silly question: I'm not sure I see a test which checks that VerbatimNotSupported is returned?

ratmice commented 1 year ago

This looks mostly good! Possibly silly question: I'm not sure I see a test which checks that VerbatimNotSupported is returned?

I meant to add one, totally forgot it after fixing up the existing tests. Will have to add it in the morning.

ltratt commented 1 year ago

Thanks! Please squash.

ratmice commented 1 year ago

Squashed.

ltratt commented 1 year ago

bors r+

bors[bot] commented 1 year ago

Build succeeded!

The publicly hosted instance of bors-ng is deprecated and will go away soon.

If you want to self-host your own instance, instructions are here. For more help, visit the forum.

If you want to switch to GitHub's built-in merge queue, visit their help page.