musa-dsl 0.14.29 → 0.21.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -1
  3. data/Gemfile +0 -1
  4. data/README.md +5 -1
  5. data/lib/musa-dsl.rb +54 -11
  6. data/lib/musa-dsl/core-ext.rb +7 -13
  7. data/lib/musa-dsl/core-ext/array-explode-ranges.rb +15 -23
  8. data/lib/musa-dsl/core-ext/arrayfy.rb +30 -12
  9. data/lib/musa-dsl/core-ext/attribute-builder.rb +194 -0
  10. data/lib/musa-dsl/core-ext/deep-copy.rb +185 -0
  11. data/lib/musa-dsl/core-ext/dynamic-proxy.rb +44 -40
  12. data/lib/musa-dsl/core-ext/inspect-nice.rb +40 -22
  13. data/lib/musa-dsl/core-ext/smart-proc-binder.rb +108 -0
  14. data/lib/musa-dsl/core-ext/with.rb +26 -0
  15. data/lib/musa-dsl/datasets.rb +8 -3
  16. data/lib/musa-dsl/datasets/dataset.rb +3 -0
  17. data/lib/musa-dsl/datasets/delta-d.rb +12 -0
  18. data/lib/musa-dsl/datasets/e.rb +61 -0
  19. data/lib/musa-dsl/datasets/gdv.rb +51 -411
  20. data/lib/musa-dsl/datasets/gdvd.rb +179 -0
  21. data/lib/musa-dsl/datasets/helper.rb +41 -0
  22. data/lib/musa-dsl/datasets/p.rb +68 -0
  23. data/lib/musa-dsl/datasets/packed-v.rb +19 -0
  24. data/lib/musa-dsl/datasets/pdv.rb +22 -15
  25. data/lib/musa-dsl/datasets/ps.rb +113 -0
  26. data/lib/musa-dsl/datasets/score.rb +210 -0
  27. data/lib/musa-dsl/datasets/score/queriable.rb +48 -0
  28. data/lib/musa-dsl/datasets/score/render.rb +31 -0
  29. data/lib/musa-dsl/datasets/score/to-mxml/process-pdv.rb +160 -0
  30. data/lib/musa-dsl/datasets/score/to-mxml/process-ps.rb +51 -0
  31. data/lib/musa-dsl/datasets/score/to-mxml/process-time.rb +153 -0
  32. data/lib/musa-dsl/datasets/score/to-mxml/to-mxml.rb +158 -0
  33. data/lib/musa-dsl/datasets/v.rb +23 -0
  34. data/lib/musa-dsl/generative.rb +5 -5
  35. data/lib/musa-dsl/generative/backboner.rb +274 -0
  36. data/lib/musa-dsl/generative/darwin.rb +102 -96
  37. data/lib/musa-dsl/generative/generative-grammar.rb +182 -187
  38. data/lib/musa-dsl/generative/markov.rb +56 -53
  39. data/lib/musa-dsl/generative/variatio.rb +234 -222
  40. data/lib/musa-dsl/logger.rb +1 -0
  41. data/lib/musa-dsl/logger/logger.rb +31 -0
  42. data/lib/musa-dsl/matrix.rb +1 -0
  43. data/lib/musa-dsl/matrix/matrix.rb +210 -0
  44. data/lib/musa-dsl/midi.rb +2 -2
  45. data/lib/musa-dsl/midi/midi-recorder.rb +54 -52
  46. data/lib/musa-dsl/midi/midi-voices.rb +187 -182
  47. data/lib/musa-dsl/music.rb +5 -5
  48. data/lib/musa-dsl/music/chord-definition.rb +54 -50
  49. data/lib/musa-dsl/music/chord-definitions.rb +13 -9
  50. data/lib/musa-dsl/music/chords.rb +236 -238
  51. data/lib/musa-dsl/music/equally-tempered-12-tone-scale-system.rb +187 -183
  52. data/lib/musa-dsl/music/scales.rb +331 -332
  53. data/lib/musa-dsl/musicxml.rb +1 -0
  54. data/lib/musa-dsl/musicxml/builder/attributes.rb +155 -0
  55. data/lib/musa-dsl/musicxml/builder/backup-forward.rb +45 -0
  56. data/lib/musa-dsl/musicxml/builder/direction.rb +322 -0
  57. data/lib/musa-dsl/musicxml/builder/helper.rb +90 -0
  58. data/lib/musa-dsl/musicxml/builder/measure.rb +137 -0
  59. data/lib/musa-dsl/musicxml/builder/note-complexities.rb +152 -0
  60. data/lib/musa-dsl/musicxml/builder/note.rb +577 -0
  61. data/lib/musa-dsl/musicxml/builder/part-group.rb +44 -0
  62. data/lib/musa-dsl/musicxml/builder/part.rb +67 -0
  63. data/lib/musa-dsl/musicxml/builder/pitched-note.rb +126 -0
  64. data/lib/musa-dsl/musicxml/builder/rest.rb +117 -0
  65. data/lib/musa-dsl/musicxml/builder/score-partwise.rb +120 -0
  66. data/lib/musa-dsl/musicxml/builder/typed-text.rb +43 -0
  67. data/lib/musa-dsl/musicxml/builder/unpitched-note.rb +112 -0
  68. data/lib/musa-dsl/neumalang.rb +1 -1
  69. data/lib/musa-dsl/neumalang/datatypes.citrus +79 -0
  70. data/lib/musa-dsl/neumalang/neuma.citrus +165 -0
  71. data/lib/musa-dsl/neumalang/neumalang.citrus +32 -242
  72. data/lib/musa-dsl/neumalang/neumalang.rb +373 -142
  73. data/lib/musa-dsl/neumalang/process.citrus +21 -0
  74. data/lib/musa-dsl/neumalang/terminals.citrus +67 -0
  75. data/lib/musa-dsl/neumalang/vectors.citrus +23 -0
  76. data/lib/musa-dsl/neumas.rb +5 -0
  77. data/lib/musa-dsl/neumas/array-to-neumas.rb +34 -0
  78. data/lib/musa-dsl/neumas/neuma-decoder.rb +63 -0
  79. data/lib/musa-dsl/neumas/neuma-gdv-decoder.rb +57 -0
  80. data/lib/musa-dsl/neumas/neuma-gdvd-decoder.rb +15 -0
  81. data/lib/musa-dsl/neumas/neumas.rb +37 -0
  82. data/lib/musa-dsl/neumas/string-to-neumas.rb +34 -0
  83. data/lib/musa-dsl/repl.rb +1 -1
  84. data/lib/musa-dsl/repl/repl.rb +128 -105
  85. data/lib/musa-dsl/sequencer.rb +1 -1
  86. data/lib/musa-dsl/sequencer/base-sequencer-implementation-control.rb +163 -136
  87. data/lib/musa-dsl/sequencer/base-sequencer-implementation-play-helper.rb +301 -286
  88. data/lib/musa-dsl/sequencer/base-sequencer-implementation.rb +552 -308
  89. data/lib/musa-dsl/sequencer/base-sequencer-public.rb +198 -176
  90. data/lib/musa-dsl/sequencer/base-sequencer-tick-based.rb +77 -0
  91. data/lib/musa-dsl/sequencer/base-sequencer-tickless-based.rb +75 -0
  92. data/lib/musa-dsl/sequencer/sequencer-dsl.rb +105 -85
  93. data/lib/musa-dsl/sequencer/timeslots.rb +34 -0
  94. data/lib/musa-dsl/series.rb +1 -1
  95. data/lib/musa-dsl/{core-ext → series}/array-to-serie.rb +1 -1
  96. data/lib/musa-dsl/series/base-series.rb +171 -168
  97. data/lib/musa-dsl/series/hash-serie-splitter.rb +134 -132
  98. data/lib/musa-dsl/series/holder-serie.rb +1 -1
  99. data/lib/musa-dsl/series/main-serie-constructors.rb +6 -1
  100. data/lib/musa-dsl/series/main-serie-operations.rb +807 -797
  101. data/lib/musa-dsl/series/proxy-serie.rb +6 -6
  102. data/lib/musa-dsl/series/queue-serie.rb +5 -5
  103. data/lib/musa-dsl/series/series.rb +2 -0
  104. data/lib/musa-dsl/transcription.rb +4 -0
  105. data/lib/musa-dsl/transcription/from-gdv-to-midi.rb +227 -0
  106. data/lib/musa-dsl/transcription/from-gdv-to-musicxml.rb +36 -0
  107. data/lib/musa-dsl/transcription/from-gdv.rb +17 -0
  108. data/lib/musa-dsl/transcription/transcription.rb +55 -0
  109. data/lib/musa-dsl/transport.rb +6 -6
  110. data/lib/musa-dsl/transport/clock.rb +26 -26
  111. data/lib/musa-dsl/transport/dummy-clock.rb +32 -30
  112. data/lib/musa-dsl/transport/external-tick-clock.rb +21 -20
  113. data/lib/musa-dsl/transport/input-midi-clock.rb +82 -80
  114. data/lib/musa-dsl/transport/timer-clock.rb +72 -71
  115. data/lib/musa-dsl/transport/timer.rb +28 -26
  116. data/lib/musa-dsl/transport/transport.rb +111 -93
  117. data/musa-dsl.gemspec +3 -3
  118. metadata +73 -24
  119. data/lib/musa-dsl/core-ext/array-apply-get.rb +0 -18
  120. data/lib/musa-dsl/core-ext/array-to-neumas.rb +0 -28
  121. data/lib/musa-dsl/core-ext/as-context-run.rb +0 -44
  122. data/lib/musa-dsl/core-ext/duplicate.rb +0 -134
  123. data/lib/musa-dsl/core-ext/key-parameters-procedure-binder.rb +0 -85
  124. data/lib/musa-dsl/core-ext/proc-nice.rb +0 -13
  125. data/lib/musa-dsl/core-ext/send-nice.rb +0 -21
  126. data/lib/musa-dsl/core-ext/string-to-neumas.rb +0 -27
  127. data/lib/musa-dsl/datasets/gdv-decorators.rb +0 -221
  128. data/lib/musa-dsl/generative/rules.rb +0 -282
  129. data/lib/musa-dsl/neuma.rb +0 -1
  130. data/lib/musa-dsl/neuma/neuma.rb +0 -181
