Repository navigation
feat(pir): print a plan's source as the statement's own lines - #178
Merged
Merged
Conversation
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>
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>
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.
A plan's
sourcewas one quoted line, so every quote inside it was escaped anda block-layout literal collapsed into a line of
\nsequences. The label nowstands 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
c4be762tightens the layout rules. It is a language change, and it is inthis PR because the
sourcetext relies on it.holding its
[, which puts a table's header:2 spaces past it. A bodyand a struct definition already took exactly 4.
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.depth is measured from the
[line; where the]goes; how a list'scontinued items line up.
[line. Nothing inthis 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 thestatement and could not otherwise sit under continued arguments.
e58a3c8measured them from the
[line a day later, which gives that layout at afixed 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 thestatement, and a function body could hold it where a script could not.
The depth is judged in the parser (
0455967).c4be762checked it in thelexer, on the line after any
[that ends its line, so an index broken acrosslines 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'sINDENT spells out how far the rows are past the line holding the
[, and theparser checks it where it opens a block literal's rows, as it does for a body
and a struct definition.
lexer.BLOCK_ROWS_ERRis gone with the lexer'scheck, as
INDENT_WIDTH_ERRwent in #141; the message is the parser's, andnothing 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
6bf6693is the second language change. It is in this PR because it came outof the split-operator work above:
f980ba1first removes the infix half ofoperator 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 nooperator 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:
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*-bsaidno prefix parse function for *- found,x = f(a*-b)saidexpected next token to be ), got OPERATOR instead, anda @= 2blamed theaat column 1. All three now sayoperator *- is not definedoroperator @ 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 aprefix-only operator begins a value wherever it stands, so
[a√b]isstill two cells, as
tests/array/array_neg.sptpins.[a -√b]is twocells 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 operatoris (
[a - √b]). Nothing in this repository needed it: all 5,127 fixturestatements parse as they did at
5feaade, and no README or docs exampleholds such a run.
docs/Pluto Conditional Value Semantics.mdstates the rule beside the onefor 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.
40f6b12fixes that:5feaade[f(a@b, c)]@, then,and)@[(a@b) c]@, then)@[f(a@b, c) d@e]@[v[a@b] c@d]]ended the row@[f(a b c@d]), then@)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 recoveryof 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
)missingaltogether 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 forbrackets 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], sox = f([1 +], 9)reported the missing operand and then the
,and the).126f725ends therow 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; eachnow reports exactly one. That is what was measured, not a proof about every
row.
TestFailedCellTakesItsBracketshas four rows, each the only test thatcatches some wrong version of the rule: 20 mutants, all caught.
FuzzParseran 3.8 million inputs on the final text without a panic or a lost statement.
f13f523droppedspell's early return for a statement that failed, on theclaim 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
.ptfile holdingr = F()followed by an unindentedxpanicked inSpelling.ba9f7bfattaches 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.
6bf6693checked a whole run at every split, which made a long prefix runquadratic: 8,000
-before a value took 4.6 s, against 5 ms at5feaade.b733155splits a validated prefix run into its tokens together, preservingeach token's rune offsets and the following lookahead; 32,000 take 32 ms.
7597f31parses items after a comma as positional values, since only astatement's first expression can be its condition.
x, y = a, b -√cnowreports the undefined operator at
-√. It also changes what a spaced minusmeans after a comma:
x, y = 1, n -1is1andn - 1, as it already wasin the value list after a condition. On master that statement, and
x, y = a > 1, b > 2 -5, were rejected witha statement condition is a single expression; both now compile.e82680adocuments the attached,named prefix case with
[a√b].Two tests pin what a review found unpinned.
0976ecbaddsTestCommaStartsPositionalValue: putting the old split back for definedoperators alone passed every test, and now fails it.
52e7a1faddsTestSinglePrefixOperatorIsNotRequeued: without the early return for anoperator 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
-allocate689 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
5feaadebyte for byte.gofmt,go vet ./...,go test -race -count=1 ./...andpython3 test.py --leak-check, 91 of 91 under its ownPTCACHE, pass on6d774de.Before and after
Within a line everything a reader could not otherwise see is still escaped —
escapeControls, the helper an operand already uses — so a source never goesinvisible 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
\tescape among them; what the escaping rules out is two statementsthat 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.Quotedoublingbackslashes:
quoteText = "hello \"world\"\\path\nnext\tcol"now prints aswritten.
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
sourceshows the continuation shifted to the section'sindent, while the operand beside it is exact.
TestPlanGoldenMultilineStringpins both spellings together, so the trade iswritten 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
__text.sourcesection elided, the plan textover master's fixtures is byte-identical — 4,115 sections on each side.
gofmt,go vet ./...,go test -race ./..., andpython3 test.py --leak-check91/91 under its ownPTCACHE.The source is the file's text
64058e0and3b73aefanswer the question the layout invited: which parensbelong in a
sourceline. The answer is the file's own, because the ast'srendering 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 (
PosandLen,8000a3d), soSpellingquotes theinput 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 planquotes it — and nothing else. Every statement a plan is built
from comes from a file, and
validateHeadalready rejects a head with nosource, so a parser that stopped spelling reports
internal: invalid plan for "a = 5": plan assign a has no source renderingrather than printing a plausible line and hiding the bug (
4600507).The last line keeps its comment since
6d774de. Until then a source endedat 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:
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.
Spellingtakes that line break in place of the last token, whichthe 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 spellingit 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.Textdamaged a statement that spanslines, 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'strailing 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 aone-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
a3d5aafhad just fixed — thepirtests keptpassing because they hand
Head.Sourceover directly and never reach thelexer. A table's
:header, which may hang two columns left of its rows, wasdeleted when a body statement's indentation was subtracted; the dedent is now
the least indentation any line of the span has. And
Textpanicked on acolumn below one.
The verification note the first review made is right: eliding
sourcesections proves nothing about them. Two things cover them now. The exact
spelling expectations in
TestStatementSpellingandTestStatementSpellingInBodypin the text itself,b = ((a))among them,since parens an author wrote are what this change is for.
TestSpellingReparsespins 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))andb = aalike — so the two are needed together. Each fix dies under one namedmutant.
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,dedentandTextare all gone and thelexer 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 standsagainst 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 everyline of a statement has the indentation the statement stands at, so
Spellingstarts at the first token and takes that indentation,
first.Column - 1, offeach later line; a blank or comment line gives up what it has, and a line a
string runs into is left alone.
marginis deleted, with the three kinds ofline 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 spelledfrom its first token:
x = 1after a tab indent, and after a NUL that ends acomment early it no longer carries the comment's text, which
997da93copiedin. 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 linewhole and trims its blanks, which only the NUL case catches. The hanging-header
case of
TestSpellingMovesASpanAsOnewent with the layout it tested.The span's first line was taken whole in
997da93.Spellingbegan at thefirst 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
PosandColumnthe wayindentation()already finds it,so every line holds what the file gives it, one rule moves them all, and
marginreads the first line's indentation off the line. No program thatcompiles 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,
d7200ecfolded the marking ofstring lines into the pass that splits them,
e249d67named a line's two bitsafter what they test, and
8ac6b95finishes a sentence inmargin's commentthat rename left half-swapped.
A seventh round found that recording a statement's tokens had three owners —
started in
parseStatement, fed bynextToken, finished by two loops — sothe 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.
700cae1givesparseStatementthe whole job, so thedeclaration path keeps nothing at all and the loops lose a responsibility that
was never theirs.
82ad719then made the regression test able to fail: it hadasked 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
nilreturn fails only thefailing body.
A sixth round found the last of it, fixed in
9b24ccf:margindecidedwhether 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.
TestSpellingMovesASpanAsOnenow quotes an indented spanin 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
√-xand asks each split piece for the runes it spells, whichputting the old code back no longer survives.
A fifth round found four faults in that rewrite, all fixed in
20afc33. Ashift operator was built after its run had been read, so
>>spelled>and>>>spelled>>; it starts at its first rune now, which also corrects itsreported 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 theheader 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.
f2cc31agives the pieces their plain lengths.TestSplitOperatorKeepsItsRunescould not tell one piece's length from theother'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.
5feaadeaddsTestSplitOperatorPlacesItsRemainder, which splits√--directly and fails if either length or the remainder's column is wrong.
Spelling's span guard, askedfor 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 madein 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
validateHeadcalls one. The span is the doc's precondition now — and7df4812made that precondition true: error recovery could put a token thatspells nothing at a span's start, so
\tx = 1was quoted from the tab.noteSpelledalready took the last token a source spells; it takes the firstthe same way, and
parseStatementstates no span of its own.A third round found one more, fixed in
1f7eb9a:dedentmeasured the rawline, 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.
Textnow cuts every line's comment first and measures what isleft.
Review fixes
Two reviews of
380cf9cfound three ways the text view hid a difference, eachreproduced through
-emit-pirand fixed ina3d5aaf:writeHeadsplit on LF alone, so a CRLF left a stray
\rat the end of the row itbroke and a lone CR never broke at all — and a lone CR and the escape
\rboth printed
\rin the operand while the first runs as0aand the secondas
0d. Every terminator the language counts as one now reads as one.escapeControlsleft the formatcharacters 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
\Upast the BMPwhere the old
\utruncated.indentskippedit as blank, since
TrimSpaceempties it. Only an empty line is skippednow, which is what separates a plan's sections.
TestRenderSourcecloses the coverage gap the second review measured —writeHeadwas the one renderer below full statement coverage, and removingescapeControlsfrom it left the suite green. Four mutants, one per fix, eachkill named subtests.
b0fbf45corrects §12, which called the source thestatement "as written" when the compiler renders
stmt.String(), and18eabfanarrows the guarantee a third review read literally: a physical taband a
\tescape do render alike, and should, since both emit09.Tests and docs
136 golden lines across
compiler/pir_test.go,pir/pir_test.go,emit_pir_test.goanddocs/Pluto IR Plan.md;TestRenderEscapesControls' line count follows the extra line;TestPlanGoldenMultilineString's comment now says what the two spellings arefor. §12 gains the
sourcerule as its own paragraph.🤖 Generated with Claude Code