Commit 41eef25
committed
feat(newline): 'terminator' mode, a NEWLINE at every line break
newline mode was built for dotenv-style grammars, but its NEWLINE is a
statement SEPARATOR: one token between two content-bearing lines, placed
at the start of the later line, with blank and comment-only lines
collapsed and nothing before the first or after the last line. A grammar
whose AST keeps blank lines and comments as lines (env-spec: File =
many(Line), Line = Stmt NEWLINE? | NEWLINE) cannot be written on that,
which is why env-spec sits on indent mode today with INDENT/DEDENT
filler in every rule and an indent-stack tree-sitter scanner it never
uses.
NewlineConfig.mode: 'terminator' emits one NEWLINE at EVERY block-context
line break, placed at the break: blank lines, comment-only lines,
leading and trailing breaks included; breaks inside flow delimiters stay
suspended; a final line with no break has none. Positions are exact per
line, so a blank-line node maps to its own line. This is also the shape
the derived tree-sitter scanner already has (stateless, one NEWLINE per
break where the grammar permits one), so the two agree more closely than
in separator mode. 'separator' stays the default and is byte-identical.
The emitted engine inherits the mode through the createLexer fallback.
The portable TS/Go/Rust newline lexers on the portable-newline-mode
branch will need the same three emission points once that lands.
Gate: test/newline-mode.ts section 7.1 parent 8c489e2 commit 41eef25
3 files changed
Lines changed: 68 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
306 | 306 | | |
307 | 307 | | |
308 | 308 | | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
309 | 313 | | |
310 | 314 | | |
311 | 315 | | |
| |||
682 | 686 | | |
683 | 687 | | |
684 | 688 | | |
| 689 | + | |
685 | 690 | | |
686 | 691 | | |
687 | 692 | | |
| |||
696 | 701 | | |
697 | 702 | | |
698 | 703 | | |
| 704 | + | |
699 | 705 | | |
700 | 706 | | |
701 | 707 | | |
| |||
728 | 734 | | |
729 | 735 | | |
730 | 736 | | |
731 | | - | |
| 737 | + | |
732 | 738 | | |
733 | 739 | | |
734 | 740 | | |
| |||
811 | 817 | | |
812 | 818 | | |
813 | 819 | | |
| 820 | + | |
814 | 821 | | |
815 | 822 | | |
816 | 823 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
438 | 438 | | |
439 | 439 | | |
440 | 440 | | |
441 | | - | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
442 | 454 | | |
443 | 455 | | |
444 | 456 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
170 | 217 | | |
171 | 218 | | |
0 commit comments