barmark 0.17.1 → 0.18.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,25 @@ Releases follow the process in [RELEASING.md](RELEASING.md).
9
9
 
10
10
  ## [Unreleased]
11
11
 
12
+ ## [0.18.0] - 2026-11-07
13
+
14
+ ### Fixed
15
+
16
+ - **A cell of many quoted words parses in linear time.** Each word
17
+ re-read the whole cell and re-split what came before it, so 20,000
18
+ words in one bar took about 25 seconds; `barmark check` on a hostile
19
+ chart, and the MusicXML import's check of what it wrote, waited on it.
20
+ - **A text line starting `constructor:` or `__proto__:` gets no near-miss
21
+ warning.** The directive and credit near misses were looked up on plain
22
+ objects, so those words found `Object.prototype` and suggested
23
+ "function Object() { [native code] }:".
24
+
25
+ ### Changed
26
+
27
+ - **`title: X` warns as a near miss, suggesting `# X`** (Kevin's ruling,
28
+ 2026-11-07, issue #173), as `meter:` suggests `time:`. A chart's title
29
+ is its `#` line; the `title:` line stays text and prints as written.
30
+
12
31
  ## [0.17.1] - 2026-11-07
13
32
 
14
33
  A parse is plain data that owns its objects, and the README says what it
@@ -546,7 +565,8 @@ The first working release: the reference parser and printer for the
546
565
 
547
566
  - **A placeholder package that holds the `barmark` name** while the spec and parser are written.
548
567
 
549
- [Unreleased]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.17.1...HEAD
568
+ [Unreleased]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.18.0...HEAD
569
+ [0.18.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.17.1...barmark-v0.18.0
550
570
  [0.17.1]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.17.0...barmark-v0.17.1
551
571
  [0.17.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.16.0...barmark-v0.17.0
552
572
  [0.16.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.15.0...barmark-v0.16.0
@@ -212,32 +212,58 @@ const outsideSyllables = (cell) => {
212
212
  */
213
213
  function readWords(cell) {
214
214
  const words = [];
215
- let bare = "";
215
+ const chars = [...cell];
216
+ const sung = inSyllables(chars);
217
+ const bare = tokenCounter();
216
218
  let open = null;
217
- const sung = inSyllables([...cell]);
218
- for (const [i, ch] of [...cell].entries()) {
219
+ for (const [i, ch] of chars.entries()) {
219
220
  if (!QUOTES.has(ch) || (sung[i] && open === null)) {
220
221
  if (open === null)
221
- bare += ch;
222
+ bare.add(ch);
222
223
  continue;
223
224
  }
224
225
  if (open === null) {
225
226
  open = i;
226
227
  continue;
227
228
  }
228
- const text = [...cell]
229
+ const text = chars
229
230
  .slice(open + 1, i)
230
231
  .join("")
231
232
  .trim();
232
233
  if (!text)
233
234
  return { problem: "empty words between quotes", token: '""' };
234
- words.push({ text, at: tokens(bare).length });
235
- bare += " ";
235
+ words.push({ text, at: bare.count() });
236
+ bare.add(" ");
236
237
  open = null;
237
238
  }
238
239
  if (open !== null)
239
- return { problem: "words need a closing quote", token: [...cell].slice(open).join("") };
240
- return { bare, words };
240
+ return { problem: "words need a closing quote", token: chars.slice(open).join("") };
241
+ return { bare: bare.text(), words };
242
+ }
243
+ /** Text built a character at a time that knows how many `tokens` it holds, without splitting it again. */
244
+ function tokenCounter() {
245
+ const parts = [];
246
+ let done = 0;
247
+ let current = false;
248
+ let depth = 0;
249
+ return {
250
+ add(ch) {
251
+ parts.push(ch);
252
+ if (ch === "{")
253
+ depth++;
254
+ if (ch === "}")
255
+ depth = Math.max(0, depth - 1);
256
+ if (/\s/.test(ch) && depth === 0) {
257
+ if (current)
258
+ done++;
259
+ current = false;
260
+ }
261
+ else
262
+ current = true;
263
+ },
264
+ count: () => done + (current ? 1 : 0),
265
+ text: () => parts.join(""),
266
+ };
241
267
  }
242
268
  /** A leading `[n/d]` and the rest of the cell; `bad` is a bracket that is no time signature. */
243
269
  function readMeter(cell) {
@@ -45,7 +45,9 @@ export function nearCredit(text, line) {
45
45
  if (LYRIC_ROW.test(text))
46
46
  return null;
47
47
  const m = /^([^\s:]+)\s*:\s*(.*)$/.exec(text);
48
- const role = m?.[1] ? NEAR_CREDITS[m[1].toLowerCase()] : undefined;
48
+ const word = m?.[1]?.toLowerCase() ?? "";
49
+ // Own keys only: `constructor:` is not a credit's near miss.
50
+ const role = Object.hasOwn(NEAR_CREDITS, word) ? NEAR_CREDITS[word] : undefined;
49
51
  if (!m || !role)
50
52
  return null;
51
53
  return {
@@ -160,10 +160,9 @@ function oldFormat(text, line) {
160
160
  const credit = nearCredit(text, line);
161
161
  if (credit)
162
162
  return credit;
163
- const near = /^(\w+)\s*:\s*(.*)$/.exec(text);
164
- const name = near?.[1] ? NEAR_DIRECTIVES[near[1].toLowerCase()] : undefined;
165
- if (near && name)
166
- return warn(`not a directive; did you mean ${name}:?`, `${name}: ${near[2]}`);
163
+ const directive = nearDirective(text);
164
+ if (directive)
165
+ return warn(directive.message, directive.suggestion);
167
166
  const undeclared = undeclaredLabel(text, line);
168
167
  if (undeclared)
169
168
  return undeclared;
@@ -175,6 +174,19 @@ function oldFormat(text, line) {
175
174
  return warn("chords outside a bar line are text", `| ${words.join(" | ")} |`);
176
175
  return null;
177
176
  }
177
+ /** A misnamed directive (`meter:`), or `title:` for the `#` title (Kevin's ruling, 2026-11-07). */
178
+ function nearDirective(text) {
179
+ const near = /^(\w+)\s*:\s*(.*)$/.exec(text);
180
+ const [, word = "", value = ""] = near ?? [];
181
+ const lower = word.toLowerCase();
182
+ if (lower === "title" && value)
183
+ return { message: "not a directive; the title is the # line", suggestion: `# ${value}` };
184
+ // Own keys only: `constructor:` is not a directive's near miss.
185
+ const name = Object.hasOwn(NEAR_DIRECTIVES, lower) ? NEAR_DIRECTIVES[lower] : undefined;
186
+ if (!near || !name)
187
+ return null;
188
+ return { message: `not a directive; did you mean ${name}:?`, suggestion: `${name}: ${value}` };
189
+ }
178
190
  /** `D \| A \|` (an editor's escaping) as the bar line it would be, if it reads cleanly. */
179
191
  function escapedBarLine(text) {
180
192
  if (!text.includes("\\|"))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "barmark",
3
- "version": "0.17.1",
3
+ "version": "0.18.0",
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": {