Module: Music::Transcription::Parsing::Duration

Includes:
PositiveInteger, Treetop::Runtime
Included in:
DurationParser, Note
Defined in:
lib/music-transcription/parsing/duration_parsing.rb

Defined Under Namespace

Modules: DenOnly0, NumAndDen0, NumOnly0

Instance Method Summary collapse

Methods included from PositiveInteger

#_nt_positive_integer

Methods included from NonnegativeInteger

#_nt_nonnegative_integer

Instance Method Details

#_nt_den_onlyObject



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

def _nt_den_only
  start_index = index
  if node_cache[:den_only].has_key?(index)
    cached = node_cache[:den_only][index]
    if cached
      node_cache[:den_only][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?("/", false, index))
    r1 = true
    @index += match_len
  else
    terminal_parse_failure("/")
    r1 = nil
  end
  s0 << r1
  if r1
    r2 = _nt_positive_integer
    s0 << r2
  end
  if s0.last
    r0 = instantiate_node(DenOnlyNode,input, i0...index, s0)
    r0.extend(DenOnly0)
  else
    @index = i0
    r0 = nil
  end

  node_cache[:den_only][start_index] = r0

  r0
end

#_nt_durationObject



17
18
19
20
21
22
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
# File 'lib/music-transcription/parsing/duration_parsing.rb', line 17

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

  i0 = index
  r1 = _nt_num_and_den
  if r1
    r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
    r0 = r1
  else
    r2 = _nt_num_only
    if r2
      r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
      r0 = r2
    else
      r3 = _nt_den_only
      if r3
        r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
        r0 = r3
      else
        @index = i0
        r0 = nil
      end
    end
  end

  node_cache[:duration][start_index] = r0

  r0
end

#_nt_num_and_denObject



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

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

  i0, s0 = index, []
  r1 = _nt_positive_integer
  s0 << r1
  if r1
    if (match_len = has_terminal?("/", false, index))
      r2 = true
      @index += match_len
    else
      terminal_parse_failure("/")
      r2 = nil
    end
    s0 << r2
    if r2
      r3 = _nt_positive_integer
      s0 << r3
    end
  end
  if s0.last
    r0 = instantiate_node(NumDenNode,input, i0...index, s0)
    r0.extend(NumAndDen0)
  else
    @index = i0
    r0 = nil
  end

  node_cache[:num_and_den][start_index] = r0

  r0
end

#_nt_num_onlyObject



113
114
115
116
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
# File 'lib/music-transcription/parsing/duration_parsing.rb', line 113

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

  i0, s0 = index, []
  r1 = _nt_positive_integer
  s0 << r1
  if r1
    if (match_len = has_terminal?("/", false, index))
      r3 = true
      @index += match_len
    else
      terminal_parse_failure("/")
      r3 = nil
    end
    if r3
      r2 = r3
    else
      r2 = instantiate_node(SyntaxNode,input, index...index)
    end
    s0 << r2
  end
  if s0.last
    r0 = instantiate_node(NumOnlyNode,input, i0...index, s0)
    r0.extend(NumOnly0)
  else
    @index = i0
    r0 = nil
  end

  node_cache[:num_only][start_index] = r0

  r0
end

#rootObject



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

def root
  @root ||= :duration
end