@@ -1,179 +1,410 @@
1
- require 'musa-dsl/series'
2
1
  require 'citrus'
3
2
 
4
- module Musa::Neumalang
5
- module Parser
6
- module Sentences
7
- include Musa::Series
3
+ require_relative '../series'
4
+ require_relative '../neumas'
5
+ require_relative '../datasets'
8
6
 
9
- def value
10
- _SE(captures(:sentence).collect(&:value), extends: Neumas)
11
- end
12
- end
7
+ module Musa
8
+ module Neumalang
9
+ module Neumalang
10
+ module Parser
11
+ module Grammar; end
13
12
 
14
- module BracketedBarSentences
15
- include Musa::Series
13
+ module Sentences
14
+ include Musa::Series
15
+ include Musa::Neumas
16
16
 
17
- def value
18
- { kind: :parallel,
19
- parallel: [{ kind: :serie, serie: S(*capture(:aa).value) }] + captures(:bb).collect { |c| { kind: :serie, serie: S(*c.value) } }
20
- }.extend(Neuma::Parallel)
21
- end
22
- end
17
+ def value
18
+ _SE(captures(:expression).collect(&:value), extends: Neuma::Serie)
19
+ end
20
+ end
23
21
 
24
- module BracketedSentences
25
- include Musa::Series
22
+ module BracketedBarSentences
23
+ include Musa::Series
24
+ include Musa::Neumas
26
25
 
