brevity 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. checksums.yaml +7 -0
  2. data/.document +3 -0
  3. data/.gitignore +7 -0
  4. data/.rspec +1 -0
  5. data/.ruby-version +1 -0
  6. data/.yardopts +1 -0
  7. data/ChangeLog.rdoc +4 -0
  8. data/Gemfile +3 -0
  9. data/LICENSE.txt +20 -0
  10. data/README.rdoc +27 -0
  11. data/Rakefile +67 -0
  12. data/bin/debrief +56 -0
  13. data/brevity.gemspec +28 -0
  14. data/examples/alley_cat.br +50 -0
  15. data/examples/hip.br +15 -0
  16. data/examples/missed_connection.br +6 -0
  17. data/examples/song1.br +11 -0
  18. data/examples/song2.br +10 -0
  19. data/examples/twinkle.br +18 -0
  20. data/lib/brevity/commands/constants.rb +18 -0
  21. data/lib/brevity/commands/expr.rb +17 -0
  22. data/lib/brevity/commands/meter.rb +20 -0
  23. data/lib/brevity/commands/part.rb +47 -0
  24. data/lib/brevity/commands/tempo.rb +13 -0
  25. data/lib/brevity/itemization.rb +73 -0
  26. data/lib/brevity/parsing/expression/dynamic.rb +280 -0
  27. data/lib/brevity/parsing/expression/dynamic.treetop +41 -0
  28. data/lib/brevity/parsing/expression/dynamic_nodes.rb +55 -0
  29. data/lib/brevity/parsing/expression/expression.rb +429 -0
  30. data/lib/brevity/parsing/expression/expression.treetop +39 -0
  31. data/lib/brevity/parsing/expression/expression_nodes.rb +26 -0
  32. data/lib/brevity/parsing/expression/gradual.rb +44 -0
  33. data/lib/brevity/parsing/expression/gradual.treetop +9 -0
  34. data/lib/brevity/parsing/expression/gradual_node.rb +11 -0
  35. data/lib/brevity/parsing/expression/label.rb +75 -0
  36. data/lib/brevity/parsing/expression/label.treetop +9 -0
  37. data/lib/brevity/parsing/expression/label_node.rb +15 -0
  38. data/lib/brevity/parsing/expression/sequence.rb +130 -0
  39. data/lib/brevity/parsing/expression/sequence.treetop +12 -0
  40. data/lib/brevity/parsing/expression/sequence_node.rb +14 -0
  41. data/lib/brevity/parsing/file/command.rb +216 -0
  42. data/lib/brevity/parsing/file/command.treetop +17 -0
  43. data/lib/brevity/parsing/file/command_node.rb +11 -0
  44. data/lib/brevity/parsing/file/comment.rb +178 -0
  45. data/lib/brevity/parsing/file/comment.treetop +21 -0
  46. data/lib/brevity/parsing/file/comment_node.rb +3 -0
  47. data/lib/brevity/parsing/file/file.rb +152 -0
  48. data/lib/brevity/parsing/file/file.treetop +16 -0
  49. data/lib/brevity/parsing/file/file_node.rb +7 -0
  50. data/lib/brevity/parsing/file/path.rb +235 -0
  51. data/lib/brevity/parsing/file/path.treetop +12 -0
  52. data/lib/brevity/parsing/modifiers/duplicate_modifier.rb +65 -0
  53. data/lib/brevity/parsing/modifiers/duplicate_modifier.treetop +11 -0
  54. data/lib/brevity/parsing/modifiers/duplicate_modifier_node.rb +8 -0
  55. data/lib/brevity/parsing/modifiers/modifier.rb +64 -0
  56. data/lib/brevity/parsing/modifiers/modifier.treetop +13 -0
  57. data/lib/brevity/parsing/modifiers/stretch_modifier.rb +69 -0
  58. data/lib/brevity/parsing/modifiers/stretch_modifier.treetop +11 -0
  59. data/lib/brevity/parsing/modifiers/stretch_modifier_node.rb +21 -0
  60. data/lib/brevity/parsing/modifiers/transpose_modifier.rb +69 -0
  61. data/lib/brevity/parsing/modifiers/transpose_modifier.treetop +11 -0
  62. data/lib/brevity/parsing/modifiers/transpose_modifier_node.rb +13 -0
  63. data/lib/brevity/parsing/note/accent.rb +44 -0
  64. data/lib/brevity/parsing/note/accent.treetop +9 -0
  65. data/lib/brevity/parsing/note/duration.rb +203 -0
  66. data/lib/brevity/parsing/note/duration.treetop +23 -0
  67. data/lib/brevity/parsing/note/duration_nodes.rb +19 -0
  68. data/lib/brevity/parsing/note/link.rb +69 -0
  69. data/lib/brevity/parsing/note/link.treetop +11 -0
  70. data/lib/brevity/parsing/note/link_node.rb +19 -0
  71. data/lib/brevity/parsing/note/note.rb +300 -0
  72. data/lib/brevity/parsing/note/note.treetop +30 -0
  73. data/lib/brevity/parsing/note/note_nodes.rb +77 -0
  74. data/lib/brevity/parsing/note/pitch.rb +81 -0
  75. data/lib/brevity/parsing/note/pitch.treetop +9 -0
  76. data/lib/brevity/parsing/note/pitch_node.rb +50 -0
  77. data/lib/brevity/parsing/numbers/nonnegative_integer.rb +53 -0
  78. data/lib/brevity/parsing/numbers/nonnegative_integer.treetop +9 -0
  79. data/lib/brevity/parsing/numbers/positive_integer.rb +91 -0
  80. data/lib/brevity/parsing/numbers/positive_integer.treetop +15 -0
  81. data/lib/brevity/read_file.rb +18 -0
  82. data/lib/brevity/score_maker.rb +64 -0
  83. data/lib/brevity/version.rb +4 -0
  84. data/lib/brevity.rb +53 -0
  85. data/manuals/brevity.pdf +0 -0
  86. data/manuals/brevity.tex +273 -0
  87. data/spec/brevity_spec.rb +8 -0
  88. data/spec/commands/expr_spec.rb +15 -0
  89. data/spec/commands/meter_spec.rb +21 -0
  90. data/spec/commands/part_spec.rb +16 -0
  91. data/spec/commands/tempo_spec.rb +20 -0
  92. data/spec/itemization_spec.rb +46 -0
  93. data/spec/parsing/expression/dynamic_nodes_spec.rb +32 -0
  94. data/spec/parsing/expression/dynamic_spec.rb +23 -0
  95. data/spec/parsing/expression/expression_nodes_spec.rb +87 -0
  96. data/spec/parsing/expression/expression_spec.rb +85 -0
  97. data/spec/parsing/expression/gradual_spec.rb +10 -0
  98. data/spec/parsing/expression/label_node_spec.rb +13 -0
  99. data/spec/parsing/expression/label_spec.rb +35 -0
  100. data/spec/parsing/file/command_node_spec.rb +29 -0
  101. data/spec/parsing/file/command_spec.rb +18 -0
  102. data/spec/parsing/file/comment_spec.rb +14 -0
  103. data/spec/parsing/file/file_node_spec.rb +19 -0
  104. data/spec/parsing/file/file_spec.rb +30 -0
  105. data/spec/parsing/modifiers/modifier_nodes_spec.rb +25 -0
  106. data/spec/parsing/modifiers/modifier_parsers_spec.rb +20 -0
  107. data/spec/parsing/note/accent_spec.rb +27 -0
  108. data/spec/parsing/note/duration_nodes_spec.rb +79 -0
  109. data/spec/parsing/note/duration_spec.rb +69 -0
  110. data/spec/parsing/note/link_node_spec.rb +30 -0
  111. data/spec/parsing/note/link_spec.rb +23 -0
  112. data/spec/parsing/note/note_nodes_spec.rb +82 -0
  113. data/spec/parsing/note/note_spec.rb +188 -0
  114. data/spec/parsing/note/pitch_node_spec.rb +48 -0
  115. data/spec/parsing/note/pitch_spec.rb +23 -0
  116. data/spec/parsing/numbers/nonnegative_integer_spec.rb +11 -0
  117. data/spec/parsing/numbers/positive_integer_spec.rb +17 -0
  118. data/spec/spec_helper.rb +112 -0
  119. metadata +293 -0
