musicality 0.1.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.
Files changed (141) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.rspec +2 -0
  4. data/.ruby-version +1 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +47 -0
  8. data/Rakefile +65 -0
  9. data/bin/midify +78 -0
  10. data/examples/hip.rb +32 -0
  11. data/examples/missed_connection.rb +26 -0
  12. data/examples/song1.rb +33 -0
  13. data/examples/song2.rb +32 -0
  14. data/lib/musicality/errors.rb +9 -0
  15. data/lib/musicality/notation/conversion/change_conversion.rb +19 -0
  16. data/lib/musicality/notation/conversion/measure_note_map.rb +40 -0
  17. data/lib/musicality/notation/conversion/measured_score_conversion.rb +70 -0
  18. data/lib/musicality/notation/conversion/measured_score_converter.rb +95 -0
  19. data/lib/musicality/notation/conversion/note_time_converter.rb +68 -0
  20. data/lib/musicality/notation/conversion/tempo_conversion.rb +25 -0
  21. data/lib/musicality/notation/conversion/unmeasured_score_conversion.rb +47 -0
  22. data/lib/musicality/notation/conversion/unmeasured_score_converter.rb +64 -0
  23. data/lib/musicality/notation/model/articulations.rb +13 -0
  24. data/lib/musicality/notation/model/change.rb +62 -0
  25. data/lib/musicality/notation/model/dynamics.rb +12 -0
  26. data/lib/musicality/notation/model/link.rb +73 -0
  27. data/lib/musicality/notation/model/meter.rb +54 -0
  28. data/lib/musicality/notation/model/meters.rb +9 -0
  29. data/lib/musicality/notation/model/note.rb +120 -0
  30. data/lib/musicality/notation/model/part.rb +54 -0
  31. data/lib/musicality/notation/model/pitch.rb +163 -0
  32. data/lib/musicality/notation/model/pitches.rb +21 -0
  33. data/lib/musicality/notation/model/program.rb +53 -0
  34. data/lib/musicality/notation/model/score.rb +132 -0
  35. data/lib/musicality/notation/packing/change_packing.rb +46 -0
  36. data/lib/musicality/notation/packing/part_packing.rb +31 -0
  37. data/lib/musicality/notation/packing/program_packing.rb +16 -0
  38. data/lib/musicality/notation/packing/score_packing.rb +108 -0
  39. data/lib/musicality/notation/parsing/articulation_parsing.rb +264 -0
  40. data/lib/musicality/notation/parsing/articulation_parsing.treetop +59 -0
  41. data/lib/musicality/notation/parsing/convenience_methods.rb +74 -0
  42. data/lib/musicality/notation/parsing/duration_nodes.rb +21 -0
  43. data/lib/musicality/notation/parsing/duration_parsing.rb +205 -0
  44. data/lib/musicality/notation/parsing/duration_parsing.treetop +25 -0
  45. data/lib/musicality/notation/parsing/link_nodes.rb +35 -0
  46. data/lib/musicality/notation/parsing/link_parsing.rb +270 -0
  47. data/lib/musicality/notation/parsing/link_parsing.treetop +33 -0
  48. data/lib/musicality/notation/parsing/meter_parsing.rb +190 -0
  49. data/lib/musicality/notation/parsing/meter_parsing.treetop +29 -0
  50. data/lib/musicality/notation/parsing/note_node.rb +40 -0
  51. data/lib/musicality/notation/parsing/note_parsing.rb +229 -0
  52. data/lib/musicality/notation/parsing/note_parsing.treetop +28 -0
  53. data/lib/musicality/notation/parsing/numbers/nonnegative_float_parsing.rb +289 -0
  54. data/lib/musicality/notation/parsing/numbers/nonnegative_float_parsing.treetop +29 -0
  55. data/lib/musicality/notation/parsing/numbers/nonnegative_integer_parsing.rb +64 -0
  56. data/lib/musicality/notation/parsing/numbers/nonnegative_integer_parsing.treetop +17 -0
  57. data/lib/musicality/notation/parsing/numbers/nonnegative_rational_parsing.rb +86 -0
  58. data/lib/musicality/notation/parsing/numbers/nonnegative_rational_parsing.treetop +20 -0
  59. data/lib/musicality/notation/parsing/numbers/positive_float_parsing.rb +503 -0
  60. data/lib/musicality/notation/parsing/numbers/positive_float_parsing.treetop +33 -0
  61. data/lib/musicality/notation/parsing/numbers/positive_integer_parsing.rb +95 -0
  62. data/lib/musicality/notation/parsing/numbers/positive_integer_parsing.treetop +19 -0
  63. data/lib/musicality/notation/parsing/numbers/positive_rational_parsing.rb +84 -0
  64. data/lib/musicality/notation/parsing/numbers/positive_rational_parsing.treetop +19 -0
  65. data/lib/musicality/notation/parsing/parseable.rb +30 -0
  66. data/lib/musicality/notation/parsing/pitch_node.rb +23 -0
  67. data/lib/musicality/notation/parsing/pitch_parsing.rb +448 -0
  68. data/lib/musicality/notation/parsing/pitch_parsing.treetop +52 -0
  69. data/lib/musicality/notation/parsing/segment_parsing.rb +141 -0
  70. data/lib/musicality/notation/parsing/segment_parsing.treetop +23 -0
  71. data/lib/musicality/notation/util/interpolation.rb +16 -0
  72. data/lib/musicality/notation/util/piecewise_function.rb +122 -0
  73. data/lib/musicality/notation/util/value_computer.rb +170 -0
  74. data/lib/musicality/performance/conversion/glissando_converter.rb +34 -0
  75. data/lib/musicality/performance/conversion/note_sequence_extractor.rb +98 -0
  76. data/lib/musicality/performance/conversion/portamento_converter.rb +24 -0
  77. data/lib/musicality/performance/conversion/score_collator.rb +126 -0
  78. data/lib/musicality/performance/midi/midi_events.rb +34 -0
  79. data/lib/musicality/performance/midi/midi_util.rb +31 -0
  80. data/lib/musicality/performance/midi/part_sequencer.rb +123 -0
  81. data/lib/musicality/performance/midi/score_sequencer.rb +45 -0
  82. data/lib/musicality/performance/model/note_attacks.rb +19 -0
  83. data/lib/musicality/performance/model/note_sequence.rb +111 -0
  84. data/lib/musicality/performance/util/note_linker.rb +28 -0
  85. data/lib/musicality/performance/util/optimization.rb +31 -0
  86. data/lib/musicality/validatable.rb +38 -0
  87. data/lib/musicality/version.rb +3 -0
  88. data/lib/musicality.rb +81 -0
  89. data/musicality.gemspec +30 -0
  90. data/spec/musicality_spec.rb +7 -0
  91. data/spec/notation/conversion/change_conversion_spec.rb +40 -0
  92. data/spec/notation/conversion/measure_note_map_spec.rb +73 -0
  93. data/spec/notation/conversion/measured_score_conversion_spec.rb +141 -0
  94. data/spec/notation/conversion/measured_score_converter_spec.rb +329 -0
  95. data/spec/notation/conversion/note_time_converter_spec.rb +81 -0
  96. data/spec/notation/conversion/tempo_conversion_spec.rb +40 -0
  97. data/spec/notation/conversion/unmeasured_score_conversion_spec.rb +71 -0
  98. data/spec/notation/conversion/unmeasured_score_converter_spec.rb +116 -0
  99. data/spec/notation/model/change_spec.rb +90 -0
  100. data/spec/notation/model/link_spec.rb +83 -0
  101. data/spec/notation/model/meter_spec.rb +97 -0
  102. data/spec/notation/model/note_spec.rb +183 -0
  103. data/spec/notation/model/part_spec.rb +69 -0
  104. data/spec/notation/model/pitch_spec.rb +180 -0
  105. data/spec/notation/model/program_spec.rb +50 -0
  106. data/spec/notation/model/score_spec.rb +211 -0
  107. data/spec/notation/packing/change_packing_spec.rb +153 -0
  108. data/spec/notation/packing/part_packing_spec.rb +66 -0
  109. data/spec/notation/packing/program_packing_spec.rb +33 -0
  110. data/spec/notation/packing/score_packing_spec.rb +301 -0
  111. data/spec/notation/parsing/articulation_parsing_spec.rb +23 -0
  112. data/spec/notation/parsing/convenience_methods_spec.rb +99 -0
  113. data/spec/notation/parsing/duration_nodes_spec.rb +83 -0
  114. data/spec/notation/parsing/duration_parsing_spec.rb +70 -0
  115. data/spec/notation/parsing/link_nodes_spec.rb +30 -0
  116. data/spec/notation/parsing/link_parsing_spec.rb +13 -0
  117. data/spec/notation/parsing/meter_parsing_spec.rb +23 -0
  118. data/spec/notation/parsing/note_node_spec.rb +87 -0
  119. data/spec/notation/parsing/note_parsing_spec.rb +46 -0
  120. data/spec/notation/parsing/numbers/nonnegative_float_spec.rb +28 -0
  121. data/spec/notation/parsing/numbers/nonnegative_integer_spec.rb +11 -0
  122. data/spec/notation/parsing/numbers/nonnegative_rational_spec.rb +11 -0
  123. data/spec/notation/parsing/numbers/positive_float_spec.rb +28 -0
  124. data/spec/notation/parsing/numbers/positive_integer_spec.rb +28 -0
  125. data/spec/notation/parsing/numbers/positive_rational_spec.rb +28 -0
  126. data/spec/notation/parsing/pitch_node_spec.rb +38 -0
  127. data/spec/notation/parsing/pitch_parsing_spec.rb +14 -0
  128. data/spec/notation/parsing/segment_parsing_spec.rb +27 -0
  129. data/spec/notation/util/value_computer_spec.rb +146 -0
  130. data/spec/performance/conversion/glissando_converter_spec.rb +93 -0
  131. data/spec/performance/conversion/note_sequence_extractor_spec.rb +230 -0
  132. data/spec/performance/conversion/portamento_converter_spec.rb +91 -0
  133. data/spec/performance/conversion/score_collator_spec.rb +183 -0
  134. data/spec/performance/midi/midi_util_spec.rb +110 -0
  135. data/spec/performance/midi/part_sequencer_spec.rb +40 -0
  136. data/spec/performance/midi/score_sequencer_spec.rb +50 -0
  137. data/spec/performance/model/note_sequence_spec.rb +147 -0
  138. data/spec/performance/util/note_linker_spec.rb +68 -0
  139. data/spec/performance/util/optimization_spec.rb +73 -0
  140. data/spec/spec_helper.rb +43 -0
  141. metadata +323 -0
