barmark 0.1.0 → 0.3.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,10 +9,50 @@ Releases follow the process in [RELEASING.md](RELEASING.md).
9
9
 
10
10
  ## [Unreleased]
11
11
 
12
+ ## [0.3.0] - 2026-11-01
13
+
14
+ A chart in another format no longer reads as an empty one. A grammar
15
+ decision (two new warnings, §9); no chart's meaning changes. Implements the
16
+ [grammar v0.1 draft](https://github.com/kevinpeckham/barmark/blob/main/docs/grammar-v0.1-draft.md).
17
+
18
+ ### Added
19
+
20
+ - **A chart with no bar lines warns.** A chart with text but no bar line
21
+ at all warns once, at its first text line, instead of looking like an
22
+ empty file (issue #1). Grammar §9 and its decisions log.
23
+ - **Escaped pipes warn, with the fix.** A text line such as `D \| A \| G`,
24
+ as some editors save a bar line, warns and suggests `| D | A | G |`.
25
+
26
+ ## [0.2.0] - 2026-10-31
27
+
28
+ Machine output for renderers and hosts (`form`, `parts`), the first
29
+ grammar decision since 0.1.0 (directives under a replay heading), and the
30
+ move to a workspace beside `@barmark/render`. Implements the
31
+ [grammar v0.1 draft](https://github.com/kevinpeckham/barmark/blob/main/docs/grammar-v0.1-draft.md),
32
+ with Appendix A's provisional calls now approved (no behaviour change).
33
+
34
+ ### Added
35
+
36
+ - **`form` on each section occurrence:** which distinct section it plays, numbered from 0 in order of first appearance. Every replay shares its written section's number, so a host can label the form (A B A B C) or mark repeated sections in a timeline.
37
+ - **`parts` on each chord record:** the canonical root, quality, extension, sus, tones and bass the canonical spelling is built from (`null` for a note set), so renderers can typeset and speak a chord without re-reading its text.
38
+
39
+ ### Changed
40
+
41
+ - **A directive under a replay heading takes effect after the replay.** A chart with `## Chorus` (a replay) followed by `key: E` used to play that Chorus in E; now the change starts at the next section, as the grammar's "written order is play order" says. Write the directive before the heading to change the replay itself.
42
+ - **Peaceful Dreams uses plain section names** (`## Verse`, not `## II Verse`): headings are the author's text, and form now comes from `form`.
43
+
44
+ ### Technical
45
+
46
+ - **`main` and release tags are protected, and publishing needs approval.** Changes reach `main` through pull requests that pass CI; `v*` tags cannot be moved or deleted; the npm publish job runs in an `npm` environment that waits for approval and that npm's trusted publisher requires. After publishing, the release workflow installs the new version from npm and reads a real chart with it (`scripts/smoke.mjs`, shared with `verify:package`).
47
+ - **Dependabot** proposes monthly, grouped updates for actions and dev dependencies, with a two-week cooldown. Jobs have time limits, superseded pull-request runs are cancelled, and releases never run concurrently. `actions/checkout` is now v7.0.1 and `actions/setup-node` v7.1.0, which ends the Node 20 deprecation warnings.
48
+ - **The repository is a Bun workspace.** The package lives in `packages/barmark/` (`package.json` names the directory), beside the coming `@barmark/render`; the verify scripts, CI's package check and the Swamp `release-check` take the package to check.
49
+ - **Releases are tagged per package:** `barmark-vX.Y.Z` (and `render-vX.Y.Z` for `@barmark/render`); the release workflow publishes the package its tag names, packed with `bun pm pack`.
50
+ - **Fallow guards the code's health.** `bun run fallow` fails on dead code, duplicated code, or complexity beyond `.fallow-health-baseline.json` (the 17 functions above threshold at 0.1.0). It runs in CI (findings annotate the pull request), in the release workflow, and in the Swamp `release-check` as a fourth assertion. Three internal-only exports lost `export`, and the verify scripts share `scripts/lib.ts`.
51
+
12
52
  ## [0.1.0] - 2026-10-31
13
53
 
14
54
  The first working release: the reference parser and printer for the
15
- [grammar v0.1 draft](docs/grammar-v0.1-draft.md).
55
+ [grammar v0.1 draft](https://github.com/kevinpeckham/barmark/blob/main/docs/grammar-v0.1-draft.md).
16
56
 
17
57
  ### Added
18
58
 
@@ -45,7 +85,9 @@ The first working release: the reference parser and printer for the
45
85
 
46
86
  - **A placeholder package that holds the `barmark` name** while the spec and parser are written.
47
87
 
48
- [Unreleased]: https://github.com/kevinpeckham/barmark/compare/v0.1.0...HEAD
88
+ [Unreleased]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.3.0...HEAD
89
+ [0.3.0]: https://github.com/kevinpeckham/barmark/compare/barmark-v0.2.0...barmark-v0.3.0
90
+ [0.2.0]: https://github.com/kevinpeckham/barmark/compare/v0.1.0...barmark-v0.2.0
49
91
  [0.1.0]: https://github.com/kevinpeckham/barmark/compare/v0.0.3...v0.1.0
50
92
  [0.0.3]: https://github.com/kevinpeckham/barmark/compare/v0.0.2...v0.0.3
51
93
  [0.0.2]: https://github.com/kevinpeckham/barmark/releases/tag/v0.0.2
package/README.md CHANGED
@@ -20,8 +20,8 @@ key: D, time: 4/4, tempo: 145
20
20
  ```
21
21
 
22
22
  A barmark file is a markdown file, with the extension `.chart.md`. The
23
- grammar is [docs/grammar-v0.1-draft.md](docs/grammar-v0.1-draft.md)
24
- (draft v0.1, for review), and [examples/](examples/) has a full chart.
23
+ grammar is [docs/grammar-v0.1-draft.md](https://github.com/kevinpeckham/barmark/blob/main/docs/grammar-v0.1-draft.md)
24
+ (draft v0.1, for review), and [examples/](https://github.com/kevinpeckham/barmark/tree/main/examples) has a full chart.
25
25
 
26
26
  ## Install
27
27
 
@@ -66,14 +66,15 @@ harteToBarmark("A:sus4(b7,9)"); // "A9sus4"
66
66
  bun install
67
67
  bun test # the test suite
68
68
  bun run check # Biome and the TypeScript typecheck
69
+ bun run fallow # dead code, duplication and complexity (Fallow)
69
70
  bun run verify:package # build, check the npm package, import it in Node
70
71
  ```
71
72
 
72
73
  CI runs these on every push and pull request. Releases follow
73
- [RELEASING.md](RELEASING.md); changes are in [CHANGELOG.md](CHANGELOG.md),
74
- and lessons learned along the way are in [FINDINGS.md](FINDINGS.md). The
74
+ [RELEASING.md](https://github.com/kevinpeckham/barmark/blob/main/RELEASING.md); changes are in [CHANGELOG.md](CHANGELOG.md),
75
+ and lessons learned along the way are in [FINDINGS.md](https://github.com/kevinpeckham/barmark/blob/main/FINDINGS.md). The
75
76
  project's founding brief, prior art and roadmap are in
76
- [BRIEF.md](BRIEF.md).
77
+ [BRIEF.md](https://github.com/kevinpeckham/barmark/blob/main/BRIEF.md).
77
78
 
78
79
  ## License
79
80
 
@@ -60,11 +60,40 @@ function oldFormat(text, line) {
60
60
  const name = near?.[1] ? NEAR_DIRECTIVES[near[1].toLowerCase()] : undefined;
61
61
  if (near && name)
62
62
  return warn(`not a directive; did you mean ${name}:?`, `${name}: ${near[2]}`);
63
+ const unescaped = escapedBarLine(text);
64
+ if (unescaped)
65
+ return warn("escaped pipes; a bar line uses a plain |", unescaped);
63
66
  const words = text.split(/\s+/);
64
67
  if (words.length >= 2 && words.every((w) => parseChord(w).ok))
65
68
  return warn("chords outside a bar line are text", `| ${words.join(" | ")} |`);
66
69
  return null;
67
70
  }
71
+ /** `D \| A \|` (an editor's escaping) as the bar line it would be, if it reads cleanly. */
72
+ function escapedBarLine(text) {
73
+ if (!text.includes("\\|"))
74
+ return null;
75
+ let fixed = text.replaceAll("\\|", "|").trim();
76
+ if (!fixed.startsWith("|"))
77
+ fixed = `| ${fixed}`;
78
+ if (!fixed.endsWith("|"))
79
+ fixed = `${fixed} |`;
80
+ const read = parseBarLine(fixed, 0);
81
+ return read.bars && read.diagnostics.length === 0 ? fixed : null;
82
+ }
83
+ /** A chart whose text holds no bar line at all says so, rather than looking empty. */
84
+ function noBarLines(lines) {
85
+ if (lines.some((l) => l.kind === "bars" || l.kind === "invalid"))
86
+ return null;
87
+ const first = lines.find((l) => l.kind === "text");
88
+ if (first?.kind !== "text")
89
+ return null;
90
+ return {
91
+ line: first.line,
92
+ severity: "warning",
93
+ message: "no bar lines in this chart; a bar line starts with |",
94
+ token: first.text,
95
+ };
96
+ }
68
97
  /** Classify every line of a chart: title, sections, directives, bar lines and text. */
69
98
  export function readDocument(text) {
70
99
  const lines = [];
@@ -112,5 +141,8 @@ export function readDocument(text) {
112
141
  diagnostics.push(old);
113
142
  lines.push({ kind: "text", line, text: t });
114
143
  });
144
+ const empty = noBarLines(lines);
145
+ if (empty)
146
+ diagnostics.push(empty);
115
147
  return { title, lines, diagnostics };
116
148
  }
@@ -249,11 +249,13 @@ export function expand(lines) {
249
249
  continue;
250
250
  }
251
251
  replayOf = source.heading.line;
252
- playItems(items, out);
253
252
  const body = itemsOf.get(source) ?? [];
254
253
  times(h.repeat, h.line, out, (into) => playItems(body, into));
255
254
  }
256
255
  const elided = !isDefinition && h.elided && removeLastBar(out);
256
+ // A replay heading stands for its bars: its own lines (directives) come after them.
257
+ if (!isDefinition)
258
+ playItems(items, out);
257
259
  events.push(...out);
258
260
  occurrences.push([
259
261
  { name: h.name, line: h.line, replayOf, firstBar: null, lastBar: null, elided },
@@ -263,9 +265,18 @@ export function expand(lines) {
263
265
  flattenBars(events).forEach((b, i) => {
264
266
  b.index = i + 1;
265
267
  });
268
+ const forms = new Map();
266
269
  const sectionsOut = occurrences.map(([occ, out]) => {
267
270
  const bars = flattenBars(out);
268
- return { ...occ, firstBar: bars[0]?.index ?? null, lastBar: bars.at(-1)?.index ?? null };
271
+ const written = occ.replayOf ?? occ.line;
272
+ if (!forms.has(written))
273
+ forms.set(written, forms.size);
274
+ return {
275
+ ...occ,
276
+ firstBar: bars[0]?.index ?? null,
277
+ lastBar: bars.at(-1)?.index ?? null,
278
+ form: forms.get(written) ?? 0,
279
+ };
269
280
  });
270
281
  return { events, sections: sectionsOut, diagnostics };
271
282
  }
@@ -117,6 +117,11 @@ export type SectionOccurrence = {
117
117
  firstBar: number | null;
118
118
  lastBar: number | null;
119
119
  elided: boolean;
120
+ /**
121
+ * Which distinct section this plays, numbered in first-appearance order
122
+ * from 0: every replay shares its written section's number.
123
+ */
124
+ form: number;
120
125
  };
121
126
  export type ChartParse = {
122
127
  title: string | null;
@@ -67,6 +67,7 @@ export function parseNoteSet(text) {
67
67
  bass,
68
68
  alteredOpen: false,
69
69
  harte: "",
70
+ parts: null,
70
71
  };
71
72
  value.harte = toHarte(value);
72
73
  return { ok: true, warnings, value };
@@ -1,6 +1,2 @@
1
- import type { Diagnostic, ParseResult } from "./types.js";
2
- /** Appendix A.5 and A.6: Unicode, rejections, then aliases into canonical vocabulary. */
3
- export declare function normalizeSymbol(symbol: string): {
4
- text: string;
5
- } | Diagnostic;
1
+ import type { ParseResult } from "./types.js";
6
2
  export declare function parseChord(symbol: string): ParseResult;
@@ -1,6 +1,6 @@
1
1
  import { toHarte } from "./harte.js";
2
2
  import { noteSemitone, transpose } from "./intervals.js";
3
- import { printChord } from "./print.js";
3
+ import { canonicalParts, printChord } from "./print.js";
4
4
  import { ALIASES, chordIntervals, EXTENSIONS, rejection, TONES, validateParts, } from "./vocabulary.js";
5
5
  const ROOT = /^[A-G][#b]?/;
6
6
  const INLINE_ALTERATION = /^(b5|#5|b9|#9|#11|b13)/;
@@ -62,7 +62,7 @@ function tokenize(symbol) {
62
62
  return { root, quality, extension: ext, sus, tones, bass };
63
63
  }
64
64
  /** Appendix A.5 and A.6: Unicode, rejections, then aliases into canonical vocabulary. */
65
- export function normalizeSymbol(symbol) {
65
+ function normalizeSymbol(symbol) {
66
66
  const text = symbol.replace(/♯/g, "#").replace(/♭/g, "b");
67
67
  const rejected = rejection(text, noteSemitone);
68
68
  if (rejected)
@@ -110,6 +110,7 @@ export function parseChord(symbol) {
110
110
  bass: parts.bass ?? parts.root,
111
111
  alteredOpen,
112
112
  harte: "",
113
+ parts: canonicalParts(parts),
113
114
  };
114
115
  value.harte = toHarte(value);
115
116
  return { ok: true, warnings, value };
@@ -1,4 +1,6 @@
1
1
  import { type ChordParts } from "./vocabulary.js";
2
+ /** The parts as the canonical spelling has them: the same parts, tones sorted. */
3
+ export declare function canonicalParts(parts: ChordParts): ChordParts;
2
4
  /** The canonical text after the root: quality, extension, sus, sorted tones. */
3
5
  export declare function printSuffix(parts: Omit<ChordParts, "root" | "bass">): string;
4
6
  /** The canonical spelling: root, suffix, bass. */
@@ -1,7 +1,13 @@
1
1
  import { byDegree, toneInterval } from "./vocabulary.js";
2
+ /** The tones in canonical order (by degree), as the canonical spelling lists them. */
3
+ const sortTones = (tones) => [...tones].sort((a, b) => byDegree(toneInterval(a), toneInterval(b)));
4
+ /** The parts as the canonical spelling has them: the same parts, tones sorted. */
5
+ export function canonicalParts(parts) {
6
+ return { ...parts, tones: sortTones(parts.tones) };
7
+ }
2
8
  /** The canonical text after the root: quality, extension, sus, sorted tones. */
3
9
  export function printSuffix(parts) {
4
- const tones = [...parts.tones].sort((a, b) => byDegree(toneInterval(a), toneInterval(b)));
10
+ const tones = sortTones(parts.tones);
5
11
  return `${parts.quality}${parts.extension ?? ""}${parts.sus ?? ""}${tones.length ? `(${tones.join(",")})` : ""}`;
6
12
  }
7
13
  /** The canonical spelling: root, suffix, bass. */
@@ -1,3 +1,4 @@
1
+ import type { ChordParts } from "./vocabulary.js";
1
2
  /** A scale degree above a root: `b3` is `{ degree: 3, alter: -1 }`. Degrees above 7 stay as written. */
2
3
  export type Interval = {
3
4
  degree: number;
@@ -19,6 +20,8 @@ export type ChordRecord = {
19
20
  bass: string;
20
21
  alteredOpen: boolean;
21
22
  harte: string;
23
+ /** The canonical parts a chord symbol is spelled from; null for a note set. */
24
+ parts: ChordParts | null;
22
25
  };
23
26
  export type ParseResult = {
24
27
  ok: true;
@@ -10,7 +10,6 @@ export type ChordParts = {
10
10
  tones: string[];
11
11
  bass: string | null;
12
12
  };
13
- export declare const QUALITIES: Record<Quality, Interval[]>;
14
13
  /** Longest first, so the tokenizer can take the first prefix that matches. */
15
14
  export declare const EXTENSIONS: [Extension, Interval[]][];
16
15
  /** Appendix A.3. */
@@ -9,7 +9,7 @@ const ivs = (...s) => s.map((x) => {
9
9
  throw new Error(`bad interval ${x}`);
10
10
  return i;
11
11
  });
12
- export const QUALITIES = {
12
+ const QUALITIES = {
13
13
  "": ivs("1", "3", "5"),
14
14
  m: ivs("1", "b3", "5"),
15
15
  dim: ivs("1", "b3", "b5"),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "barmark",
3
- "version": "0.1.0",
3
+ "version": "0.3.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": {
@@ -31,24 +31,17 @@
31
31
  ],
32
32
  "author": "Kevin Peckham",
33
33
  "license": "MIT",
34
- "homepage": "https://github.com/kevinpeckham/barmark#readme",
34
+ "homepage": "https://github.com/kevinpeckham/barmark/tree/main/packages/barmark#readme",
35
35
  "repository": {
36
36
  "type": "git",
37
- "url": "git+https://github.com/kevinpeckham/barmark.git"
37
+ "url": "git+https://github.com/kevinpeckham/barmark.git",
38
+ "directory": "packages/barmark"
38
39
  },
39
40
  "devDependencies": {
40
- "@biomejs/biome": "^2.6.4",
41
- "@types/bun": "^1.4.4",
42
- "@varlock/1password-plugin": "^2.0.5",
43
- "typescript": "^7.0.2",
44
- "varlock": "^1.23.0"
41
+ "@types/bun": "^1.4.4"
45
42
  },
46
43
  "scripts": {
47
- "test": "bun test",
48
- "check": "biome check . && tsc",
49
44
  "build": "rm -rf dist && tsc -p tsconfig.build.json",
50
- "verify:package": "bun scripts/verify-package.ts",
51
- "verify:release": "bun scripts/verify-release.ts",
52
45
  "prepack": "bun run build"
53
46
  },
54
47
  "bugs": {