public
Description: A Ruby-based parsing DSL based on parsing expression grammars.
Homepage: http://treetop.rubyforge.org
Clone URL: git://github.com/nathansobo/treetop.git
Established distinction between child results and non-local dependencies.
Nathan Sobo (author)
Fri Apr 04 15:20:23 -0700 2008
commit  5a76b7e281f6cf4436038bcace27d857ac8b413c
tree    0e47f544072346e1acde3cdef8575d5cb0a849bf
parent  c982695d7b9f51b85022785131876a45e9f3c0f9
...
1
2
3
4
 
5
6
7
...
1
2
3
 
4
5
6
7
0
@@ -1,7 +1,7 @@
0
 module Treetop
0
   module Runtime
0
     class ParseResult
0
- attr_reader :dependent_results, :dependencies, :dependents, :memoizations
0
+ attr_reader :dependent_results, :dependencies, :child_results, :dependents, :memoizations
0
       attr_accessor :interval, :parent, :registered, :result_cache
0
       alias :registered? :registered
0
       
...
64
65
66
 
 
 
 
 
 
 
 
67
68
69
70
 
71
72
73
...
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
0
@@ -64,10 +64,19 @@ module Treetop
0
       def register_result(result)
0
         return if result.registered?
0
         result.result_cache = self
0
+
0
+ if result.child_results
0
+ result.child_results.each do |child_result|
0
+ child_result.parent = result
0
+ register_result(child_result)
0
+ end
0
+ end
0
+
0
         result.dependencies.each do |subresult|
0
           subresult.dependents.push(result)
0
           register_result(subresult)
0
         end
0
+
0
         result.registered = true
0
         results.push(result)
0
       end
...
6
7
8
9
10
11
12
13
14
15
16
17
 
 
18
19
20
...
57
58
59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
61
62
63
...
6
7
8
 
 
 
 
 
 
 
 
 
9
10
11
12
13
...
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
0
@@ -6,15 +6,8 @@ module Treetop
0
       def initialize(input, interval, child_results = nil)
0
         super(interval)
0
         @input = input
0
-
0
- if child_results
0
- @dependencies = child_results
0
- @elements = child_results.map do |child_result|
0
- element = child_result.element
0
- element.parent = self
0
- element
0
- end
0
- end
0
+ @child_results = child_results
0
+ set_elements_from_child_results_and_become_parent if child_results
0
       end
0
 
0
       def element
0
@@ -57,6 +50,22 @@ module Treetop
0
           "SyntaxNode(text value is nil!)"
0
         end
0
       end
0
+
0
+ def expire
0
+ super
0
+ parent.expire if parent
0
+ end
0
+
0
+ protected
0
+ def set_elements_from_child_results_and_become_parent
0
+ @elements = []
0
+ child_results.each do |child_result|
0
+ child_result.parent = self
0
+ element = child_result.element
0
+ element.parent = self
0
+ elements.push(element)
0
+ end
0
+ end
0
     end
0
   end
0
 end
0
\ No newline at end of file
...
63
64
65
66
67
68
69
70
71
72
...
63
64
65
 
 
 
 
66
67
68
0
@@ -63,10 +63,6 @@ module AndPredicateSpec
0
         result.elements[1].should be_epsilon
0
       end
0
       
0
- it "depends on its elements" do
0
- result.dependencies.should == result.elements
0
- end
0
-
0
       it "is expired when a character is inserted between 'foo' and 'bar'" do
0
         result_cache.should have_result(:expression_under_test, 0)
0
         input.replace('fooxbar')
...
80
81
82
83
84
85
86
87
88
89
...
80
81
82
 
 
 
 
83
84
85
0
@@ -80,10 +80,6 @@ module NotPredicateSpec
0
           result.should_not be_nil
0
         end
0
         
0
- it "has its elements as dependencies" do
0
- result.dependencies.should == result.elements
0
- end
0
-
0
         it "has the epsilon result of the predicated terminal as its second element" do
0
           result.elements[1].should be_epsilon
0
         end
...
59
60
61
62
 
63
64
65
66
67
68
69
70
71
 
 
 
 
72
73
74
...
59
60
61
 
62
63
 
 
 
 
 
 
 
 
64
65
66
67
68
69
70
0
@@ -59,16 +59,12 @@ module OneOrMoreSpec
0
           result.interval.should == (0..6)
0
         end
0
 
0
- it "depends on the 2 successful parsings and one failed parsing of the repeated subexpression" do
0
+ it "depends on the failed parsing of the repeated subexpression" do
0
           dependencies = result.dependencies
0
- dependencies.size.should == 3
0
- dependencies[0].text_value.should == 'foo'
0
- dependencies[0].interval.should == (0...3)
0
- dependencies[1].text_value.should == 'foo'
0
- dependencies[1].interval.should == (3...6)
0
- dependencies[2].should be_an_instance_of(Runtime::TerminalParseFailure)
0
- dependencies[2].index.should == 6
0
- dependencies[2].expected_string.should == 'foo'
0
+ dependencies.size.should == 1
0
+ dependencies.first.should be_an_instance_of(Runtime::TerminalParseFailure)
0
+ dependencies.first.index.should == 6
0
+ dependencies.first.expected_string.should == 'foo'
0
         end
0
       end
0
 
...
31
32
33
34
35
36
37
38
39
40
...
31
32
33
 
 
 
 
34
35
36
0
@@ -31,10 +31,6 @@ module SequenceSpec
0
       it "has the method defined in the trailing block" do
0
         result.should respond_to(:a_method)
0
       end
0
-
0
- it "has the sequence elements as its #dependencies" do
0
- result.dependencies.should == result.elements
0
- end
0
     end
0
 
0
     describe "upon failing to match input starting at index 3" do
...
64
65
66
67
 
68
69
70
71
72
73
74
75
76
 
 
 
 
77
78
79
...
64
65
66
 
67
68
 
 
 
 
 
 
 
 
69
70
71
72
73
74
75
0
@@ -64,16 +64,12 @@ module ZeroOrMoreSpec
0
           result.interval.should == (0..6)
0
         end
0
 
0
- it "depends on the 2 successful parsings and one failed parsing of the repeated subexpression" do
0
+ it "depends on the failed parsing of the repeated subexpression" do
0
           dependencies = result.dependencies
0
- dependencies.size.should == 3
0
- dependencies[0].text_value.should == 'foo'
0
- dependencies[0].interval.should == (0...3)
0
- dependencies[1].text_value.should == 'foo'
0
- dependencies[1].interval.should == (3...6)
0
- dependencies[2].should be_an_instance_of(Runtime::TerminalParseFailure)
0
- dependencies[2].index.should == 6
0
- dependencies[2].expected_string.should == 'foo'
0
+ dependencies.size.should == 1
0
+ dependencies.first.should be_an_instance_of(Runtime::TerminalParseFailure)
0
+ dependencies.first.index.should == 6
0
+ dependencies.first.expected_string.should == 'foo'
0
         end
0
       end
0
 
...
149
150
151
152
 
153
154
155
...
149
150
151
 
152
153
154
155
0
@@ -149,7 +149,7 @@ module ResultCacheSpec
0
         @non_local_dependency = TerminalParseFailure.new(5...15, 'x' * 10)
0
 
0
         parent.dependencies.push(non_local_dependency)
0
- parent.dependencies.should == [child, epsilon_node, non_local_dependency]
0
+ parent.dependencies.should == [non_local_dependency]
0
 
0
         cache.store_result(:foo, parent)
0
       end

Comments

    No one has commented yet.