brevity 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +3 -0
- data/.gitignore +7 -0
- data/.rspec +1 -0
- data/.ruby-version +1 -0
- data/.yardopts +1 -0
- data/ChangeLog.rdoc +4 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +27 -0
- data/Rakefile +67 -0
- data/bin/debrief +56 -0
- data/brevity.gemspec +28 -0
- data/examples/alley_cat.br +50 -0
- data/examples/hip.br +15 -0
- data/examples/missed_connection.br +6 -0
- data/examples/song1.br +11 -0
- data/examples/song2.br +10 -0
- data/examples/twinkle.br +18 -0
- data/lib/brevity/commands/constants.rb +18 -0
- data/lib/brevity/commands/expr.rb +17 -0
- data/lib/brevity/commands/meter.rb +20 -0
- data/lib/brevity/commands/part.rb +47 -0
- data/lib/brevity/commands/tempo.rb +13 -0
- data/lib/brevity/itemization.rb +73 -0
- data/lib/brevity/parsing/expression/dynamic.rb +280 -0
- data/lib/brevity/parsing/expression/dynamic.treetop +41 -0
- data/lib/brevity/parsing/expression/dynamic_nodes.rb +55 -0
- data/lib/brevity/parsing/expression/expression.rb +429 -0
- data/lib/brevity/parsing/expression/expression.treetop +39 -0
- data/lib/brevity/parsing/expression/expression_nodes.rb +26 -0
- data/lib/brevity/parsing/expression/gradual.rb +44 -0
- data/lib/brevity/parsing/expression/gradual.treetop +9 -0
- data/lib/brevity/parsing/expression/gradual_node.rb +11 -0
- data/lib/brevity/parsing/expression/label.rb +75 -0
- data/lib/brevity/parsing/expression/label.treetop +9 -0
- data/lib/brevity/parsing/expression/label_node.rb +15 -0
- data/lib/brevity/parsing/expression/sequence.rb +130 -0
- data/lib/brevity/parsing/expression/sequence.treetop +12 -0
- data/lib/brevity/parsing/expression/sequence_node.rb +14 -0
- data/lib/brevity/parsing/file/command.rb +216 -0
- data/lib/brevity/parsing/file/command.treetop +17 -0
- data/lib/brevity/parsing/file/command_node.rb +11 -0
- data/lib/brevity/parsing/file/comment.rb +178 -0
- data/lib/brevity/parsing/file/comment.treetop +21 -0
- data/lib/brevity/parsing/file/comment_node.rb +3 -0
- data/lib/brevity/parsing/file/file.rb +152 -0
- data/lib/brevity/parsing/file/file.treetop +16 -0
- data/lib/brevity/parsing/file/file_node.rb +7 -0
- data/lib/brevity/parsing/file/path.rb +235 -0
- data/lib/brevity/parsing/file/path.treetop +12 -0
- data/lib/brevity/parsing/modifiers/duplicate_modifier.rb +65 -0
- data/lib/brevity/parsing/modifiers/duplicate_modifier.treetop +11 -0
- data/lib/brevity/parsing/modifiers/duplicate_modifier_node.rb +8 -0
- data/lib/brevity/parsing/modifiers/modifier.rb +64 -0
- data/lib/brevity/parsing/modifiers/modifier.treetop +13 -0
- data/lib/brevity/parsing/modifiers/stretch_modifier.rb +69 -0
- data/lib/brevity/parsing/modifiers/stretch_modifier.treetop +11 -0
- data/lib/brevity/parsing/modifiers/stretch_modifier_node.rb +21 -0
- data/lib/brevity/parsing/modifiers/transpose_modifier.rb +69 -0
- data/lib/brevity/parsing/modifiers/transpose_modifier.treetop +11 -0
- data/lib/brevity/parsing/modifiers/transpose_modifier_node.rb +13 -0
- data/lib/brevity/parsing/note/accent.rb +44 -0
- data/lib/brevity/parsing/note/accent.treetop +9 -0
- data/lib/brevity/parsing/note/duration.rb +203 -0
- data/lib/brevity/parsing/note/duration.treetop +23 -0
- data/lib/brevity/parsing/note/duration_nodes.rb +19 -0
- data/lib/brevity/parsing/note/link.rb +69 -0
- data/lib/brevity/parsing/note/link.treetop +11 -0
- data/lib/brevity/parsing/note/link_node.rb +19 -0
- data/lib/brevity/parsing/note/note.rb +300 -0
- data/lib/brevity/parsing/note/note.treetop +30 -0
- data/lib/brevity/parsing/note/note_nodes.rb +77 -0
- data/lib/brevity/parsing/note/pitch.rb +81 -0
- data/lib/brevity/parsing/note/pitch.treetop +9 -0
- data/lib/brevity/parsing/note/pitch_node.rb +50 -0
- data/lib/brevity/parsing/numbers/nonnegative_integer.rb +53 -0
- data/lib/brevity/parsing/numbers/nonnegative_integer.treetop +9 -0
- data/lib/brevity/parsing/numbers/positive_integer.rb +91 -0
- data/lib/brevity/parsing/numbers/positive_integer.treetop +15 -0
- data/lib/brevity/read_file.rb +18 -0
- data/lib/brevity/score_maker.rb +64 -0
- data/lib/brevity/version.rb +4 -0
- data/lib/brevity.rb +53 -0
- data/manuals/brevity.pdf +0 -0
- data/manuals/brevity.tex +273 -0
- data/spec/brevity_spec.rb +8 -0
- data/spec/commands/expr_spec.rb +15 -0
- data/spec/commands/meter_spec.rb +21 -0
- data/spec/commands/part_spec.rb +16 -0
- data/spec/commands/tempo_spec.rb +20 -0
- data/spec/itemization_spec.rb +46 -0
- data/spec/parsing/expression/dynamic_nodes_spec.rb +32 -0
- data/spec/parsing/expression/dynamic_spec.rb +23 -0
- data/spec/parsing/expression/expression_nodes_spec.rb +87 -0
- data/spec/parsing/expression/expression_spec.rb +85 -0
- data/spec/parsing/expression/gradual_spec.rb +10 -0
- data/spec/parsing/expression/label_node_spec.rb +13 -0
- data/spec/parsing/expression/label_spec.rb +35 -0
- data/spec/parsing/file/command_node_spec.rb +29 -0
- data/spec/parsing/file/command_spec.rb +18 -0
- data/spec/parsing/file/comment_spec.rb +14 -0
- data/spec/parsing/file/file_node_spec.rb +19 -0
- data/spec/parsing/file/file_spec.rb +30 -0
- data/spec/parsing/modifiers/modifier_nodes_spec.rb +25 -0
- data/spec/parsing/modifiers/modifier_parsers_spec.rb +20 -0
- data/spec/parsing/note/accent_spec.rb +27 -0
- data/spec/parsing/note/duration_nodes_spec.rb +79 -0
- data/spec/parsing/note/duration_spec.rb +69 -0
- data/spec/parsing/note/link_node_spec.rb +30 -0
- data/spec/parsing/note/link_spec.rb +23 -0
- data/spec/parsing/note/note_nodes_spec.rb +82 -0
- data/spec/parsing/note/note_spec.rb +188 -0
- data/spec/parsing/note/pitch_node_spec.rb +48 -0
- data/spec/parsing/note/pitch_spec.rb +23 -0
- data/spec/parsing/numbers/nonnegative_integer_spec.rb +11 -0
- data/spec/parsing/numbers/positive_integer_spec.rb +17 -0
- data/spec/spec_helper.rb +112 -0
- metadata +293 -0
@@ -0,0 +1,130 @@
|
|
1
|
+
# Autogenerated from a Treetop grammar. Edits may be lost.
|
2
|
+
|
3
|
+
|
4
|
+
module Brevity
|
5
|
+
|
6
|
+
module Sequence
|
7
|
+
include Treetop::Runtime
|
8
|
+
|
9
|
+
def root
|
10
|
+
@root ||= :sequence
|
11
|
+
end
|
12
|
+
|
13
|
+
include Note
|
14
|
+
|
15
|
+
include Modifier
|
16
|
+
|
17
|
+
module Sequence0
|
18
|
+
def note
|
19
|
+
elements[1]
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
module Sequence1
|
25
|
+
def first
|
26
|
+
elements[0]
|
27
|
+
end
|
28
|
+
|
29
|
+
def more
|
30
|
+
elements[1]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def _nt_sequence
|
35
|
+
start_index = index
|
36
|
+
if node_cache[:sequence].has_key?(index)
|
37
|
+
cached = node_cache[:sequence][index]
|
38
|
+
if cached
|
39
|
+
node_cache[:sequence][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_note
|
47
|
+
s0 << r1
|
48
|
+
if r1
|
49
|
+
s2, i2 = [], index
|
50
|
+
loop do
|
51
|
+
i3, s3 = index, []
|
52
|
+
s4, i4 = [], index
|
53
|
+
loop do
|
54
|
+
if has_terminal?(@regexps[gr = '\A[\\s]'] ||= Regexp.new(gr), :regexp, index)
|
55
|
+
r5 = true
|
56
|
+
@index += 1
|
57
|
+
else
|
58
|
+
terminal_parse_failure('[\\s]')
|
59
|
+
r5 = nil
|
60
|
+
end
|
61
|
+
if r5
|
62
|
+
s4 << r5
|
63
|
+
else
|
64
|
+
break
|
65
|
+
end
|
66
|
+
end
|
67
|
+
if s4.empty?
|
68
|
+
@index = i4
|
69
|
+
r4 = nil
|
70
|
+
else
|
71
|
+
r4 = instantiate_node(SyntaxNode,input, i4...index, s4)
|
72
|
+
end
|
73
|
+
s3 << r4
|
74
|
+
if r4
|
75
|
+
r6 = _nt_note
|
76
|
+
s3 << r6
|
77
|
+
if r6
|
78
|
+
i7 = index
|
79
|
+
r8 = _nt_modifier
|
80
|
+
if r8
|
81
|
+
r7 = nil
|
82
|
+
else
|
83
|
+
@index = i7
|
84
|
+
r7 = instantiate_node(SyntaxNode,input, index...index)
|
85
|
+
end
|
86
|
+
s3 << r7
|
87
|
+
end
|
88
|
+
end
|
89
|
+
if s3.last
|
90
|
+
r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
|
91
|
+
r3.extend(Sequence0)
|
92
|
+
else
|
93
|
+
@index = i3
|
94
|
+
r3 = nil
|
95
|
+
end
|
96
|
+
if r3
|
97
|
+
s2 << r3
|
98
|
+
else
|
99
|
+
break
|
100
|
+
end
|
101
|
+
end
|
102
|
+
if s2.empty?
|
103
|
+
@index = i2
|
104
|
+
r2 = nil
|
105
|
+
else
|
106
|
+
r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
|
107
|
+
end
|
108
|
+
s0 << r2
|
109
|
+
end
|
110
|
+
if s0.last
|
111
|
+
r0 = instantiate_node(SequenceNode,input, i0...index, s0)
|
112
|
+
r0.extend(Sequence1)
|
113
|
+
else
|
114
|
+
@index = i0
|
115
|
+
r0 = nil
|
116
|
+
end
|
117
|
+
|
118
|
+
node_cache[:sequence][start_index] = r0
|
119
|
+
|
120
|
+
r0
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
class SequenceParser < Treetop::Runtime::CompiledParser
|
126
|
+
include Sequence
|
127
|
+
end
|
128
|
+
|
129
|
+
|
130
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Brevity
|
2
|
+
|
3
|
+
DEFAULT_START_DYNAMIC = Music::Transcription::Dynamics::MF
|
4
|
+
|
5
|
+
class SequenceNode < Treetop::Runtime::SyntaxNode
|
6
|
+
def itemize(env)
|
7
|
+
Itemization.new(notes: notes)
|
8
|
+
end
|
9
|
+
|
10
|
+
def notes
|
11
|
+
[ first.to_note ] + more.elements.map {|el| el.note.to_note }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,216 @@
|
|
1
|
+
# Autogenerated from a Treetop grammar. Edits may be lost.
|
2
|
+
|
3
|
+
|
4
|
+
module Brevity
|
5
|
+
|
6
|
+
module Command
|
7
|
+
include Treetop::Runtime
|
8
|
+
|
9
|
+
def root
|
10
|
+
@root ||= :command
|
11
|
+
end
|
12
|
+
|
13
|
+
module Command0
|
14
|
+
def cmd_name
|
15
|
+
elements[1]
|
16
|
+
end
|
17
|
+
|
18
|
+
def braced_args
|
19
|
+
elements[2]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def _nt_command
|
24
|
+
start_index = index
|
25
|
+
if node_cache[:command].has_key?(index)
|
26
|
+
cached = node_cache[:command][index]
|
27
|
+
if cached
|
28
|
+
node_cache[:command][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
29
|
+
@index = cached.interval.end
|
30
|
+
end
|
31
|
+
return cached
|
32
|
+
end
|
33
|
+
|
34
|
+
i0, s0 = index, []
|
35
|
+
if (match_len = has_terminal?("\\", false, index))
|
36
|
+
r1 = true
|
37
|
+
@index += match_len
|
38
|
+
else
|
39
|
+
terminal_parse_failure("\\")
|
40
|
+
r1 = nil
|
41
|
+
end
|
42
|
+
s0 << r1
|
43
|
+
if r1
|
44
|
+
r2 = _nt_cmd_name
|
45
|
+
s0 << r2
|
46
|
+
if r2
|
47
|
+
s3, i3 = [], index
|
48
|
+
loop do
|
49
|
+
r4 = _nt_braced_arg
|
50
|
+
if r4
|
51
|
+
s3 << r4
|
52
|
+
else
|
53
|
+
break
|
54
|
+
end
|
55
|
+
end
|
56
|
+
r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
|
57
|
+
s0 << r3
|
58
|
+
end
|
59
|
+
end
|
60
|
+
if s0.last
|
61
|
+
r0 = instantiate_node(CommandNode,input, i0...index, s0)
|
62
|
+
r0.extend(Command0)
|
63
|
+
else
|
64
|
+
@index = i0
|
65
|
+
r0 = nil
|
66
|
+
end
|
67
|
+
|
68
|
+
node_cache[:command][start_index] = r0
|
69
|
+
|
70
|
+
r0
|
71
|
+
end
|
72
|
+
|
73
|
+
def _nt_cmd_name
|
74
|
+
start_index = index
|
75
|
+
if node_cache[:cmd_name].has_key?(index)
|
76
|
+
cached = node_cache[:cmd_name][index]
|
77
|
+
if cached
|
78
|
+
node_cache[:cmd_name][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
79
|
+
@index = cached.interval.end
|
80
|
+
end
|
81
|
+
return cached
|
82
|
+
end
|
83
|
+
|
84
|
+
s0, i0 = [], index
|
85
|
+
loop do
|
86
|
+
if has_terminal?(@regexps[gr = '\A[a-z]'] ||= Regexp.new(gr), :regexp, index)
|
87
|
+
r1 = true
|
88
|
+
@index += 1
|
89
|
+
else
|
90
|
+
terminal_parse_failure('[a-z]')
|
91
|
+
r1 = nil
|
92
|
+
end
|
93
|
+
if r1
|
94
|
+
s0 << r1
|
95
|
+
else
|
96
|
+
break
|
97
|
+
end
|
98
|
+
end
|
99
|
+
if s0.empty?
|
100
|
+
@index = i0
|
101
|
+
r0 = nil
|
102
|
+
else
|
103
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
104
|
+
end
|
105
|
+
|
106
|
+
node_cache[:cmd_name][start_index] = r0
|
107
|
+
|
108
|
+
r0
|
109
|
+
end
|
110
|
+
|
111
|
+
module BracedArg0
|
112
|
+
end
|
113
|
+
|
114
|
+
module BracedArg1
|
115
|
+
def text
|
116
|
+
elements[1]
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
def _nt_braced_arg
|
122
|
+
start_index = index
|
123
|
+
if node_cache[:braced_arg].has_key?(index)
|
124
|
+
cached = node_cache[:braced_arg][index]
|
125
|
+
if cached
|
126
|
+
node_cache[:braced_arg][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
127
|
+
@index = cached.interval.end
|
128
|
+
end
|
129
|
+
return cached
|
130
|
+
end
|
131
|
+
|
132
|
+
i0, s0 = index, []
|
133
|
+
if (match_len = has_terminal?("{", false, index))
|
134
|
+
r1 = true
|
135
|
+
@index += match_len
|
136
|
+
else
|
137
|
+
terminal_parse_failure("{")
|
138
|
+
r1 = nil
|
139
|
+
end
|
140
|
+
s0 << r1
|
141
|
+
if r1
|
142
|
+
s2, i2 = [], index
|
143
|
+
loop do
|
144
|
+
i3, s3 = index, []
|
145
|
+
i4 = index
|
146
|
+
if (match_len = has_terminal?("}", false, index))
|
147
|
+
r5 = true
|
148
|
+
@index += match_len
|
149
|
+
else
|
150
|
+
terminal_parse_failure("}")
|
151
|
+
r5 = nil
|
152
|
+
end
|
153
|
+
if r5
|
154
|
+
r4 = nil
|
155
|
+
else
|
156
|
+
@index = i4
|
157
|
+
r4 = instantiate_node(SyntaxNode,input, index...index)
|
158
|
+
end
|
159
|
+
s3 << r4
|
160
|
+
if r4
|
161
|
+
if index < input_length
|
162
|
+
r6 = true
|
163
|
+
@index += 1
|
164
|
+
else
|
165
|
+
terminal_parse_failure("any character")
|
166
|
+
r6 = nil
|
167
|
+
end
|
168
|
+
s3 << r6
|
169
|
+
end
|
170
|
+
if s3.last
|
171
|
+
r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
|
172
|
+
r3.extend(BracedArg0)
|
173
|
+
else
|
174
|
+
@index = i3
|
175
|
+
r3 = nil
|
176
|
+
end
|
177
|
+
if r3
|
178
|
+
s2 << r3
|
179
|
+
else
|
180
|
+
break
|
181
|
+
end
|
182
|
+
end
|
183
|
+
r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
|
184
|
+
s0 << r2
|
185
|
+
if r2
|
186
|
+
if (match_len = has_terminal?("}", false, index))
|
187
|
+
r7 = true
|
188
|
+
@index += match_len
|
189
|
+
else
|
190
|
+
terminal_parse_failure("}")
|
191
|
+
r7 = nil
|
192
|
+
end
|
193
|
+
s0 << r7
|
194
|
+
end
|
195
|
+
end
|
196
|
+
if s0.last
|
197
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
198
|
+
r0.extend(BracedArg1)
|
199
|
+
else
|
200
|
+
@index = i0
|
201
|
+
r0 = nil
|
202
|
+
end
|
203
|
+
|
204
|
+
node_cache[:braced_arg][start_index] = r0
|
205
|
+
|
206
|
+
r0
|
207
|
+
end
|
208
|
+
|
209
|
+
end
|
210
|
+
|
211
|
+
class CommandParser < Treetop::Runtime::CompiledParser
|
212
|
+
include Command
|
213
|
+
end
|
214
|
+
|
215
|
+
|
216
|
+
end
|
@@ -0,0 +1,178 @@
|
|
1
|
+
# Autogenerated from a Treetop grammar. Edits may be lost.
|
2
|
+
|
3
|
+
|
4
|
+
module Brevity
|
5
|
+
|
6
|
+
module Comment
|
7
|
+
include Treetop::Runtime
|
8
|
+
|
9
|
+
def root
|
10
|
+
@root ||= :comment
|
11
|
+
end
|
12
|
+
|
13
|
+
module Comment0
|
14
|
+
end
|
15
|
+
|
16
|
+
module Comment1
|
17
|
+
end
|
18
|
+
|
19
|
+
def _nt_comment
|
20
|
+
start_index = index
|
21
|
+
if node_cache[:comment].has_key?(index)
|
22
|
+
cached = node_cache[:comment][index]
|
23
|
+
if cached
|
24
|
+
node_cache[:comment][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, s0 = index, []
|
31
|
+
if (match_len = has_terminal?("#", false, index))
|
32
|
+
r1 = true
|
33
|
+
@index += match_len
|
34
|
+
else
|
35
|
+
terminal_parse_failure("#")
|
36
|
+
r1 = nil
|
37
|
+
end
|
38
|
+
s0 << r1
|
39
|
+
if r1
|
40
|
+
s2, i2 = [], index
|
41
|
+
loop do
|
42
|
+
i3, s3 = index, []
|
43
|
+
i4 = index
|
44
|
+
r5 = _nt_newline
|
45
|
+
if r5
|
46
|
+
r4 = nil
|
47
|
+
else
|
48
|
+
@index = i4
|
49
|
+
r4 = instantiate_node(SyntaxNode,input, index...index)
|
50
|
+
end
|
51
|
+
s3 << r4
|
52
|
+
if r4
|
53
|
+
if index < input_length
|
54
|
+
r6 = true
|
55
|
+
@index += 1
|
56
|
+
else
|
57
|
+
terminal_parse_failure("any character")
|
58
|
+
r6 = nil
|
59
|
+
end
|
60
|
+
s3 << r6
|
61
|
+
end
|
62
|
+
if s3.last
|
63
|
+
r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
|
64
|
+
r3.extend(Comment0)
|
65
|
+
else
|
66
|
+
@index = i3
|
67
|
+
r3 = nil
|
68
|
+
end
|
69
|
+
if r3
|
70
|
+
s2 << r3
|
71
|
+
else
|
72
|
+
break
|
73
|
+
end
|
74
|
+
end
|
75
|
+
r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
|
76
|
+
s0 << r2
|
77
|
+
end
|
78
|
+
if s0.last
|
79
|
+
r0 = instantiate_node(CommentNode,input, i0...index, s0)
|
80
|
+
r0.extend(Comment1)
|
81
|
+
else
|
82
|
+
@index = i0
|
83
|
+
r0 = nil
|
84
|
+
end
|
85
|
+
|
86
|
+
node_cache[:comment][start_index] = r0
|
87
|
+
|
88
|
+
r0
|
89
|
+
end
|
90
|
+
|
91
|
+
def _nt_newline
|
92
|
+
start_index = index
|
93
|
+
if node_cache[:newline].has_key?(index)
|
94
|
+
cached = node_cache[:newline][index]
|
95
|
+
if cached
|
96
|
+
node_cache[:newline][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
97
|
+
@index = cached.interval.end
|
98
|
+
end
|
99
|
+
return cached
|
100
|
+
end
|
101
|
+
|
102
|
+
i0 = index
|
103
|
+
r1 = _nt_windows_newline
|
104
|
+
if r1
|
105
|
+
r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
|
106
|
+
r0 = r1
|
107
|
+
else
|
108
|
+
r2 = _nt_unix_newline
|
109
|
+
if r2
|
110
|
+
r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
|
111
|
+
r0 = r2
|
112
|
+
else
|
113
|
+
@index = i0
|
114
|
+
r0 = nil
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
node_cache[:newline][start_index] = r0
|
119
|
+
|
120
|
+
r0
|
121
|
+
end
|
122
|
+
|
123
|
+
def _nt_windows_newline
|
124
|
+
start_index = index
|
125
|
+
if node_cache[:windows_newline].has_key?(index)
|
126
|
+
cached = node_cache[:windows_newline][index]
|
127
|
+
if cached
|
128
|
+
node_cache[:windows_newline][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
129
|
+
@index = cached.interval.end
|
130
|
+
end
|
131
|
+
return cached
|
132
|
+
end
|
133
|
+
|
134
|
+
if (match_len = has_terminal?("\r\n", false, index))
|
135
|
+
r0 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
136
|
+
@index += match_len
|
137
|
+
else
|
138
|
+
terminal_parse_failure("\r\n")
|
139
|
+
r0 = nil
|
140
|
+
end
|
141
|
+
|
142
|
+
node_cache[:windows_newline][start_index] = r0
|
143
|
+
|
144
|
+
r0
|
145
|
+
end
|
146
|
+
|
147
|
+
def _nt_unix_newline
|
148
|
+
start_index = index
|
149
|
+
if node_cache[:unix_newline].has_key?(index)
|
150
|
+
cached = node_cache[:unix_newline][index]
|
151
|
+
if cached
|
152
|
+
node_cache[:unix_newline][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
153
|
+
@index = cached.interval.end
|
154
|
+
end
|
155
|
+
return cached
|
156
|
+
end
|
157
|
+
|
158
|
+
if (match_len = has_terminal?("\n", false, index))
|
159
|
+
r0 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
160
|
+
@index += match_len
|
161
|
+
else
|
162
|
+
terminal_parse_failure("\n")
|
163
|
+
r0 = nil
|
164
|
+
end
|
165
|
+
|
166
|
+
node_cache[:unix_newline][start_index] = r0
|
167
|
+
|
168
|
+
r0
|
169
|
+
end
|
170
|
+
|
171
|
+
end
|
172
|
+
|
173
|
+
class CommentParser < Treetop::Runtime::CompiledParser
|
174
|
+
include Comment
|
175
|
+
end
|
176
|
+
|
177
|
+
|
178
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Brevity
|
2
|
+
|
3
|
+
grammar Comment
|
4
|
+
rule comment
|
5
|
+
"#" (!newline .)* <CommentNode>
|
6
|
+
end
|
7
|
+
|
8
|
+
rule newline
|
9
|
+
windows_newline / unix_newline
|
10
|
+
end
|
11
|
+
|
12
|
+
rule windows_newline
|
13
|
+
"\r\n"
|
14
|
+
end
|
15
|
+
|
16
|
+
rule unix_newline
|
17
|
+
"\n"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|