barmark 0.14.1 → 0.15.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.15.0] - 2026-11-04
13
+
14
+ A grammar change: credit lines (7.5). Charts that read before read the
15
+ same, unless a text line starts with a credit's name and a colon.
16
+ 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
+ - **Credit lines** (grammar 7.5): `composer:`, `lyricist:`, `arranger:`
22
+ and `copyright:`, each a line of its own, allowed anywhere in a chart
23
+ and repeatable. `ChartParse.credits` lists each role's entries in
24
+ written order; a `Line` of kind `"credit"` keeps the line, and the
25
+ printer writes it where it was written. An empty credit is an error;
26
+ `author:`, `music:`, `words:`, `arr:`, `rights:` and the other near
27
+ misses warn with the right name. `CREDIT_ROLES` is exported.
28
+ - A text line starting with one of the four names and a colon is now a
29
+ credit, not text.
30
+
12
31
  ## [0.14.1] - 2026-11-03
13
32
 
14
33
  ### Fixed
@@ -364,7 +383,8 @@ The first working release: the reference parser and printer for the
364
383
 
365
384
  - **A placeholder package that holds the `barmark` name** while the spec and parser are written.
366
385
 
367
- [Unreleased]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.14.1...HEAD
386
+ [Unreleased]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.15.0...HEAD
387
+ [0.15.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.14.1...barmark-v0.15.0
368
388
  [0.14.1]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.14.0...barmark-v0.14.1
369
389
  [0.14.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.13.0...barmark-v0.14.0
370
390
  [0.13.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.12.0...barmark-v0.13.0
package/README.md CHANGED
@@ -51,6 +51,7 @@ import {
51
51
  const chart = parseChart(text);
52
52
  chart.title; // "Example Song"
53
53
  chart.parts; // [{ label: "Gtr", name: "Electric Guitar 1" }] from part: Gtr = Electric Guitar 1, in score order
54
+ chart.credits; // { composer: ["Kevin Peckham"], lyricist: [], arranger: [], copyright: [] } from composer: Kevin Peckham
54
55
  chart.bars; // every bar in play order: its number as written, slots, section, key, meter, tempo, feel (and swingPercent)
55
56
  chart.sections; // each section as played, with its first and last bar
56
57
  chart.diagnostics; // errors and warnings, each with a line number
@@ -0,0 +1,9 @@
1
+ import type { ChartDiagnostic, CreditRole, Credits, Line } from "./types.js";
2
+ /** The credit roles, in the order MusicXML writes them (grammar 7.5). */
3
+ export declare const CREDIT_ROLES: readonly CreditRole[];
4
+ /** A credit line, or null when the line isn't one (grammar 7.5). */
5
+ export declare function readCredit(text: string, line: number, diagnostics: ChartDiagnostic[]): Line | null;
6
+ /** A text line that reads like a credit under another name: `author: X`. */
7
+ export declare function nearCredit(text: string, line: number): ChartDiagnostic | null;
8
+ /** Every credit line's text, by role, in written order. */
9
+ export declare function creditsOf(lines: Line[]): Credits;
@@ -0,0 +1,62 @@
1
+ import { DIRECTIVE_AFTER } from "./directives.js";
2
+ /** The credit roles, in the order MusicXML writes them (grammar 7.5). */
3
+ export const CREDIT_ROLES = [
4
+ "composer",
5
+ "lyricist",
6
+ "arranger",
7
+ "copyright",
8
+ ];
9
+ const NEAR_CREDITS = {
10
+ author: "composer",
11
+ writer: "composer",
12
+ music: "composer",
13
+ words: "lyricist",
14
+ lyrics: "lyricist",
15
+ arr: "arranger",
16
+ arranged: "arranger",
17
+ rights: "copyright",
18
+ "©": "copyright",
19
+ };
20
+ /** A credit line, or null when the line isn't one (grammar 7.5). */
21
+ export function readCredit(text, line, diagnostics) {
22
+ const m = /^(composer|lyricist|arranger|copyright)\s*:(.*)$/i.exec(text);
23
+ if (!m)
24
+ return null;
25
+ const role = (m[1] ?? "").toLowerCase();
26
+ const value = (m[2] ?? "").trim().replace(/\s+/g, " ");
27
+ if (!value) {
28
+ diagnostics.push({ line, severity: "error", message: `${role}: needs a value`, token: text });
29
+ return { kind: "text", line, text };
30
+ }
31
+ const after = DIRECTIVE_AFTER.exec(value);
32
+ if (after)
33
+ diagnostics.push({
34
+ line,
35
+ severity: "warning",
36
+ message: `a credit runs to the end of the line; put ${after[1]?.toLowerCase()}: on its own line`,
37
+ token: text,
38
+ });
39
+ return { kind: "credit", line, role, text: value };
40
+ }
41
+ /** A text line that reads like a credit under another name: `author: X`. */
42
+ export function nearCredit(text, line) {
43
+ const m = /^([^\s:]+)\s*:\s*(.*)$/.exec(text);
44
+ const role = m?.[1] ? NEAR_CREDITS[m[1].toLowerCase()] : undefined;
45
+ if (!m || !role)
46
+ return null;
47
+ return {
48
+ line,
49
+ severity: "warning",
50
+ message: `not a credit; did you mean ${role}:?`,
51
+ token: text,
52
+ ...(m[2] && { suggestion: `${role}: ${m[2]}` }),
53
+ };
54
+ }
55
+ /** Every credit line's text, by role, in written order. */
56
+ export function creditsOf(lines) {
57
+ const credits = { composer: [], lyricist: [], arranger: [], copyright: [] };
58
+ for (const l of lines)
59
+ if (l.kind === "credit")
60
+ credits[l.role].push(l.text);
61
+ return credits;
62
+ }
@@ -1,5 +1,7 @@
1
1
  import type { ChartDiagnostic, Directives, Meter } from "./types.js";
2
2
  export declare const DIRECTIVE_NAMES: readonly ["key", "time", "tempo", "feel"];
3
+ /** A directive written after a comma, in a line that runs to its end (`part:`, credits). */
4
+ export declare const DIRECTIVE_AFTER: RegExp;
3
5
  /** `n/d` with n from 1 to 32 and d in 2, 4, 8, 16. */
4
6
  export declare function parseMeter(text: string): Meter | null;
5
7
  /** Beats per bar: compound meters (6/8, 9/8, 12/8) count dotted quarters. */
@@ -1,4 +1,6 @@
1
1
  export const DIRECTIVE_NAMES = ["key", "time", "tempo", "feel"];
2
+ /** A directive written after a comma, in a line that runs to its end (`part:`, credits). */
3
+ export const DIRECTIVE_AFTER = /,\s*(key|time|tempo|feel)\s*:/i;
2
4
  const MODES = [
3
5
  "major",
4
6
  "minor",
@@ -1,9 +1,10 @@
1
- import type { ChartDiagnostic, Line, Part } from "./types.js";
1
+ import type { ChartDiagnostic, Credits, Line, Part } from "./types.js";
2
2
  /** Classify every line of a chart: title, sections, directives, bar lines and text. */
3
3
  export declare function readDocument(text: string): {
4
4
  title: string | null;
5
5
  part: Part | null;
6
6
  parts: Part[];
7
+ credits: Credits;
7
8
  lines: Line[];
8
9
  diagnostics: ChartDiagnostic[];
9
10
  };
@@ -1,6 +1,7 @@
1
1
  import { parseChord } from "../chords/parse.js";
2
2
  import { misplacedRepeat, parseBarLine, readRepeat, repeatTail } from "./barLine.js";
3
- import { parseDirectiveLine } from "./directives.js";
3
+ import { creditsOf, nearCredit, readCredit } from "./credits.js";
4
+ import { DIRECTIVE_AFTER, parseDirectiveLine } from "./directives.js";
4
5
  import { groupSystems } from "./systems.js";
5
6
  const NEAR_DIRECTIVES = {
6
7
  meter: "time",
@@ -10,7 +11,6 @@ const NEAR_DIRECTIVES = {
10
11
  instrument: "part",
11
12
  parts: "part",
12
13
  };
13
- const DIRECTIVE_AFTER = /,\s*(key|time|tempo|feel)\s*:/i;
14
14
  /** A `part:` line's label and name, or why it has none (grammar 7.3). */
15
15
  function readPart(text) {
16
16
  const m = /^part\s*:(.*)$/i.exec(text);
@@ -149,6 +149,9 @@ function oldFormat(text, line) {
149
149
  const label = /^\[([^\]]+)\]$/.exec(text) ?? /^([A-Za-z][\w ]*):$/.exec(text);
150
150
  if (label?.[1])
151
151
  return warn("a section label; barmark headings start with ##", `## ${label[1].trim()}`);
152
+ const credit = nearCredit(text, line);
153
+ if (credit)
154
+ return credit;
152
155
  const near = /^(\w+)\s*:\s*(.*)$/.exec(text);
153
156
  const name = near?.[1] ? NEAR_DIRECTIVES[near[1].toLowerCase()] : undefined;
154
157
  if (near && name)
@@ -215,6 +218,9 @@ export function readDocument(text) {
215
218
  return { kind: "part", line, ...read };
216
219
  };
217
220
  const otherLine = (t, line) => {
221
+ const credit = readCredit(t, line, diagnostics);
222
+ if (credit)
223
+ return credit;
218
224
  const read = readPart(t);
219
225
  if (read)
220
226
  return partLine(read, t, line);
@@ -293,6 +299,7 @@ export function readDocument(text) {
293
299
  title,
294
300
  part: parts.length === 1 ? (parts[0] ?? null) : null,
295
301
  parts,
302
+ credits: creditsOf(lines),
296
303
  lines: grouped.lines,
297
304
  diagnostics,
298
305
  };
@@ -1,4 +1,5 @@
1
1
  export { parseBarLine } from "./barLine.js";
2
+ export { CREDIT_ROLES } from "./credits.js";
2
3
  export { degreeOf } from "./degree.js";
3
4
  export { printDirection } from "./direction.js";
4
5
  export { beatsOf, DIRECTIVE_NAMES, parseDirectiveLine, parseMeter } from "./directives.js";
@@ -1,4 +1,5 @@
1
1
  export { parseBarLine } from "./barLine.js";
2
+ export { CREDIT_ROLES } from "./credits.js";
2
3
  export { degreeOf } from "./degree.js";
3
4
  export { printDirection } from "./direction.js";
4
5
  export { beatsOf, DIRECTIVE_NAMES, parseDirectiveLine, parseMeter } from "./directives.js";
@@ -93,6 +93,7 @@ export function parseChart(text) {
93
93
  title: doc.title,
94
94
  part: doc.part,
95
95
  parts: doc.parts,
96
+ credits: doc.credits,
96
97
  lines: doc.lines,
97
98
  events: played.events,
98
99
  bars: flattenBars(played.events),
@@ -121,6 +122,7 @@ export function extractPart(text, label) {
121
122
  title: doc.title,
122
123
  part,
123
124
  parts: [part],
125
+ credits: doc.credits,
124
126
  lines,
125
127
  events: played.events,
126
128
  bars: flattenBars(played.events),
@@ -148,6 +148,8 @@ export function printLine(l, beats = []) {
148
148
  return printDirectives(l.set);
149
149
  case "part":
150
150
  return `part: ${l.label ? `${l.label} = ` : ""}${l.name}`;
151
+ case "credit":
152
+ return `${l.role}: ${l.text}`;
151
153
  case "bars":
152
154
  return joinPieces(barPieces(l, beats));
153
155
  default:
@@ -106,7 +106,7 @@ export function pairRepeats(lines, error) {
106
106
  for (const l of lines) {
107
107
  if (l.kind === "bars" && l.ending)
108
108
  takeEnding(st, l, error);
109
- else if (st.endings && l.kind === "text")
109
+ else if (st.endings && (l.kind === "text" || l.kind === "credit"))
110
110
  st.endings.between.push({ line: l, repeat: null });
111
111
  else {
112
112
  finish();
@@ -134,6 +134,10 @@ export type Cell = {
134
134
  label: string;
135
135
  };
136
136
  export type Repeat = number | "open" | null;
137
+ /** Who a credit line names (grammar 7.5). */
138
+ export type CreditRole = "composer" | "lyricist" | "arranger" | "copyright";
139
+ /** A chart's credits, each role's entries in written order (grammar 7.5). */
140
+ export type Credits = Record<CreditRole, string[]>;
137
141
  export type Line = {
138
142
  kind: "title";
139
143
  line: number;
@@ -171,6 +175,13 @@ export type Line = {
171
175
  line: number;
172
176
  text: string;
173
177
  }
178
+ /** `composer: …` and the other credit lines (grammar 7.5). */
179
+ | {
180
+ kind: "credit";
181
+ line: number;
182
+ role: CreditRole;
183
+ text: string;
184
+ }
174
185
  /**
175
186
  * A bar line dropped for an error, kept as written so its section still
176
187
  * counts as written out; `written` is how many bars its pipes write.
@@ -265,6 +276,8 @@ export type ChartParse = {
265
276
  part: Part | null;
266
277
  /** Every part the chart declares, in score order (grammar 7.4); empty when none. */
267
278
  parts: Part[];
279
+ /** The credit lines (grammar 7.5); each list empty when none is written. */
280
+ credits: Credits;
268
281
  lines: Line[];
269
282
  events: ChartEvent[];
270
283
  /** `events` flattened, with an open repeat's pass included once. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "barmark",
3
- "version": "0.14.1",
3
+ "version": "0.15.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": {