Skip to content

feat(pir): print a plan's source as the statement's own lines - #178

Merged
thiremani merged 39 commits into
masterfrom
pir-source-lines
Nov 26, 2026
Merged

thiremani merged 39 commits into
masterfrom
pir-source-lines

Conversation

@thiremani

@thiremani thiremani commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

A plan's source was one quoted line, so every quote inside it was escaped and
a block-layout literal collapsed into a line of \n sequences. The label now
stands alone and the statement's own lines sit one level in, as its author
wrote them.

It also carries two breaking changes, each described below: a block literal's
rows are indented exactly 4 spaces, and a run of operator characters that
names no operator is an error.

Breaking change: a block literal's rows take exactly 4 spaces

c4be762 tightens the layout rules. It is a language change, and it is in
this PR because the source text relies on it.

  • The rule. A block literal's rows sit exactly 4 spaces past the line
    holding its [, which puts a table's header : 2 spaces past it. A body
    and a struct definition already took exactly 4.
  • What is now an error. Rows at any other depth — rows 2 or 8 spaces in
    compiled before — and a table header level with its statement or one column
    left of it. The message is a block literal's rows are indented 4 spaces past the line holding its '[', and a table's header ':' 2.
  • What is unchanged. Rows under a call's continued arguments, since the
    depth is measured from the [ line; where the ] goes; how a list's
    continued items line up.
  • Migration. Re-indent the rows to 4 spaces past the [ line. Nothing in
    this repository needed it: all 124 fixture files parse as before, and none
    of the 16 block literals in the README's and docs' examples moved.

The free depth dates from 8a371a5 (#141), when rows were measured from the
statement and could not otherwise sit under continued arguments. e58a3c8
measured them from the [ line a day later, which gives that layout at a
fixed depth too. The header one column left of its statement, legal since
37da04a, was the one layout in which a line of a statement began left of the
statement, and a function body could hold it where a script could not.

The depth is judged in the parser (0455967). c4be762 checked it in the
lexer, on the line after any [ that ends its line, so an index broken across
lines drew the rows message ahead of the real error; the lexer cannot tell
whether that [ opens a literal. The lexer now only measures: a rows block's
INDENT spells out how far the rows are past the line holding the [, and the
parser checks it where it opens a block literal's rows, as it does for a body
and a struct definition. lexer.BLOCK_ROWS_ERR is gone with the lexer's
check, as INDENT_WIDTH_ERR went in #141; the message is the parser's, and
nothing outside the parser named the constant. Five mutants of that
arrangement each fail a test.

Breaking change: an operator run that names no operator is an error

6bf6693 is the second language change. It is in this PR because it came out
of the split-operator work above: f980ba1 first removes the infix half of
operator splitting, which never ran.

  • The rule. A named prefix-only operator can open a cell even when it
    touches the preceding value, as in [a√b]. A run such as -√ has no
    operator of its own. It can open the next cell or the value after a
    statement condition when a space separates it from the preceding value.

  • What is now an error. A run of prefix operators attached to the value
    before it, which used to begin a new value without a word:

    [a-√b]          # was two cells, [16 -2] for a = 16 and b = 4
    [a--b]          # was two cells, [16 4]
    x = a > 1-√b    # was the condition a > 1 with the value -√b
    

    Each is now operator -√ is not defined (or --), reported at the run.

  • What only changes its message. A run that never parsed is reported as
    what it is, at the run: x = a*-b said no prefix parse function for *- found, x = f(a*-b) said expected next token to be ), got OPERATOR instead, and a @= 2 blamed the a at column 1. All three now say
    operator *- is not defined or operator @ is not defined.

  • What is unchanged. An operator that is defined keeps its reading: *
    before a value still has no prefix parse function for * found, and a
    prefix-only operator begins a value wherever it stands, so [a√b] is
    still two cells, as tests/array/array_neg.spt pins. [a -√b] is two
    cells and [a - √b] is one, as before.

  • Migration. Put a space before the run where a new value is meant
    ([a -√b], x = a > 1 -√b), or spaces on both sides where one operator
    is ([a - √b]). Nothing in this repository needed it: all 5,127 fixture
    statements parse as they did at 5feaade, and no README or docs example
    holds such a run.

docs/Pluto Conditional Value Semantics.md states the rule beside the one
for cells.

A failed cell takes its brackets

An array row is the one place the parser reads on after a failure, so a later
cell can report its own error. A cell that failed inside its brackets stopped
there, and the row read what was left of it as cells. 40f6b12 fixes that:

Row At 5feaade Now
[f(a@b, c)] 3 errors: @, then , and ) 1: @
[(a@b) c] 2: @, then ) 1: @
[f(a@b, c) d@e] 4: two real, two spurious 2: both @
[v[a@b] c@d] 1: the index's ] ended the row 2: both @
[f(a b c@d] 2: the missing ), then @ 1: the missing )

The parser counts the parentheses and square brackets open where a token
stands. After each cell the row reads on until the brackets that cell opened
are closed, stopping short of the row's own ] and at the end of the line.
That is one rule in parseRow; a call, a group and an index need no recovery
of their own, and none of them could tell its own closer from one an inner
failure stopped on. Outside a row nothing changes, since a statement that
fails skips its line.

The last row of the table is the one that reports less: with a ) missing
altogether the row cannot tell where the call ends, so it reads to its own
end and the @ shows once the first error is fixed. The counts are exact for
brackets that nest; a stack that knew each bracket's kind would also read on
in [[f(a b] c@d] and is not built.

An earlier version of this description said no row reports an error that is
not there. That was wrong, on master and here alike: a cell that failed at its
row's own ] left the row reading past that ], so x = f([1 +], 9)
reported the missing operand and then the , and the ). 126f725 ends the
row there. Of 276 inputs holding one fault each, in rows, calls, groups and
indexes, 34 reported more than one error at e82680a, all of this kind; each
now reports exactly one. That is what was measured, not a proof about every
row.

TestFailedCellTakesItsBrackets has four rows, each the only test that
catches some wrong version of the rule: 20 mutants, all caught. FuzzParse
ran 3.8 million inputs on the final text without a panic or a lost statement.

f13f523 dropped spell's early return for a statement that failed, on the
claim that every statement starts at a token its source spells. That is
false. A function with no indented body has the end of its next line taken
for a statement, and that token spells no source, so a .pt file holding
r = F() followed by an unindented x panicked in Spelling. ba9f7bf
attaches the source where a print statement is built and where a completed
let statement is returned, so a failed statement is never spelled, and the
parser closes capture on every exit. That file now reports the missing
indentation.

6bf6693 checked a whole run at every split, which made a long prefix run
quadratic: 8,000 - before a value took 4.6 s, against 5 ms at 5feaade.
b733155 splits a validated prefix run into its tokens together, preserving
each token's rune offsets and the following lookahead; 32,000 take 32 ms.

7597f31 parses items after a comma as positional values, since only a
statement's first expression can be its condition. x, y = a, b -√c now
reports the undefined operator at -√. It also changes what a spaced minus
means after a comma: x, y = 1, n -1 is 1 and n - 1, as it already was
in the value list after a condition. On master that statement, and
x, y = a > 1, b > 2 -5, were rejected with a statement condition is a single expression; both now compile. e82680a documents the attached,
named prefix case with [a√b].

Two tests pin what a review found unpinned. 0976ecb adds
TestCommaStartsPositionalValue: putting the old split back for defined
operators alone passed every test, and now fails it. 52e7a1f adds
TestSinglePrefixOperatorIsNotRequeued: without the early return for an
operator that is already one prefix operator the parse is the same, but each
operator of a run copies the tokens still queued, and 4,096 - allocate
689 MB against 1.94 MB. The test asks for no allocation on that path.

Across 124 fixtures the serialized ASTs, including token positions and source
spellings for 5,127 statements, matched 5feaade byte for byte. gofmt,
go vet ./..., go test -race -count=1 ./... and
python3 test.py --leak-check, 91 of 91 under its own PTCACHE, pass on
6d774de.

Before and after

assign scores
    source "scores = [\n  : Name Score\n    \"Ada\" 10\n]"
assign scores
    source
        scores = [
          : Name Score
            "Ada" 10
        ]

Within a line everything a reader could not otherwise see is still escaped —
escapeControls, the helper an operand already uses — so a source never goes
invisible and never breaks the layout. Only a line terminator becomes a line.
Two statements still render alike where they hold the same text, a physical tab
and a \t escape among them; what the escaping rules out is two statements
that differ.
That takes the escaping off all 136 source lines the tests and docs hold, 44
of which carried an escaped quote, and it also stops strconv.Quote doubling
backslashes: quoteText = "hello \"world\"\\path\nnext\tcol" now prints as
written.

The one place the two rules disagree

A node's operand keeps the opposite rule — one physical line, line breaks
escaped with everything else — because a node is one line. §12 now states the
two separately. For a string literal that spans lines they disagree about what
the text holds: the source shows the continuation shifted to the section's
indent, while the operand beside it is exact.

assign s
    source
        s = "line one
        line two"

    execute
        %t0 = eval Str "line one\nline two"

TestPlanGoldenMultilineString pins both spellings together, so the trade is
written down rather than implied. The alternative — printing a source's lines
at their original columns — is faithful for every construct but leaves
flush-left lines inside an indented block; shifting uniformly keeps the
relative indentation that Pluto's block layout actually depends on, and avoids
a carve-out for string literals.

Evidence

  • Machine code: all 89 fixture executables have an identical __text.
  • Nothing else moved: with every source section elided, the plan text
    over master's fixtures is byte-identical — 4,115 sections on each side.
  • Gate: gofmt, go vet ./..., go test -race ./..., and
    python3 test.py --leak-check 91/91 under its own PTCACHE.

The source is the file's text

64058e0 and 3b73aef answer the question the layout invited: which parens
belong in a source line. The answer is the file's own, because the ast's
rendering spells out its own nesting — every infix and prefix expression
parenthesises itself, which is exactly what the parser's precedence oracle
asserts. Stripping those at the top only relocates the problem.

So a statement now carries the text its file gives it. Every token carries the
runes that spell it (Pos and Len, 8000a3d), so Spelling quotes the
input from a statement's first token to the line break that ends it: the
lines around the statement are simply not in the span, and the string
literals it spans say which lines hold a string's own characters rather than
the file's layout (cf72f5b). The parser keeps that span as it consumes tokens, and a plan
quotes it — and nothing else. Every statement a plan is built
from comes from a file, and validateHead already rejects a head with no
source, so a parser that stopped spelling reports
internal: invalid plan for "a = 5": plan assign a has no source rendering
rather than printing a plausible line and hiding the bug (4600507).

b = a + 2 * 3          was  b = (a + (2 * 3))
n = -a                 was  n = (-a)
h1 = "foo" ⊕ "bar"     was  h1 = ("foo" ⊕ "bar")
imp = 5a               was  imp = (5 ⋅ a)
hc = a > 2 7           was  hc = (a > 2) 7
f = -8 >> 1 # arithmetic right shift
                       was  f = (-8 >> 1)

The last line keeps its comment since 6d774de. Until then a source ended
at the statement's last token, so a comment after that token was cut while a
comment any earlier line of the statement ended with lay between two of its
tokens and was kept:

v = [ # opens
    "Ada" 1 # top scorer
]                           "# closes" was cut here

A one-line statement has only a last line, so its comment was always cut.
The source now runs to the line break that ends the statement, and every
line keeps what it ends with; a blank left at the end of the line is still
trimmed. Spelling takes that line break in place of the last token, which
the parser no longer tracks. 36 of the fixtures' 5,127 statement sources
gain the comment their last line ends with, and nothing else in any of their
ASTs changes; no golden plan held such a comment. Six mutants of the new end
each fail a test. Paragraphs below that speak of a span ending at the last
token, or of a comment the statement never reaches, describe the code
before this commit.

The operand lines are unchanged — a node is one line, showing the ast's
spelling — so a reader sees what they wrote beside what the planner made of
it. ast.String() is untouched, so the precedence oracle keeps the spelling
it asserts and no parser expectation moves.

Each of the 52 golden source blocks was checked to differ from its old text
only inside the source section before it was replaced.

Two reviews then found four ways Lexer.Text damaged a statement that spans
lines, each on a program that compiles without an error, all fixed in
74c3522. It moved every line of a span left and trimmed every line's
trailing space — including the lines a string literal runs into, where those
characters are the string's content. A function body chopped four runes off a
flush-left continuation and could delete a short closing line whole, leaving
the quote open; at the script root "hello , a one-space line and a
one-tab line all rendered as if empty, so three different strings rendered
alike, which is exactly what §12 forbids. That last one reinstated, one stage
earlier, the space-only line a3d5aaf had just fixed — the pir tests kept
passing because they hand Head.Source over directly and never reach the
lexer. A table's : header, which may hang two columns left of its rows, was
deleted when a body statement's indentation was subtracted; the dedent is now
the least indentation any line of the span has. And Text panicked on a
column below one.

The verification note the first review made is right: eliding source
sections proves nothing about them. Two things cover them now. The exact
spelling expectations in TestStatementSpelling and
TestStatementSpellingInBody pin the text itself, b = ((a)) among them,
since parens an author wrote are what this change is for. TestSpellingReparses
pins that nothing is lost: it parses each statement's own spelling and compares
the statement it gets back. It catches content a span drops or adds, but not
spelling — it compares the ast's rendering, which reads b = ((a)) and
b = a alike — so the two are needed together. Each fix dies under one named
mutant.

A fourth round replaced the mechanism rather than patching it again. Quoting
whole lines is what swept in a comment the statement never reached and what
forced the renderer to be told which lines a string ran through; the two side
tables and the line cache were bookkeeping for that reconstruction, and four
of the five bugs above lived in them. With token extents the span is exact, so
comments, stringBreaks, lines, dedent and Text are all gone and the
lexer is 32 lines lighter. A span moves as one: the margin is the least
indentation its lines can all spare, so a table's hanging : still stands
against its rows, while a blank or comment-only line neither sets the margin
nor loses more than it has. One rendering change comes with it: a comment between two
of a statement's own tokens reads as the author wrote it where it used to
leave a blank line — no fixture or golden holds one, so none moved.

The common margin and the whole first line, described in the paragraphs around
this one, are both gone again (a0b7d93). With rows at a fixed depth every
line of a statement has the indentation the statement stands at, so Spelling
starts at the first token and takes that indentation, first.Column - 1, off
each later line; a blank or comment line gives up what it has, and a line a
string runs into is left alone. margin is deleted, with the three kinds of
line it read past, and so is the arithmetic that found the first line's start.
All 5,127 statements of the 124 fixture files are byte for byte what they were
at 997da93. On a line the lexer rejects, a recovered statement is spelled
from its first token: x = 1 after a tab indent, and after a NUL that ends a
comment early it no longer carries the comment's text, which 997da93 copied
in. A test pins each, and neither file reaches a plan. Nine mutants each fail
a named test: eight of the new Spelling, and one that takes the first line
whole and trims its blanks, which only the NUL case catches. The hanging-header
case of TestSpellingMovesASpanAsOne went with the layout it tested.

The span's first line was taken whole in 997da93. Spelling began at the
first token, past the indentation of its line, and padded that line back with
spaces inside the loop that moves the lines left, which read as indentation
made up for the occasion. It begins at the start of that line instead, found
from the token's Pos and Column the way indentation() already finds it,
so every line holds what the file gives it, one rule moves them all, and
margin reads the first line's indentation off the line. No program that
compiles spells differently: all 5,127 statements of the 124 fixture files are
byte for byte what they were. The one difference is on a line the lexer
rejects: a statement on a tab-indented line is quoted with its tab, as it was
written, and such a line never reaches a plan. That is the spelling 7df4812
(below) removed, back for a different reason — the line is whole, where then
the span began at a token that spells nothing — and it makes that commit's
rule carry more. The illegal token a tab is lexed as stands at the tab's
column, so a span begun there would open before the statement's own line: a
tab after two spaces on a file's first line indexes the input at -2. The
recovery test's old input, a lone tab at the start of the file, could not show
that, so it uses a tab after spaces on a later line and fails against both the
old start rule and the padding. Before it, d7200ec folded the marking of
string lines into the pass that splits them, e249d67 named a line's two bits
after what they test, and 8ac6b95 finishes a sentence in margin's comment
that rename left half-swapped.

A seventh round found that recording a statement's tokens had three owners —
started in parseStatement, fed by nextToken, finished by two loops — so
the path that parses a code file's declarations fed it without ever starting
or finishing it. Every string token in such a file was kept for the parser's
life: 10,000 of them, about 870 KiB, for a file of 10,000 constants, while a
script kept none. 700cae1 gives parseStatement the whole job, so the
declaration path keeps nothing at all and the loops lose a responsibility that
was never theirs. 82ad719 then made the regression test able to fail: it had
asked a parser that never recorded anything, for a length rather than a
capacity, so it passed with the close removed. Each case now puts a function
first and asks what the buffer still holds, one body parsing and one not —
removing the close fails both, moving it below the nil return fails only the
failing body.

A sixth round found the last of it, fixed in 9b24ccf: margin decided
whether a line was blank or a comment after trimming spaces alone, and Pluto
allows a tab on either, so a tab-indented comment or a line of one tab counted
as a line of the statement with no indentation and left the whole statement
four columns right. TestSpellingMovesASpanAsOne now quotes an indented span
in the lexer itself — the tabbed comment, the tab-only line, the hanging
header, a flush-left comment and two literals on one line — rather than
reaching those shapes only through the parser. The span guard compares against
what is left of the input instead of adding to its start, and an ast-level
case reads √-x and asks each split piece for the runes it spells, which
putting the old code back no longer survives.

A fifth round found four faults in that rewrite, all fixed in 20afc33. A
shift operator was built after its run had been read, so >> spelled > and
>>> spelled >>; it starts at its first rune now, which also corrects its
reported column, and the extent oracle covers the shifts, the comparisons, a
float opening with a dot and a table header. Clamping each line's indentation
separately moved a hanging : and its rows by different amounts, so the
header stopped standing against them and the text no longer parsed — hence the
common margin above. Walking every literal for every line was quadratic: on an
8,000-row table of strings, 118ms before and 5.5ms after one forward pass.
And a split operator kept neither half's runes. That fix clamped each piece's
length against a run shorter than the operator matched inside it, which no
path produces: a run is as long as its literal and the operator is a prefix of
it. f2cc31a gives the pieces their plain lengths.
TestSplitOperatorKeepsItsRunes could not tell one piece's length from the
other's: both pieces of √- are one rune, and no parse shows a difference,
since only a prefix run is split and every prefix operator is one rune.
5feaade adds TestSplitOperatorPlacesItsRemainder, which splits √--
directly and fails if either length or the remainder's column is wrong. Spelling's span guard, asked
for by that round and hardened against overflow by the next, is gone again in
71f4dca: its one caller is the parser, handing over tokens this lexer made
in the order it read them, so no clause in it could hold — and returning ""
for a span a caller invented answered a compiler bug with the very state
validateHead calls one. The span is the doc's precondition now — and
7df4812 made that precondition true: error recovery could put a token that
spells nothing at a span's start, so \tx = 1 was quoted from the tab.
noteSpelled already took the last token a source spells; it takes the first
the same way, and parseStatement states no span of its own.

A third round found one more, fixed in 1f7eb9a: dedent measured the raw
line, so a comment inside a multi-line statement held the whole statement
back. A comment at column one — which Pluto allows anywhere — measured as no
indentation and left a body statement four columns right of where it belongs;
a tab-indented comment did the same, since counting leading spaces stops at
the tab. Text now cuts every line's comment first and measures what is
left.

Review fixes

Two reviews of 380cf9c found three ways the text view hid a difference, each
reproduced through -emit-pir and fixed in a3d5aaf:

  • A line terminator read differently depending on its spelling. writeHead
    split on LF alone, so a CRLF left a stray \r at the end of the row it
    broke and a lone CR never broke at all — and a lone CR and the escape \r
    both printed \r in the operand while the first runs as 0a and the second
    as 0d. Every terminator the language counts as one now reads as one.
  • An invisible rune lost its spelling. escapeControls left the format
    characters raw, so a zero-width space between two letters rendered as
    nothing — in the source since this branch, in an operand all along. It now
    spells out every rune Unicode calls unprintable, with \U past the BMP
    where the old \u truncated.
  • A line of spaces lost four columns in a function body. indent skipped
    it as blank, since TrimSpace empties it. Only an empty line is skipped
    now, which is what separates a plan's sections.

TestRenderSource closes the coverage gap the second review measured —
writeHead was the one renderer below full statement coverage, and removing
escapeControls from it left the suite green. Four mutants, one per fix, each
kill named subtests. b0fbf45 corrects §12, which called the source the
statement "as written" when the compiler renders stmt.String(), and
18eabfa narrows the guarantee a third review read literally: a physical tab
and a \t escape do render alike, and should, since both emit 09.

Tests and docs

136 golden lines across compiler/pir_test.go, pir/pir_test.go,
emit_pir_test.go and docs/Pluto IR Plan.md;
TestRenderEscapesControls' line count follows the extra line;
TestPlanGoldenMultilineString's comment now says what the two spellings are
for. §12 gains the source rule as its own paragraph.

🤖 Generated with Claude Code

thiremani and others added 30 commits November 23, 2026 15:44
A plan's source was one quoted line, so every quote inside it was escaped
and a block-layout literal was a single line of \n sequences. The label
now stands alone and the statement's lines sit one level in, as its author
wrote them:

    assign scores
        source
            scores = [
              : Name Score
                "Ada" 10
            ]

Within a line every control character is still escaped, so a source never
goes invisible and never breaks the layout; only a line break becomes a
line. That drops the escaping from 126 of the 129 source lines the tests
and docs hold, 43 of which carried an escaped quote.

A node's operand keeps the opposite rule, one line with its line breaks
escaped, which §12 now states separately. The two disagree for a string
literal that spans lines: the source shows the continuation shifted to the
section's indent, while the operand beside it is exact, and
TestPlanGoldenMultilineString pins both spellings together.

Machine code is untouched: all 89 fixture executables have an identical
__text, and with every source section elided the plan text over master's
fixtures is byte-identical, 4,115 sections on each side.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Two reviews found three ways the text view hid a difference, each
reproduced through -emit-pir.

A line terminator read differently depending on how the file spelled it.
writeHead split on LF alone, so a CRLF left a stray \r at the end of the
row it broke and a lone CR never broke at all; worse, a lone CR and the
escape \r both rendered \r in the operand while the first runs as 0a and
the second as 0d. Every terminator the language counts as one — LF, CRLF
and CR (README) — now reads as one, so a terminator breaks a source line
and prints \n in an operand, and only an escape in the source prints \r.

An invisible rune lost its spelling. escapeControls escaped controls and
the line and paragraph separators, which left the format characters raw:
a zero-width space between two letters rendered as nothing at all, in the
source since this branch and in an operand all along. It now spells out
every rune Unicode calls unprintable, with \U for one past the BMP, where
the old \u truncated.

A line of spaces lost four columns in a function body. indent skipped it
as blank, since TrimSpace empties it, so a multi-line string's middle
line sat at nine columns where the margin alone is twelve. Only an empty
line is skipped now, which is what separates a plan's sections.

TestRenderSource covers what writeHead renders: a source of several
lines, an empty line, a line of spaces and a line of one tab, controls,
invisibles, a raw quote and backslash, CR and CRLF, and each of those a
function body indents. TestRenderEscapesControls gains the operand side
of the terminator and invisible rules. Four mutants, one per fix, each
kill named subtests.

Machine code is untouched: all 89 fixture executables still have an
identical __text, and with every source section elided the plan text over
master's fixtures is still byte-identical, so no operand in the fixtures
moved either.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
§12 called the source the statement "as written", which a review noted it
is not: the compiler renders stmt.String(), so an operator root carries
the pair it wraps itself in (`d = (Twice(d) + 1)`) and a block literal's
rows carry the ast's indentation rather than the file's. The rule now says
so, states that LF, CRLF and CR each count as one terminator, and names
what a line escapes. The sentence about `commit` and `advance`, left
tacked onto the end when this paragraph split in two, goes back to its own.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
A review read §12's "no two statements render alike" literally and found
the counter-example: a physical tab and a `\t` escape render the same
`\t`, and so they should, since both hold one tab and emit 09. The same
goes for a physical line break and a `\n` escape, which both emit 0a. What
the rules rule out is two statements that DIFFER rendering alike, which is
exactly what a CR used to do against `\r` — one emits 0a, the other 0d.
§12 now says that, with the tab as the named harmless case.

a3d5aaf's subject overclaims the same way; it stays as it was pushed.

logicalNewlines cites lexer.LogicalRune rather than the README, since the
lexer is what it has to agree with: it reads CRLF and a lone CR as one
`\n` and nothing else, which is the set this mirrors.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
A plan quoted the ast's rendering of its statement, which spells out its
own nesting: every infix and prefix expression parenthesises itself, so
`b = a + 2 * 3` read `b = (a + (2 * 3))` and `5a` read `(5 ⋅ a)`. Stripping
those at the top only moves the problem, since the ast adds them for a
reason — the parser's precedence oracle is exactly that spelling.

So a statement now carries the text its file gives it. The lexer keeps the
input's lines and notes where each line's comment starts, and Text quotes a
span: the lines it covers, each cut before a comment that line ends with,
dedented to the line it starts on so a caller can place them at its own
level. Every terminator the language counts as one ends one line, as
LogicalRune reads them. The parser fills Src from the token a statement
started at to the one it ended on, for a let and for a print.

Nothing reads Src yet. The ast's own String stays as it was, so the
precedence oracle keeps the spelling it asserts.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
A plan's source is now the text the file spells the statement with, so the
parens it shows are the ones its author wrote:

    b = a + 2 * 3          was  b = (a + (2 * 3))
    n = -a                 was  n = (-a)
    h1 = "foo" ⊕ "bar"     was  h1 = ("foo" ⊕ "bar")
    imp = 5a               was  imp = (5 ⋅ a)
    hc = a > 2 7           was  hc = (a > 2) 7
    f = -8 >> 1            was  f = (-8 >> 1), the line's comment cut

A statement no file spells — one a caller built — falls back to the ast's
rendering, which is what pir's own hand-built plans carry.

The operand lines are unchanged: a node is one line, and what it shows is
the ast's spelling, parens and `⋅` included. So a reader sees what they
wrote beside what the planner made of it, which is the split §12 already
draws.

Every one of the 52 golden source blocks was checked to differ from its
old text only inside the source section before it was replaced. All 89
fixture executables have an identical __text, and with every source
section elided the plan text over master's fixtures is byte-identical.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…ement

Text moved every line of a span left and trimmed every line's trailing
space, including the lines a string literal runs into, where those
characters are what the string holds. Two reviews found four ways that
shows, each on a program that compiles without a single error.

A function body chopped its strings. `s = "line one` with `line two"`
flush-left under a four-space body lost four runes of content, printing
` two"`, and a closing line shorter than the indentation vanished whole,
leaving the quote open. A line a string runs into is no longer moved.

Trailing space inside a string disappeared even at the script root:
`"hello   `, a line of one space and a line of one tab all rendered as if
empty, so three different strings rendered alike — which is what §12 says
cannot happen, and which reinstated, one stage earlier, the space-only
line a3d5aaf had just fixed. The pir tests passed throughout because they
hand Head.Source over directly, never reaching the lexer. A line a string
runs into is no longer trimmed.

A table's `:` header may hang two columns left of its rows, so a body's
header can start left of its own statement; dedenting by the statement's
indentation deleted it. The dedent is now the least indentation any line
of the span has, which keeps the header and its alignment both.

Text panicked on a column below one rather than reporting no span.

Tests: the four cases in the lexer, the two string shapes through the
parser, and TestSpellingReparses, which parses each statement's spelling
on its own and compares the statement it gets back — an oracle that holds
whatever the span drops or adds. Each fix dies under one mutant, named.

Lines is unexported, since Text is its only caller and it hands out the
slice it keeps. The renderer's comments now say the source is the file's
text with the ast as its fallback.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
A comment inside a statement of several lines held the whole statement
back. dedent read the raw line, so a comment at column one — which Pluto
allows anywhere — measured as no indentation at all and the statement kept
its body's four spaces, printing `out =` at sixteen columns where it
belongs at twelve. A tab-indented comment did the same, since counting
leading spaces stops at the tab, and a comment at column two left one.

Text now cuts every line's comment once, measures the dedent over what is
left, and applies the dedent and the trailing trim to those same lines.
A line its comment leaves blank holds nothing, so it no longer counts.

Two reviews reported it and gave the same two shapes, both tested: a
comment at column one inside a body's block literal, and one indented
with a tab. `b = ((a))` joins the spelling expectations, since parens an
author wrote are what this change is for, and only an exact expectation
pins them — TestSpellingReparses compares the ast's rendering, which
reads `b = ((a))` and `b = a` alike.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The builder fell back to the ast's rendering where a statement carried no
source of its own. Nothing produces that: the parser is the only place a
let or a print statement is built, and both of its statement loops spell
every one it returns. The fallback's only exercise was the test written
for it.

What a plan with no source actually wants is to say so, and it already
does — validateHead rejects an empty head source, a rule TestValidateRejects
and TestValidatePrintRejects both pin, and lowerPlanned turns that into an
ICE. With the parser spelling nothing, compiling `a = 5` now reports

    internal: invalid plan for "a = 5": plan assign a has no source rendering

rather than quietly printing a plausible source line and hiding the bug.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Src's comment still offered String() as what a statement carries where a
file spelled none, which 4600507 removed. It matters more than a stale
phrase usually would: NewScriptCompiler takes an ast a caller built, so
the field's comment is where such a caller learns that a plan requires a
spelling, and that validateHead rejects a plan without one.

escapeControls kept the absolute claim that no two statements render
alike, which 18eabfa narrowed in §12 for the reason a review gave: a
physical tab and a `\t` escape render alike, and should. It now says what
holds — two statements that differ never render alike.

While here: 4600507's message names TestValidatePrintRejects for the rule
that rejects a print plan with no source. The test is TestValidatePrint,
whose NoSource case carries it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
A token carried where it starts and nothing about how far it runs, so
quoting a statement had to rebuild it from whole lines and keep two side
tables to undo what that swept in: where each line's comment begins, and
which lines a string literal runs past. Both are bookkeeping for a
reconstruction that offsets make unnecessary.

Pos and Len say where a token's source spelling begins and how long it is.
The lexer knows both already: tokenAt runs at the token's first rune, and
lex leaves the input just past the token it returns, so one funnel gives
every token its length — including the ':' and ']' the layout rules lex
ahead of the line they start, which go through the queue rather than
straight out, and which this was getting wrong until the funnel covered
them too. A layout token spells no source and says so with a zero length.

TestTokenExtents is the oracle: for every token a source spells, the runes
at Pos run exactly as long as Len and read as the token's own spelling.
Nothing uses the fields yet.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Text rebuilt a statement from the lines it covered, so it swept in a
comment the statement never reached and had to cut it back out, and it
reshaped every line it took, so it had to be told which lines a string
literal ran through. Those two side tables, the line cache they read, and
the four bugs they cost are all bookkeeping for the reconstruction.

Spelling takes the span instead: the input from the first token's start to
the last token's end. A comment past the statement is simply not in it. A
line after the first moves left by the indentation the first stands at, or
by its own leading spaces where it has fewer, so nothing a line spells is
ever cut — a table's hanging `:` keeps its colon without a span-wide
minimum. The literals a statement spans say which lines hold a string's
own characters: one a literal runs into is not moved, one it runs out of
is not trimmed.

The parser keeps what that needs as it consumes tokens: the last token a
source spells, since the layout token a statement ends on reaches past it,
and the string literals in between. Both reset per statement and die with
it, where the maps lived as long as the lexer.

One rendering change: a comment between two of a statement's own tokens
now reads as the author wrote it, where it used to leave a blank line. No
fixture or golden holds one, so none moved; §12 says so, and
TestSpellingReparses gains the shape to pin that it still parses.

The lexer loses 32 lines net. comments, stringBreaks, lines, dedent, Text,
noteComment and noteStringBreak are gone.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
… one

Two reviews of the token-span rewrite found four faults, each reproduced.

A shift operator was made after its run had been read, so `>>` carried the
position of its second `>` and spelled `>`, and `>>>` spelled `>>`. It is
made at its first rune now, which also puts its reported column there. The
extent oracle covers the shifts, the comparisons, a float opening with a
dot, and a table header, the other token the layout rules lex ahead.

Clamping each line's indentation on its own moved a table's hanging `:`
and its rows by different amounts, so the header stopped standing against
them and the text no longer parsed. A span moves as one again: the margin
is the least indentation its lines can all spare, the first line carries
what it keeps, and a blank or comment-only line neither sets the margin
nor loses more than it has — which is what let the per-line clamp in.

Walking every literal for every line cost a statement quadratic time.
Lines and literals are both in source order, so one forward pass settles
each. On an 8,000-row table of strings: 118ms before, 5.5ms after.

Spelling guarded a span too loosely for an exported function: a column
before the first, a position outside the input, a length below zero or a
reach past the end each slid past it into a panic. All of them, and both
margin rules, are named cases now.

A split operator kept neither half's runes. `√-x` left two tokens with no
extent at all, which no plan reads today but a diagnostic would.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
margin decided whether a line was blank or a comment after trimming
spaces alone, and Pluto allows a tab on either. So a tab-indented comment
and a line of one tab each counted as a line of the statement with no
indentation at all, dragging the margin to nothing and leaving the whole
statement four columns right of where it belongs. Both shapes compile
without an error; both are reported.

This is the second time that pair has broken, and the second time a test
that pinned it went out with a rewrite rather than with a decision.
TestSpellingMovesASpanAsOne quotes an indented span the way a body's
statement is quoted, so the tabbed comment, the tab-only line, the hanging
header, a flush-left comment and two literals on one line are all pinned
in the lexer rather than only through the parser.

Spelling measured the reach past its last token by adding to its start,
which a length a caller invented could carry past what an int holds. It
compares against what is left of the input instead.

The pieces a split operator leaves had no test: putting the old code back
passed the whole parser suite. An ast-level case reads `√-x` and asks each
piece for the runes it spells.

§12 describes the common margin, which has replaced the per-line clamp
since 20afc33 but was still written as one.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Recording a statement's tokens was started in one place, fed in another,
and finished by two callers that each had to remember it. A path that
parses something else entirely — a code file's declarations, which no plan
is built from — fed the recording without ever starting or finishing it,
so every string token in such a file was kept for as long as the parser
lived. A file of 10,000 string constants held 10,000 of them, about
870 KiB; a script held none, since every statement there resets.

parseStatement starts the recording and, on a named return, hands the
statement its spelling before it goes. noteSpelled keeps nothing while no
statement is being parsed, so the declaration path now keeps nothing at
all — len and cap both zero where they were 10,000 and 11,161 — and the
two statement loops lose a responsibility that was never theirs.

A statement that failed to parse is no longer spelled, where the loops
used to skip it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The retention test asked a parser that had never recorded anything, and
asked it for a length. So it passed with the close removed, and it would
pass again with a buffer emptied but kept: a `.pt` file holding a function
and then string constants would retain them all and nothing would say so.

Each case now puts a function first, so the recording has been on and has
to have been closed, and asks for the buffer's capacity. One body parses
and one does not, since a statement that fails takes its own way out of
parseStatement: with the close removed both cases fail, and with it moved
below the nil return only the failing body does.

The let inside parseStatement no longer shares the name of the statement
that function returns. A nil *ast.LetStatement is not a nil ast.Statement,
so it has to be named and tested rather than returned straight through,
but naming it after the return meant a reader had to work out which one
the deferred spelling reads.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Spelling opened with seven clauses on its two tokens, and not one of them
can hold. The parser is its only caller, and it hands over tokens this
lexer made, taken after skipIndented so both spell source of their own, in
the order it read them. A length above zero, a position inside the input,
a column from one and a first at or before a last are what a token the
lexer produced already is.

They came in as a review asked the exported function to defend itself,
and a second asked the arithmetic in that defence to be overflow-safe.
Both requests were right about the check they were looking at; neither
asked whether a check belonged there. Returning "" for a span a caller
invented is also the wrong answer to it: an empty source is the state
validateHead calls a compiler bug, so the check turned one bug into
another, reported further from where it was made.

The span is the doc's precondition now, and 47 lines of tests for the
answers it used to give are gone with it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The precondition 71f4dca wrote down was not true yet. parseStatement took
the token it first saw as the span's start, and error recovery can put a
token that spells nothing there: an indent of tabs is reported and lexed as
a token of its own, the expression parser steps over it, and the statement
after it was then quoted from the tab. `\tx = 1` spelled "\tx = 1" rather
than "x = 1". It panicked at neither end, since Spelling reads first.Pos
and not first.Len, which is why the guard it replaced never caught this
either — it answered "" instead, one wrong spelling for another.

noteSpelled already took the last token a source spells, because the layout
token a statement ends on reaches past it. It takes the first the same way
now, so one rule gives Spelling both ends and parseStatement states no
span of its own.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
spanLine carried where each line began and ended, and nothing read those
once the literals had been marked: the margin and the emitting both go by
a line's text and the two bits. They were scaffolding for a second pass
over data the first had just walked.

Splitting the span and marking it are one pass now, so the offsets never
leave it and the type is the three things its readers want. The ordering
that makes one cursor enough — lines read in source order, literals given
in it — is a loop invariant rather than a promise between two functions.

Six lines shorter, and no behaviour: the tabs, the hanging header, two
literals on one line and every line ending still answer as they did.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
content and open said nothing about what they held. They answer whether a
string literal is open at a line's start and at its end, which is the
whole reason either exists: a line that begins inside a literal opens with
the string's own characters, so moving it left would take them, and one
that ends inside a literal ends with them, so trimming it would. A middle
line of a literal of several lines does both.

beginsInString and endsInString say that, and the two rules they guard
read as the rules they are.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
e249d67 renamed the two bits a line carries and replaced the words around
the old name in margin's comment without finishing the sentence, which read
"A line a literal runs begins inside a string holds its characters". It says
what it meant now: a line that begins inside a string holds the string's
characters, so it does not set the margin.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Spelling began its span at the first token, past the indentation of that
token's line, while every later line arrived with its own. The first line
was then padded back with spaces inside the loop that moves the lines left,
which read as indentation made up for the occasion. The span begins at the
start of first's line now, found as indentation() already finds it from
position and column, so every line holds what the file gives it, one rule
moves them all, and margin reads the first line's indentation off the line.

No program that compiles spells differently: all 5,127 statements of the
124 fixture files are byte for byte what they were. The one difference is on
a line the lexer rejects. A statement on a tab-indented line is quoted with
its tab, as written, where spaces standing in for the indentation dropped
it; such a line is an indentation error and never reaches a plan.

That makes the first-spelled-token rule of 7df4812 carry more than it did.
The illegal token a tab is lexed as stands at the tab's column, so a span
begun there would open before the statement's own line: a tab after two
spaces on a file's first line indexes the input at -2. The recovery test's
old input, a lone tab at the start of the file, cannot show that, so it uses
a tab after spaces on a later line, and fails against both the old start
rule and the padding.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A block literal's rows could sit at any depth past the line holding its
'['. A table's header hangs 2 spaces left of its rows, so it could stand
level with its statement, or one column left of it when the rows were one
space in. That was the only layout in which a line of a statement began
left of the statement, and a function body could hold it where a script
could not.

Rows now sit exactly 4 spaces past the line holding the '[', as a body or
a struct definition does past the line that opens it, which puts a table's
header 2 spaces past that line. Rows under a call's continued arguments,
the layout the depth was freed for in 8a371a5, still work: since e58a3c8
the depth is measured from the '[' line, not from the statement.

BREAKING CHANGE: rows at any other depth are an error, and so is a table
header that is not 2 spaces past the line holding its '['. No fixture or
docs example used those layouts.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Spelling took a statement's first line whole and moved every line left by
the least indentation they could all spare, which margin found by reading
each line past blanks, comments and strings. The one layout that needed
it was a table header standing left of its statement, which is no longer
legal.

Every line of a statement now has the indentation the statement stands
at. Spelling starts at the first token and takes that much off each later
line, and a blank or comment line gives up what it has. margin is gone,
and so is the arithmetic that found the first line's start.

Starting at the first token also keeps a recovered statement to itself.
After a tab indent it is "x = 1", where 997da93 gave the tab too, and
after a NUL that ends a comment early it no longer carries the comment's
text; a test pins each. No plan is built from either file. Every
statement in the fixtures is spelled as before.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
c4be762 fixed a block literal's rows at 4 spaces by checking the depth in
the lexer, on the line after any '[' that ends its line. The lexer cannot
tell whether that '[' opens a block literal, so an index broken across
lines, `x = a[` with its next line 2 spaces in, drew "a block literal's
rows are indented 4 spaces" ahead of the real error. It also put a depth
in the lexer, where 49c56fc had left none: the lexer measures and the
parser judges.

That holds for rows again. A rows block's INDENT spells out how far the
rows are past the line holding the '[', the line they hang from, as a
body's spells out how far it is past its block, and the lexer reports
nothing about it. Where the parser opens a block literal's rows it checks
that INDENT as it checks a body's, with the rows' message, so the 4 is
written in the parser alone. Rows at or left of that line spell no
indentation and are reported the same way.

lexer.BLOCK_ROWS_ERR goes with the lexer's check, as INDENT_WIDTH_ERR did
in 49c56fc; the message is the parser's blockRowsErr, and nothing outside
the parser named the constant.

The lexer still places a header line 2 columns right of its ':', the
width of the ':' and its one space: that is what makes a header and its
rows one block of tokens, which is layout rather than a rule about depth.
An index broken across lines whose ']' stands off its line's column still
draws the ']' message after the real one, as it does on master.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
splitOperator clamped the length of each piece it cuts an operator run
into, min(matched, tok.Len) for the first and max(tok.Len-matched, 0) for
the rest. Neither clamp can act. The run's length is the number of runes
in its literal, the matched operator is a prefix of that literal, and the
second piece is only built when something is left, so the first piece is
matched runes long and the rest is what remains.

The clamps came with 20afc33 as a guard against a state no path produces.
All 2,115 operator tokens in the fixtures have a length equal to their
literal's, and TestSplitOperatorKeepsItsRunes fails if either length is
wrong.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
f2cc31a said TestSplitOperatorKeepsItsRunes fails if either piece's length
is wrong. It does not. The test reads the pieces of "√-" from the AST, and
both are one rune, so the remainder given the matched length, or the first
piece given the run's length less the matched one, passed the whole parser
suite. No parse can show the difference: only a prefix run is split, and
every prefix operator is one rune, so the pieces a parse ends with are all
one rune long.

TestSplitOperatorPlacesItsRemainder calls splitOperator on "√--", whose
pieces are one rune and two, and checks that each spells its own runes. It
also checks each piece's column, which no parser test pinned: a remainder
left at the run's column passed too.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
parseExpressionTail called normalizePeekInfixOperator to split a run such
as "*-" at its longest infix operator. It never split one. The loop first
compares the run's precedence, and only a run that is an operator itself
has one, so a run that could be split stopped the loop before the call
and a run that reached the call matched whole. `a*-b` has always been an
operator "*-" that nothing defines, which is the rule the language keeps:
a run of operator characters between two values is one operator.

The call goes, with normalizePeekInfixOperator, the OpType switch that
chose between the prefix and infix tables, and findLongestOp's infix arm.
splitOperator splits a run that begins a value at its first prefix
operator, the one thing it ever did, and says so.

TestOperatorRunBetweenValuesIsOneOperator pins the reading of `a*-b`. No
statement parses differently: the fixtures' 5,127 statements are what
they were.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A run of operator characters that names no operator was never reported
as one. It ended the value before it, and whatever came next complained:
`x = a*-b` said "no prefix parse function for *- found", `x = f(a*-b)`
said "expected next token to be ), got OPERATOR", and `a @= 2` blamed the
`a`. When the run was made of prefix operators nothing complained at all:
`[a-√b]` was two cells, `a` and `-√b`, and `x = a > 1-√b` was the
condition `a > 1` with the value `-√b`.

A run is one operator. Attached to the value before it, it stands between
two values, so it has to be an operator that takes two, and one that
nothing defines is reported at the run as `operator -√ is not defined`.
After a space, a run made of prefix operators begins the next value where
one may begin: a row's next cell, or a statement's value after its
condition. Where no value may begin, as in `x = 1 -√b` and `f(a -√b)`, it
is the same error. At a value's start a run is split only when it is made
of prefix operators alone, so `-*b` is an undefined `-*` and not a
negation of `*b`.

Operators that are defined keep their reading. `*` before a value still
has "no prefix parse function for * found", and a prefix-only operator
begins a value wherever it stands, so `[a√b]` is still two cells, as
tests/array/array_neg.spt pins.

The docs state the rule beside the one for cells, with the three
spellings of `a`, `-` and `√b`.

BREAKING CHANGE: a run of prefix operators attached to the value before
it no longer begins a new value. `[a-√b]` printed `[16 -2]` for a = 16
and b = 4 and is now `operator -√ is not defined`; `[a--b]` and
`x = a > 1-√b` fail the same way. Put a space before the run where a new
value is meant (`[a -√b]`, `x = a > 1 -√b`), or spaces on both sides
where one operator is (`[a - √b]`). No fixture, README or docs example
needed the change.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
An array row is the one place the parser reads on after a failure, so
that a later cell can still report its own error. A cell that failed
inside its brackets stopped there, and the row read what was left of it
as cells: `x = [f(a@b, c)]` reported the undefined `@` and then the `,`
and the `)`, three errors for one mistake. A broken index did the
opposite. Its `]` was taken for the row's, so the row ended early and
`x = [v[a@b] c@d]` never reported the second `@`.

The parser now counts the parentheses and square brackets open where a
token stands, kept by nextToken. After each cell the row reads on until
the brackets that cell opened are closed, stopping short of the row's
own `]` and at the end of the line. That is one rule in parseRow; a call,
a group and an index need no recovery of their own, and none of them can
tell its own closer from one an inner failure stopped on. Each cell
counts from where it starts, so a stray `)` earlier in the row changes
nothing for the cells after it.

`[f(a@b, c)]` and `[(a@b) c]` now give one error each, `[f(a@b, c) d@e]`
two, and `[v[a@b] c@d]` both of its own. Outside a row nothing changes:
a statement that fails skips its line, as before.

One row reports less. Where a `)` is missing altogether the row cannot
tell where the call ends and reads to its own end, so `[f(a b c@d]`
gives the missing `)` and not the `@` behind it, which shows once the
first is fixed. No row reports an error that is not there.

The counts are exact for brackets that nest. A stack that knew each
bracket's kind would also read on in `[[f(a b] c@d]`; it is not built.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
thiremani and others added 9 commits November 26, 2026 09:35
spell returned early for a nil statement. Its switch already does nothing
for one, since nil is neither of the two statements a plan quotes, so the
test only saved computing a spelling nobody reads.

Spelling is still handed tokens it can quote: a statement starts at a
token its source spells whether or not it parses, so the span is one of
this input. The two cases stay two, because Src is a field of each
statement and not of ast.Statement.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Attach the source directly when returning a let or a print, and stop recording on every exit. A code file whose function has no indented body can return nil without recording a source token. Preserve its parse diagnostic without sending an empty span to the lexer.
Decompose a validated run together and queue its tokens in source order. This avoids walking all remaining suffixes at every recursive prefix parse while preserving each operator’s position and leading-space flag.
A comma starts another positional value. Only the initial expression can introduce a statement condition. Report a space-prefixed run such as -√ at the run itself when it follows a positional value.
Show why a root can start an attached array cell while a combined prefix run requires a leading space. The examples describe the spacing used by existing rows and the migration for attached runs.
7597f31 stopped splitting at a spaced prefix after a comma, and its one
test is the error for an undefined run, `x, y = a, b -√c`. Nothing pinned
what the change does to a defined operator: with the old split put back
for defined operators alone, every test passed.

TestCommaStartsPositionalValue parses `x, y, z = 1, n -1, b > 2 -5` and
checks that the statement has no condition and the values `1`, `n - 1`
and `(b > 2) - 5`. The two items are the two shapes master rejected with
"a statement condition is a single expression", one after an identifier
and one after a comparison. That mutant now fails it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
normalizeCurrentPrefixOperator returns early for an operator that is one
prefix operator already. Without that return the parse is the same, so no
test noticed, but the function then rebuilds the queue of waiting tokens
for every operator of a run it has already split. 4,096 `-` before a
value allocate 689 MB against 1.94 MB, which is the quadratic cost
b733155 removed, back in memory instead of time.

TestSinglePrefixOperatorIsNotRequeued asks for no allocation when the
current token is a lone `-`. It measures one with the early return
removed. A count needs no timing threshold, and it holds under the race
detector.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A cell that failed at its row's own ']' left the row reading on. parseRow
stepped past the token every cell ends on, which here was that ']', and
took what followed the literal for cells: `x = f([1 +], 9)` reported the
missing operand and then the `,` and the `)`. master does the same.

The bracket counts already say when this has happened. A closer counts as
soon as it is current, so once a cell leaves fewer square brackets open
than it started with, the row's own ']' has been reached, and the row
stops there. An index the cell opened and closed leaves the count where
it was, so `[v[1 +] c@d]` still reads its second cell.

`x = f([1 +], 9)` goes from three errors to one, and
`x = [f([1 +], 9) c@d]` from four to its two real ones.

40f6b12 said no row reports an error that is not there. That was wrong,
and this is the case that shows it. What was measured since: of 276
inputs holding one fault each, in rows, calls, groups and indexes, 34
reported more than one error before this change, all of this kind, and
each reports exactly one after it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A statement's source ran from its first token to its last. A comment
after the last token was outside that span and was cut, while a comment
any earlier line of the statement ended with lay between two of its
tokens and was kept:

    v = [ # opens
        "Ada" 1 # top scorer
    ]                           "# closes" was cut here

A one-line statement has only a last line, so its comment was always
cut. The source now runs to the line break that ends the statement, so
every line keeps what it ends with: `t = x * 2 # doubled` is spelled
whole. A blank left after the last token or the comment is still
trimmed, and the lines around the statement are still not part of it.

Spelling takes that line break in place of the last token. A statement
that parses leaves the parser on it, so the parser hands over its
current token and no longer tracks the last token a source spells.

36 of the fixtures' 5,127 statement sources change, each by gaining the
comment its last line ends with, and nothing else in any of their ASTs
does. No golden plan held such a comment, so no plan text in the tests
or the docs moves.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@thiremani
thiremani merged commit c85d326 into master Nov 26, 2026
2 checks passed
@thiremani
thiremani deleted the pir-source-lines branch November 26, 2026 06:44
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.

2 participants