Module: Music::Transcription::Parsing::NonnegativeFloat

Includes:
Treetop::Runtime
Included in:
NonnegativeFloatParser, Segment
Defined in:
lib/music-transcription/parsing/numbers/nonnegative_float_parsing.rb

Defined Under Namespace

Modules: Exponent0, Float10, Float20, NonnegativeFloat0

Instance Method Summary collapse

Instance Method Details

#_nt_exponentObject



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
# File 'lib/music-transcription/parsing/numbers/nonnegative_float_parsing.rb', line 210

def _nt_exponent
  start_index = index
  if node_cache[:exponent].has_key?(index)
    cached = node_cache[:exponent][index]
    if cached
      node_cache[:exponent][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
      @index = cached.interval.end
    end
    return cached
  end

  i0, s0 = index, []
  if (match_len = has_terminal?("e", false, index))
    r1 = true
    @index += match_len
  else
    terminal_parse_failure("e")
    r1 = nil
  end
  s0 << r1
  if r1
    if has_terminal?(@regexps[gr = '\A[+-]'] ||= Regexp.new(gr), :regexp, index)
      r3 = true
      @index += 1
    else
      terminal_parse_failure('[+-]')
      r3 = nil
    end
    if r3
      r2 = r3
    else
      r2 = instantiate_node(SyntaxNode,input, index...index)
    end
    s0 << r2
    if r2
      s4, i4 = [], index
      loop do
        if has_terminal?(@regexps[gr = '\A[0-9]'] ||= Regexp.new(gr), :regexp, index)
          r5 = true
          @index += 1
        else
          terminal_parse_failure('[0-9]')
          r5 = nil
        end
        if r5
          s4 << r5
        else
          break
        end
      end
      if s4.empty?
        @index = i4
        r4 = nil
      else
        r4 = instantiate_node(SyntaxNode,input, i4...index, s4)
      end
      s0 << r4
    end
  end
  if s0.last
    r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
    r0.extend(Exponent0)
  else
    @index = i0
    r0 = nil
  end

  node_cache[:exponent][start_index] = r0

  r0
end

#_nt_float1Object



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
# File 'lib/music-transcription/parsing/numbers/nonnegative_float_parsing.rb', line 63

def _nt_float1
  start_index = index
  if node_cache[:float1].has_key?(index)
    cached = node_cache[:float1][index]
    if cached
      node_cache[:float1][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
      @index = cached.interval.end
    end
    return cached
  end

  i0, s0 = index, []
  s1, i1 = [], index
  loop do
    if has_terminal?(@regexps[gr = '\A[0-9]'] ||= Regexp.new(gr), :regexp, index)
      r2 = true
      @index += 1
    else
      terminal_parse_failure('[0-9]')
      r2 = nil
    end
    if r2
      s1 << r2
    else
      break
    end
  end
  if s1.empty?
    @index = i1
    r1 = nil
  else
    r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
  end
  s0 << r1
  if r1
    r3 = _nt_exponent
    s0 << r3
  end
  if s0.last
    r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
    r0.extend(Float10)
  else
    @index = i0
    r0 = nil
  end

  node_cache[:float1][start_index] = r0

  r0
end

#_nt_float2Object



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
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/music-transcription/parsing/numbers/nonnegative_float_parsing.rb', line 117

def _nt_float2
  start_index = index
  if node_cache[:float2].has_key?(index)
    cached = node_cache[:float2][index]
    if cached
      node_cache[:float2][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
      @index = cached.interval.end
    end
    return cached
  end

  i0, s0 = index, []
  s1, i1 = [], index
  loop do
    if has_terminal?(@regexps[gr = '\A[0-9]'] ||= Regexp.new(gr), :regexp, index)
      r2 = true
      @index += 1
    else
      terminal_parse_failure('[0-9]')
      r2 = nil
    end
    if r2
      s1 << r2
    else
      break
    end
  end
  if s1.empty?
    @index = i1
    r1 = nil
  else
    r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
  end
  s0 << r1
  if r1
    if has_terminal?(@regexps[gr = '\A[.]'] ||= Regexp.new(gr), :regexp, index)
      r3 = true
      @index += 1
    else
      terminal_parse_failure('[.]')
      r3 = nil
    end
    s0 << r3
    if r3
      s4, i4 = [], index
      loop do
        if has_terminal?(@regexps[gr = '\A[0-9]'] ||= Regexp.new(gr), :regexp, index)
          r5 = true
          @index += 1
        else
          terminal_parse_failure('[0-9]')
          r5 = nil
        end
        if r5
          s4 << r5
        else
          break
        end
      end
      if s4.empty?
        @index = i4
        r4 = nil
      else
        r4 = instantiate_node(SyntaxNode,input, i4...index, s4)
      end
      s0 << r4
      if r4
        r7 = _nt_exponent
        if r7
          r6 = r7
        else
          r6 = instantiate_node(SyntaxNode,input, index...index)
        end
        s0 << r6
      end
    end
  end
  if s0.last
    r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
    r0.extend(Float20)
  else
    @index = i0
    r0 = nil
  end

  node_cache[:float2][start_index] = r0

  r0
end

#_nt_nonnegative_floatObject



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
# File 'lib/music-transcription/parsing/numbers/nonnegative_float_parsing.rb', line 23

def _nt_nonnegative_float
  start_index = index
  if node_cache[:nonnegative_float].has_key?(index)
    cached = node_cache[:nonnegative_float][index]
    if cached
      node_cache[:nonnegative_float][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
      @index = cached.interval.end
    end
    return cached
  end

  i0 = index
  r1 = _nt_float1
  if r1
    r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
    r0 = r1
    r0.extend(NonnegativeFloat0)
  else
    r2 = _nt_float2
    if r2
      r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
      r0 = r2
      r0.extend(NonnegativeFloat0)
    else
      @index = i0
      r0 = nil
    end
  end

  node_cache[:nonnegative_float][start_index] = r0

  r0
end

#rootObject



11
12
13
# File 'lib/music-transcription/parsing/numbers/nonnegative_float_parsing.rb', line 11

def root
  @root ||= :nonnegative_float
end