Stop a backslash-newline in a string leaking to stdout - #4
Merged
Conversation
Flex's `.` never matches a newline, so `<STR>\\.` could not match a backslash escaping the end of a line. With no rule for it the backslash fell through to flex's DEFAULT ECHO rule and was printed straight to stdout -- a stray `\` on every parse of such a file, in the middle of whatever the program was writing. The newline was then picked up by the content-run rule and became part of the string. Both characters are now matched and kept verbatim in the literal. Kept rather than dropped on purpose. StringLiteral::toString() wraps the stored text in quotes to reproduce the source, so cooking escapes here would make the pretty-printer emit real newlines and quotes and corrupt the file it was formatting. Resolving escapes belongs where the literal is evaluated; this side's job is to describe the source faithfully.
This was referenced Aug 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Flex's
.never matches a newline, so<STR>\\.could not match a backslash escaping the end of a line. With no rule for it, the backslash fell through to flex's default ECHO rule and was printed straight to stdout — a stray\on every parse of such a file, in the middle of whatever the program was writing. The newline was then picked up by the content-run rule and became part of the string.Both characters are now matched and kept verbatim in the literal.
Why kept, not dropped
StringLiteral::toString()wraps the stored text in quotes to reproduce the source. Cooking escapes here would make the pretty-printer emit real newlines and quotes and corrupt the file it was formatting. Resolving escapes belongs where the literal is evaluated; this side's job is to describe the source faithfully.Testing
Two tests: the literal keeps
\+LF and\+CRLF verbatim, and the continued line still advances the line number (YY_USER_ACTIONcounts newlines per rule, so this comes for free — but it would be silent if it broke, and every position after a multi-line string would be one line short).632 tests pass. Negative-controlled: removing the rule fails the verbatim test, and the stray
\reappears in the test runner's own output.