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
Search Repo:
Sequences whose last elements include their endpoint also include their 
endpoints
Nathan Sobo (author)
Sun Apr 06 16:41:29 -0700 2008
commit  b7cbd6cda710d671947542aa3d0120da8e487575
tree    25ee27dd5bb758ae098edc3cd0e21e4a0890bfa9
parent  5a76b7e281f6cf4436038bcace27d857ac8b413c
...
11
12
13
14
 
15
16
17
...
11
12
13
 
14
15
16
17
0
@@ -11,7 +11,7 @@ module Treetop
0
           assign_result subexpression_result_var
0
         end
0
         builder.else_ do
0
- assign_result epsilon_node(true)
0
+ assign_result epsilon_node
0
           accumulate_dependency subexpression_result_var
0
         end
0
       end
...
86
87
88
89
90
91
 
 
92
93
94
...
86
87
88
 
 
 
89
90
91
92
93
0
@@ -86,9 +86,8 @@ module Treetop
0
         builder.assign 'self.index', start_index_var
0
       end
0
       
0
- def epsilon_node(include_endpoint = false)
0
- elipsis = include_endpoint ? '..' : '...'
0
- "SyntaxNode.new(input, index#{elipsis}index)"
0
+ def epsilon_node
0
+ "SyntaxNode.new(input, index..index)"
0
       end
0
       
0
       def assign_failure(start_index_var)
...
8
9
10
11
 
12
13
14
...
8
9
10
 
11
12
13
14
0
@@ -8,7 +8,7 @@ module Treetop
0
         compile_sequence_elements(sequence_elements)
0
         builder.assign '@max_terminal_failure_last_index', 'local_max_terminal_failure_last_index'
0
         builder.if__ "!#{accumulator_var}.last.is_a?(ParseFailure)" do
0
- builder.assign "interval", "#{accumulator_var}.last.epsilon? ? #{start_index_var}..index : #{start_index_var}...index"
0
+ builder.assign "interval", "#{accumulator_var}.last.interval.exclude_end? ? #{start_index_var}...index : #{start_index_var}..index"
0
           assign_result "(#{node_class_name}).new(input, interval, #{accumulator_var})"
0
           extend_result sequence_element_accessor_module_name if sequence_element_accessor_module_name
0
           extend_result_with_inline_module
...
14
15
16
17
 
18
19
 
20
21
22
...
14
15
16
 
17
18
 
19
20
21
22
0
@@ -14,9 +14,9 @@ module AndPredicateSpec
0
         @result = parse(input, :consume_all_input => false)
0
       end
0
 
0
- it "is an epsilon node" do
0
+ it "is an epsilon node that includes its endpoint" do
0
         result.should be_epsilon
0
- result.interval.should == (0...0)
0
+ result.interval.should == (0..0)
0
       end
0
       
0
       it "depends on the result of the predicated subexpression" do
...
72
73
74
75
 
76
77
78
...
97
98
99
 
 
 
 
 
 
 
 
 
 
 
 
100
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
102
103
...
72
73
74
 
75
76
77
78
...
97
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
135
136
137
138
139
140
141
142
143
144
145
146
147
0
@@ -72,7 +72,7 @@ module SequenceSpec
0
     end
0
   end
0
 
0
- describe "a sequence of non-terminals" do
0
+ describe "A sequence of non-terminals" do
0
     testing_grammar %{
0
       grammar TestGrammar
0
         rule sequence
0
@@ -97,7 +97,51 @@ module SequenceSpec
0
       end
0
     end
0
   end
0
+
0
+ describe "A sequence whose last subexpression may include its endpoint" do
0
+ describe "when its last subexpression is optional" do
0
+ testing_expression "'a' 'c'?"
0
+
0
+ it "when the the optional subexpression results in epsilon, produces a result that includes its endpoint" do
0
+ parse('a').interval.should == (0..1)
0
+ end
0
+ end
0
+
0
+ describe "when its last subexpression is a zero or more" do
0
+ testing_expression "'a' 'c'*"
0
   
0
+ it "includes its endpoint when the result of its last subexpression does" do
0
+ parse('a').interval.should == (0..1)
0
+ end
0
+ end
0
+
0
+ describe "when its last subexpression is a one or more" do
0
+ testing_expression "'a' 'c'+"
0
+
0
+ it "includes its endpoint when the result of its last subexpression does" do
0
+ parse('ac').interval.should == (0..2)
0
+ end
0
+ end
0
+
0
+ describe "when its last subexpression is another sequence whose results may include its endpoint" do
0
+ testing_grammar %{
0
+ grammar EndpointInclusion
0
+ rule foo
0
+ 'a' bar
0
+ end
0
+
0
+ rule bar
0
+ 'b' 'c'?
0
+ end
0
+ end
0
+ }
0
+
0
+ it "includes its endpoint when the result of its last subexpression does" do
0
+ parse('ab').interval.should == (0..2)
0
+ end
0
+ end
0
+ end
0
+
0
   describe "Compiling a sequence containing various white-space errors" do
0
     it "should succeed on a valid sequence" do
0
       compiling_expression('foo:"foo" "bar" <SequenceSpec::Foo> { def a_method; end }').should_not raise_error
...
73
74
75
76
 
77
78
79
...
73
74
75
 
76
77
78
79
0
@@ -73,7 +73,7 @@ module SyntaxNodeSpec
0
       node.should_not be_epsilon
0
     end
0
   end
0
-
0
+
0
   describe "A new epsilon syntax node" do
0
     attr_reader :node
0
     

Comments

    No one has commented yet.