Navigation Menu

Skip to content

Commit

Permalink
Runtime no longer filters up nested failures. New gem 1.1.6.
Browse files Browse the repository at this point in the history
  • Loading branch information
nathansobo committed Dec 9, 2007
1 parent 3a411e5 commit a7a3dd8
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 139 deletions.
2 changes: 1 addition & 1 deletion trunk/Rakefile
Expand Up @@ -15,7 +15,7 @@ end

gemspec = Gem::Specification.new do |s|
s.name = "treetop"
s.version = "1.1.5"
s.version = "1.1.6"
s.author = "Nathan Sobo"
s.email = "nathansobo@gmail.com"
s.homepage = "http://functionalform.blogspot.com"
Expand Down
111 changes: 39 additions & 72 deletions trunk/examples/lambda_calculus/lambda_calculus.rb
Expand Up @@ -2,12 +2,7 @@ module LambdaCalculus
include Treetop::Runtime

def root
result = _nt_program
if index == input.size
return result
else
return ParseFailure.new(input, index, result.nested_failures)
end
@root || :program
end

include Arithmetic
Expand Down Expand Up @@ -55,13 +50,13 @@ def _nt_program
return cached
end

i0, s0, nr0 = index, [], []
i0, s0 = index, []
r1 = _nt_expression
s0 << r1
if r1.success?
s2, nr2, i2 = [], [], index
s2, i2 = [], index
loop do
i3, s3, nr3 = index, [], []
i3, s3 = index, []
r4 = parse_terminal(';', SyntaxNode)
s3 << r4
if r4.success?
Expand All @@ -77,16 +72,15 @@ def _nt_program
r3.extend(Program0)
else
self.index = i3
r3 = ParseFailure.new(input, i3, s3)
r3 = ParseFailure.new(input, i3)
end
nr2 << r3
if r3.success?
s2 << r3
else
break
end
end
r2 = SyntaxNode.new(input, i2...index, s2, nr2)
r2 = SyntaxNode.new(input, i2...index, s2)
s0 << r2
end
if s0.last.success?
Expand All @@ -95,7 +89,7 @@ def _nt_program
r0.extend(Program2)
else
self.index = i0
r0 = ParseFailure.new(input, i0, s0)
r0 = ParseFailure.new(input, i0)
end

node_cache[:program][start_index] = r0
Expand All @@ -111,39 +105,29 @@ def _nt_expression
return cached
end

i0, nr0 = index, []
i0 = index
r1 = _nt_definition
nr0 << r1
if r1.success?
r0 = r1
r1.update_nested_results(nr0)
else
r2 = _nt_conditional
nr0 << r2
if r2.success?
r0 = r2
r2.update_nested_results(nr0)
else
r3 = _nt_application
nr0 << r3
if r3.success?
r0 = r3
r3.update_nested_results(nr0)
else
r4 = _nt_function
nr0 << r4
if r4.success?
r0 = r4
r4.update_nested_results(nr0)
else
r5 = super
nr0 << r5
if r5.success?
r0 = r5
r5.update_nested_results(nr0)
else
self.index = i0
r0 = ParseFailure.new(input, i0, nr0)
r0 = ParseFailure.new(input, i0)
end
end
end
Expand Down Expand Up @@ -187,7 +171,7 @@ def _nt_definition
return cached
end

i0, s0, nr0 = index, [], []
i0, s0 = index, []
r1 = parse_terminal('def', SyntaxNode)
s0 << r1
if r1.success?
Expand All @@ -212,7 +196,7 @@ def _nt_definition
r0.extend(Definition1)
else
self.index = i0
r0 = ParseFailure.new(input, i0, s0)
r0 = ParseFailure.new(input, i0)
end

node_cache[:definition][start_index] = r0
Expand Down Expand Up @@ -276,7 +260,7 @@ def _nt_conditional
return cached
end

i0, s0, nr0 = index, [], []
i0, s0 = index, []
r1 = parse_terminal('if', SyntaxNode)
s0 << r1
if r1.success?
Expand Down Expand Up @@ -333,7 +317,7 @@ def _nt_conditional
r0.extend(Conditional1)
else
self.index = i0
r0 = ParseFailure.new(input, i0, s0)
r0 = ParseFailure.new(input, i0)
end

node_cache[:conditional][start_index] = r0
Expand All @@ -349,21 +333,17 @@ def _nt_primary
return cached
end

i0, nr0 = index, []
i0 = index
r1 = _nt_application
nr0 << r1
if r1.success?
r0 = r1
r1.update_nested_results(nr0)
else
r2 = super
nr0 << r2
if r2.success?
r0 = r2
r2.update_nested_results(nr0)
else
self.index = i0
r0 = ParseFailure.new(input, i0, nr0)
r0 = ParseFailure.new(input, i0)
end
end

Expand Down Expand Up @@ -412,7 +392,7 @@ def _nt_application
return cached
end

i0, s0, nr0 = index, [], []
i0, s0 = index, []
r1 = _nt_operator
s0 << r1
if r1.success?
Expand All @@ -429,7 +409,7 @@ def _nt_application
r0.extend(Application1)
else
self.index = i0
r0 = ParseFailure.new(input, i0, s0)
r0 = ParseFailure.new(input, i0)
end

node_cache[:application][start_index] = r0
Expand All @@ -445,21 +425,17 @@ def _nt_operator
return cached
end

