/
grammar.treetop
193 lines (125 loc) · 3.65 KB
/
grammar.treetop
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
module Cosy
grammar Sequence
rule root
space? (statement ';' space?)* statement? space? <CosyNode>
end
rule statement
assignment / sequence_root
end
rule assignment
var space? '=' sequence_root <AssignmentNode>
end
rule sequence_root
parallel_sequence
end
rule parallel_sequence
space? choice (space? '==' space? choice)* space? <ParallelNode>
end
rule choice
space? sequence (space? '|' space? sequence)* space? <ChoiceNode>
end
rule sequence
space? sequence_element (space sequence_element)* space? <SequenceNode>
end
rule sequence_element
command / chain modifier:modifier <ModifiedNode> / chain / foreach
end
rule chain
chain_element (':' chain_element)* <ChainNode>
end
rule chain_element
element modifier:modifier <ModifiedNode> / element
end
rule foreach
'(' sequence_root ')@(' sequence_root ')' ('@(' sequence_root ')')* <ForEachNode>
end
rule element
'(' subsequence:sequence_root ')' !'@' / chord / primitive
end
rule modifier
operator:operator operand:element <BehaviorNode>
end
rule operator
space? ('*'/'&') space? <OperatorNode>
end
rule chord
'[' space? primitive (space primitive)* space? ']' <ChordNode>
end
rule primitive
interval / pitch / velocity / duration / number / string / label / var / ruby / osc_address
end
rule pitch
note_name:[A-Ga-g] ![A-Zac-z] accidentals:('#'/'b'/'+'/'_')* octave:(int)? <PitchNode>
/
('pitch'/'pit'/'PIT') number:(number/ruby) <NumericPitchNode>
end
rule interval
sign:[+-]?
quality:(
'major' / 'maj' / 'minor' / 'min' / 'perfect' / 'per' / 'augmented' / 'aug' / 'diminished' / 'dim' /
'MAJOR' / 'MAJ' / 'MINOR' / 'MIN' / 'PERFECT' / 'PER' / 'AUGMENTED' / 'AUG' / 'DIMINISHED' / 'DIM' /
[MmpP] )
degree:[0-9]+ <IntervalNode>
/
('interval'/[Ii]) number:(number/ruby) <NumericIntervalNode>
end
rule velocity
( ('mezzo' '-'?)? ('piano'/'forte') / 'fortissimo' / 'pianissimo' /
'mp' / 'ppp' / 'pp' / 'p' / 'mf' / 'fff' / 'ff' / 'fo' /
'MP' / 'PPP' / 'PP' / 'P' / 'MF' / 'FFF' / 'FF' / 'FO'
) ![\w] <VelocityNode>
/
('velocity'/'vel'/'VEL'/[Vv]) number:(number/ruby) <NumericVelocityNode>
end
rule duration
multiplier:(number/'-')? metrical_duration:metrical_duration modifier:duration_modifier* <DurationNode>
/
('duration'/'dur'/'DUR') number:(number/ruby) <NumericDurationNode>
end
rule metrical_duration
'whole' / 'half' / 'quarter' / 'eighth' / 'ei' / 'EI' / 'sixteenth' /
'thirty' '-'? 'second' / 'sixty' '-'? 'fourth' /
[WwHhQqIiSsRrXx]
end
rule duration_modifier
't' / '.'
end
rule number
ratio / float / int
end
rule ratio
int '/' int <RatioNode>
end
rule float
'-'? [0-9]+ '.' [0-9]+ <FloatNode>
end
rule int
'-'? [0-9]+ <IntNode>
end
rule string
"'" ("\\'" / !"'" .)* "'" <StringNode>
/
'"' ('\"' / !'"' .)* '"' <StringNode>
end
rule label
'#' [\w-]+ <LabelNode>
end
rule var
'$' [A-Za-z] [\w-]* <VariableNode>
/
'$'+ <VariableNode>
end
rule ruby
'{' script:( string / !('}'/'"'/"'") . )* '}' <RubyNode>
end
rule command
'{{' script:( string / !('}}'/'"'/"'") . )* '}}' <CommandNode>
end
rule osc_address
'/' [A-Za-z0-9_/.]* <OscAddressNode>
end
rule space
[\s]+
end
end
end