27
- def value
28
- { kind: :serie,
29
- serie: S(*capture(:sentences).value) }.extend Neuma
30
- end
31
- end
26
+ def value
27
+ { kind: :parallel,
28
+ parallel: [{ kind: :serie,
29
+ serie: S(*capture(:aa).value) }] +
30
+ captures(:bb).collect { |c| { kind: :serie, serie: S(*c.value) } }
31
+ }.extend(Neuma::Parallel)
32
+ end
33
+ end
32
34
 
33
- module ReferenceExpression
34
- def value
35
- { kind: :reference,
36
- reference: capture(:expression).value }.extend Neuma
37
- end
38
- end
35
+ module BracketedSentences
36
+ include Musa::Series
37
+ include Musa::Neumas
39
38
 
40
- module VariableAssign
41
- def value
42
- { kind: :assign_to,
43
- assign_to: captures(:use_variable).collect { |c| c.value[:use_variable] }, assign_value: capture(:expression).value
44
- }.extend Neuma
45
- end
46
- end
39
+ def value
40
+ { kind: :serie,
41
+ serie: S(*capture(:sentences).value) }.extend Neuma
42
+ end
43
+ end
47
44
 
48
- module Event
49
- def value
50
- { kind: :event,
51
- event: capture(:name).value.to_sym
52
- }.merge(capture(:parameters) ? capture(:parameters).value : {}).extend Neuma
53
- end
54
- end
45
+ module ReferenceExpression
46
+ include Musa::Neumas
55
47
 