@@ -0,0 +1,503 @@
1
+ # Autogenerated from a Treetop grammar. Edits may be lost.
2
+
3
+
4
+ module Musicality
5
+ module Parsing
6
+
7
+ module PositiveFloat
8
+ include Treetop::Runtime
9
+
10
+ def root
11
+ @root ||= :positive_float
12
+ end
13
+
14
+ module PositiveFloat0
15
+ def to_f
16
+ text_value.to_f
17
+ end
18
+
19
+ alias :to_num :to_f
20
+ end
21
+
22
+ def _nt_positive_float
23
+ start_index = index
24
+ if node_cache[:positive_float].has_key?(index)
25
+ cached = node_cache[:positive_float][index]
26
+ if cached
27
+ node_cache[:positive_float][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
28
+ @index = cached.interval.end
29
+ end
30
+ return cached
31
+ end
32
+
33
+ i0 = index
34
+ r1 = _nt_float1
35
+ if r1
36
+ r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
37
+ r0 = r1
38
+ r0.extend(PositiveFloat0)
39
+ else
40
+ r2 = _nt_float2
41
+ if r2
42
+ r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
43
+ r0 = r2
44
+ r0.extend(PositiveFloat0)
45
+ else
46
+ r3 = _nt_float3
47
+ if r3
48
+ r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
49
+ r0 = r3
50
+ r0.extend(PositiveFloat0)
51
+ else
52
+ @index = i0
53
+ r0 = nil
54
+ end
55
+ end
56
+ end
57
+
58
+ node_cache[:positive_float][start_index] = r0
59
+
60
+ r0
61
+ end
62
+
63
+ module Float10
64
+ def exponent
65
+ elements[3]
66
+ end
67
+ end
68
+
69
+ def _nt_float1
70
+ start_index = index
71
+ if node_cache[:float1].has_key?(index)
72
+ cached = node_cache[:float1][index]
73
+ if cached
74
+ node_cache[:float1][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
75
+ @index = cached.interval.end
76
+ end
77
+ return cached
78
+ end
79
+
80
+ i0, s0 = index, []
81
+ s1, i1 = [], index
82
+ loop do
83
+ if has_terminal?(@regexps[gr = '\A[0]'] ||= Regexp.new(gr), :regexp, index)
84
+ r2 = true
85
+ @index += 1
86
+ else
87
+ terminal_parse_failure('[0]')
88
+ r2 = nil
89
+ end
90
+ if r2
91
+ s1 << r2
92
+ else
93
+ break
94
+ end
95
+ end
96
+ r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
97
+ s0 << r1
98
+ if r1
99
+ s3, i3 = [], index
100
+ loop do
101
+ if has_terminal?(@regexps[gr = '\A[1-9]'] ||= Regexp.new(gr), :regexp, index)
102
+ r4 = true
103
+ @index += 1
104
+ else
105
+ terminal_parse_failure('[1-9]')
106
+ r4 = nil
107
+ end
108
+ if r4
109
+ s3 << r4
110
+ else
111
+ break
112
+ end
113
+ end
114
+ if s3.empty?
115
+ @index = i3
116
+ r3 = nil
117
+ else
118
+ r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
119
+ end
120
+ s0 << r3
121
+ if r3
122
+ s5, i5 = [], index
123
+ loop do
124
+ if has_terminal?(@regexps[gr = '\A[0-9]'] ||= Regexp.new(gr), :regexp, index)
125
+ r6 = true
126
+ @index += 1
127
+ else
128
+ terminal_parse_failure('[0-9]')
129
+ r6 = nil
130
+ end
131
+ if r6
132
+ s5 << r6
133
+ else
134
+ break
135
+ end
136
+ end
137
+ r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
138
+ s0 << r5
139
+ if r5
140
+ r7 = _nt_exponent
141
+ s0 << r7
142
+ end
143
+ end
144
+ end
145
+ if s0.last
146
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
147
+ r0.extend(Float10)
148
+ else
149
+ @index = i0
150
+ r0 = nil
151
+ end
152
+
153
+ node_cache[:float1][start_index] = r0
154
+
155
+ r0
156
+ end
157
+
158
+ module Float20
159
+ end
160
+
161
+ def _nt_float2
162
+ start_index = index
163
+ if node_cache[:float2].has_key?(index)
164
+ cached = node_cache[:float2][index]
165
+ if cached
166
+ node_cache[:float2][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
167
+ @index = cached.interval.end
168
+ end
169
+ return cached
170
+ end
171
+
172
+ i0, s0 = index, []
173
+ s1, i1 = [], index
174
+ loop do
175
+ if has_terminal?(@regexps[gr = '\A[0]'] ||= Regexp.new(gr), :regexp, index)
176
+ r2 = true
177
+ @index += 1
178
+ else
179
+ terminal_parse_failure('[0]')
180
+ r2 = nil
181
+ end
182
+ if r2
183
+ s1 << r2
184
+ else
185
+ break
186
+ end
187
+ end
188
+ r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
189
+ s0 << r1
190
+ if r1
191
+ s3, i3 = [], index
192
+ loop do
193
+ if has_terminal?(@regexps[gr = '\A[1-9]'] ||= Regexp.new(gr), :regexp, index)
194
+ r4 = true
195
+ @index += 1
196
+ else
197
+ terminal_parse_failure('[1-9]')
198
+ r4 = nil
199
+ end
200
+ if r4
201
+ s3 << r4
202
+ else
203
+ break
204
+ end
205
+ end
206
+ if s3.empty?
207
+ @index = i3
208
+ r3 = nil
209
+ else
210
+ r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
211
+ end
212
+ s0 << r3
213
+ if r3
214
+ s5, i5 = [], index
215
+ loop do
216
+ if has_terminal?(@regexps[gr = '\A[0-9]'] ||= Regexp.new(gr), :regexp, index)
217
+ r6 = true
218
+ @index += 1
219
+ else
220
+ terminal_parse_failure('[0-9]')
221
+ r6 = nil
222
+ end
223
+ if r6
224
+ s5 << r6
225
+ else
226
+ break
227
+ end
228
+ end
229
+ r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
230
+ s0 << r5
231
+ if r5
232
+ if has_terminal?(@regexps[gr = '\A[.]'] ||= Regexp.new(gr), :regexp, index)
233
+ r7 = true
234
+ @index += 1
235
+ else
236
+ terminal_parse_failure('[.]')
237
+ r7 = nil
238
+ end
239
+ s0 << r7
240
+ if r7
241
+ s8, i8 = [], index
242
+ loop do
243
+ if has_terminal?(@regexps[gr = '\A[0-9]'] ||= Regexp.new(gr), :regexp, index)
244
+ r9 = true
245
+ @index += 1
246
+ else
247
+ terminal_parse_failure('[0-9]')
248
+ r9 = nil
249
+ end
250
+ if r9
251
+ s8 << r9
252
+ else
253
+ break
254
+ end
255
+ end
256
+ if s8.empty?
257
+ @index = i8
258
+ r8 = nil
259
+ else
260
+ r8 = instantiate_node(SyntaxNode,input, i8...index, s8)
261
+ end
262
+ s0 << r8
263
+ if r8
264
+ r11 = _nt_exponent
265
+ if r11
266
+ r10 = r11
267
+ else
268
+ r10 = instantiate_node(SyntaxNode,input, index...index)
269
+ end
270
+ s0 << r10
271
+ end
272
+ end
273
+ end
274
+ end
275
+ end
276
+ if s0.last
277
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
278
+ r0.extend(Float20)
279
+ else
280
+ @index = i0
281
+ r0 = nil
282
+ end
283
+
284
+ node_cache[:float2][start_index] = r0
285
+
286
+ r0
287
+ end
288
+
289
+ module Float30
290
+ end
291
+
292
+ def _nt_float3
293
+ start_index = index
294
+ if node_cache[:float3].has_key?(index)
295
+ cached = node_cache[:float3][index]
296
+ if cached
297
+ node_cache[:float3][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
298
+ @index = cached.interval.end
299
+ end
300
+ return cached
301
+ end
302
+
303
+ i0, s0 = index, []
304
+ s1, i1 = [], index
305
+ loop do
306
+ if has_terminal?(@regexps[gr = '\A[0]'] ||= Regexp.new(gr), :regexp, index)
307
+ r2 = true
308
+ @index += 1
309
+ else
310
+ terminal_parse_failure('[0]')
311
+ r2 = nil
312
+ end
313
+ if r2
314
+ s1 << r2
315
+ else
316
+ break
317
+ end
318
+ end
319
+ if s1.empty?
320
+ @index = i1
321
+ r1 = nil
322
+ else
323
+ r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
324
+ end
325
+ s0 << r1
326
+ if r1
327
+ if has_terminal?(@regexps[gr = '\A[.]'] ||= Regexp.new(gr), :regexp, index)
328
+ r3 = true
329
+ @index += 1
330
+ else
331
+ terminal_parse_failure('[.]')
332
+ r3 = nil
333
+ end
334
+ s0 << r3
335
+ if r3
336
+ s4, i4 = [], index
337
+ loop do
338
+ if has_terminal?(@regexps[gr = '\A[0]'] ||= Regexp.new(gr), :regexp, index)
339
+ r5 = true
340
+ @index += 1
341
+ else
342
+ terminal_parse_failure('[0]')
343
+ r5 = nil
344
+ end
345
+ if r5
346
+ s4 << r5
347
+ else
348
+ break
349
+ end
350
+ end
351
+ r4 = instantiate_node(SyntaxNode,input, i4...index, s4)
352
+ s0 << r4
353
+ if r4
354
+ s6, i6 = [], index
355
+ loop do
356
+ if has_terminal?(@regexps[gr = '\A[1-9]'] ||= Regexp.new(gr), :regexp, index)
357
+ r7 = true
358
+ @index += 1
359
+ else
360
+ terminal_parse_failure('[1-9]')
361
+ r7 = nil
362
+ end
363
+ if r7
364
+ s6 << r7
365
+ else
366
+ break
367
+ end
368
+ end
369
+ if s6.empty?
370
+ @index = i6
371
+ r6 = nil
372
+ else
373
+ r6 = instantiate_node(SyntaxNode,input, i6...index, s6)
374
+ end
375
+ s0 << r6
376
+ if r6
377
+ s8, i8 = [], index
378
+ loop do
379
+ if has_terminal?(@regexps[gr = '\A[0-9]'] ||= Regexp.new(gr), :regexp, index)
380
+ r9 = true
381
+ @index += 1
382
+ else
383
+ terminal_parse_failure('[0-9]')
384
+ r9 = nil
385
+ end
386
+ if r9
387
+ s8 << r9
388
+ else
389
+ break
390
+ end
391
+ end
392
+ r8 = instantiate_node(SyntaxNode,input, i8...index, s8)
393
+ s0 << r8
394
+ if r8
395
+ r11 = _nt_exponent
396
+ if r11
397
+ r10 = r11
398
+ else
399
+ r10 = instantiate_node(SyntaxNode,input, index...index)
400
+ end
401
+ s0 << r10
402
+ end
403
+ end
404
+ end
405
+ end
406
+ end
407
+ if s0.last
408
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
409
+ r0.extend(Float30)
410
+ else
411
+ @index = i0
412
+ r0 = nil
413
+ end
414
+
415
+ node_cache[:float3][start_index] = r0
416
+
417
+ r0
418
+ end
419
+
420
+ module Exponent0
421
+ end
422
+
423
+ def _nt_exponent
424
+ start_index = index
425
+ if node_cache[:exponent].has_key?(index)
426
+ cached = node_cache[:exponent][index]
427
+ if cached
428
+ node_cache[:exponent][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
429
+ @index = cached.interval.end
430
+ end
431
+ return cached
432
+ end
433
+
434
+ i0, s0 = index, []
435
+ if (match_len = has_terminal?("e", false, index))
436
+ r1 = true
437
+ @index += match_len
438
+ else
439
+ terminal_parse_failure("e")
440
+ r1 = nil
441
+ end
442
+ s0 << r1
443
+ if r1
444
+ if has_terminal?(@regexps[gr = '\A[+-]'] ||= Regexp.new(gr), :regexp, index)
445
+ r3 = true
446
+ @index += 1
447
+ else
448
+ terminal_parse_failure('[+-]')
449
+ r3 = nil
450
+ end
451
+ if r3
452
+ r2 = r3
453
+ else
454
+ r2 = instantiate_node(SyntaxNode,input, index...index)
455
+ end
456
+ s0 << r2
457
+ if r2
458
+ s4, i4 = [], index
459
+ loop do
460
+ if has_terminal?(@regexps[gr = '\A[0-9]'] ||= Regexp.new(gr), :regexp, index)
461
+ r5 = true
462
+ @index += 1
463
+ else
464
+ terminal_parse_failure('[0-9]')
465
+ r5 = nil
466
+ end
467
+ if r5
468
+ s4 << r5
469
+ else
470
+ break
471
+ end
472
+ end
473
+ if s4.empty?
474
+ @index = i4
475
+ r4 = nil
476
+ else
477
+ r4 = instantiate_node(SyntaxNode,input, i4...index, s4)
478
+ end
479
+ s0 << r4
480
+ end
481
+ end
482
+ if s0.last
483
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
484
+ r0.extend(Exponent0)
485
+ else
486
+ @index = i0
487
+ r0 = nil
488
+ end
489
+
490
+ node_cache[:exponent][start_index] = r0
491
+
492
+ r0
493
+ end
494
+
495
+ end
496
+
497
+ class PositiveFloatParser < Treetop::Runtime::CompiledParser
498
+ include PositiveFloat
499
+ end
500
+
501
+
502
+ end
503
+ end
@@ -0,0 +1,33 @@
1
+ module Musicality
2
+ module Parsing
3
+
4
+ grammar PositiveFloat
5
+ rule positive_float
6
+ (float1 / float2 / float3) {
7
+ def to_f
8
+ text_value.to_f
9
+ end
10
+
11
+ alias :to_num :to_f
12
+ }
13
+ end
14
+
15
+ rule float1
16
+ [0]* [1-9]+ [0-9]* exponent
17
+ end
18
+
19
+ rule float2
20
+ [0]* [1-9]+ [0-9]* [.] [0-9]+ exponent?
21
+ end
22
+
23
+ rule float3
24
+ [0]+ [.] [0]* [1-9]+ [0-9]* exponent?
25
+ end
26
+
27
+ rule exponent
28
+ "e" [+-]? [0-9]+
29
+ end
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,95 @@
1
+ # Autogenerated from a Treetop grammar. Edits may be lost.
2
+
3
+
4
+ module Musicality
5
+ module Parsing
6
+
7
+ module PositiveInteger
8
+ include Treetop::Runtime
9
+
10
+ def root
11
+ @root ||= :positive_integer
12
+ end
13
+
14
+ include NonnegativeInteger
15
+
16
+ module PositiveInteger0
17
+ def nonnegative_integer
18
+ elements[2]
19
+ end
20
+ end
21
+
22
+ module PositiveInteger1
23
+ def to_i
24
+ text_value.to_i
25
+ end
26
+
27
+ alias :to_num :to_i
28
+ end
29
+
30
+ def _nt_positive_integer
31
+ start_index = index
32
+ if node_cache[:positive_integer].has_key?(index)
33
+ cached = node_cache[:positive_integer][index]
34
+ if cached
35
+ node_cache[:positive_integer][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
36
+ @index = cached.interval.end
37
+ end
38
+ return cached
39
+ end
40
+
41
+ i0, s0 = index, []
42
+ s1, i1 = [], index
43
+ loop do
44
+ if has_terminal?(@regexps[gr = '\A[0]'] ||= Regexp.new(gr), :regexp, index)
45
+ r2 = true
46
+ @index += 1
47
+ else
48
+ terminal_parse_failure('[0]')
49
+ r2 = nil
50
+ end
51
+ if r2
52
+ s1 << r2
53
+ else
54
+ break
55
+ end
56
+ end
57
+ r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
58
+ s0 << r1
59
+ if r1
60
+ if has_terminal?(@regexps[gr = '\A[1-9]'] ||= Regexp.new(gr), :regexp, index)
61
+ r3 = true
62
+ @index += 1
63
+ else
64
+ terminal_parse_failure('[1-9]')
65
+ r3 = nil
66
+ end
67
+ s0 << r3
68
+ if r3
69
+ r4 = _nt_nonnegative_integer
70
+ s0 << r4
71
+ end
72
+ end
73
+ if s0.last
74
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
75
+ r0.extend(PositiveInteger0)
76
+ r0.extend(PositiveInteger1)
77
+ else
78
+ @index = i0
79
+ r0 = nil
80
+ end
81
+
82
+ node_cache[:positive_integer][start_index] = r0
83
+
84
+ r0
85
+ end
86
+
87
+ end
88
+
89
+ class PositiveIntegerParser < Treetop::Runtime::CompiledParser
90
+ include PositiveInteger
91
+ end
92
+
93
+
94
+ end
95
+ end
@@ -0,0 +1,19 @@
1
+ module Musicality
2
+ module Parsing
3
+
4
+ grammar PositiveInteger
5
+ include NonnegativeInteger
6
+
7
+ rule positive_integer
8
+ [0]* [1-9] nonnegative_integer {
9
+ def to_i
10
+ text_value.to_i
11
+ end
12
+
13
+ alias :to_num :to_i
14
+ }
15
+ end
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,84 @@
1
+ # Autogenerated from a Treetop grammar. Edits may be lost.
2
+
3
+
4
+ module Musicality
5
+ module Parsing
6
+
7
+ module PositiveRational
8
+ include Treetop::Runtime
9
+
10
+ def root
11
+ @root ||= :positive_rational
12
+ end
13
+
14
+ include PositiveInteger
15
+
16
+ module PositiveRational0
17
+ def positive_integer1
18
+ elements[0]
19
+ end
20
+
21
+ def positive_integer2
22
+ elements[2]
23
+ end
24
+ end
25
+
26
+ module PositiveRational1
27
+ def to_r
28
+ text_value.to_r
29
+ end
30
+
31
+ alias :to_num :to_r
32
+ end
33
+
34
+ def _nt_positive_rational
35
+ start_index = index
36
+ if node_cache[:positive_rational].has_key?(index)
37
+ cached = node_cache[:positive_rational][index]
38
+ if cached
39
+ node_cache[:positive_rational][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
40
+ @index = cached.interval.end
41
+ end
42
+ return cached
43
+ end
44
+
45
+ i0, s0 = index, []
46
+ r1 = _nt_positive_integer
47
+ s0 << r1
48
+ if r1
49
+ if (match_len = has_terminal?("/", false, index))
50
+ r2 = true
51
+ @index += match_len
52
+ else
53
+ terminal_parse_failure("/")
54
+ r2 = nil
55
+ end
56
+ s0 << r2
57
+ if r2
58
+ r3 = _nt_positive_integer
59
+ s0 << r3
60
+ end
61
+ end
62
+ if s0.last
63
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
64
+ r0.extend(PositiveRational0)
65
+ r0.extend(PositiveRational1)
66
+ else
67
+ @index = i0
68
+ r0 = nil
69
+ end
70
+
71
+ node_cache[:positive_rational][start_index] = r0
72
+
73
+ r0
74
+ end
75
+
76
+ end
77
+
78
+ class PositiveRationalParser < Treetop::Runtime::CompiledParser
79
+ include PositiveRational
80
+ end
81
+
82
+
83
+ end
84
+ end