Repository navigation
lexer: build a working scanner with flex 2.6.16 and later - #1473
Merged
Merged
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
macOS CI regenerates the lexer with Homebrew's flex, which moved past
2.6.4, and every test that boots the driver failed: a function-like macro
call lost the character after its ')' to a stray '(' (`to_string(value);`
in /std/json.lpc compiled as `("" + (value)) (`), so the testsuite's
simul_efun could not load.
Two flex changes are involved.
flex 2.6.16 ("end yytext at the token after input()") keeps the NUL that
terminates yytext at the end of the token, in a new yy_hold_ptr, while
yyinput() advances yy_c_buf_p past it. lpc_lex_push_prepared_buffer()
flushed the held character at yy_c_buf_p, so after the macro collector's
raw reads it overwrote the next unread byte. It, and the held character
lpc_lex_buffer_extents() reports, now use yy_hold_ptr on 2.6.16+ and
yy_c_buf_p before.
Since flex 2.6.5 (westes/flex#885), a never-interactive scanner no longer backs up
to the last accepting position when a NUL has no transition: the skeleton
guards that code with M4_NOT_MODE_INTERACTIVE, which flex never defines.
The token before a NUL swallowed it, and embedded_nul_hang.lpc's NUL in a
comment, a dead #if branch or after an identifier compiled cleanly. Drop
%option never-interactive: every buffer is in memory and non-interactive
already, so it only selected that code path. The one buffer created from
yyin is pinned non-interactive so a terminal on stdin cannot change that.
The committed scanner is still generated by stock flex 2.6.4 (the pin).
Verified with stock flex 2.6.4 and 2.7.2: GTest and the LPC suite pass on
both, and on an ASan/UBSan build with 2.7.2.
gesslar
force-pushed
the
fix/flex-2.7
branch
from
November 20, 2026 17:19
3bb9e90 to
5704ea2
Compare
Since flex 2.6.5, YYLMAX is substituted into the skeleton at generation time from `%option yylmax` (default BUFSIZ), so lexer.l's `#define YYLMAX 65536` no longer reaches the scanner. The token cap fell to 8K on glibc and to 1K on macOS, where a 5000-byte string literal aborted the compile (LexerTest.String_TooLong_Error and TemplateLiteral_OverflowDuringMiddleFragment_DoesNotLeakNesting on Homebrew flex 2.7). flex 2.6.4 rejects the option, so lexer.l can't carry it. For 2.6.5+, scan a build-dir copy with `yylmax=65536` appended to the `%option array` line (same line count, so #line numbers still match lexer.l). The copy-back stamp still hashes the real lexer.l. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
thefallentree
approved these changes
Nov 23, 2026
thefallentree
left a comment
Member
There was a problem hiding this comment.
Reviewed; macOS now green with the yylmax follow-up. All 18 checks pass.
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.
macOS CI has been failing on master: every macOS runner image since 20261111 ships Homebrew flex 2.6.16+, CI regenerates the lexer with it, and the resulting driver can't load the testsuite's simul_efun. A function-like macro call loses the character after its
)to a stray(, soreturn to_string(value);in/std/json.lpccompiles asreturn ("" + (value)) (.Two flex changes are involved; the fix is all in
lexer.land works with stock flex from 2.6.4 through 2.7.2. The pin stays at 2.6.4.Held character moved (flex 2.6.16, "end yytext at the token after input()"). The NUL that terminates
yytextnow stays at the end of the token, recorded in a newyy_hold_ptr, whileyyinput()advancesyy_c_buf_ppast it.lpc_lex_push_prepared_buffer()flushed the held character atyy_c_buf_p, so after the macro-argument collector's raw reads it overwrote the next unread byte.LPC_YY_HOLD_PTR()picks the right field by the generated scanner's version macros; the push andlpc_lex_buffer_extents()(whichlpc_lex_peek()and the diagnostic snippets read) use it.NUL jam no longer backs up under
never-interactive(flex bug since 2.6.5, westes/flex#885, fix pending in westes/flex#886). When a NUL has no transition, the skeleton should back up to the last accepting position beforeyy_find_action. Incpp-flex.skl/c99-flex.sklthat code is guarded byM4_NOT_MODE_INTERACTIVE, but flex only definesM4_MODE_NO_INTERACTIVE, so it is never emitted. The token before a NUL swallows it and the embedded-NUL rule never fires:embedded_nul_hang.lpc's NUL-in-comment, NUL-in-dead-#ifand NUL-after-identifier cases compiled cleanly. Reproduced with a three-rule standalone scanner, wherenever-interactivealone triggers it. The fix drops%option never-interactive: every buffer the lexer scans is in memory and already non-interactive, so the option only selected that code path. The one buffer created fromyyinis pinned non-interactive so a terminal on stdin can't change that.The committed
lexer.autogen.ccis regenerated with stock flex 2.6.4 built from the release tarball (distro-patched 2.6.4 builds emit different tables).Testing
embedded_nul_hang.lpcfailed with only the first fix).