56
- module BracedCommand
57
- def value
58
- { kind: :command,
59
- command: eval("proc { #{capture(:complex_command).value.strip} }")
60
- }.merge(capture(:parameters) ? capture(:parameters).value : {}).extend Neuma
61
- end
62
- end
48
+ def value
49
+ { kind: :reference,
50
+ reference: capture(:expression).value }.extend Neuma
51
+ end
52
+ end
63
53
 
64
- module CallMethodsExpression
65
- def value
66
- { kind: :call_methods,
67
- call_methods: captures(:method_call).collect(&:value),
68
- on: capture(:object_expression).value }.extend Neuma
69
- end
70
- end
54
+ module VariableAssign
55
+ include Musa::Neumas
71
56
 
72
- module UseVariable
73
- def value
74
- { kind: :use_variable,
75
- use_variable: "@#{capture(:name).value}".to_sym }.extend Neuma
76
- end
77
- end
57
+ def value
58
+ { kind: :assign_to,
59
+ assign_to: captures(:use_variable).collect { |c| c.value[:use_variable] },
60
+ assign_value: capture(:expression).value
61
+ }.extend Neuma
62
+ end
63
+ end
78
64
 
79
- module NeumaAsDottedAttributesBeginningWithSimpleAttribute
80
- def value
81
- { kind: :neuma,
82
- neuma: (capture(:a) ? [capture(:a).value] : []) + captures(:b).collect(&:value) }.extend Neuma
83
- end
84
- end
65
+ module Event
66
+ include Musa::Neumas
85
67
 
86
- module NeumaAsDottedAttributesBeginningWithDot
87
- def value
88
- { kind: :neuma,
89
- neuma: (capture(:attribute) ? [ nil ] : []) + captures(:attribute).collect(&:value) }.extend Neuma
90
- end
91
- end
68
+ def value
69
+ { kind: :event,
70
+ event: capture(:name).value.to_sym
71
+ }.merge(capture(:parameters) ? capture(:parameters).value : {}).extend Neuma
72
+ end
73
+ end
92
74
 
93
- module NeumaBetweenAnglesAttributes
94
- def value
95
- { kind: :neuma,
96
- neuma: (capture(:simple_attribute) ? [capture(:simple_attribute).value] : []) + captures(:attribute).collect(&:value) }.extend Neuma
97
- end
98
- end
75
+ module Parameters
76
+ def value
77
+ value_parameters = []
78
+ key_value_parameters = {}
99
79
 
100
- module Symbol
101
- def value
102
- { kind: :value,
103
- value: capture(:name).value.to_sym }.extend Neuma
104
- end
105
- end
80
+ captures(:parameter).each do |pp|
81
+ p = pp.value
82
+ if p.has_key? :key_value
83
+ key_value_parameters.merge! p[:key_value]
84
+ else
85
+ value_parameters << p[:value]
86
+ end
87
+ end
106
88
 
