Skip to content

Fix #62 — parse %%score / %%staves into a StaffPlan - #93

Merged
sbeitzel merged 2 commits into
developfrom
feature/fix_62
Aug 19, 2026
Merged

Fix #62 — parse %%score / %%staves into a StaffPlan#93
sbeitzel merged 2 commits into
developfrom
feature/fix_62

Conversation

@sbeitzel

Copy link
Copy Markdown
Owner

Closes #62. Parser and model only — no renderer consumes the plan yet (#63, #64), so
SVGEmitter.swift:250's note about braces and brackets stays accurate.

What it does

Both spellings normalise to one StaffPlan, so nothing downstream can tell which was
written: %%staves inverts the sense of |, and that inversion is a single flag applied
where each joint is built. Joints are paired with the node they precede, so a branch
cannot be empty and the joint count is structurally correct without index arithmetic.

The line classifier splits %%name payload on the first space only, with no bracket
awareness (LineClassifier.swift:79-87), so StaffPlanParser owns every delimiter. It
tracks UTF-8 offsets while scanning to give each voice id its own SourceRange, which is
what lets a diagnostic point at the offending id rather than at the whole line. On any
syntax error the whole directive is dropped rather than stored as a partial tree, matching
how the other directives recover.

Custom == / hash(into:)

StaffPlan and StaffPlanVoice ignore SourceRange in their Hashable conformance —
the first types in CeolKitModel to do so, so the divergence is documented at the type.
Two spellings of the same plan have different payload lengths and therefore can never
carry matching ranges; the ranges are provenance for diagnostics, not part of what the
plan is. Every other type in the tree keeps its synthesized conformance and inherits the
semantics through these two.

The tests assert offsets directly (floatingVoiceSourceRange, diagnosticPosition) so
ignoring source in == cannot mask a regression in computing it, and pin the
conformance from the other side too: [S A] != [S|A] (joints) and [S A] != {S A}
(nesting).

Wiring

Directive names live in three hand-synced lists — isStandardDirective, the
parseCeolKitDirective switch, and the applyBodyDirective allowlist. All three learn
score and staves; the third is what keeps a body %%score from reporting
unknownDirective.

Also corrects CLAUDE.md, which documented a CeolKitDirective.unknown(name:payload:)
case that does not exist.

Verification

734 tests in 51 suites pass from a clean checkout (713 before, 21 new). All four
acceptance tunes parse to the expected tree, and ckprobe confirms it end to end on
%%score [{Vln1 | Vln2} | Vla | Vc | DB] — bracket/brace nesting, continuedBarline
joints, and Vln1 located at line 3 column 11.

Independent of #92; either can merge first.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Ti4qg7EGCvA5Pa7o9TL8fF

sbeitzel and others added 2 commits August 18, 2026 16:10
Parser and model only; no renderer consumes the plan yet (#63, #64).

Both spellings normalise to one StaffPlan, so nothing downstream can tell
which was written: %%staves inverts the sense of `|`, and that is a single
flag applied where each joint is built.  Joints are paired with the node
they precede, so a branch cannot be empty and the joint count is
structurally correct without index arithmetic.

The line classifier splits `%%name payload` on the first space only, with
no bracket awareness, so StaffPlanParser owns every delimiter.  It tracks
UTF-8 offsets while scanning to give each voice id its own SourceRange,
which is what lets a diagnostic point at the offending id rather than at
the line.  On any syntax error the whole directive is dropped rather than
stored as a partial tree, matching how the other directives recover.

StaffPlan and StaffPlanVoice get custom Equatable/Hashable that ignore
SourceRange — the first in CeolKitModel to do so.  Two spellings of the
same plan have different payload lengths and so can never carry matching
ranges; the ranges are provenance for diagnostics, not part of what the
plan is.

Directive names live in three hand-synced lists (isStandardDirective, the
parseCeolKitDirective switch, and the applyBodyDirective allowlist); all
three learn `score` and `staves`, the third being what keeps a body
%%score from reporting unknownDirective.

Also corrects CLAUDE.md, which documented a CeolKitDirective.unknown case
that does not exist.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ti4qg7EGCvA5Pa7o9TL8fF
@sbeitzel
sbeitzel merged commit be6d47c into develop Aug 19, 2026
2 checks passed
@sbeitzel
sbeitzel deleted the feature/fix_62 branch August 19, 2026 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant