barmark 0.25.0 → 0.25.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,35 @@ Releases follow the process in [RELEASING.md](RELEASING.md).
9
9
 
10
10
  ## [Unreleased]
11
11
 
12
+ ## [0.25.1] - 2026-11-29
13
+
14
+ ### Fixed
15
+
16
+ - **A heading that plays no bars no longer costs a scan of the chart.**
17
+ Each such heading's error (it names the line where a section of that
18
+ name is written later, if one is) searched every section of the chart,
19
+ so the parse took time quadratic in their number: 8,000 empty headings
20
+ took over 2 s, and 8,000 more sections after them some 10 to 13 s. The
21
+ parse now finds that line in constant time: 8,000 empty headings take
22
+ about 15 ms, and about 0.4 s with the 8,000 sections after them.
23
+ - **The sections after an `al Coda`'s Coda no longer cost a scan each.**
24
+ Whether a bar follows the Coda asked every later heading whether it is a
25
+ replay, each from the top of the chart: 32,000 sections after the Coda
26
+ took about 1.5 s, and now take about 0.4 s, growing linearly.
27
+ - **Lines that play nothing are no longer walked on every pass.** Text
28
+ lines, lyric rows, credits and breaks were walked each time their
29
+ section was replayed and each time a repeat around them played a pass,
30
+ so N replays of N such lines, or `|: … :| x N` around them, took time
31
+ quadratic in N (8,000 replays of 8,000 lines: about 1 s; 1 MB of either
32
+ shape: over 30 s). They are now left out of what plays, at the top of a
33
+ section and inside its repeats: 8,000 replays take about 40 ms, and
34
+ 1 MB under a second. Directive lines are still applied every time, so
35
+ repeating a run of them is still quadratic (seconds at 100 kB, a minute
36
+ or more at 1 MB): that is open.
37
+
38
+ No chart reads differently: the same bars, events and sections, and the
39
+ same diagnostics at the same lines in the same order.
40
+
12
41
  ## [0.25.0] - 2026-11-19
13
42
 
14
43
  Grammar changes: more spellings of the major seventh (Kevin, 2026-11-18).
@@ -929,7 +958,8 @@ The first working release: the reference parser and printer for the
929
958
 
930
959
  - **A placeholder package that holds the `barmark` name** while the spec and parser are written.
931
960
 
