Skip to main content

croma_core/syntax/
field.rs

1//! Field and directive surface AST: inline/body music fields, score and
2//! preserved stylesheet directives, and the unsupported/malformed markers used
3//! when a music token cannot be represented.
4
5use crate::diagnostic::Span;
6use crate::parse::field::{
7    KeySignature, Meter, ScoreDirective, Spanned, UnitNoteLength, VoiceDefinition,
8};
9use crate::syntax::lyric::{LyricLineSyntax, SymbolLineSyntax};
10
11#[derive(Debug, Clone, PartialEq, Eq)]
12pub struct InlineFieldSyntax {
13    pub span: Span,
14    pub marker_span: Span,
15    pub code: char,
16    pub value: Spanned<String>,
17    pub voice: Option<Spanned<VoiceDefinition>>,
18}
19
20#[derive(Debug, Clone, PartialEq, Eq)]
21pub struct MusicFieldLine {
22    pub line_index: usize,
23    pub code: char,
24    pub line_span: Span,
25    pub marker_span: Span,
26    pub value: Spanned<String>,
27    pub kind: MusicFieldLineKind,
28}
29
30#[allow(clippy::large_enum_variant)]
31#[derive(Debug, Clone, PartialEq, Eq)]
32pub enum MusicFieldLineKind {
33    Meter(Spanned<Meter>),
34    UnitNoteLength(Spanned<UnitNoteLength>),
35    Key(Spanned<KeySignature>),
36    Voice(Spanned<VoiceDefinition>),
37    Lyric(LyricLineSyntax),
38    Symbol(SymbolLineSyntax),
39    PostTuneText(Spanned<String>),
40    Score(ScoreDirective),
41    Tempo(Spanned<String>),
42    /// A body/inline `P:` section label (ABC 2.1 ยง4.3). Only the BODY position
43    /// produces this; a header `P:ABAB` play-order macro is dropped upstream.
44    SectionLabel(Spanned<String>),
45    Unknown(Spanned<String>),
46    Other,
47}
48
49#[derive(Debug, Clone, PartialEq, Eq)]
50pub struct ScoreDirectiveSyntax {
51    pub line_index: usize,
52    pub span: Span,
53    pub marker_span: Span,
54    pub name_span: Span,
55    pub value: Spanned<String>,
56    pub directive: ScoreDirective,
57}
58
59#[derive(Debug, Clone, PartialEq, Eq)]
60pub struct PreservedDirectiveSyntax {
61    pub line_index: usize,
62    pub span: Span,
63    pub marker_span: Span,
64    pub name: Spanned<String>,
65    pub value: Spanned<String>,
66}
67
68#[derive(Debug, Clone, PartialEq, Eq)]
69pub struct UnsupportedSyntax {
70    pub span: Span,
71    pub kind: UnsupportedSyntaxKind,
72}
73
74#[derive(Debug, Clone, Copy, PartialEq, Eq)]
75pub enum UnsupportedSyntaxKind {
76    Chord,
77    GraceGroup,
78    Tuplet,
79    Slur,
80    Tie,
81    Decoration,
82    BrokenRhythm,
83    RepeatEnding,
84    QuotedText,
85    Reserved,
86}
87
88#[derive(Debug, Clone, PartialEq, Eq)]
89pub struct MalformedSyntax {
90    pub span: Span,
91    pub kind: MalformedSyntaxKind,
92}
93
94#[derive(Debug, Clone, Copy, PartialEq, Eq)]
95pub enum MalformedSyntaxKind {
96    DanglingAccidental,
97    StandaloneOctave,
98    StandaloneLength,
99    InvalidLength,
100    UnclosedInlineField,
101    UnclosedChord,
102    UnclosedGraceGroup,
103    UnclosedQuotedText,
104    UnclosedSlur,
105    UnclosedDecoration,
106    InvalidBarline,
107    InvalidTuplet,
108    InvalidRepeatEnding,
109    InvalidDecoration,
110    UnknownToken,
111}