@@ -0,0 +1,152 @@
1
+ # Autogenerated from a Treetop grammar. Edits may be lost.
2
+
3
+
4
+ module Brevity
5
+
6
+ module File
7
+ include Treetop::Runtime
8
+
9
+ def root
10
+ @root ||= :file
11
+ end
12
+
13
+ include Comment
14
+
15
+ include Command
16
+
17
+ module File0
18
+ def node
19
+ elements[1]
20
+ end
21
+ end
22
+
23
+ module File1
24
+ def nodes
25
+ elements[0]
26
+ end
27
+
28
+ end
29
+
30
+ def _nt_file
31
+ start_index = index
32
+ if node_cache[:file].has_key?(index)
33
+ cached = node_cache[:file][index]
34
+ if cached
35
+ node_cache[:file][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
+ i2, s2 = index, []
45
+ s3, i3 = [], index
46
+ loop do
47
+ if has_terminal?(@regexps[gr = '\A[\\s]'] ||= Regexp.new(gr), :regexp, index)
48
+ r4 = true
49
+ @index += 1
50
+ else
51
+ terminal_parse_failure('[\\s]')
52
+ r4 = nil
53
+ end
54
+ if r4
55
+ s3 << r4
56
+ else
57
+ break
58
+ end
59
+ end
60
+ r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
61
+ s2 << r3
62
+ if r3
63
+ r5 = _nt_node
64
+ s2 << r5
65
+ end
66
+ if s2.last
67
+ r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
68
+ r2.extend(File0)
69
+ else
70
+ @index = i2
71
+ r2 = nil
72
+ end
73
+ if r2
74
+ s1 << r2
75
+ else
76
+ break
77
+ end
78
+ end
79
+ r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
80
+ s0 << r1
81
+ if r1
82
+ s6, i6 = [], index
83
+ loop do
84
+ if has_terminal?(@regexps[gr = '\A[\\s]'] ||= Regexp.new(gr), :regexp, index)
85
+ r7 = true
86
+ @index += 1
87
+ else
88
+ terminal_parse_failure('[\\s]')
89
+ r7 = nil
90
+ end
91
+ if r7
92
+ s6 << r7
93
+ else
94
+ break
95
+ end
96
+ end
97
+ r6 = instantiate_node(SyntaxNode,input, i6...index, s6)
98
+ s0 << r6
99
+ end
100
+ if s0.last
101
+ r0 = instantiate_node(FileNode,input, i0...index, s0)
102
+ r0.extend(File1)
103
+ else
104
+ @index = i0
105
+ r0 = nil
106
+ end
107
+
108
+ node_cache[:file][start_index] = r0
109
+
110
+ r0
111
+ end
112
+
113
+ def _nt_node
114
+ start_index = index
115
+ if node_cache[:node].has_key?(index)
116
+ cached = node_cache[:node][index]
117
+ if cached
118
+ node_cache[:node][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
119
+ @index = cached.interval.end
120
+ end
121
+ return cached
122
+ end
123
+
124
+ i0 = index
125
+ r1 = _nt_comment
126
+ if r1
127
+ r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
128
+ r0 = r1
129
+ else
130
+ r2 = _nt_command
131
+ if r2
132
+ r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
133
+ r0 = r2
134
+ else
135
+ @index = i0
136
+ r0 = nil
137
+ end
138
+ end
139
+
140
+ node_cache[:node][start_index] = r0
141
+
142
+ r0
143
+ end
144
+
145
+ end
146
+
147
+ class FileParser < Treetop::Runtime::CompiledParser
148
+ include File
149
+ end
150
+
151
+
152
+ end
@@ -0,0 +1,16 @@
1
+ module Brevity
2
+
3
+ grammar File
4
+ include Comment
5
+ include Command
6
+
7
+ rule file
8
+ nodes:([\s]* node)* [\s]* <FileNode>
9
+ end
10
+
11
+ rule node
12
+ comment / command
13
+ end
14
+ end
15
+
16
+ end
@@ -0,0 +1,7 @@
1
+ module Brevity
2
+ class FileNode < Treetop::Runtime::SyntaxNode
3
+ def command_nodes
4
+ nodes.elements.select {|el| el.node.is_a? CommandNode }.map {|el| el.node }
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,235 @@
1
+ # Autogenerated from a Treetop grammar. Edits may be lost.
2
+
3
+
4
+ module Brevity
5
+
6
+ module Path
7
+ include Treetop::Runtime
8
+
9
+ def root
10
+ @root ||= :path
11
+ end
12
+
13
+ module Path0
14
+ end
15
+
16
+ module Path1
17
+ def name
18
+ elements[2]
19
+ end
20
+ end
21
+
22
+ def _nt_path
23
+ start_index = index
24
+ if node_cache[:path].has_key?(index)
25
+ cached = node_cache[:path][index]
26
+ if cached
27
+ node_cache[:path][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, s0 = index, []
34
+ i2 = index
35
+ if (match_len = has_terminal?("./", false, index))
36
+ r3 = instantiate_node(SyntaxNode,input, index...(index + match_len))
37
+ @index += match_len
38
+ else
39
+ terminal_parse_failure("./")
40
+ r3 = nil
41
+ end
42
+ if r3
43
+ r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
44
+ r2 = r3
45
+ else
46
+ if (match_len = has_terminal?("/", false, index))
47
+ r4 = true
48
+ @index += match_len
49
+ else
50
+ terminal_parse_failure("/")
51
+ r4 = nil
52
+ end
53
+ if r4
54
+ r4 = SyntaxNode.new(input, (index-1)...index) if r4 == true
55
+ r2 = r4
56
+ else
57
+ @index = i2
58
+ r2 = nil
59
+ end
60
+ end
61
+ if r2
62
+ r1 = r2
63
+ else
64
+ r1 = instantiate_node(SyntaxNode,input, index...index)
65
+ end
66
+ s0 << r1
67
+ if r1
68
+ s5, i5 = [], index
69
+ loop do
70
+ i6, s6 = index, []
71
+ i7 = index
72
+ if (match_len = has_terminal?("..", false, index))
73
+ r8 = instantiate_node(SyntaxNode,input, index...(index + match_len))
74
+ @index += match_len
75
+ else
76
+ terminal_parse_failure("..")
77
+ r8 = nil
78
+ end
79
+ if r8
80
+ r8 = SyntaxNode.new(input, (index-1)...index) if r8 == true
81
+ r7 = r8
82
+ else
83
+ r9 = _nt_name
84
+ if r9
85
+ r9 = SyntaxNode.new(input, (index-1)...index) if r9 == true
86
+ r7 = r9
87
+ else
88
+ @index = i7
89
+ r7 = nil
90
+ end
91
+ end
92
+ s6 << r7
93
+ if r7
94
+ if (match_len = has_terminal?("/", false, index))
95
+ r10 = true
96
+ @index += match_len
97
+ else
98
+ terminal_parse_failure("/")
99
+ r10 = nil
100
+ end
101
+ s6 << r10
102
+ end
103
+ if s6.last
104
+ r6 = instantiate_node(SyntaxNode,input, i6...index, s6)
105
+ r6.extend(Path0)
106
+ else
107
+ @index = i6
108
+ r6 = nil
109
+ end
110
+ if r6
111
+ s5 << r6
112
+ else
113
+ break
114
+ end
115
+ end
116
+ if s5.empty?
117
+ @index = i5
118
+ r5 = nil
119
+ else
120
+ r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
121
+ end
122
+ s0 << r5
123
+ if r5
124
+ r11 = _nt_name
125
+ s0 << r11
126
+ end
127
+ end
128
+ if s0.last
129
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
130
+ r0.extend(Path1)
131
+ else
132
+ @index = i0
133
+ r0 = nil
134
+ end
135
+
136
+ node_cache[:path][start_index] = r0
137
+
138
+ r0
139
+ end
140
+
141
+ module Name0
142
+ end
143
+
144
+ def _nt_name
145
+ start_index = index
146
+ if node_cache[:name].has_key?(index)
147
+ cached = node_cache[:name][index]
148
+ if cached
149
+ node_cache[:name][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
150
+ @index = cached.interval.end
151
+ end
152
+ return cached
153
+ end
154
+
155
+ i0, s0 = index, []
156
+ i1 = index
157
+ i2 = index
158
+ if (match_len = has_terminal?(".", false, index))
159
+ r3 = true
160
+ @index += match_len
161
+ else
162
+ terminal_parse_failure(".")
163
+ r3 = nil
164
+ end
165
+ if r3
166
+ r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
167
+ r2 = r3
168
+ else
169
+ if (match_len = has_terminal?("..", false, index))
170
+ r4 = instantiate_node(SyntaxNode,input, index...(index + match_len))
171
+ @index += match_len
172
+ else
173
+ terminal_parse_failure("..")
174
+ r4 = nil
175
+ end
176
+ if r4
177
+ r4 = SyntaxNode.new(input, (index-1)...index) if r4 == true
178
+ r2 = r4
179
+ else
180
+ @index = i2
181
+ r2 = nil
182
+ end
183
+ end
184
+ if r2
185
+ r1 = nil
186
+ else
187
+ @index = i1
188
+ r1 = instantiate_node(SyntaxNode,input, index...index)
189
+ end
190
+ s0 << r1
191
+ if r1
192
+ s5, i5 = [], index
193
+ loop do
194
+ if has_terminal?(@regexps[gr = '\A[A-Za-z0-9_,:\\.]'] ||= Regexp.new(gr), :regexp, index)
195
+ r6 = true
196
+ @index += 1
197
+ else
198
+ terminal_parse_failure('[A-Za-z0-9_,:\\.]')
199
+ r6 = nil
200
+ end
201
+ if r6
202
+ s5 << r6
203
+ else
204
+ break
205
+ end
206
+ end
207
+ if s5.empty?
208
+ @index = i5
209
+ r5 = nil
210
+ else
211
+ r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
212
+ end
213
+ s0 << r5
214
+ end
215
+ if s0.last
216
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
217
+ r0.extend(Name0)
218
+ else
219
+ @index = i0
220
+ r0 = nil
221
+ end
222
+
223
+ node_cache[:name][start_index] = r0
224
+
225
+ r0
226
+ end
227
+
228
+ end
229
+
230
+ class PathParser < Treetop::Runtime::CompiledParser
231
+ include Path
232
+ end
233
+
234
+
235
+ end
@@ -0,0 +1,12 @@
1
+ module Brevity
2
+
3
+ grammar Path
4
+ rule path
5
+ ("./" / "/")? ((".." / name) "/")+ name
6
+ end
7
+ rule name
8
+ !("." / "..") [A-Za-z0-9_,:\.]+
9
+ end
10
+ end
11
+
12
+ end
@@ -0,0 +1,65 @@
1
+ # Autogenerated from a Treetop grammar. Edits may be lost.
2
+
3
+
4
+ module Brevity
5
+
6
+ module DuplicateModifier
7
+ include Treetop::Runtime
8
+
9
+ def root
10
+ @root ||= :duplicate_modifier
11
+ end
12
+
13
+ include PositiveInteger
14
+
15
+ module DuplicateModifier0
16
+ def ntimes
17
+ elements[1]
18
+ end
19
+ end
20
+
21
+ def _nt_duplicate_modifier
22
+ start_index = index
23
+ if node_cache[:duplicate_modifier].has_key?(index)
24
+ cached = node_cache[:duplicate_modifier][index]
25
+ if cached
26
+ node_cache[:duplicate_modifier][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
27
+ @index = cached.interval.end
28
+ end
29
+ return cached
30
+ end
31
+
32
+ i0, s0 = index, []
33
+ if (match_len = has_terminal?(":", false, index))
34
+ r1 = true
35
+ @index += match_len
36
+ else
37
+ terminal_parse_failure(":")
38
+ r1 = nil
39
+ end
40
+ s0 << r1
41
+ if r1
42
+ r2 = _nt_positive_integer
43
+ s0 << r2
44
+ end
45
+ if s0.last
46
+ r0 = instantiate_node(DuplicateModifierNode,input, i0...index, s0)
47
+ r0.extend(DuplicateModifier0)
48
+ else
49
+ @index = i0
50
+ r0 = nil
51
+ end
52
+
53
+ node_cache[:duplicate_modifier][start_index] = r0
54
+
55
+ r0
56
+ end
57
+
58
+ end
59
+
60
+ class DuplicateModifierParser < Treetop::Runtime::CompiledParser
61
+ include DuplicateModifier
62
+ end
63
+
64
+
65
+ end
@@ -0,0 +1,11 @@
1
+ module Brevity
2
+
3
+ grammar DuplicateModifier
4
+ include PositiveInteger
5
+
6
+ rule duplicate_modifier
7
+ ":" ntimes:positive_integer <DuplicateModifierNode>
8
+ end
9
+ end
10
+
11
+ end
@@ -0,0 +1,8 @@
1
+ module Brevity
2
+ class DuplicateModifierNode < Treetop::Runtime::SyntaxNode
3
+ def process primitives
4
+ n = ntimes.text_value.to_i
5
+ Array.new(n){|i| primitives.clone }.flatten
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,64 @@
1
+ # Autogenerated from a Treetop grammar. Edits may be lost.
2
+
3
+
4
+ module Brevity
5
+
6
+ module Modifier
7
+ include Treetop::Runtime
8
+
9
+ def root
10
+ @root ||= :modifier
11
+ end
12
+
13
+ include DuplicateModifier
14
+
15
+ include TransposeModifier
16
+
17
+ include StretchModifier
18
+
19
+ def _nt_modifier
20
+ start_index = index
21
+ if node_cache[:modifier].has_key?(index)
22
+ cached = node_cache[:modifier][index]
23
+ if cached
24
+ node_cache[:modifier][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
25
+ @index = cached.interval.end
26
+ end
27
+ return cached
28
+ end
29
+
30
+ i0 = index
31
+ r1 = _nt_transpose_modifier
32
+ if r1
33
+ r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
34
+ r0 = r1
35
+ else
36
+ r2 = _nt_duplicate_modifier
37
+ if r2
38
+ r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
39
+ r0 = r2
40
+ else
41
+ r3 = _nt_stretch_modifier
42
+ if r3
43
+ r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
44
+ r0 = r3
45
+ else
46
+ @index = i0
47
+ r0 = nil
48
+ end
49
+ end
50
+ end
51
+
52
+ node_cache[:modifier][start_index] = r0
53
+
54
+ r0
55
+ end
56
+
57
+ end
58
+
59
+ class ModifierParser < Treetop::Runtime::CompiledParser
60
+ include Modifier
61
+ end
62
+
63
+
64
+ end
@@ -0,0 +1,13 @@
1
+ module Brevity
2
+
3
+ grammar Modifier
4
+ include DuplicateModifier
5
+ include TransposeModifier
6
+ include StretchModifier
7
+
8
+ rule modifier
9
+ transpose_modifier / duplicate_modifier / stretch_modifier
10
+ end
11
+ end
12
+
13
+ end
@@ -0,0 +1,69 @@
1
+ # Autogenerated from a Treetop grammar. Edits may be lost.
2
+
3
+
4
+ module Brevity
5
+
6
+ module StretchModifier
7
+ include Treetop::Runtime
8
+
9
+ def root
10
+ @root ||= :stretch_modifier
11
+ end
12
+
13
+ include Duration
14
+
15
+ module StretchModifier0
16
+ def op
17
+ elements[0]
18
+ end
19
+
20
+ def duration
21
+ elements[1]
22
+ end
23
+ end
24
+
25
+ def _nt_stretch_modifier
26
+ start_index = index
27
+ if node_cache[:stretch_modifier].has_key?(index)
28
+ cached = node_cache[:stretch_modifier][index]
29
+ if cached
30
+ node_cache[:stretch_modifier][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
31
+ @index = cached.interval.end
32
+ end
33
+ return cached
34
+ end
35
+
36
+ i0, s0 = index, []
37
+ if has_terminal?(@regexps[gr = '\A[=*]'] ||= Regexp.new(gr), :regexp, index)
38
+ r1 = true
39
+ @index += 1
40
+ else
41
+ terminal_parse_failure('[=*]')
42
+ r1 = nil
43
+ end
44
+ s0 << r1
45
+ if r1
46
+ r2 = _nt_duration
47
+ s0 << r2
48
+ end
49
+ if s0.last
50
+ r0 = instantiate_node(StretchModifierNode,input, i0...index, s0)
51
+ r0.extend(StretchModifier0)
52
+ else
53
+ @index = i0
54
+ r0 = nil
55
+ end
56
+
57
+ node_cache[:stretch_modifier][start_index] = r0
58
+
59
+ r0
60
+ end
61
+
62
+ end
63
+
64
+ class StretchModifierParser < Treetop::Runtime::CompiledParser
65
+ include StretchModifier
66
+ end
67
+
68
+
69
+ end
@@ -0,0 +1,11 @@
1
+ module Brevity
2
+
3
+ grammar StretchModifier
4
+ include Duration
5
+
6
+ rule stretch_modifier
7
+ op:[=*] duration <StretchModifierNode>
8
+ end
9
+ end
10
+
11
+ end
@@ -0,0 +1,21 @@
1
+ module Brevity
2
+ class StretchModifierNode < Treetop::Runtime::SyntaxNode
3
+ def process primitives
4
+ if op.text_value == "*"
5
+ ratio = duration.to_r
6
+ else
7
+ p_duration = primitives.map do |p|
8
+ p.respond_to?(:duration) ? p.duration : 0
9
+ end.inject(0,:+)
10
+ if p_duration == 0
11
+ require 'pry'
12
+ binding.pry
13
+ end
14
+ ratio = duration.to_r / p_duration
15
+ end
16
+ primitives.map do |p|
17
+ p.respond_to?(:stretch) ? p.stretch(ratio) : p
18
+ end
19
+ end
20
+ end
21
+ end