public
Fork of nathansobo/treetop
Description: A Ruby-based parsing DSL based on parsing expression grammars.
Homepage: http://treetop.rubyforge.org
Clone URL: git://github.com/juretta/treetop.git
The failure indicates a remaining problem with expiration.
Nathan Sobo (author)
Fri Mar 07 18:34:18 -0800 2008
commit  a2bd3cfc8c921fb74f0e67404cf4226ebc2e05b9
tree    ec1a00d54dc2b1fed1679c951fec8c04cc292e79
parent  58105b94402a177427b87315faa67eaacca50fa2
...
52
53
54
 
 
 
 
 
 
 
 
 
 
 
 
55
56
57
...
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
0
@@ -52,6 +52,18 @@ module Treetop
0
         results_to_delete.push(result)
0
       end
0
 
0
+ def inspect
0
+ s = ""
0
+ node_index.each do |rule_name, subhash|
0
+ s += "#{rule_name}: "
0
+ subhash.each do |i, v|
0
+ s += "#{i} => #{v.inspect}, "
0
+ end
0
+ s += "\n"
0
+ end
0
+ s
0
+ end
0
+
0
       protected
0
       
0
       def register_result(result)
...
159
160
161
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162
163
...
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
0
@@ -159,4 +159,79 @@ module IterativeParsingSpec
0
       node_cache.should have_result(:number, 2)
0
     end
0
   end
0
+
0
+ describe "A parser for a simplified addition grammar" do
0
+ testing_grammar %{
0
+ grammar Addition
0
+ rule addition
0
+ primary '+' addition / primary
0
+ end
0
+
0
+ rule primary
0
+ '(' addition ')' / number
0
+ end
0
+
0
+ rule number
0
+ [0-9]
0
+ end
0
+ end
0
+ }
0
+
0
+ it "expires the stale failure of addition as successive characters are added to the buffer" do
0
+ input = '('
0
+ parse(input).should be_nil
0
+ node_cache.should have_result(:addition, 0)
0
+ node_cache.should have_result(:primary, 0)
0
+ node_cache.should have_result(:number, 0)
0
+
0
+ expire(1..1, 1)
0
+ node_cache.should_not have_result(:addition, 0)
0
+ node_cache.should_not have_result(:primary, 0)
0
+ node_cache.should have_result(:number, 0)
0
+
0
+ input.replace('(1')
0
+ reparse.should be_nil
0
+ node_cache.should have_result(:addition, 0)
0
+ node_cache.should have_result(:addition, 1)
0
+ node_cache.should have_result(:primary, 0)
0
+ node_cache.should have_result(:primary, 1)
0
+ node_cache.should have_result(:number, 0)
0
+ node_cache.should have_result(:number, 1)
0
+
0
+ expire(2..2, 1)
0
+ node_cache.should_not have_result(:addition, 0)
0
+ node_cache.should_not have_result(:addition, 1)
0
+ node_cache.should_not have_result(:primary, 0)
0
+ node_cache.should have_result(:primary, 1) # is this true?
0
+ node_cache.should have_result(:number, 0)
0
+ node_cache.should have_result(:number, 1)
0
+
0
+ input.replace('(1+')
0
+ reparse.should be_nil
0
+ node_cache.should have_result(:addition, 0)
0
+ node_cache.should have_result(:addition, 1)
0
+ node_cache.should have_result(:primary, 0)
0
+ node_cache.should have_result(:primary, 1)
0
+ node_cache.should have_result(:number, 0)
0
+ node_cache.should have_result(:number, 1)
0
+
0
+ expire(3..3, 1)
0
+ node_cache.should_not have_result(:addition, 0)
0
+ node_cache.should_not have_result(:addition, 1)
0
+ node_cache.should_not have_result(:addition, 2)
0
+ node_cache.should_not have_result(:primary, 0)
0
+ node_cache.should have_result(:primary, 1) # is this true?
0
+ node_cache.should_not have_result(:primary, 2)
0
+ node_cache.should have_result(:number, 0)
0
+ node_cache.should have_result(:number, 1)
0
+ node_cache.should_not have_result(:number, 2)
0
+
0
+ input.replace('(1+2')
0
+ reparse.should be_nil
0
+
0
+ expire(4..4, 1)
0
+ input.replace('(1+2)')
0
+ reparse.should_not be_nil
0
+ end
0
+ end
0
 end
0
\ No newline at end of file
...
21
22
23
24
 
25
26
27
28
 
29
30
31
...
21
22
23
 
24
25
26
27
 
28
29
30
31
0
@@ -21,11 +21,11 @@ class TextraDocument < Rucola::RCDocument
0
     parser.send(:input).replace(text)
0
     
0
     puts 'after expiry'
0
- pp node_index
0
+ p node_cache
0
 
0
     result = parser.reparse
0
     puts 'after reparse'
0
- pp node_index
0
+ p node_cache
0
     
0
     
0
     

Comments

    No one has commented yet.