Module: Musicality::Parsing::PositiveInteger

Includes:
NonnegativeInteger, Treetop::Runtime
Included in:
Duration, Meter, NonnegativeRational, PositiveIntegerParser, PositiveRational
Defined in:
lib/musicality/notation/parsing/numbers/positive_integer_parsing.rb

Defined Under Namespace

Modules: PositiveInteger0, PositiveInteger1

Instance Method Summary collapse

Methods included from NonnegativeInteger

#_nt_nonnegative_integer

Instance Method Details

#_nt_positive_integerObject



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
61
62
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
# File 'lib/musicality/notation/parsing/numbers/positive_integer_parsing.rb', line 27

def _nt_positive_integer
  start_index = index
  if node_cache[:positive_integer].has_key?(index)
    cached = node_cache[:positive_integer][index]
    if cached
      node_cache[:positive_integer][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]'] ||= Regexp.new(gr), :regexp, index)
      r2 = true
      @index += 1
    else
      terminal_parse_failure('[0]')
      r2 = nil
    end
    if r2
      s1 << r2
    else
      break
    end
  end
  r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
  s0 << r1
  if r1
    if has_terminal?(@regexps[gr = '\A[1-9]'] ||= Regexp.new(gr), :regexp, index)
      r3 = true
      @index += 1
    else
      terminal_parse_failure('[1-9]')
      r3 = nil
    end
    s0 << r3
    if r3
      r5 = _nt_nonnegative_integer
      if r5
        r4 = r5
      else
        r4 = instantiate_node(SyntaxNode,input, index...index)
      end
      s0 << r4
    end
  end
  if s0.last
    r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
    r0.extend(PositiveInteger0)
    r0.extend(PositiveInteger1)
  else
    @index = i0
    r0 = nil
  end

  node_cache[:positive_integer][start_index] = r0

  r0
end

#rootObject



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

def root
  @root ||= :positive_integer
end