932
- [Unreleased]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.25.0...HEAD
961
+ [Unreleased]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.25.1...HEAD
962
+ [0.25.1]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.25.0...barmark-v0.25.1
933
963
  [0.25.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.24.0...barmark-v0.25.0
934
964
  [0.24.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.23.1...barmark-v0.24.0
935
965
  [0.23.1]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.23.0...barmark-v0.23.1
@@ -64,8 +64,15 @@ function missingMarks(jump, plan, first) {
64
64
  const writes = (l) => l.kind === "bars" || l.kind === "invalid";
65
65
  /** Whether the section heading at `i` is a replay: no bar line before the next heading. */
66
66
  function isReplay(lines, i) {
67
- const next = lines.findIndex((l, k) => k > i && l.kind === "section");
68
- return !lines.slice(i + 1, next < 0 ? undefined : next).some(writes);
67
+ // It looks ahead from the heading, not from the top: barAfter asks every heading after a Coda.
68
+ for (let k = i + 1; k < lines.length; k++) {
69
+ const l = lines[k];
70
+ if (l.kind === "section")
71
+ return true;
72
+ if (writes(l))
73
+ return false;
74
+ }
75
+ return true;
69
76
  }
70
77
  /** Whether a bar follows `m`: on its line, on a later one, or in a later replay (grammar 5.2). */
71
78
  function barAfter(lines, m) {
@@ -79,13 +79,26 @@ function pushesIn(slots, meter) {
79
79
  }
80
80
  const normalize = (name) => name.toLowerCase().replace(/\s+/g, " ").trim();
81
81
  const isWritten = (s) => s.lines.some((l) => l.kind === "bars" || l.kind === "invalid");
82
- /** Grammar §6: an empty section that matches nothing, and how to fix it. */
83
- function unmatchedReplay(heading, sections) {
84
- const name = normalize(heading.name);
85
- const later = sections.find((s) => s.heading &&
86
- s.heading.line > heading.line &&
87
- normalize(s.heading.name) === name &&
88
- isWritten(s))?.heading;
82
+ /**
83
+ * For each section, the first written section after it with its name, when
84
+ * there is one: one pass from the end, so an empty heading's message costs
85
+ * constant time, not a scan of the chart.
86
+ */
87
+ function writtenLater(sections) {
88
+ const next = new Map();
89
+ const later = new Map();
90
+ for (let i = sections.length - 1; i >= 0; i--) {
91
+ const s = sections[i];
92
+ if (!s.heading)
93
+ continue;
94
+ later.set(s, next.get(s.key));
95
+ if (isWritten(s))
96
+ next.set(s.key, s.heading);
97
+ }
98
+ return later;
99
+ }
100
+ /** Grammar §6: an empty section that matches nothing, and how to fix it; `later` is where it is written, if it is. */
101
+ function unmatchedReplay(heading, later) {
89
102
  const fix = later
90
103
  ? `replays use only earlier sections (it is written at line ${later.line})`
91
104
  : "write its bars under it, or remove the heading";
@@ -141,10 +154,10 @@ sing) {
141
154
  reported.add(key);
142
155
  diagnostics.push({ line, severity: "error", message, token });
143
156
  };
144
- const sections = [{ heading: null, lines: [] }];
157
+ const sections = [{ heading: null, key: "", lines: [] }];
145
158
  for (const l of readable) {
146
159
  if (l.kind === "section")
147
- sections.push({ heading: l, lines: [] });
160
+ sections.push({ heading: l, key: normalize(l.name), lines: [] });
148
161
  else if (l.kind !== "title")
149
162
  sections.at(-1)?.lines.push(l);
150
163
  }
@@ -228,8 +241,16 @@ sing) {
228
241
  const unused = pending.mark;
229
242
  if (unused)
230
243
  error(unused.line, "a rehearsal mark marks the bar after it; none follows", `@${unused.label}`);
231
- // Pair |: and :| within each section, with any endings.
232
- const itemsOf = new Map(sections.map((s) => [s, pairRepeats(s.lines, error)]));
244
+ // Pair |: and :| within each section, with any endings. A line that is neither bars nor a
245
+ // directive plays nothing, so it is left out, at the top and inside a repeat (an ending holds
246
+ // only bar lines): each pass and each replay walks only what it plays.
247
+ const plays = (e) => e.line.kind === "bars" || e.line.kind === "directive";
248
+ const playing = (items) => items.flatMap((it) => {
249
+ if (it.kind === "line")
250
+ return plays(it) ? [it] : [];
251
+ return [{ ...it, entries: it.entries.filter(plays) }];
252
+ });
253
+ const itemsOf = new Map(sections.map((s) => [s, playing(pairRepeats(s.lines, error))]));
233
254
  const plan = planJump(readable, error);
234
255
  const start = () => ({
235
256
  key: null,
@@ -515,6 +536,7 @@ sing) {
515
536
  const events = [];
516
537
  const occurrences = [];
517
538
  const definitions = new Map();
539
+ const later = writtenLater(sections);
518
540
  /** Headings already played, so a written section played again by the jump is a replay. */
519
541
  const heard = new Set();
520
542
  const playSections = () => {
@@ -526,7 +548,7 @@ sing) {
526
548
  };
527
549
  /** A written section's bars into `out`. */
528
550
  const playWritten = (s, h, out) => {
529
- definitions.set(normalize(h.name), s);
551
+ definitions.set(s.key, s);
530
552
  if (h.elided)
531
553
  error(h.line, "-> is only for a replay; leave the bar out instead", "->");
532
554
  times(h.repeat, h.line, out, (into) => playItems(itemsOf.get(s) ?? [], into));
@@ -543,9 +565,9 @@ sing) {
543
565
  // A nameless heading is already an error; it has nothing to replay.
544
566
  if (!h.name)
545
567
  return null;
546
- const source = definitions.get(normalize(h.name));
568
+ const source = definitions.get(s.key);
547
569
  if (!source?.heading) {
548
- error(h.line, unmatchedReplay(h, sections), h.name);
570
+ error(h.line, unmatchedReplay(h, later.get(s)), h.name);
549
571
  return null;
550
572
  }
551
573
  where.replay = h.line;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "barmark",
3
- "version": "0.25.0",
3
+ "version": "0.25.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": {