Fix #62 — parse %%score / %%staves into a StaffPlan - #93
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 waswritten:
%%stavesinverts the sense of|, and that inversion is a single flag appliedwhere 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 payloadon the first space only, with no bracketawareness (
LineClassifier.swift:79-87), soStaffPlanParserowns every delimiter. Ittracks UTF-8 offsets while scanning to give each voice id its own
SourceRange, which iswhat 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:)StaffPlanandStaffPlanVoiceignoreSourceRangein theirHashableconformance —the first types in
CeolKitModelto 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) soignoring
sourcein==cannot mask a regression in computing it, and pin theconformance 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, theparseCeolKitDirectiveswitch, and theapplyBodyDirectiveallowlist. All three learnscoreandstaves; the third is what keeps a body%%scorefrom reportingunknownDirective.Also corrects
CLAUDE.md, which documented aCeolKitDirective.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
ckprobeconfirms it end to end on%%score [{Vln1 | Vln2} | Vla | Vc | DB]— bracket/brace nesting,continuedBarlinejoints, and
Vln1located at line 3 column 11.Independent of #92; either can merge first.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Ti4qg7EGCvA5Pa7o9TL8fF