i0, nr0 = index, []
i0 = index
r1 = _nt_function
nr0 << r1
if r1.success?
r0 = r1
r1.update_nested_results(nr0)
else
r2 = _nt_variable
nr0 << r2
if r2.success?
r0 = r2
r2.update_nested_results(nr0)
else
self.index = i0
r0 = ParseFailure.new(input, i0, nr0)
r0 = ParseFailure.new(input, i0)
end
end

Expand All @@ -476,21 +452,17 @@ def _nt_non_application
return cached
end

i0, nr0 = index, []
i0 = index
r1 = _nt_function
nr0 << r1
if r1.success?
r0 = r1
r1.update_nested_results(nr0)
else
r2 = _nt_variable
nr0 << r2
if r2.success?
r0 = r2
r2.update_nested_results(nr0)
else
self.index = i0
r0 = ParseFailure.new(input, i0, nr0)
r0 = ParseFailure.new(input, i0)
end
end

Expand Down Expand Up @@ -545,7 +517,7 @@ def _nt_function
return cached
end

i0, s0, nr0 = index, [], []
i0, s0 = index, []
r1 = parse_terminal('\\', SyntaxNode)
s0 << r1
if r1.success?
Expand All @@ -570,7 +542,7 @@ def _nt_function
r0.extend(Function1)
else
self.index = i0
r0 = ParseFailure.new(input, i0, s0)
r0 = ParseFailure.new(input, i0)
end

node_cache[:function][start_index] = r0
Expand Down Expand Up @@ -599,14 +571,14 @@ def _nt_variable
return cached
end

i0, s0, nr0 = index, [], []
i0, s0 = index, []
i1 = index
r2 = _nt_keyword
if r2.success?
r1 = ParseFailure.new(input, i1, r2.nested_failures)
r1 = ParseFailure.new(input, i1)
else
self.index = i1
r1 = SyntaxNode.new(input, index...index, r2.nested_failures)
r1 = SyntaxNode.new(input, index...index)
end
s0 << r1
if r1.success?
Expand All @@ -619,7 +591,7 @@ def _nt_variable
r0.extend(Variable1)
else
self.index = i0
r0 = ParseFailure.new(input, i0, s0)
r0 = ParseFailure.new(input, i0)
end

node_cache[:variable][start_index] = r0
Expand All @@ -638,33 +610,29 @@ def _nt_keyword
return cached
end

i0, s0, nr0 = index, [], []
i1, nr1 = index, []
i0, s0 = index, []
i1 = index
r2 = parse_terminal('if', SyntaxNode)
nr1 << r2
if r2.success?
r1 = r2
r2.update_nested_results(nr1)
else
r3 = parse_terminal('else', SyntaxNode)
nr1 << r3
if r3.success?
r1 = r3
r3.update_nested_results(nr1)
else
self.index = i1
r1 = ParseFailure.new(input, i1, nr1)
r1 = ParseFailure.new(input, i1)
end
end
s0 << r1
if r1.success?
i4 = index
r5 = _nt_non_space_char
if r5.success?
r4 = ParseFailure.new(input, i4, r5.nested_failures)
r4 = ParseFailure.new(input, i4)
else
self.index = i4
r4 = SyntaxNode.new(input, index...index, r5.nested_failures)
r4 = SyntaxNode.new(input, index...index)
end
s0 << r4
end
Expand All @@ -673,7 +641,7 @@ def _nt_keyword
r0.extend(Keyword0)
else
self.index = i0
r0 = ParseFailure.new(input, i0, s0)
r0 = ParseFailure.new(input, i0)
end

node_cache[:keyword][start_index] = r0
Expand All @@ -692,14 +660,14 @@ def _nt_non_space_char
return cached
end

i0, s0, nr0 = index, [], []
i0, s0 = index, []
i1 = index
r2 = parse_char_class(/[ \n]/, ' \n', SyntaxNode)
if r2.success?
r1 = ParseFailure.new(input, i1, r2.nested_failures)
r1 = ParseFailure.new(input, i1)
else
self.index = i1
r1 = SyntaxNode.new(input, index...index, r2.nested_failures)
r1 = SyntaxNode.new(input, index...index)
end
s0 << r1
if r1.success?
Expand All @@ -711,7 +679,7 @@ def _nt_non_space_char
r0.extend(NonSpaceChar0)
else
self.index = i0
r0 = ParseFailure.new(input, i0, s0)
r0 = ParseFailure.new(input, i0)
end

node_cache[:non_space_char][start_index] = r0
Expand All @@ -727,17 +695,16 @@ def _nt_space
return cached
end

s0, nr0, i0 = [], [], index
s0, i0 = [], index
loop do
r1 = parse_char_class(/[ \n]/, ' \n', SyntaxNode)
nr0 << r1
if r1.success?
s0 << r1
else
break
end
end
r0 = SyntaxNode.new(input, i0...index, s0, nr0)
r0 = SyntaxNode.new(input, i0...index, s0)

node_cache[:space][start_index] = r0

Expand Down
2 changes: 1 addition & 1 deletion trunk/examples/lambda_calculus/test_helper.rb
Expand Up @@ -10,7 +10,7 @@ def assert_evals_to_self(input)
def parse(input)
result = @parser.parse(input)
if result.failure?
puts result.nested_failures.join("\n")
puts @parser.terminal_failures.join("\n")
end
assert result.success?
result
Expand Down

0 comments on commit a7a3dd8

Please sign in to comment.