barmark 0.26.0 → 0.26.1

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,64 @@ Releases follow the process in [RELEASING.md](RELEASING.md).
9
9
 
10
10
  ## [Unreleased]
11
11
 
12
+ ## [0.26.1] - 2026-11-30
13
+
14
+ ### Fixed
15
+
16
+ - **Directive lines applied too many times stop the expansion.** Every
17
+ repetition of a section (a replay, `## A x N`, `|: … :| x N`, the
18
+ return after a jump) applies each of its directive lines again, and
19
+ applying one charged no work, so N repetitions of N `key:` lines took
20
+ time quadratic in N: 8,000 replays of 8,000 lines about 2 s, 100 kB
21
+ (10,000 replays of 7,100 lines) 1.3 to 2 s, 1 MB 62 to 108 s when the
22
+ section plays a bar and 309 to 507 s when its only bar line is `| |`;
23
+ and `## A x ...` replays of such a section met no limit at all (1.8 MB:
24
+ 98 s). Play now applies at most ten times its work budget in directive
25
+ lines: 1,000,000 for one stream, and its share for each of several (a
26
+ stream is a part, or one line of a part that writes lines; `extractPart`
27
+ of a two-line part shares it between them, and of a part without lines,
28
+ or of one named line, has it all). A chart past it stops with an error
29
+ on the directive line it reached
30
+ ("expansion stopped after 278 bars: its directive lines are applied too
31
+ many times (1,000,000)"), which, as at every other limit, is then the
32
+ only report of what it cut short: each of those shapes now takes under
33
+ 0.4 s. The budget is far above real charts, not only above slow ones:
34
+ the examples and fixtures apply at most 10 of 1,000,000, the owner's
35
+ songs at most 2, while a chart that applies just over 1,000,000 took
36
+ under 0.1 s (2,000 replays of 2,000 `key: D` lines, 24 kB, now stops
37
+ after 501 bars). A chart under the budget reads exactly as before.
38
+ - **The parser no longer throws on a long chart.** It passed some of its
39
+ lists to a call one argument per element (`events.push(...out)`, and
40
+ the same for diagnostics, repeats' lines and `Math.max`), and an engine
41
+ takes only so many, so `parseChart` threw a `RangeError` on charts as
42
+ small as a few kilobytes of a particular shape: `## A x 355` over 355
43
+ lines of `| @A | x ...` (4.6 kB) under Node, `## A x 800` (10.4 kB)
44
+ under Bun; and under Node a directive line of 150,000 settings
45
+ (900 kB), an unclosed `|:` before 150,000 lines (1 MB), or a section of
46
+ 99,000 fermatas on a small stack. Each list is now appended to one
47
+ element at a time, with the same result in the same order; a test
48
+ parses those charts under Node and Bun, and another keeps the pattern
49
+ out of the parser's source.
50
+ - **A pass of an open repeat counts toward the expansion's work.** A
51
+ counted pass (`x 3`, a section's pass) cost one unit of the work budget
52
+ and a pass of `x ...` cost nothing, so a bar line with its own `x ...`
53
+ that plays no bar and no fermata (`| @A | x ...`, `| Segno | x ...`)
54
+ could be repeated without limit: N replays of N such lines took time
55
+ and memory quadratic in N (36 kB: 1.5 s, 4 million events, 1.8 GB;
56
+ 72 kB: 5 to 7 s, 16 million, 6.8 GB; `## A x ...` replays at 768 kB:
57
+ 52 to 85 s). Each open pass now costs one unit, as a counted one does,
58
+ so such a chart stops with "expansion stopped after N bars: its repeats
59
+ play too many times", as repeats of fermatas do: each of those shapes
60
+ now takes under 0.3 s and 200 MB, and no chart makes more than 100,000
61
+ open events. A chart whose work stays within the budget reads exactly
62
+ as before.
63
+ - **A replay with `->` no longer walks its section's lines again.**
64
+ Whether `->` cuts a bar looked for the section's last written bar on
65
+ every replay, walking each of its lines, so N `->` replays of a section
66
+ of N lines of any kind took time quadratic in N (4,000 of 4,000 text
67
+ lines took 9 to 12 times as long as 1,000 of 1,000). The bar is now
68
+ found once per section, and nothing in the parse changes.
69
+
12
70
  ## [0.26.0] - 2026-11-29
13
71
 
14
72
  ### Added
@@ -976,7 +1034,8 @@ The first working release: the reference parser and printer for the
976
1034
 
977
1035
  - **A placeholder package that holds the `barmark` name** while the spec and parser are written.
978
1036
 
979
- [Unreleased]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.26.0...HEAD
1037
+ [Unreleased]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.26.1...HEAD
1038
+ [0.26.1]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.26.0...barmark-v0.26.1
980
1039
  [0.26.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.25.1...barmark-v0.26.0
981
1040
  [0.25.1]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.25.0...barmark-v0.25.1
982
1041
  [0.25.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.24.0...barmark-v0.25.0
@@ -617,6 +617,7 @@ export function parseBarLine(text, line) {
617
617
  body = `${body.slice(0, -2)}|`;
618
618
  const written = barsWritten(body);
619
619
  const stray = strayEnding(body);
620
+ // bounded: a message and its token.
620
621
  if (stray)
621
622
  error(...stray);
622
623
  if (body.includes(":|") || body.includes("|:"))
@@ -118,6 +118,7 @@ export function planJump(lines, error) {
118
118
  const jump = first.get("jump");
119
119
  const plan = jump?.direction.kind === "jump" ? jump.direction : null;
120
120
  if (jump && plan)
121
+ // bounded: at most the four marks a jump can miss.
121
122
  problems.push(...missingMarks(jump, plan, first).map((m) => [jump, m]));
122
123
  const coda = first.get("coda");
123
124
  // Only the Coda an al Coda goes on; an unused one is an error of its own.
@@ -5,6 +5,7 @@ import { parseDirectiveLine } from "./directives.js";
5
5
  import { continueEndings } from "./endingLines.js";
6
6
  import { checkLines } from "./lines.js";
7
7
  import { attachLyrics, readLyricRow } from "./lyricRows.js";
8
+ import { append } from "./many.js";
8
9
  import { readPart } from "./partLine.js";
9
10
  import { groupSystems } from "./systems.js";
10
11
  const NEAR_DIRECTIVES = {
@@ -274,7 +275,7 @@ export function readDocument(text) {
274
275
  return partLine(read, t, line);
275
276
  const directive = parseDirectiveLine(t, line);
276
277
  if (directive) {
277
- diagnostics.push(...directive.diagnostics);
278
+ append(diagnostics, directive.diagnostics);
278
279
  return { kind: "directive", line, set: directive.set };
279
280
  }
280
281
  const old = oldFormat(t, line);
@@ -284,7 +285,7 @@ export function readDocument(text) {
284
285
  };
285
286
  const barLine = (t, line) => {
286
287
  const r = parseBarLine(t, line);
287
- diagnostics.push(...r.diagnostics);
288
+ append(diagnostics, r.diagnostics);
288
289
  return r.bars ?? { kind: "invalid", line, text: t, written: r.written };
289
290
  };
290
291
  /** A labelled line that can't be read: no space before its pipe, or a bad line name. */
@@ -322,7 +323,7 @@ export function readDocument(text) {
322
323
  /** `lyrics:` or `lyrics N:` then a bar line (grammar 7.7); one with an error stays text. */
323
324
  const lyricRow = (t, line) => {
324
325
  const read = readLyricRow(t, line);
325
- diagnostics.push(...read.diagnostics);
326
+ append(diagnostics, read.diagnostics);
326
327
  if (read.row || read.diagnostics.length)
327
328
  return read.row ?? { kind: "text", line, text: t };
328
329
  return null;
@@ -365,7 +366,8 @@ export function readDocument(text) {
365
366
  const grouped = groupParts(lines, read);
366
367
  const lyrics = attachLyrics(grouped.lines);
367
368
  const ended = continueEndings(lyrics.lines);
368
- diagnostics.push(...grouped.diagnostics, ...lyrics.diagnostics, ...ended.diagnostics);
369
+ for (const found of [grouped, lyrics, ended])
370
+ append(diagnostics, found.diagnostics);
369
371
  const { parts } = grouped;
370
372
  return {
371
373
  title,
@@ -30,6 +30,18 @@ export declare const MAX_EXPANDED_BARS = 10000;
30
30
  * times the lines never multiply.
31
31
  */
32
32
  export declare const workFor: (share: number) => number;
33
+ /**
34
+ * The directive lines one of `share` streams may apply: ten times its
35
+ * work. A stream is a part, or one line of a part that writes lines, so a
36
+ * chart's two-line part has two and each applies 500,000; `extractPart`
37
+ * plays a part of no lines, or one named line, as one stream. Every
38
+ * repetition of a section applies its directive lines again, so N
39
+ * repetitions of N lines would cost N squared with no bound but the
40
+ * file's size. An application costs about 30 ns, so a million bound it at
41
+ * tens of milliseconds; real charts apply a handful (the examples and
42
+ * fixtures at most 10, the owner's songs at most 2).
43
+ */
44
+ export declare const directivesFor: (share: number) => number;
33
45
  /** Every played bar in order, with an open repeat's pass included once. */
34
46
  export declare function flattenBars(events: ChartEvent[]): PlayedBar[];
35
47
  /**
@@ -1,5 +1,6 @@
1
1
  import { planJump } from "./direction.js";
2
2
  import { beatsOf } from "./directives.js";
3
+ import { append } from "./many.js";
3
4
  import { pedalWarnings } from "./pedal.js";
4
5
  import { pairRepeats } from "./repeats.js";
5
6
  import { perWritten, slotTimes } from "./shares.js";
@@ -13,6 +14,18 @@ const barsFor = (share) => Math.max(1, Math.floor(MAX_EXPANDED_BARS / share));
13
14
  * times the lines never multiply.
14
15
  */
15
16
  export const workFor = (share) => barsFor(share) * 10;
17
+ /**
18
+ * The directive lines one of `share` streams may apply: ten times its
19
+ * work. A stream is a part, or one line of a part that writes lines, so a
20
+ * chart's two-line part has two and each applies 500,000; `extractPart`
21
+ * plays a part of no lines, or one named line, as one stream. Every
22
+ * repetition of a section applies its directive lines again, so N
23
+ * repetitions of N lines would cost N squared with no bound but the
24
+ * file's size. An application costs about 30 ns, so a million bound it at
25
+ * tens of milliseconds; real charts apply a handful (the examples and
26
+ * fixtures at most 10, the owner's songs at most 2).
27
+ */
28
+ export const directivesFor = (share) => workFor(share) * 10;
16
29
  /**
17
30
  * The lines one of several parts reads: its share of the work, since the
18
31
  * parts times the lines would otherwise multiply; and the first it
@@ -143,6 +156,7 @@ sing) {
143
156
  const maxBars = barsFor(share);
144
157
  // Repeats of bodies that play no bars (fermatas only) are bounded too.
145
158
  const maxWork = workFor(share);
159
+ const maxApplied = directivesFor(share);
146
160
  const { readable, unread } = shareOf(lines, share, maxWork);
147
161
  // The return after a jump plays sections again: it reports only what the first pass did not.
148
162
  const reported = new Set();
@@ -310,6 +324,7 @@ sing) {
310
324
  };
311
325
  let count = 0;
312
326
  let work = 0;
327
+ let applied = 0;
313
328
  let capped = false;
314
329
  let openDepth = 0;
315
330
  const nestedOpen = new Set();
@@ -318,20 +333,20 @@ sing) {
318
333
  let againSung = 0;
319
334
  /** Bars a replay's `->` cut after they played: `count` counts them, the output doesn't. */
320
335
  let cutBars = 0;
321
- /** Stop playing, saying why: the bar cap, the verses sung again, repeats that play too much, or a part's lines. */
336
+ /** Why play stopped, after the bars it played: each limit but the bar cap's. */
337
+ const reasons = {
338
+ verses: () => `the bars played again sing too many verses (${againSung.toLocaleString("en-US")})`,
339
+ lines: () => `each of ${share} parts reads at most ${maxWork} lines`,
340
+ work: () => "its repeats play too many times",
341
+ directives: () => `its directive lines are applied too many times (${maxApplied.toLocaleString("en-US")})`,
342
+ };
343
+ /** Stop playing, saying why: the bar cap, the verses sung again, repeats that play too much, directive lines applied too often, or a part's lines. */
322
344
  const stop = (line, why = "work") => {
323
345
  capped = true;
324
- const what = () => {
325
- if (why === "bars")
326
- return `expansion stopped at ${maxBars} bars`;
327
- const after = `expansion stopped after ${count - cutBars} bars`;
328
- if (why === "verses")
329
- return `${after}: the bars played again sing too many verses (${againSung.toLocaleString("en-US")})`;
330
- if (why === "lines")
331
- return `${after}: each of ${share} parts reads at most ${maxWork} lines`;
332
- return `${after}: its repeats play too many times`;
333
- };
334
- error(line, what(), "x");
346
+ const what = why === "bars"
347
+ ? `expansion stopped at ${maxBars} bars`
348
+ : `expansion stopped after ${count - cutBars} bars: ${reasons[why]()}`;
349
+ error(line, what, "x");
335
350
  };
336
351
  /** A part that stopped reading its lines before play stopped says so. */
337
352
  const readAll = (next) => {
@@ -465,9 +480,16 @@ sing) {
465
480
  count++;
466
481
  out.push({ kind: "bar", bar: played });
467
482
  };
468
- /** Play `body` `repeat` times into `out`; an open repeat plays one pass inside an open event. */
483
+ /**
484
+ * Play `body` `repeat` times into `out`; an open repeat plays one pass
485
+ * inside an open event. Its pass is work, as a counted pass is: a pass
486
+ * that plays nothing would otherwise repeat for free.
487
+ */
469
488
  const times = (repeat, line, out, body) => {
470
489
  if (repeat === "open") {
490
+ // Not once play has stopped: the stop is the only report of what it cut short.
491
+ if (!capped && ++work > maxWork)
492
+ return stop(line);
471
493
  if (openDepth > 0) {
472
494
  if (!nestedOpen.has(line))
473
495
  error(line, "an open repeat inside another open repeat", "x ...");
@@ -499,11 +521,17 @@ sing) {
499
521
  }
500
522
  Object.assign(where, { pass: outer.pass, passes: outer.passes });
501
523
  };
524
+ /** A directive line applied as play reaches it, once the budget has room for it. */
525
+ const applyLine = (l) => {
526
+ if (++applied > maxApplied)
527
+ return stop(l.line, "directives");
528
+ apply(l.set, l.line);
529
+ };
502
530
  const playLine = ({ line: l, repeat }, out) => {
503
531
  if (stopped())
504
532
  return;
505
533
  if (l.kind === "directive")
506
- apply(l.set, l.line);
534
+ return applyLine(l);
507
535
  if (l.kind !== "bars")
508
536
  return;
509
537
  times(repeat, l.line, out, (into) => {
@@ -564,11 +592,20 @@ sing) {
564
592
  times(h.repeat, h.line, out, (into) => playItems(itemsOf.get(s) ?? [], into));
565
593
  return { replayOf: null, elided: false };
566
594
  };
567
- /** Whether `out` ends with the last bar written in `s` (grammar 6: what `->` cuts). */
568
- const reachesEnd = (s, out) => {
595
+ /** The written number of the last bar written in each section, found once: every `->` replay asks. */
596
+ const lastWritten = new Map();
597
+ const lastIn = (s) => {
598
+ if (lastWritten.has(s))
599
+ return lastWritten.get(s);
569
600
  const bars = s.lines.flatMap((l) => (l.kind === "bars" ? (resolved.get(l) ?? []) : []));
570
601
  const last = bars.findLast((p) => p.kind === "bar");
571
- return last?.kind === "bar" && flattenBars(out).at(-1)?.written === last.written;
602
+ lastWritten.set(s, last?.kind === "bar" ? last.written : undefined);
603
+ return lastWritten.get(s);
604
+ };
605
+ /** Whether `out` ends with the last bar written in `s` (grammar 6: what `->` cuts). */
606
+ const reachesEnd = (s, out) => {
607
+ const last = lastIn(s);
608
+ return last !== undefined && flattenBars(out).at(-1)?.written === last;
572
609
  };
573
610
  /** A replay's bars into `out`, then its own lines; null when it replays nothing. */
574
611
  const playReplay = (s, h, out) => {
@@ -616,7 +653,7 @@ sing) {
616
653
  const played = isWritten(s) ? playWritten(s, h, out) : playReplay(s, h, out);
617
654
  if (!played)
618
655
  return;
619
- events.push(...out);
656
+ append(events, out);
620
657
  record(h, out, played.replayOf, played.elided);
621
658
  };
622
659
  playSections();
@@ -645,6 +682,6 @@ sing) {
645
682
  };
646
683
  });
647
684
  if (pedal)
648
- diagnostics.push(...pedalWarnings(flattenBars(events)));
685
+ append(diagnostics, pedalWarnings(flattenBars(events)));
649
686
  return { events, sections: sectionsOut, diagnostics, stopped: capped, firsts };
650
687
  }
@@ -1,3 +1,4 @@
1
+ import { append } from "./many.js";
1
2
  /** At most this many lines per part (grammar 7.6). */
2
3
  export const MAX_LINES = 4;
3
4
  const isLabelled = (l) => (l.kind === "bars" || l.kind === "invalid") && l.part !== undefined;
@@ -35,9 +36,13 @@ function nameLines(lines, report) {
35
36
  }
36
37
  /** Push `item` onto the list at `key`, starting it if new: a copy per item would cost the list squared. */
37
38
  function pushAt(map, key, ...items) {
39
+ pushAllAt(map, key, items);
40
+ }
41
+ /** Push `items` onto the list at `key` in order, starting it if new: one push per item, never a spread. */
42
+ function pushAllAt(map, key, items) {
38
43
  const known = map.get(key);
39
44
  if (known)
40
- known.push(...items);
45
+ append(known, items);
41
46
  else
42
47
  map.set(key, items);
43
48
  }
@@ -79,7 +84,7 @@ function bareBeside(systems) {
79
84
  for (const [part, own] of system) {
80
85
  const bare = own.filter((l) => l.lineName === undefined);
81
86
  if (bare.length && bare.length < own.length)
82
- pushAt(out, part, ...bare);
87
+ pushAllAt(out, part, bare);
83
88
  }
84
89
  return out;
85
90
  }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Arrays as long as the input, used whole without spreading them into a
3
+ * call: a spread passes one argument per element, and an engine takes only
4
+ * so many (V8 about 100,000, Bun more), so `xs.push(...ys)` and
5
+ * `Math.max(...ys)` throw a `RangeError` on a large enough chart.
6
+ */
7
+ /** Append `items` to `to` in order, as `to.push(...items)` would. */
8
+ export declare function append<T>(to: T[], items: readonly T[]): void;
9
+ /** The largest of `from` and `xs`, as `Math.max(from, ...xs)` would be; -Infinity for none. */
10
+ export declare function largest(xs: Iterable<number>, from?: number): number;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Arrays as long as the input, used whole without spreading them into a
3
+ * call: a spread passes one argument per element, and an engine takes only
4
+ * so many (V8 about 100,000, Bun more), so `xs.push(...ys)` and
5
+ * `Math.max(...ys)` throw a `RangeError` on a large enough chart.
6
+ */
7
+ /** Append `items` to `to` in order, as `to.push(...items)` would. */
8
+ export function append(to, items) {
9
+ for (const x of items)
10
+ to.push(x);
11
+ }
12
+ /** The largest of `from` and `xs`, as `Math.max(from, ...xs)` would be; -Infinity for none. */
13
+ export function largest(xs, from = Number.NEGATIVE_INFINITY) {
14
+ let most = from;
15
+ for (const x of xs)
16
+ most = Math.max(most, x);
17
+ return most;
18
+ }
@@ -1,6 +1,7 @@
1
1
  import { readDocument } from "./document.js";
2
2
  import { expand, flattenBars, workFor } from "./expand.js";
3
3
  import { withFirstWritten } from "./firstWritten.js";
4
+ import { append, largest } from "./many.js";
4
5
  import { projectPart, projectPartLines } from "./parts.js";
5
6
  import { pedalWarnings } from "./pedal.js";
6
7
  import { numberFromPickup } from "./pickup.js";
@@ -64,7 +65,7 @@ const lineOf = (e) => (e.kind === "bar" ? e.bar.line : e.line);
64
65
  /** The first event at which some part's timeline differs in shape from the lead's, or -1. */
65
66
  function stepAt(each) {
66
67
  const [lead = []] = each;
67
- const longest = Math.max(...each.map((events) => events.length));
68
+ const longest = largest(each.map((events) => events.length));
68
69
  for (let i = 0; i < longest; i++)
69
70
  if (each.some((events) => events[i]?.kind !== lead[i]?.kind))
70
71
  return i;
@@ -213,7 +214,7 @@ function playStreams(lines, parts, shown, voices) {
213
214
  const stopped = played.some((p) => p.stopped);
214
215
  const zipped = zipEvents(played.map((p) => p.events), (d) => diagnostics.push(d), stopped);
215
216
  const events = foldEvents(zipped, byPart(streams, shown), shown);
216
- diagnostics.push(...linedPedalWarnings(events, shown));
217
+ append(diagnostics, linedPedalWarnings(events, shown));
217
218
  // The bars carry the first stream's numbers (`zipBar`), so its lines' numbers are the chart's.
218
219
  const lead = played[0];
219
220
  return {
@@ -3,6 +3,7 @@ import { printDirection } from "./direction.js";
3
3
  import { beatsOf } from "./directives.js";
4
4
  import { readDocument } from "./document.js";
5
5
  import { printKey } from "./keys.js";
6
+ import { largest } from "./many.js";
6
7
  import { extractPart, parseChart } from "./parse.js";
7
8
  import { splitSyllable } from "./syllable.js";
8
9
  /** A slot with no attack of its own continues whatever sounds before it. A repeated chord name is a re-attack. */
@@ -210,7 +211,7 @@ function partsIndex(parts) {
210
211
  if (!at.has(p.label))
211
212
  at.set(p.label, i);
212
213
  });
213
- const width = Math.max(...parts.flatMap(labelsOf).map((label) => label.length));
214
+ const width = largest(parts.flatMap(labelsOf).map((label) => label.length));
214
215
  const made = { at, width };
215
216
  partsKnown.set(parts, made);
216
217
  return made;
@@ -233,7 +234,7 @@ const spanOf = (k, bars, n) => [
233
234
  const roomOf = (columns, [a, b]) => columns.slice(a, b + 1).reduce((x, y) => x + y, 0) + 3 * (b - a);
234
235
  /** Each column's width: the widest of the bar lines' cells, widened for a row's cell that won't fit. */
235
236
  function columnsOf(lines, rows, bars) {
236
- const columns = (lines[0]?.cells ?? []).map((_, i) => Math.max(...lines.map((p) => p.cells[i]?.length ?? 0)));
237
+ const columns = (lines[0]?.cells ?? []).map((_, i) => largest(lines.map((p) => p.cells[i]?.length ?? 0)));
237
238
  for (const r of rows)
238
239
  for (const [k, c] of r.cells.entries()) {
239
240
  const room = roomOf(columns, spanOf(k, bars, columns.length));
@@ -248,7 +249,7 @@ function columnsOf(lines, rows, bars) {
248
249
  * pipes lined up; a row's cell spans the cells of its bar (grammar 7.7).
249
250
  */
250
251
  function alignBlock(lines, rows, bars, width) {
251
- const w = Math.max(width, ...rows.map((r) => r.label.length));
252
+ const w = largest(rows.map((r) => r.label.length), width);
252
253
  const columns = columnsOf(lines, rows, bars);
253
254
  const print = (p, pad) => `${p.label.padEnd(w)} ${joinPieces({ ...p, cells: p.cells.map(pad) })}`.trimEnd();
254
255
  const texts = new Map();
@@ -302,7 +303,7 @@ const lastKnown = new WeakMap();
302
303
  function lastOf(covers) {
303
304
  let last = lastKnown.get(covers);
304
305
  if (last === undefined) {
305
- last = Math.max(...covers);
306
+ last = largest(covers);
306
307
  lastKnown.set(covers, last);
307
308
  }
308
309
  return last;
@@ -1,7 +1,8 @@
1
1
  import { BETWEEN_ENDINGS } from "./endingLines.js";
2
+ import { append, largest } from "./many.js";
2
3
  const passesToken = (b) => `|${(b.ending ?? []).join(",")}`;
3
4
  const asLine = (line) => ({ kind: "line", line, repeat: null });
4
- const highestPass = (endings) => Math.max(...endings.flatMap((b) => b.ending ?? []));
5
+ const highestPass = (endings) => largest(endings.flatMap((b) => b.ending ?? []));
5
6
  /** Every pass from 1 to the highest has exactly one ending, and the highest is at least 2. */
6
7
  function passProblems(endings, last) {
7
8
  const highest = highestPass(endings);
@@ -112,7 +113,7 @@ export function pairRepeats(lines, error) {
112
113
  const st = { items: [], open: null, endings: null };
113
114
  const finish = () => {
114
115
  if (st.endings)
115
- st.items.push(...closeEndings(st.endings, error));
116
+ append(st.items, closeEndings(st.endings, error));
116
117
  st.endings = null;
117
118
  };
118
119
  for (const l of lines) {
@@ -130,7 +131,7 @@ export function pairRepeats(lines, error) {
130
131
  finish();
131
132
  if (st.open) {
132
133
  error(st.open.line, "|: is never closed in this section", "|:");
133
- st.items.push(...st.open.entries.map((e) => ({ kind: "line", ...e })));
134
+ append(st.items, st.open.entries.map((e) => ({ kind: "line", ...e })));
134
135
  }
135
136
  return st.items;
136
137
  }
@@ -93,6 +93,7 @@ function shorthandFor(intervals) {
93
93
  * by a flat sixth (`C(b6,9)`, not `C6/9(b6)`), else the first.
94
94
  */
95
95
  function bestSuffix(candidates, exact, intervals) {
96
+ // bounded: the candidates are suffixes of the fixed vocabulary, a few at most.
96
97
  const most = Math.max(...candidates.map(exact));
97
98
  const tied = candidates.filter((c) => exact(c) === most);
98
99
  const shorthand = shorthandFor(intervals);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "barmark",
3
- "version": "0.26.0",
3
+ "version": "0.26.1",
4
4
  "description": "Markdown-inspired plain-text notation for chord charts: a parser, a canonical printer and Harte-label conversion.",
5
5
  "type": "module",
6
6
  "exports": {