barmark 0.21.0 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -9,6 +9,194 @@ Releases follow the process in [RELEASING.md](RELEASING.md).
9
9
 
10
10
  ## [Unreleased]
11
11
 
12
+ ## [0.23.0] - 2026-11-10
13
+
14
+ Grammar changes: an unreadable slot keeps its bar, stacked chord
15
+ spellings read, and an ending may continue onto the lines after it
16
+ (Kevin, 2026-11-10). Implements the
17
+ [grammar v0.1 draft](https://github.com/kevinpeckham/barmark/blob/main/docs/grammar-v0.1-draft.md).
18
+
19
+ ### Added
20
+
21
+ - **Stacked chord spellings read, with a warning** (grammar 3, A.5;
22
+ stem-shovel issue 16). Notation programs print alterations run together
23
+ ("D6 add9 omit5"): items run together in one parenthesis
24
+ (`D6(omit5add9)`, `D6(no5add9)`, `C7(b9#11)`) and a bare `omit`/`no`
25
+ trailing the chord's name, after the quality however it is spelled and
26
+ before any parenthesis or slash bass (`Gadd9omit3`, `Gomit5`, `Gno5`,
27
+ `G-7omit5`, `CΔno3`; not `Cno5maj7` or `Cno3add9`) now read as their
28
+ comma-separated form instead of being unreadable. The warning's
29
+ `suggestion` is that form (`D6(omit5,add9)`, `Gadd9(omit3)`,
30
+ `G(omit5)`); the printer writes the canonical form (`D6(9,no5)`), so
31
+ `format` fixes them. Items that are wrong on their own stay errors
32
+ (`C(omit5omit5)`). A chord warning's `suggestion` now reaches the
33
+ chart's diagnostic.
34
+ - **An altered fifth before the parenthesis gets a suggestion**:
35
+ `F#b5(omit3)` is still an error (grammar 3 keeps `Ab5` the A♭ power
36
+ chord), now suggesting `F#(b5,omit3)`. Where the root's accidental could
37
+ be the fifth's, there is no suggestion, and the message says the symbol
38
+ is ambiguous when the fifth reading would itself read (`Gb5(omit3)`,
39
+ as `G(b5,omit3)`; not `Gb5(no7)`).
40
+ - **An ending may continue onto the lines after it** (grammar 5.1, Kevin
41
+ 2026-11-10, stem-shovel issue #16). An ending not closed by `:|` on its
42
+ own line continues through the plain `|` lines after it, up to its `:|`
43
+ or the next ending: `|1 G | A | B | C |` then `| D :|` is a five-bar
44
+ first ending, so a chart keeps four bars a row. The last ending still
45
+ ends at its own line. Each continuation line carries the ending's passes
46
+ as the new optional `continues` on its bar line in the parse tree (A.7),
47
+ and plays on that ending's passes only. Text, credit, lyric-row and
48
+ `---` lines may sit between an ending's lines; a heading, a directive
49
+ line, a `|:` line or a line that can't be read ends it, and a directive
50
+ line that stops an ending continuing is an error naming it. Only the
51
+ endings of a paired repeat continue. A chart that
52
+ read cleanly before reads the same; an ending before the last that runs
53
+ into the next ending with no `:|` now gives one error, "an ending before
54
+ the last goes back with :|", on its first line, where it gave two.
55
+ - **`printedAsWritten(parse)`** and **`unreadSlots(line)`**: the lines the
56
+ printer prints as written (spec §8), and a bar line's unreadable slots,
57
+ so a renderer draws what the printer prints.
58
+
59
+ ### Changed
60
+
61
+ - **An unreadable slot is kept as unknown harmony with its text** (grammar
62
+ principle 4, 2.3, 3). An unknown chord symbol (`CM7`, `CSus4`, `C69`),
63
+ a bad note set (`{H}`), a voicing note not in its chord, a syllable on a
64
+ chord name, a lone `-`, a mark that can't be read (`<<<C`, `+?`) or a
65
+ misplaced or bad dot (`| C. |`, `C._D._E`) is
66
+ still an error with the same message, token and suggestion, so `check`
67
+ still fails; but the slot becomes `{ kind: "unknown", text }` and the
68
+ line keeps its bars, so a chart plays as long as it is written. Only a
69
+ bar line whose structure can't be read (a stray `|:` or `:|`, a bad
70
+ ending or `x N`, an empty group member, `%`, `...`, a direction or a
71
+ mark sharing a cell, an empty cell, a bad `[n/d]`, an unclosed quote)
72
+ is still excluded.
73
+ Before, any error dropped the whole line.
74
+ - **`SimpleSlot`'s `unknown` has an optional `text`** (A.7): the slot as
75
+ written, absent for a written `?`. `printSlot` and `printLine` print it
76
+ as written, a dotted member's dot back in its place.
77
+ - **`format` prints a bar line whose only errors are unreadable slots in
78
+ canonical form** (spec §8), each slot's text as written. A line
79
+ excluded for its structure, or with any other error, still prints as
80
+ written.
81
+ - **`transposeChart` moves the readable chords on a line with an
82
+ unreadable slot** (Kevin, 2026-11-10): `key: C`, `| C | CM7 | G |` to D
83
+ is `| D | CM7 | A |`, with the warning "CM7 can't move: it can't be
84
+ read, so it stays as written" on the slot. A line excluded for its
85
+ structure still stays as written, with "not transposed: this line has
86
+ an error".
87
+ - A part's notes line (7.6) with an unreadable note set has that error
88
+ alone, not a second one for harmony on the line.
89
+
90
+ ### Fixed
91
+
92
+ - A chord symbol with many `add` tones in its parenthesis read in time
93
+ quadratic in its length (20,000 items took seconds); reading a chord
94
+ symbol is now linear.
95
+
96
+ ## [0.22.0] - 2026-11-09
97
+
98
+ A grammar change: a chart's pickup is bar 0 (2.4), which now defines a
99
+ pickup. Charts without a pickup read and number as before. Implements the
100
+ [grammar v0.1 draft](https://github.com/kevinpeckham/barmark/blob/main/docs/grammar-v0.1-draft.md).
101
+
102
+ ### Added
103
+
104
+ - **`ChartParse.pickup`**: true when the chart's first written bar is a
105
+ pickup (grammar 2.4: in a one-bar meter shorter, by value, than the
106
+ meter in force at the next written bar, and that bar not short itself).
107
+ **`opensWithPickup(bars)`** gives the same answer from played bars
108
+ alone. The grammar now defines a pickup.
109
+
110
+ ### Changed
111
+
112
+ - **A pickup is bar 0** (grammar 2.4): in a chart that opens with one,
113
+ every played bar's `written` is one less than before, so bar 1 is the
114
+ first full bar, as notation and the MusicXML export number it; a repeat,
115
+ replay or D.C. that plays the pickup again shows 0 too. Charts without
116
+ a pickup are numbered as before. `index`, the play position, does not
117
+ change, so times keyed by it stay valid.
118
+
119
+ - **A line's passes that sing nothing are one warning.** "pass 3 of this
120
+ repeat sings nothing: its bars have verses 1 and 2" stays as it was for
121
+ one pass; several are now listed together, a run of three or more as a
122
+ range ("passes 1 and 3–9 of this repeat sing nothing: …"), and a list
123
+ past five items shows four and counts the rest ("verses 1, 2, 3, 4 and
124
+ 2496 more"). 2,500 verses over a bar played 10,000 times gave 7,500
125
+ warnings of about 14 KB each (105 million characters, which the site
126
+ rendered as one list); now one of 92 characters.
127
+
128
+ - **The npm homepage is https://www.barmark.dev**, not the package's
129
+ folder on GitHub.
130
+
131
+ ### Fixed
132
+
133
+ - **A bar played many times no longer costs its size on every play.** A
134
+ shared chart of one bar with thousands of lyric syllables, notes or
135
+ slots, repeated thousands of times, made the parse copy every syllable
136
+ for every play (lyrics) and walk every slot of every play twice (the
137
+ pedal warnings, through a matrix of every slot of every played bar):
138
+ seconds to minutes and over a gigabyte from a few kilobytes. A played
139
+ bar now shares its written bar's data: two plays of one bar return the
140
+ same `slots`, `words` and `lyrics[].syllables` arrays (and the same
141
+ `PlayedLyrics` object), which a caller must not mutate; each written
142
+ bar's syllables, pushes and pedal effect are read once per meter it
143
+ plays in. The parse costs the written chart plus the played bars, never
144
+ their product. The parse's data is otherwise unchanged; `pedalStates`
145
+ still builds its matrix for callers that want it, but `parseChart`
146
+ doesn't call it.
147
+ - **A chart of many parts parses in time near linear in its size, not
148
+ cubic.** Each part's projection scanned the whole system for its own
149
+ line at every line it projected, and rebuilt the systems by copying;
150
+ choosing a system's reference line compared every line with every
151
+ other; reading a labelled line re-listed the declared parts; finding
152
+ who sings read every bar line once per part, and gathered the lyric
153
+ rows by copying their list for each row; folding a bar looked for each
154
+ part's streams among all of them. 600 one-bar parts in one system
155
+ (19 KB) took about 9 s; at 50 KB, 1,500 such parts took minutes (now
156
+ 0.9 s), 1,383 parts under 1,383 verses 18 s (now 1.3 s). And each part
157
+ read every line of the chart although it may play only its share of
158
+ the bars: 3,227 parts resting through 2,000 systems one part writes
159
+ took 19 s, 2,113 parts under 6,339 tutti lines 27 s (now 1.1 s each).
160
+ A part of a chart of several now reads at most ten times its share of
161
+ the bars in lines; one that stops there says so ("expansion stopped
162
+ after 0 bars: each of 1000 parts reads at most 100 lines"). Real charts
163
+ read every line: four parts may each read 25,000.
164
+ A third review, and an audit of every loop over parts, voices, lines,
165
+ systems, rows and played bars, found more of the same: each part's
166
+ voice was looked for among every voice and every stream (1,979 parts
167
+ each singing, 50 KB: 59 s, now 0.3 s); a part's own line was looked up
168
+ again at every line of its system, and every part walked every line of
169
+ the chart (800 parts of four lines: 3.3 s, now 0.7 s; 777 parts of two
170
+ lines in two systems: 1.9 s, now 0.6 s), and the parts' score order
171
+ read every system once per part; a lyric row under a replay heading
172
+ was copied onto every part's line of the replayed system (1,354 parts
173
+ and 1,354 replays, each with its own row: 3.8 s, now 0.3 s), and so was
174
+ each row's list of covered lines. Printing a 10,000-bar line counted
175
+ its bars again for every bar (2.2 s, now 0.5 s). A test now parses each
176
+ of these shapes at eight times the parts and fails if it takes twenty
177
+ times as long.
178
+ - **The verses a bar sings count toward the expansion's budget.** Outside
179
+ a repeat a bar sings every verse written over it, so 1,560 verses under
180
+ one bar replayed 5,000 times (55 KB) made 7.8 million verse references
181
+ (1.3 s, 61 MB). Each verse a written bar sings when it plays again now
182
+ counts as work (its first play's are as many as are written), and a
183
+ chart past the budget stops with an error that says so ("expansion
184
+ stopped after 64 bars: the bars played again sing too many verses
185
+ (98,280)"; both numbers count only the bars output, so a bar a
186
+ replay's `->` cuts is not counted, and a bar the budget stops is
187
+ neither sung nor checked): now 0.1 s and 2 MB. Once play stops at any
188
+ limit, the stop is the only report of what it cut short: no "the parts
189
+ fall out of step" for a part that stopped early, and no "verse N is
190
+ never sung" for verses the stop left unsung: a row play never reached,
191
+ or reached in a repeat with passes enough for its verse. A verse its
192
+ repeat can never reach is still reported (`lyrics 3:` under `x2`), stop
193
+ or not. A part whose play ended at `Fine`, after the jump, reports no
194
+ stop for the lines past its share, which it would never have played. Repeats that play too much with no
195
+ bars to count (fermatas) now say "expansion stopped after N bars: its
196
+ repeats play too many times", not the bar cap's "expansion stopped at
197
+ 10000 bars", which is kept for the bar cap itself. Real charts use a tiny share of it: the examples
198
+ and fixtures at most 153 of 100,000.
199
+
12
200
  ## [0.21.0] - 2026-11-08
13
201
 
14
202
  ### Added
@@ -656,7 +844,9 @@ The first working release: the reference parser and printer for the
656
844
 
657
845
  - **A placeholder package that holds the `barmark` name** while the spec and parser are written.
658
846
 
659
- [Unreleased]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.21.0...HEAD
847
+ [Unreleased]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.23.0...HEAD
848
+ [0.23.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.22.0...barmark-v0.23.0
849
+ [0.22.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.21.0...barmark-v0.22.0
660
850
  [0.21.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.20.0...barmark-v0.21.0
661
851
  [0.20.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.19.1...barmark-v0.20.0
662
852
  [0.19.1]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.19.0...barmark-v0.19.1
package/README.md CHANGED
@@ -58,6 +58,7 @@ chart.title; // "Example Song"
58
58
  chart.parts; // [{ label: "Gtr", name: "Electric Guitar 1" }] from part: Gtr = Electric Guitar 1, in score order
59
59
  chart.credits; // { composer: ["Kevin Peckham"], lyricist: [], arranger: [], copyright: [] } from composer: Kevin Peckham
60
60
  chart.bars; // every bar in play order: its number as written, slots, section, key, meter (and in a one-bar meter the time: meter, whose beat tempo counts), tempo, feel (and swingPercent)
61
+ chart.pickup; // true when the first written bar is a pickup (time: 4/4 then | [1/4] G | C |): it is bar 0
61
62
  chart.sections; // each section as played, with its first and last bar
62
63
  chart.diagnostics; // errors and warnings, each with a line number
63
64
 
@@ -195,9 +196,11 @@ an object. It has two kinds of field:
195
196
  - `events` is play order with fermatas and an open repeat kept as
196
197
  events.
197
198
  - `bars` is the same flattened to one `PlayedBar` per measure played,
198
- repeats, endings, jumps and replays spelled out. A bar's `index` counts
199
- in play order; `written` is the number a band reads on the page, the
200
- same on every pass. Each bar carries its slots, section, key, meter,
199
+ repeats, endings, jumps and replays spelled out. A bar's `index` is
200
+ its position in play order, not a bar number; `written` is the number
201
+ a band reads on the page, the same on every pass. A pickup (grammar
202
+ 2.4: a short first bar before a full one) is bar 0, and `pickup` says
203
+ the chart has one; otherwise bars count from 1. Each bar carries its slots, section, key, meter,
201
204
  tempo, feel and, when sung, each verse's syllables (`lyrics`).
202
205
  - `sections` is each section as played, with its first and last bar and
203
206
  `form` (which distinct section it is; replays share their section's
@@ -220,7 +223,8 @@ package's minor versions: 0.17.0, for example, added the `break` and
220
223
  diagnostics with `severity: "error"`; store `printChart(text)` to keep
221
224
  one spelling of each chart.
222
225
  - **Times in a recording** belong beside the chart, not in it: key them
223
- by `PlayedBar.index`, which names the same bar however the chart is
226
+ by `PlayedBar.index`, the play position (not the bar number, which
227
+ is `written`), which names the same bar however the chart is
224
228
  reformatted or its repeats are spelled (`|: :|` or `x2`), until the
225
229
  music itself changes. An open repeat (`x ...`) plays its bars once in
226
230
  `bars`, so its later passes have no index of their own.
@@ -1,7 +1,9 @@
1
- import type { Cell, ChartDiagnostic, Line, Meter, Repeat, Slot, Words } from "./types.js";
1
+ import type { Cell, ChartDiagnostic, Line, Meter, Repeat, SimpleSlot, Slot, Words } from "./types.js";
2
2
  type BarsLine = Extract<Line, {
3
3
  kind: "bars";
4
4
  }>;
5
+ /** Each simple slot of these cells, a group's members each. */
6
+ export declare const simpleSlots: (cells: Cell[]) => SimpleSlot[];
5
7
  /** Whether a cell is a bar: `...`, a direction and a rehearsal mark mark a place between bars. */
6
8
  export declare const isBar: (c: Cell) => c is {
7
9
  kind: "slots";
@@ -28,8 +30,10 @@ export declare function repeatTail(text: string, boundary: boolean): {
28
30
  export declare function misplacedRepeat(token: string): string | null;
29
31
  /**
30
32
  * One bar line: cells between pipes, each cell's slots, the `|:` and `:|`
31
- * marks and an `x N` tail. Any error drops the whole line (`bars` is null);
32
- * `written` still says how many bars it writes.
33
+ * marks and an `x N` tail. An error in its structure drops the whole line
34
+ * (`bars` is null); `written` still says how many bars it writes. A slot
35
+ * that can't be read is an error too, but keeps its place as unknown
36
+ * harmony with its text (grammar principle 4).
33
37
  */
34
38
  export declare function parseBarLine(text: string, line: number): {
35
39
  bars: BarsLine | null;
@@ -5,6 +5,8 @@ import { isDirectionWord, readDirection } from "./direction.js";
5
5
  import { parseMeter } from "./directives.js";
6
6
  import { readSyllable, splitSyllable } from "./syllable.js";
7
7
  const FERMATA = new Set(["...", "…"]);
8
+ /** Each simple slot of these cells, a group's members each. */
9
+ export const simpleSlots = (cells) => cells.flatMap((c) => c.kind === "slots" ? c.slots.flatMap((s) => (s.kind === "group" ? s.members : [s])) : []);
8
10
  /** Whether a cell is a bar: `...`, a direction and a rehearsal mark mark a place between bars. */
9
11
  export const isBar = (c) => c.kind === "slots" || c.kind === "simile";
10
12
  const QUOTES = new Set(['"', "“", "”", "„"]);
@@ -435,72 +437,30 @@ function rehearsalCell(bare, meter, words) {
435
437
  suggestion: `| ${mark} | ${others} |`,
436
438
  };
437
439
  }
440
+ /** An unreadable slot (grammar principle 4): unknown harmony keeping what the author wrote. */
441
+ const unreadable = (text, dotted) => ({
442
+ kind: "unknown",
443
+ text,
444
+ ...(dotted ? { dotted: true } : {}),
445
+ });
446
+ /** A sung member's text without its rhythm's dot: `{H}.:la` is `{H}:la`. */
447
+ const undotted = ({ note, syllable }) => `${note.slice(0, -1)}${syllable === null ? "" : `:${syllable}`}`;
438
448
  /**
439
- * One bar line: cells between pipes, each cell's slots, the `|:` and `:|`
440
- * marks and an `x N` tail. Any error drops the whole line (`bars` is null);
441
- * `written` still says how many bars it writes.
449
+ * The reader of one slot token: a simple slot or a `_` group of them. A
450
+ * slot it can't read is an error and becomes unknown harmony with its
451
+ * text (`unread`), a misplaced or bad dot included; a misplaced `%`,
452
+ * `...`, direction or `x N`, or an empty member is an error in the bar
453
+ * line's structure (`error`).
442
454
  */
443
- export function parseBarLine(text, line) {
444
- const diagnostics = [];
445
- let listed = 0;
446
- const add = (d) => {
447
- listed++;
448
- if (listed <= MAX_LINE_DIAGNOSTICS)
449
- diagnostics.push(d);
450
- else if (listed === MAX_LINE_DIAGNOSTICS + 1)
451
- diagnostics.push({
452
- line,
453
- severity: "error",
454
- message: "further problems on this line are not listed",
455
- token: "",
456
- });
457
- };
458
- const error = (message, token, suggestion) => {
459
- add({ line, severity: "error", message, token, ...(suggestion ? { suggestion } : {}) });
460
- return null;
461
- };
462
- const warn = (message, token) => add({ line, severity: "warning", message, token });
463
- let body = text.trim();
464
- let repeat = null;
465
- const lastPipe = body.lastIndexOf("|");
466
- const tail = repeatTail(body.slice(lastPipe + 1), true);
467
- if (tail) {
468
- body = body.slice(0, lastPipe + 1) + tail.rest;
469
- repeat = readRepeat(tail.count, line, diagnostics);
470
- }
471
- const leading = readEnding(body);
472
- body = leading.body;
473
- const ending = leading.ending;
474
- if (leading.bad)
475
- error(ENDING_FORM, leading.bad);
476
- const opens = body.startsWith("|:");
477
- if (opens)
478
- body = `|${body.slice(2)}`;
479
- const closes = body.endsWith(":|");
480
- if (closes)
481
- body = `${body.slice(0, -2)}|`;
482
- const written = barsWritten(body);
483
- const stray = strayEnding(body);
484
- if (stray)
485
- error(...stray);
486
- if (body.includes(":|") || body.includes("|:"))
487
- error("|: must open a bar line and :| must close one", body.includes(":|") ? ":|" : "|:");
488
- // A misplaced mark makes the cells unreadable: report it once, not again as chords.
489
- if (diagnostics.some((d) => d.severity === "error"))
490
- return { bars: null, written, diagnostics };
491
- const parts = body.split("|").slice(1);
492
- if (parts.at(-1)?.trim() === "")
493
- parts.pop();
494
- else
495
- warn("missing trailing |", parts.at(-1)?.trim() ?? "");
496
- const report = (p) => error(p.problem, p.token, p.suggestion);
455
+ function slotReader({ error, unread, warn, broken }) {
456
+ const report = (p) => unread(p.problem, p.token, p.suggestion);
497
457
  const simple = (token) => {
498
458
  if (token === "/")
499
459
  return { kind: "hold" };
500
460
  if (SILENCE.has(token))
501
461
  return { kind: "silence" };
502
462
  if (token === "-")
503
- return error("a lone - is not a slot; silence is --", token, "--");
463
+ return unread("a lone - is not a slot; silence is --", token, "--");
504
464
  if (token === "?") {
505
465
  warn("unknown harmony", token);
506
466
  return { kind: "unknown" };
@@ -524,14 +484,14 @@ export function parseBarLine(text, line) {
524
484
  return report(v);
525
485
  for (const r of v.warnings)
526
486
  for (const w of r.ok ? r.warnings : [])
527
- warn(w.message, w.token);
487
+ warn(w.message, w.token, w.suggestion);
528
488
  return { kind: "chord", chord: v.chord, voicing: v.voicing };
529
489
  }
530
490
  const r = brace === 0 ? parseNoteSet(token) : parseChord(token);
531
491
  if (!r.ok)
532
- return error(r.error.message, token, r.error.suggestion);
492
+ return unread(r.error.message, token, r.error.suggestion);
533
493
  for (const w of r.warnings)
534
- warn(w.message, w.token);
494
+ warn(w.message, w.token, w.suggestion);
535
495
  return { kind: "chord", chord: r.value };
536
496
  };
537
497
  /** A slot with its push and articulation, if written. */
@@ -563,35 +523,110 @@ export function parseBarLine(text, line) {
563
523
  const withSyllable = ({ note, syllable }, read) => {
564
524
  const written = `${note}:${syllable}`;
565
525
  if (syllable !== null && !note)
566
- return error(NOT_A_NOTE_SET, written);
526
+ return unread(NOT_A_NOTE_SET, written);
567
527
  const slot = read(note);
568
528
  if (syllable === null || !slot)
569
529
  return slot;
570
530
  const sung = sungOn(slot, syllable);
571
- return "problem" in sung ? error(sung.problem, written) : sung;
531
+ return "problem" in sung ? unread(sung.problem, written) : sung;
572
532
  };
573
- /** One slot token: a simple slot, or a `_` group of them. */
574
- const slotOf = (token) => {
575
- const members = groupMembers(token).map(splitSyllable);
576
- const dots = members.filter((m) => isDotted(m.note)).length;
577
- if (dots && (members.length !== 2 || dots > 1))
578
- return error(DOT_PLACE, token);
579
- const [only] = members;
580
- if (only && members.length === 1)
581
- return withSyllable(only, (n) => markedSlot(n, false));
582
- return groupOf(members, token);
533
+ /** A member as read, or as written when it can't be; null once the structure has broken. */
534
+ const keep = (split, read, written) => {
535
+ const slot = withSyllable(split, read);
536
+ if (slot || broken())
537
+ return slot;
538
+ return isDotted(split.note) ? unreadable(undotted(split), true) : unreadable(written, false);
583
539
  };
584
540
  const groupOf = (members, token) => {
585
541
  const out = [];
586
542
  for (const m of members) {
587
543
  const s = m.note || m.syllable !== null
588
- ? withSyllable(m, memberOf)
544
+ ? keep(m, memberOf, m.syllable === null ? m.note : `${m.note}:${m.syllable}`)
589
545
  : error("an empty member in a group", token);
590
546
  if (s)
591
547
  out.push(s);
592
548
  }
593
549
  return { kind: "group", members: out };
594
550
  };
551
+ return (token) => {
552
+ const members = groupMembers(token).map(splitSyllable);
553
+ const dots = members.filter((m) => isDotted(m.note)).length;
554
+ // A dot never changes the bar count: a misplaced one is the slot's error (Kevin, 2026-11-10).
555
+ if (dots && (members.length !== 2 || dots > 1))
556
+ return unread(DOT_PLACE, token) ?? unreadable(token, false);
557
+ const [only] = members;
558
+ if (only && members.length === 1)
559
+ return keep(only, (n) => markedSlot(n, false), token);
560
+ return groupOf(members, token);
561
+ };
562
+ }
563
+ /**
564
+ * One bar line: cells between pipes, each cell's slots, the `|:` and `:|`
565
+ * marks and an `x N` tail. An error in its structure drops the whole line
566
+ * (`bars` is null); `written` still says how many bars it writes. A slot
567
+ * that can't be read is an error too, but keeps its place as unknown
568
+ * harmony with its text (grammar principle 4).
569
+ */
570
+ export function parseBarLine(text, line) {
571
+ const diagnostics = [];
572
+ let listed = 0;
573
+ let broken = false;
574
+ const add = (d) => {
575
+ listed++;
576
+ if (listed <= MAX_LINE_DIAGNOSTICS)
577
+ diagnostics.push(d);
578
+ else if (listed === MAX_LINE_DIAGNOSTICS + 1)
579
+ diagnostics.push({
580
+ line,
581
+ severity: "error",
582
+ message: "further problems on this line are not listed",
583
+ token: "",
584
+ });
585
+ };
586
+ const unread = (message, token, suggestion) => {
587
+ add({ line, severity: "error", message, token, ...(suggestion ? { suggestion } : {}) });
588
+ return null;
589
+ };
590
+ const error = (message, token, suggestion) => {
591
+ broken = true;
592
+ return unread(message, token, suggestion);
593
+ };
594
+ const warn = (message, token, suggestion) => add({ line, severity: "warning", message, token, ...(suggestion ? { suggestion } : {}) });
595
+ let body = text.trim();
596
+ let repeat = null;
597
+ const lastPipe = body.lastIndexOf("|");
598
+ const tail = repeatTail(body.slice(lastPipe + 1), true);
599
+ if (tail) {
600
+ body = body.slice(0, lastPipe + 1) + tail.rest;
601
+ repeat = readRepeat(tail.count, line, diagnostics);
602
+ }
603
+ const leading = readEnding(body);
604
+ body = leading.body;
605
+ const ending = leading.ending;
606
+ if (leading.bad)
607
+ error(ENDING_FORM, leading.bad);
608
+ const opens = body.startsWith("|:");
609
+ if (opens)
610
+ body = `|${body.slice(2)}`;
611
+ const closes = body.endsWith(":|");
612
+ if (closes)
613
+ body = `${body.slice(0, -2)}|`;
614
+ const written = barsWritten(body);
615
+ const stray = strayEnding(body);
616
+ if (stray)
617
+ error(...stray);
618
+ if (body.includes(":|") || body.includes("|:"))
619
+ error("|: must open a bar line and :| must close one", body.includes(":|") ? ":|" : "|:");
620
+ // A misplaced mark makes the cells unreadable: report it once, not again as chords.
621
+ if (diagnostics.some((d) => d.severity === "error"))
622
+ return { bars: null, written, diagnostics };
623
+ const parts = body.split("|").slice(1);
624
+ if (parts.at(-1)?.trim() === "")
625
+ parts.pop();
626
+ else
627
+ warn("missing trailing |", parts.at(-1)?.trim() ?? "");
628
+ const report = (p) => error(p.problem, p.token, p.suggestion);
629
+ const slotOf = slotReader({ error, unread, warn, broken: () => broken });
595
630
  const readCell = (raw) => {
596
631
  const rest = raw.trim();
597
632
  if (!rest)
@@ -620,9 +655,8 @@ export function parseBarLine(text, line) {
620
655
  if (parts.length === 0)
621
656
  error("a bar line needs at least one cell", text.trim());
622
657
  const cells = parts.map(readCell).filter((c) => c !== null);
623
- const failed = diagnostics.some((d) => d.severity === "error");
624
658
  return {
625
- bars: failed ? null : { kind: "bars", line, opens, closes, cells, repeat, ending },
659
+ bars: broken ? null : { kind: "bars", line, opens, closes, cells, repeat, ending },
626
660
  written,
627
661
  diagnostics,
628
662
  };
@@ -2,6 +2,7 @@ import { parseChord } from "../chords/parse.js";
2
2
  import { misplacedRepeat, parseBarLine, readRepeat, repeatTail } from "./barLine.js";
3
3
  import { creditsOf, nearCredit, readCredit } from "./credits.js";
4
4
  import { parseDirectiveLine } from "./directives.js";
5
+ import { continueEndings } from "./endingLines.js";
5
6
  import { checkLines } from "./lines.js";
6
7
  import { attachLyrics, readLyricRow } from "./lyricRows.js";
7
8
  import { readPart } from "./partLine.js";
@@ -24,6 +25,8 @@ function checkParts(lines, diagnostics) {
24
25
  return declared.map(partOf);
25
26
  const seen = new Map();
26
27
  const parts = [];
28
+ // Where each declaration is, found once: finding it again for every bad one costs the lines times the bad ones.
29
+ let at;
27
30
  for (const l of declared) {
28
31
  const problem = partProblem(l, seen);
29
32
  if (!problem) {
@@ -32,7 +35,10 @@ function checkParts(lines, diagnostics) {
32
35
  }
33
36
  const text = l.label ? `part: ${l.label} = ${l.name}` : `part: ${l.name}`;
34
37
  diagnostics.push({ line: l.line, severity: "error", token: text, ...problem });
35
- lines[lines.indexOf(l)] = { kind: "text", line: l.line, text };
38
+ at ??= new Map(lines.map((m, i) => [m, i]));
39
+ const i = at.get(l);
40
+ if (i !== undefined)
41
+ lines[i] = { kind: "text", line: l.line, text };
36
42
  }
37
43
  return parts;
38
44
  }
@@ -94,7 +100,7 @@ function readHeading(text, line, diagnostics) {
94
100
  }
95
101
  /** A declared label written before a bar line, exactly, or a part's label, a dot and a line's name (grammar 7.6). */
96
102
  function findLabel(word, declared) {
97
- const match = (w) => declared.find((p) => p.label?.toLowerCase() === w.toLowerCase())?.label;
103
+ const match = (w) => declared.get(w.toLowerCase());
98
104
  const exact = match(word);
99
105
  if (exact)
100
106
  return { part: exact };
@@ -234,6 +240,9 @@ export function readDocument(text) {
234
240
  const lines = [];
235
241
  const diagnostics = [];
236
242
  let title = null;
243
+ /** The parts declared so far, by lowercased label (the first of a label), and whether a bar line has been read. */
244
+ const labels = new Map();
245
+ let barred = false;
237
246
  /** The line kept as text, with why it isn't what it looks like. */
238
247
  const asText = (t, line, severity, message) => {
239
248
  diagnostics.push({ line, severity, message, token: t });
@@ -249,8 +258,11 @@ export function readDocument(text) {
249
258
  const partLine = (read, t, line) => {
250
259
  if (typeof read === "string")
251
260
  return asText(t, line, "error", read);
252
- if (lines.some((l) => l.kind === "bars" || l.kind === "invalid"))
261
+ if (barred)
253
262
  return asText(t, line, "error", "part: names the whole chart; put it before the first bar");
263
+ const label = read.label?.toLowerCase();
264
+ if (label !== undefined && !labels.has(label))
265
+ labels.set(label, read.label ?? "");
254
266
  return { kind: "part", line, ...read };
255
267
  };
256
268
  const otherLine = (t, line) => {
@@ -275,7 +287,6 @@ export function readDocument(text) {
275
287
  diagnostics.push(...r.diagnostics);
276
288
  return r.bars ?? { kind: "invalid", line, text: t, written: r.written };
277
289
  };
278
- const declaredParts = () => lines.filter((l) => l.kind === "part");
279
290
  /** A labelled line that can't be read: no space before its pipe, or a bad line name. */
280
291
  const badLabel = (t, line, word, rest, owner) => {
281
292
  const space = t.length > word.length + rest.length;
@@ -291,7 +302,7 @@ export function readDocument(text) {
291
302
  /** A declared part's bar line, or one of its lines (`Pno.RH`, grammar 7.6). */
292
303
  const labelledLine = (t, line) => {
293
304
  const split = splitLabel(t);
294
- const owner = split && findLabel(split.word, declaredParts());
305
+ const owner = split && findLabel(split.word, labels);
295
306
  if (!split || !owner)
296
307
  return null;
297
308
  const { word, space, rest } = split;
@@ -340,8 +351,12 @@ export function readDocument(text) {
340
351
  .split(/\r?\n/)
341
352
  .forEach((raw, i) => {
342
353
  const t = raw.trim();
343
- if (t && !t.startsWith("```"))
344
- lines.push(classify(t, i + 1));
354
+ if (!t || t.startsWith("```"))
355
+ return;
356
+ const l = classify(t, i + 1);
357
+ if (l.kind === "bars" || l.kind === "invalid")
358
+ barred = true;
359
+ lines.push(l);
345
360
  });
346
361
  const empty = noBarLines(lines);
347
362
  if (empty)
@@ -349,14 +364,15 @@ export function readDocument(text) {
349
364
  const read = checkParts(lines, diagnostics);
350
365
  const grouped = groupParts(lines, read);
351
366
  const lyrics = attachLyrics(grouped.lines);
352
- diagnostics.push(...grouped.diagnostics, ...lyrics.diagnostics);
367
+ const ended = continueEndings(lyrics.lines);
368
+ diagnostics.push(...grouped.diagnostics, ...lyrics.diagnostics, ...ended.diagnostics);
353
369
  const { parts } = grouped;
354
370
  return {
355
371
  title,
356
372
  part: parts.length === 1 ? (parts[0] ?? null) : null,
357
373
  parts,
358
374
  credits: creditsOf(lines),
359
- lines: lyrics.lines,
375
+ lines: ended.lines,
360
376
  diagnostics,
361
377
  };
362
378
  }
@@ -0,0 +1,13 @@
1
+ import type { ChartDiagnostic, Line } from "./types.js";
2
+ /** Lines that may sit between endings, and between an ending's lines (grammar 5.1): they mean nothing to the timeline. */
3
+ export declare const BETWEEN_ENDINGS: Set<"bars" | "break" | "credit" | "directive" | "invalid" | "lyrics" | "part" | "section" | "text" | "title">;
4
+ /**
5
+ * Mark the plain bar lines that continue an ending onto further lines
6
+ * (grammar 5.1, Kevin's decision 2026-11-10): each gets the ending's
7
+ * passes as `continues`. Only an ending of a paired repeat continues, so
8
+ * an ending with no `|:` before it leaves a stray `:|` stray. Never throws.
9
+ */
10
+ export declare function continueEndings(lines: Line[]): {
11
+ lines: Line[];
12
+ diagnostics: ChartDiagnostic[];
13
+ };