107
- module String
108
- def value
109
- { kind: :value,
110
- value: capture(:everything_except_double_quote).value }.extend Neuma
111
- end
112
- end
89
+ {}.tap do |_|
90
+ _[:value_parameters] = value_parameters unless value_parameters.empty?
91
+ _[:key_parameters] = key_value_parameters unless key_value_parameters.empty?
92
+ end
93
+ end
94
+ end
113
95
 
114
- module Float
115
- def value
116
- { kind: :value,
117
- value: capture(:str).value.to_f }.extend Neuma
118
- end
119
- end
96
+ module Parameter
97
+ def value
98
+ if capture(:key_value_parameter)
99
+ { key_value: capture(:key_value_parameter).value }
100
+ else
101
+ { value: capture(:expression).value }
102
+ end
103
+ end
104
+ end
120
105
 
121
- module Integer
122
- def value
123
- { kind: :value,
124
- value: capture(:digits).value.to_i }.extend Neuma
125
- end
126
- end
106
+ module BracedCommand
107
+ include Musa::Neumas
127
108
 
128
- module Rational
129
- def value
130
- { kind: :value,
131
- value: capture(:str).value.to_r }.extend Neuma
132
- end
133
- end
134
- end
109
+ def value
110
+ { kind: :command,
111
+ command: eval("proc { #{capture(:complex_command).value.strip} }")
112
+ }.merge(capture(:parameters) ? capture(:parameters).value : {}).extend Neuma
113
+ end
114
+ end
135
115
 
136
- def self.register(grammar_path)
137
- Citrus.load grammar_path
138
- end
116
+ module CallMethodsExpression
117
+ include Musa::Neumas
118
+
119
+ def value
120
+ { kind: :call_methods,
121
+ call_methods: captures(:method_call).collect(&:value),
122
+ on: capture(:object_expression).value }.extend Neuma
123
+ end
124
+ end
139
125
 
140
- def self.parse(string_or_file, language: nil, decode_with: nil, debug: nil)
141
- language ||= Neumalang
126
+ module UseVariable
127
+ include Musa::Neumas
142
128
 
143
- match = nil
129
+ def value
130
+ { kind: :use_variable,
131
+ use_variable: "@#{capture(:name).value}".to_sym }.extend Neuma
132
+ end
133
+ end
144
134
 
145
- if string_or_file.is_a? String
146
- match = language.parse string_or_file
135
+ module NeumaAsAttributes
136
+ include Musa::Neumas
137
+ include Musa::Datasets
147
138
 
148
- elsif string_or_file.is_a? File
149
- match = language.parse string_or_file.read
139
+ def value
140
+ h = {}.extend GDVd
150
141
 
151
- else
152
- raise ArgumentError, 'Only String or File allowed to be parsed'
153
- end
142
+ capture(:grade)&.value&.tap { |_| h.merge! _ if _ }
143
+ capture(:octave)&.value&.tap { |_| h.merge! _ if _ }
144
+ capture(:duration)&.value&.tap { |_| h.merge! _ if _ }
145
+ capture(:velocity)&.value&.tap { |_| h.merge! _ if _ }
154
146
 
155
- match.dump if debug
147
+ h[:modifiers] = {} unless captures(:modifiers).empty?
148
+ captures(:modifiers).collect(&:value).each { |_| h[:modifiers].merge! _ if _ }
149
+
150
+ { kind: :gdvd, gdvd: h }.extend Neuma
151
+ end
152
+ end
156
153
 
