Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
332 lines (295 sloc) 5.79 KB
# Autogenerated from a Treetop grammar. Edits may be lost.
module Measurement
include Treetop::Runtime
def root
@root ||= :measurement
end
module Measurement0
def part1
elements[0]
end
def part2
elements[2]
end
end
def _nt_measurement
start_index = index
if node_cache[:measurement].has_key?(index)
cached = node_cache[:measurement][index]
if cached
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
@index = cached.interval.end
end
return cached
end
i0 = index
r1 = _nt_part
if r1
r0 = r1
else
i2, s2 = index, []
r3 = _nt_part
s2 << r3
if r3
if has_terminal?(' or ', false, index)
r4 = instantiate_node(SyntaxNode,input, index...(index + 4))
@index += 4
else
terminal_parse_failure(' or ')
r4 = nil
end
s2 << r4
if r4
r5 = _nt_part
s2 << r5
end
end
if s2.last
r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
r2.extend(Measurement0)
else
@index = i2
r2 = nil
end
if r2
r0 = r2
else
@index = i0
r0 = nil
end
end
node_cache[:measurement][start_index] = r0
r0
end
module Part0
def n
elements[0]
end
def unit
elements[1]
end
def blah
elements[2]
end
end
module Part1
def value
(unit == '') ? n.to_i : n.to_i.send(unit)
end
end
module Part2
def fraction
elements[0]
end
def unit
elements[1]
end
def blah
elements[2]
end
end
module Part3
def value
fraction.value.send(unit)
end
end
def _nt_part
start_index = index
if node_cache[:part].has_key?(index)
cached = node_cache[:part][index]
if cached
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
@index = cached.interval.end
end
return cached
end
i0 = index
i1, s1 = index, []
s2, i2 = [], index
loop do
if has_terminal?('\G[0-9]', true, index)
r3 = true
@index += 1
else
r3 = nil
end
if r3
s2 << r3
else
break
end
end
if s2.empty?
@index = i2
r2 = nil
else
r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
end
s1 << r2
if r2
r4 = _nt_unit
s1 << r4
if r4
r5 = _nt_unit
s1 << r5
end
end
if s1.last
r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
r1.extend(Part0)
r1.extend(Part1)
else
@index = i1
r1 = nil
end
if r1
r0 = r1
else
i6, s6 = index, []
r7 = _nt_fraction
s6 << r7
if r7
r8 = _nt_unit
s6 << r8
if r8
r9 = _nt_unit
s6 << r9
end
end
if s6.last
r6 = instantiate_node(SyntaxNode,input, i6...index, s6)
r6.extend(Part2)
r6.extend(Part3)
else
@index = i6
r6 = nil
end
if r6
r0 = r6
else
@index = i0
r0 = nil
end
end
node_cache[:part][start_index] = r0
r0
end
module Fraction0
def a
elements[0]
end
def b
elements[2]
end
end
module Fraction1
def value
a.to_i / b.to_i
end
end
def _nt_fraction
start_index = index
if node_cache[:fraction].has_key?(index)
cached = node_cache[:fraction][index]
if cached
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
@index = cached.interval.end
end
return cached
end
i0, s0 = index, []
if has_terminal?('\G[1-9]', true, index)
r1 = true
@index += 1
else
r1 = nil
end
s0 << r1
if r1
if has_terminal?('/', false, index)
r2 = instantiate_node(SyntaxNode,input, index...(index + 1))
@index += 1
else
terminal_parse_failure('/')
r2 = nil
end
s0 << r2
if r2
if has_terminal?('\G[1-9]', true, index)
r3 = true
@index += 1
else
r3 = nil
end
s0 << r3
end
end
if s0.last
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
r0.extend(Fraction0)
r0.extend(Fraction1)
else
@index = i0
r0 = nil
end
node_cache[:fraction][start_index] = r0
r0
end
module Unit0
end
def _nt_unit
start_index = index
if node_cache[:unit].has_key?(index)
cached = node_cache[:unit][index]
if cached
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
@index = cached.interval.end
end
return cached
end
i0, s0 = index, []
if has_terminal?(' ', false, index)
r2 = instantiate_node(SyntaxNode,input, index...(index + 1))
@index += 1
else
terminal_parse_failure(' ')
r2 = nil
end
if r2
r1 = r2
else
r1 = instantiate_node(SyntaxNode,input, index...index)
end
s0 << r1
if r1
s3, i3 = [], index
loop do
if has_terminal?('\G[a-zA-Z]', true, index)
r4 = true
@index += 1
else
r4 = nil
end
if r4
s3 << r4
else
break
end
end
r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
s0 << r3
end
if s0.last
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
r0.extend(Unit0)
else
@index = i0
r0 = nil
end
node_cache[:unit][start_index] = r0
r0
end
end
class MeasurementParser < Treetop::Runtime::CompiledParser
include Measurement
end