Skip to content

fix(lua): Mode-D nested-function recall + literal-shield tokenisation - #2441

Merged
squid-protocol merged 1 commit into
mainfrom
tri-comparison-sweep-lua
Aug 29, 2026
Merged

squid-protocol merged 1 commit into
mainfrom
tri-comparison-sweep-lua

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

What

tri-comparison-ledger-sweep for lua. All 8 flagged discrepancy shapes investigated and
marked validated in the ledger. Two confirmed GitGalaxy engine defects, both fixed here.

Engine fixes

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 — the exact bug ruby had ("0/117 real methods detected"). Fixed with a
function_opener entry in ScopeParsingRegistry["lua"]: a second, nesting-independent pass over
every real declaration line, gated on the key so shell/vb/elixir (no corpus audit yet) keep
their existing behavior.

2. _apply_literal_shield mis-tokenised Lua

  • The shared default comment-marker set #|--|// treated # (Lua's length operator) and //
    (floor division, 5.3+) as line comments — so for i = 1, #arg do ... end was truncated at the
    #, dropping the do ... end's end from the Mode-D keyword count (a +1 desync per vararg
    loop, which cascaded into an oversized _[Truncated] remnant and a _slice_by_labels re-scan
    emitting every real function a second time at the wrong line).
  • Lua long-bracket literals [[ ... ]] / [=[ ... ]=] / --[[ ... ]] were never shielded, so
    function / for / end tokens inside their bodies (gc.lua's local 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:

Metric Before After
found_functions 505 557
extra_functions (lower better) 12 7
args_exact_match 463 516

Lua recall 81.5% → 89.8%, precision 97.7% → 98.8%.

Differential Scan

  • Both golden masters re-blessed — diff is lua files + directory-group summaries + topological
    coordinate ripple on a handful of unrelated files (expected: the 3D projection depends on the
    whole graph's mass distribution). crucible_check.py --mode both PASS.
  • tests/tree_sitter_accuracy_baseline_lua.json regenerated (--regenerate, no gate override
    needed — all gated metrics improved). Summary table in language_standards.py updated.
  • tree_sitter_accuracy_audit.py --all --ci — 31/31 OK. tri_comparison_chart.py --all --ci OK.
  • lua extraction gauntlet (41) + strict (78) + full tests/extraction/ (6239) + full
    tests/core_engine/ (569) all pass. audit_check.py clean.
  • Ledger / chart / points-of-interest regenerated with --all --write.

Docs

  • New 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.py documents ctags-Lua's over-tagging (~442 of ~1085 corpus tags are
    spurious — it tags the LHS of any statement whose RHS contains the token function) and its
    missing 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_start heuristic matches ALL_CAPS data tables), #2440 (polyglot segmentation splits a
function when a [[ ]] string carries embedded HTML/CSS).

Incidental observation (not filed — no corpus to verify): the shared default comment_markers
#|--|// is also questionable for vb (# date literals / directives), but vb has no
tri-comparison corpus audit.

🤖 Generated with Claude Code

https://claude.ai/code/session_019Zm1uVBpVEZJ9SB7bWFR8S

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
squid-protocol force-pushed the tri-comparison-sweep-lua branch from 90d61a3 to af87fac Compare August 29, 2026 18:53
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-protocol
squid-protocol merged commit eba5939 into main Aug 29, 2026
30 checks passed
@squid-protocol
squid-protocol deleted the tri-comparison-sweep-lua branch August 29, 2026 18:57
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant