Skip to content

compiler: tabbing controls and escaped \& keep their identity through a macro (#760 sites 3 and 4) - #761

Merged
d-q222 merged 1 commit into
mainfrom
agent/daniel-parent/gh760-span
Sep 17, 2026
Merged

d-q222 merged 1 commit into
mainfrom
agent/daniel-parent/gh760-span

Conversation

@d-q222

@d-q222 d-q222 commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

What

Fixes sites 3 and 4 of #760 — two more instances of the #756 pattern:
deciding what a token means by comparing its source-span byte width to a
literal constant. A token copied out of a macro's replacement text carries the
invocation's span, so the width test was really measuring how long a name
the user happened to give the macro.

  • parser::is_tabbing_control (parser.rs:10320) — \= \> \< \+ \-
    in tabbing. Now takes maps_to_invocation/definition and measures the
    token's own source bytes. Both callers pass the provenance through.
  • parser::tabular::is_escaped_ampersand (parser/tabular.rs:535) — a new
    helper replacing the inline !input.maps_to_invocation && span.end - span.start == 2
    guard, doing the same for the escaped \& that must not open the next entry.

Both use the idiom control_symbol_kern (parser.rs:10329) already proves on
the same characters:

let span = if maps_to_invocation { definition? } else { span };

Expanded text with no definition bytes cannot prove it spells a control
symbol, so it falls back to the visible reading: \=-family tokens are typeset
and & separates. Nothing is invented here; the mechanism is the one
control_symbol_kern's doc comment already describes.

math.rs is untouched — sites 1 and 2 (math.rs:1586, math.rs:2998) are
held by daniel-muse-lead-2 and additionally need provenance threaded into the
math token stream.

Why

The failure runs in both directions at both sites, and the second direction
is the one nobody noticed: a wrong glyph is visible, a missing one is not.
Measured through the full compile path (protocol::handle_line), every emitted
item's text:

case before after
tabbing \= via 3-byte macro \ts [xx][=][yy] — prints a literal =, sets no tab stop [xx][yy]
tabbing literal = via 2-byte macro \q [xx][yy] — the = vanished [xx][=][yy]
the same \q in running text (control) [xx][=][yy] [xx][=][yy] — unchanged
tabular{ll} a\am b, \newcommand{\am}{\&} two cells — identical to unescaped a&b one cell, a & b

The \& case is the worst of #760's four: an escaped ampersand arriving from a
macro silently becomes a column break, so every later cell in the row shifts.
That corrupts a table's structure, not just its spacing — and it reported
extra alignment tab: this row has more entries than the 2 columns of the table on a table that had exactly two.

No corpus change is expected. The render route builds against the frozen
vendor/compiler, so this is invisible until the re-pin (#711); it is proved in
the compiler's own tests instead. vendor/ is untouched.

Overlap check

Test results

cargo test  (crates/compiler, full)
  77 suites, "test result: ok" in every one — 918 passed; 0 failed

cargo test  (crates/bridge, full — also depends on the live compiler crate)
  170 passed; 0 failed

Reverting only the two source hunks and keeping the tests fails exactly the
four new regression tests and nothing else:

test tab_stop_reached_through_a_long_macro_still_sets_a_stop ... FAILED
test tab_jump_reached_through_a_long_macro_still_jumps ... FAILED
test a_plain_character_from_a_two_byte_macro_is_not_a_tabbing_control ... FAILED
test tabular::tests::escaped_ampersand_from_a_macro_is_text_not_a_column_break ... FAILED
  panicked: [Diagnostic { severity: Error, message: "extra alignment tab: this
  row has more entries than the 2 columns of the table", ... }]

test result: FAILED. 13 passed; 3 failed   (tests/tabbing.rs)
test result: FAILED. 20 passed; 1 failed   (tabular::tests)

The four guard tests pass both with and without the fix, which is what makes
them guards — they pin the ways an over-broad fix would break things:

  • the_same_macro_prints_the_character_in_running_text_and_in_tabbing — running
    text is unaffected;
  • a_literal_tabbing_control_is_unaffected — the ordinary non-macro \= path;
  • a_real_ampersand_from_a_two_byte_macro_still_breaks_the_column — a genuine
    alignment tab still separates when it arrives through a macro of exactly the
    shape the old width test keyed on;
  • literal_ampersands_keep_their_meanings — bare a&b still makes two cells,
    literal a\&b still makes one.

cargo fmt --check on the four touched files reports nothing on any added line
(the crate carries pre-existing repo-wide rustfmt drift across ~65 files).

Not done

🤖 Generated with Claude Code

https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz

… a macro (#760)

What changed:

Two more instances of the #756 pattern — deciding what a token *means* by
comparing its source-span width to a literal constant. A token copied out of
a macro's replacement text carries the *invocation's* span, so the width test
was really measuring how long a name the user happened to give the macro.

- `parser::is_tabbing_control` (`\=` `\>` `\<` `\+` `\-` in `tabbing`) now
  takes `maps_to_invocation`/`definition` and measures the token's own source
  bytes, exactly as `control_symbol_kern` already does for `\,`. Both callers
  pass the provenance through.
- `parser::tabular::is_escaped_ampersand`, a new helper replacing the inline
  `!input.maps_to_invocation && span.end - span.start == 2` guard, does the
  same for the escaped `\&` that must not open the next entry.

Expanded text with no definition bytes cannot prove it spells a control
symbol, so it falls back to the visible reading: `\=`-family tokens are
typeset and `&` separates.

The failure ran in both directions at both sites, and the second direction is
silent — a wrong glyph is visible, a missing one is not:

  tabbing \= via 3-byte macro \ts    before [xx][=][yy]  after [xx][yy]
  tabbing literal = via 2-byte \q    before [xx][yy]     after [xx][=][yy]
  tabular a\am b, \newcommand{\am}{\&}
                                     before two cells    after one cell "a & b"

The `\&` case is the worst of the three: it corrupts a table's structure, not
just its spacing, shifting every later cell in the row.

No corpus change is expected — the render route builds against the frozen
vendor/compiler, so this is invisible until the re-pin (#711).

What was run:

  cargo test -p flashtex-compiler (crates/compiler, full)
    77 suites, "test result: ok" in every one, 918 passed, 0 failed
  cargo test (crates/bridge, full)
    170 passed, 0 failed

  Reverting only the two source hunks (tests kept) fails exactly the four new
  regression tests and no others:
    tabbing::tab_stop_reached_through_a_long_macro_still_sets_a_stop FAILED
    tabbing::tab_jump_reached_through_a_long_macro_still_jumps FAILED
    tabbing::a_plain_character_from_a_two_byte_macro_is_not_a_tabbing_control FAILED
    tabular::tests::escaped_ampersand_from_a_macro_is_text_not_a_column_break FAILED
      -> "extra alignment tab: this row has more entries than the 2 columns"

  The four guard tests (running text, literal `\=`, literal `a&b` and `a\&b`,
  and a genuine `&` reached through a two-byte macro) pass both with and
  without the fix, which is what makes them guards.

Next step: sites 1 and 2 of #760 (math.rs:1586, math.rs:2998) are held by
daniel-muse-lead-2 and additionally need provenance threaded into the math
token stream; math.rs is untouched here.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
@d-q222
d-q222 merged commit 96721be into main Sep 17, 2026
21 of 22 checks passed
d-q222 added a commit that referenced this pull request Sep 17, 2026
 #784

All eight independently reviewed APPROVE. Batch verification: compiler
935/0, render-pipeline 487/0, perf-bench 14/0, perf gate OK (270 metrics,
no regression), swift build --build-tests OK, CompletionTests 29/0.

Commit-Executor: daniel-parent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
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