157
- serie = match.value
154
+ module PackedVector
155
+ include Musa::Neumas
156
+
157
+ def value
158
+ { kind: :packed_v, packed_v: capture(:raw_packed_vector).value }.extend(Neuma)
159
+ end
160
+ end
161
+
162
+ module RawPackedVector
163
+ include Musa::Datasets
164
+
165
+ def value
166
+ captures(:key_value).collect(&:value).to_h.extend(PackedV)
167
+ end
168
+ end
169
+
170
+ module Vector
171
+ include Musa::Neumas
172
+
173
+ def value
174
+ { kind: :v, v: capture(:raw_vector).value }.extend(Neuma)
175
+ end
176
+ end
177
+
178
+ module RawVector
179
+ include Musa::Datasets
180
+
181
+ def value
182
+ captures(:raw_number).collect(&:value).extend(V)
183
+ end
184
+ end
185
+
186
+ module ProcessOfVectors
187
+ include Musa::Datasets
188
+ include Musa::Neumas
189
+
190
+ def value
191
+ durations_rest = []
192
+ i = 0
193
+
194
+ rests = captures(:rest).collect(&:value)
195
+ captures(:durations).collect(&:value).each do |duration|
196
+ durations_rest[i * 2] = duration
197
+ durations_rest[i * 2 + 1] = rests[i]
198
+ i += 1
199
+ end
200
+
201
+ p = ([ capture(:first).value ] + durations_rest).extend(P)
202
+ { kind: :p, p: p }.extend(Neuma)
203
+ end
204
+ end
158
205
 
