Module: Musicality::Parsing::NonnegativeInteger

Includes:
Treetop::Runtime
Included in:
NonnegativeIntegerParser, NonnegativeRational, Pitch, PositiveInteger, Segment
Defined in:
lib/musicality/notation/parsing/numbers/nonnegative_integer_parsing.rb

Defined Under Namespace

Modules: NonnegativeInteger0

Instance Method Summary collapse

Instance Method Details

#_nt_nonnegative_integerObject



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
54
55
56
57
58
59
60
# File 'lib/musicality/notation/parsing/numbers/nonnegative_integer_parsing.rb', line 22

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

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

  node_cache[:nonnegative_integer][start_index] = r0

  r0
end

#rootObject



10
11
12
# File 'lib/musicality/notation/parsing/numbers/nonnegative_integer_parsing.rb', line 10

def root
  @root ||= :nonnegative_integer
end