Module: Musicality::Parsing::Segment

Includes:
NonnegativeFloat, NonnegativeInteger, NonnegativeRational, Treetop::Runtime
Included in:
SegmentParser
Defined in:
lib/musicality/notation/parsing/segment_parsing.rb

Defined Under Namespace

Modules: Range0, Range1

Instance Method Summary collapse

Methods included from NonnegativeRational

#_nt_nonnegative_rational

Methods included from PositiveInteger

#_nt_positive_integer

Methods included from NonnegativeInteger

#_nt_nonnegative_integer

Methods included from NonnegativeFloat

#_nt_exponent, #_nt_float1, #_nt_float2, #_nt_nonnegative_float

Instance Method Details

#_nt_nonnegative_numberObject



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/musicality/notation/parsing/segment_parsing.rb', line 98

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

  i0 = index
  r1 = _nt_nonnegative_float
  if r1
    r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
    r0 = r1
  else
    r2 = _nt_nonnegative_rational
    if r2
      r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
      r0 = r2
    else
      r3 = _nt_nonnegative_integer
      if r3
        r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
        r0 = r3
      else
        @index = i0
        r0 = nil
      end
    end
  end

  node_cache[:nonnegative_number][start_index] = r0

  r0
end

#_nt_rangeObject



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
88
89
90
91
92
93
94
95
96
# File 'lib/musicality/notation/parsing/segment_parsing.rb', line 36

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

  i0, s0 = index, []
  r1 = _nt_nonnegative_number
  s0 << r1
  if r1
    s2, i2 = [], index
    loop do
      if has_terminal?(@regexps[gr = '\A[.]'] ||= Regexp.new(gr), :regexp, index)
        r3 = true
        @index += 1
      else
        terminal_parse_failure('[.]')
        r3 = nil
      end
      if r3
        s2 << r3
      else
        break
      end
      if s2.size == 3
        break
      end
    end
    if s2.size < 2
      @index = i2
      r2 = nil
    else
      if s2.size < 3
        @terminal_failures.pop
      end
      r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
    end
    s0 << r2
    if r2
      r4 = _nt_nonnegative_number
      s0 << r4
    end
  end
  if s0.last
    r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
    r0.extend(Range0)
    r0.extend(Range1)
  else
    @index = i0
    r0 = nil
  end

  node_cache[:range][start_index] = r0

  r0
end

#rootObject



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

def root
  @root ||= :range
end