159
- if decode_with
160
- serie.eval do |e|
161
- if e[:kind] == :neuma
162
- decode_with.decode(e[:neuma])
206
+ module DeltaGradeAttribute
207
+ def value
208
+
209
+ value = {}
210
+
211
+ sign = capture(:sign)&.value || 1
212
+
213
+ value[:delta_grade] = capture(:grade).value * sign if capture(:grade)
214
+ value[:delta_sharps] = capture(:accidentals).value * sign if capture(:accidentals)
215
+
216
+ value[:delta_interval] = capture(:interval).value if capture(:interval)
217
+ value[:delta_interval_sign] = sign if capture(:interval) && capture(:sign)
218
+
219
+ value
220
+ end
221
+ end
222
+
223
+ module AbsGradeAttribute
224
+ def value
225
+ value = {}
226
+
227
+ value[:abs_grade] = capture(:grade).value if capture(:grade)
228
+ value[:abs_grade] ||= capture(:interval).value.to_sym if capture(:interval)
229
+
230
+ value[:abs_sharps] = capture(:accidentals).value if capture(:accidentals)
231
+
232
+ value
233
+ end
234
+ end
235
+
236
+ module DeltaOctaveAttribute
237
+ def value
238
+ { delta_octave: capture(:sign).value * capture(:number).value }
239
+ end
240
+ end
241
+
242
+ module AbsOctaveAttribute
243
+ def value
244
+ { abs_octave: capture(:number).value }
245
+ end
246
+ end
247
+
248
+ module DurationCalculation
249
+ def duration
250
+ base = capture(:number)&.value
251
+
252
+ slashes = capture(:slashes)&.value || 0
253
+ base ||= Rational(1, 2**slashes.to_r)
254
+
255
+ dots_extension = 0
256
+ capture(:mid_dots)&.value&.times do |i|
257
+ dots_extension += Rational(base, 2**(i+1))
258
+ end
259
+
260
+ base + dots_extension
261
+ end
262
+ end
263
+
264
+ module DeltaDurationAttribute
265
+ include DurationCalculation
266
+
267
+ def value
268
+ sign = capture(:sign).value
269
+
270
+ { delta_duration: sign * duration }
271
+ end
272
+ end
273
+
274
+ module AbsDurationAttribute
275
+ include DurationCalculation
276
+
277
+ def value
278
+ { abs_duration: duration }
279
+ end
280
+ end
281
+
282
+ module FactorDurationAttribute
283
+ def value
284
+ { factor_duration: capture(:number).value ** (capture(:factor).value == '/' ? -1 : 1) }
285
+ end
286
+ end
287
+
288
+ module AbsVelocityAttribute
289
+ def value
290
+ if capture(:p)
291
+ v = -capture(:p).length
292
+ elsif capture(:mp)
293
+ v = 0
294
+ elsif capture(:mf)
295
+ v = 1
296
+ else
297
+ v = capture(:f).length + 1
298
+ end
299
+
300
+ { abs_velocity: v }
301
+ end
302
+ end
303
+
304
+ module DeltaVelocityAttribute
305
+ def value
306
+ d = capture(:delta).value
307
+ s = capture(:sign).value
308
+
309
+ if /p+/.match?(d)
310
+ v = -d.length
311
+ else
312
+ v = d.length
313
+ end
314
+
315
+ { delta_velocity: s * v }
316
+ end
317
+ end
318
+
319
+ module AppogiaturaNeuma
320
+ def value
321
+ capture(:base).value.tap do |_|
322
+ _[:gdvd][:modifiers] ||= {}
323
+ _[:gdvd][:modifiers][:appogiatura] = capture(:appogiatura).value[:gdvd]
324
+ end
325
+ end
326
+ end
327
+
328
+ module Symbol
329
+ include Musa::Neumas
330
+
331
+ def value
332
+ { kind: :value,
333
+ value: capture(:name).value.to_sym }.extend Neuma
334
+ end
335
+ end
336
+
337
+ module String
338
+ include Musa::Neumas
339
+
340
+ def value
341
+ { kind: :value,
342
+ value: capture(:everything_except_double_quote).value }.extend Neuma
343
+ end
344
+ end
345
+
346
+ module Number
347
+ include Musa::Neumas
348
+
349
+ def value
350
+ { kind: :value,
351
+ value: capture(:raw_number).value }.extend Neuma
352
+ end
353
+ end
354
+
355
+ module Special
356
+ include Musa::Neumas
357
+
358
+ def value
359
+ v = captures(0)
360
+ { kind: :value,
361
+ value: v == 'nil' ? nil : (v == 'true' ? true : false) }.extend Neuma
362
+ end
363
+ end
364
+ end
365
+
366
+ extend self
367
+
368
+ def parse(string_or_file, decode_with: nil, debug: nil)
369
+ if string_or_file.is_a? String
370
+ match = Parser::Grammar::Grammar.parse string_or_file
371
+
372
+ elsif string_or_file.is_a? File
373
+ match = Parser::Grammar::Grammar.parse string_or_file.read
374
+
375
+ else
376
+ raise ArgumentError, 'Only String or File allowed to be parsed'
377
+ end
378
+
379
+ match.dump if debug
380
+
381
+ serie = match.value
382
+
383
+ if decode_with
384
+ serie.eval do |e|
385
+ if e[:kind] == :gdvd
386
+ decode_with.decode(e[:gdvd])
387
+ else
388
+ raise ArgumentError, "Don't know how to convert #{e} to neumas"
389
+ end
390
+ end
163
391
  else
164
- raise ArgumentError, "Don't know how to convert #{e} to neuma"
392
+ serie
165
393
  end
166
394
  end
167
- else
168
- serie
169
- end
170
- end
171
395
 
172
- def self.parse_file(filename, decode_with: nil, debug: nil)
173
- File.open filename do |file|
174
- parse file, decode_with: decode_with, debug: debug
396
+ def parse_file(filename, decode_with: nil, debug: nil)
397
+ File.open filename do |file|
398
+ parse file, decode_with: decode_with, debug: debug
399
+ end
400
+ end
401
+
402
+ Citrus.load File.join(File.dirname(__FILE__), 'terminals.citrus')
403
+ Citrus.load File.join(File.dirname(__FILE__), 'datatypes.citrus')
404
+ Citrus.load File.join(File.dirname(__FILE__), 'neuma.citrus')
405
+ Citrus.load File.join(File.dirname(__FILE__), 'vectors.citrus')
406
+ Citrus.load File.join(File.dirname(__FILE__), 'process.citrus')
407
+ Citrus.load File.join(File.dirname(__FILE__), 'neumalang.citrus')
175
408
  end
176
409
  end
177
-
178
- register File.join(File.dirname(__FILE__), 'neumalang')
179
410
  end