Repository navigation
fix(lua): Mode-D nested-function recall + literal-shield tokenisation - #2441
Merged
Merged
Conversation
tri-comparison-ledger-sweep for lua: all 8 flagged discrepancy shapes investigated and marked `validated`. Two confirmed engine defects, both fixed here: 1. Mode-D recall gap (#1262 class): `function` / `local function` declared inside a `do` block, nested in another function's body, or after a keyword-count desync was folded into the enclosing satellite instead of getting its own FunctionNode. Fixed with a `function_opener` entry in `ScopeParsingRegistry["lua"]` -- a second, nesting-independent pass over every real declaration line, exactly ruby's own #1262 mechanism, gated on the key so shell/vb/elixir keep their behavior. 2. `_apply_literal_shield` mis-tokenised Lua: the shared default comment-marker set `#|--|//` treated `#` (length operator) and `//` (floor division) as comments, so `for i = 1, #arg do ... end` lost its `end` from the Mode-D keyword count (a +1 desync per vararg loop). It also never shielded Lua long-bracket literals `[[ ... ]]` / `--[[ ... ]]`, so `function`/`for`/`end` tokens in their bodies corrupted the depth stack and were mis-sliced as declarations. Fixed with a lua branch (`comment_markers = "--"`) plus a dedicated long-bracket sub run before the quote pass. Measured effect (`tree_sitter_accuracy_audit.py --lang lua`): found_functions 505 -> 557, extra_functions 12 -> 7, args_exact_match 463 -> 516; lua recall 81.5% -> 89.8%, precision 97.7% -> 98.8%. Both golden masters re-blessed (lua files + topological ripple only), `tests/tree_sitter_accuracy_baseline_lua.json` regenerated, summary table updated. Ledger verdicts, chart, and points-of-interest regenerated (`--all`). New `docs/language_status/lua.md` with the tri-comparison capstone as §9. `tests/tools/ctags_reader.py` documents ctags-Lua's over-tagging (~442 of ~1085 corpus tags) and its missing `signature:` field. Residual routed to issues: #2437 (mid-file keyword desync -- no remaining lua repro after this pass), #2438 (dotted/method declaration heads not name-resolved in the nested pass), #2439 (class_start heuristic matches ALL_CAPS data tables), #2440 (polyglot segmentation splits a function when a `[[ ]]` string carries embedded HTML/CSS). Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_019Zm1uVBpVEZJ9SB7bWFR8S
squid-protocol
force-pushed
the
tri-comparison-sweep-lua
branch
from
August 29, 2026 18:53
90d61a3 to
af87fac
Compare
Contributor
squid-protocol
added a commit
that referenced
this pull request
Aug 29, 2026
…tic (#2444) Follow-on to #2441, closing three issues the lua tri-comparison sweep filed. opener/closer count, so their net Mode-D scope change is <= 0: the primary scan filed them as global dust and the `function_opener` pass skipped them (`depth_before_line[i] <= 0` gate). Affected plain names, redefinitions, method heads, and every declaration nested in a bare `do` block. Fixed by extending `function_opener` to top-level self-closing declarations, lua-scoped so ruby/matlab/livecode keep the strict gate. The Anonymous_Block name-borrow fallback is taught to skip a completed one-liner so an adjacent `coroutine.wrap(function() ... end)` closure isn't mislabeled with the previous line's name. (The issue's "dotted head" framing was a misdiagnosis -- `_extract_semantic_name` already resolves `a.b.c.f1` / `a:deep`.) raw text, so the HTML inside `Write([[<!doctype html> ... ]])` in redbean demo files was carved into a `css` segment mid-function, producing a `<name>_[Truncated]` satellite. Fixed by running the trigger scan against a view where lua long-bracket literals are blanked to same-length filler (offsets + line numbers preserved; segment slicing unchanged). Same mask added to prism's `_partition_embedded_languages`. tables (`local FISH = { ... }`, one-letter fixtures). Fixed by requiring a proto-table tell -- `function Name[.:]`, `Name.__index`, `setmetatable(..., Name)`, or `Name[.:]new` -- within a bounded window for the heuristic branch; the explicit `---@class` branch is never gated. Measured (`tree_sitter_accuracy_audit.py --lang lua`): found_functions 557 -> 618, extra_functions 7 -> 1, extra_classes 14 -> 1, args_exact_match 516 -> 572. Lua recall 89.8% -> 99.7%, precision 98.8% -> 99.8%. Both golden masters re-blessed (lua files + topological ripple only), lua baseline + summary table regenerated, ledger verdicts + chart + points-of-interest regenerated (`--all`), `docs/language_status/lua.md` §9 updated. One residual, not filed: a `\z` line-continuation inside a single-quoted string defeats the newline-bounded literal shield (`events.lua`), a pre-existing cross-language gap -- the last lua `_[Truncated]` in the corpus. #2437 has no remaining lua repro. Claude-Session: https://claude.ai/code/session_019Zm1uVBpVEZJ9SB7bWFR8S Co-authored-by: Claude Sonnet 5 <[email protected]>
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.
What
tri-comparison-ledger-sweepfor lua. All 8 flagged discrepancy shapes investigated andmarked
validatedin the ledger. Two confirmed GitGalaxy engine defects, both fixed here.Engine fixes
1. Mode-D recall gap (#1262 class)
function/local functiondeclared inside adoblock, nested in another function's body, orafter a keyword-count desync was folded into the enclosing satellite instead of getting its own
FunctionNode— the exact bug ruby had ("0/117 real methods detected"). Fixed with afunction_openerentry inScopeParsingRegistry["lua"]: a second, nesting-independent pass overevery real declaration line, gated on the key so
shell/vb/elixir(no corpus audit yet) keeptheir existing behavior.
2.
_apply_literal_shieldmis-tokenised Lua#|--|//treated#(Lua's length operator) and//(floor division, 5.3+) as line comments — so
for i = 1, #arg do ... endwas truncated at the#, dropping thedo ... end'sendfrom the Mode-D keyword count (a +1 desync per varargloop, which cascaded into an oversized
_[Truncated]remnant and a_slice_by_labelsre-scanemitting every real function a second time at the wrong line).
[[ ... ]]/[=[ ... ]=]/--[[ ... ]]were never shielded, sofunction/for/endtokens inside their bodies (gc.lua'slocal prog = [[ ... function foo ... ]]) corrupted the depth stack and were mis-sliced as declarations.Fixed with a lua branch:
comment_markers = "--"only, plus a dedicated long-bracket sub(
(?:--)?\[(=*)\[.*?\]\1\]) run before the quote pass.Measured effect
tree_sitter_accuracy_audit.py --lang lua:found_functionsextra_functions(lower better)args_exact_matchLua recall 81.5% → 89.8%, precision 97.7% → 98.8%.
Differential Scan
coordinate ripple on a handful of unrelated files (expected: the 3D projection depends on the
whole graph's mass distribution).
crucible_check.py --mode bothPASS.tests/tree_sitter_accuracy_baseline_lua.jsonregenerated (--regenerate, no gate overrideneeded — all gated metrics improved). Summary table in
language_standards.pyupdated.tree_sitter_accuracy_audit.py --all --ci— 31/31 OK.tri_comparison_chart.py --all --ciOK.tests/extraction/(6239) + fulltests/core_engine/(569) all pass.audit_check.pyclean.--all --write.Docs
docs/language_status/lua.md— standard §1–8 snapshot + a tri-comparison capstone as §9(same shape as
yacc.md). Index updated.tests/tools/ctags_reader.pydocuments ctags-Lua's over-tagging (~442 of ~1085 corpus tags arespurious — it tags the LHS of any statement whose RHS contains the token
function) and itsmissing
signature:field.Issues
Filed / referenced: #2437 (mid-file keyword desync — no remaining lua repro after this pass),
#2438 (dotted / method-style declaration heads not name-resolved in the nested pass), #2439
(
class_startheuristic matches ALL_CAPS data tables), #2440 (polyglot segmentation splits afunction when a
[[ ]]string carries embedded HTML/CSS).Incidental observation (not filed — no corpus to verify): the shared default
comment_markers#|--|//is also questionable forvb(#date literals / directives), but vb has notri-comparison corpus audit.
🤖 Generated with Claude Code
https://claude.ai/code/session_019Zm1uVBpVEZJ9SB7bWFR8S