parser/lexer: 5.1 error-token quoting + pin break-outside-loop wording (#95, #105)#112
Merged
Merged
Conversation
#95, #105) Lua 5.1's luaX_lexerror/error_expected wrap the whole near/expected token in LUA_QS ('%s') unconditionally, so the special multi-char labels (<eof>, <name>, <number>, <string>) come out quoted. 5.2 rewrote txtToken/ luaX_token2str to leave those bare and quote only symbols/reserved/literals. lua-rs implemented the 5.2+ rule on every version, so all 5.1 syntax errors involving a special token diverged by exactly the surrounding quotes. Fix #105: snapshot the active LuaVersion onto LexState at lexer setup (the error formatters take only &LexState, so this avoids threading &LuaState through every syntax-error callsite) and quote the token >= TK_EOS arm of token2str_raw for 5.1. This covers both the near-token (lex_error/txt_token) and the expected-token (error_expected/token2str) paths. The 5.2+ path is byte-identical (`token < TK_EOS || version == V51` reduces to the old condition for non-5.1). #95: the break-outside-loop wording is already version-gated in breakstat/ undef_goto; this adds regression tests pinning all five arms (5.1 eager "no loop to break near '<eof>'", 5.2/5.3 "<break> at line N not inside a loop", 5.4 "break outside loop at line N", 5.5 "break outside loop near 'break'") so a refactor can't collapse them. 5.1's arm also gains its quote from the #105 fix. Tests: 6 new multiversion_oracle cases (all 5 versions); full crate suite green; official errors/constructs/attrib/goto pass on 5.4. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Closes #105. Closes #95.
What
Two localized, version-gated parser/lexer wording fixes landed together (they overlap on Lua 5.1's
breakmessage).#105 — 5.1 quotes special near/expected tokens
Lua 5.1's
luaX_lexerror/error_expectedwrap the whole near/expected token inLUA_QS('%s') unconditionally, so the special multi-char labels (<eof>,<name>,<number>,<string>) come out quoted. 5.2 rewrotetxtToken/luaX_token2strto leave those bare and quote only symbols/reserved/literals. lua-rs implemented the 5.2+ rule on every version, so all 5.1 syntax errors involving a special token diverged by exactly the surrounding quotes.-e)ifunexpected symbol near <eof>unexpected symbol near '<eof>'local<name> expected near <eof>'<name>' expected near '<eof>'return 1 2<eof> expected near '2''<eof>' expected near '2'breakno loop to break near <eof>no loop to break near '<eof>'Seam: snapshot the active
LuaVersionontoLexStateat lexer setup (the error formatters take only&LexState, so this avoids threading&LuaStatethrough every syntax-error callsite), and quote thetoken >= TK_EOSarm oftoken2str_rawfor 5.1. Covers both the near-token (lex_error/txt_token) and expected-token (error_expected/token2str) paths. The 5.2+ path is provably byte-identical (token < TK_EOS || version == V51reduces to the old condition for non-5.1).#95 — break-outside-loop wording
The wording was already correctly version-gated in
breakstat/undef_goto. This PR adds regression tests pinning all five arms so a future refactor can't collapse them, and 5.1's arm picks up its quote from the #105 fix:no loop to break near '<eof>'<break> at line N not inside a loopbreak outside loop at line Nbreak outside loop near 'break'Tests
crates/lua-rs-runtime/tests/multiversion_oracle.rscovering all 5 versions (the differential oracle); the parser/lexer: 5.1 doesn't quote special near/expected tokens (<eof>, <name>, ...) #105 cases failed before the fix and pass after.lua-rs-runtime+lua-lex+lua-parsecrate suites green.errors/constructs/attrib/gotopass; CLI verified end-to-end across all five versions viaLUA_RS_VERSION.🤖 Generated with Claude Code