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
Search Repo:
Fixed more bugs with char classes and interpolation sequences and deleted 
dead code
Nathan Sobo (author)
Fri Feb 01 11:00:23 -0800 2008
commit  59dc3145576ec1a50de26acc0b34a0f352e20b5a
tree    3930f8f9e17658f3c7ef29ec5c034eb1ee12ab87
parent  386c475d75d55eaac8f28c27d59bcaed01f5fe47
...
15
16
17
18
 
19
20
21
...
15
16
17
 
18
19
20
21
0
@@ -15,7 +15,7 @@ end
0
 
0
 gemspec = Gem::Specification.new do |s|
0
   s.name = "treetop"
0
- s.version = "1.2.0"
0
+ s.version = "1.2.1"
0
   s.author = "Nathan Sobo"
0
   s.email = "nathansobo@gmail.com"
0
   s.homepage = "http://functionalform.blogspot.com"
...
4
5
6
7
 
8
9
10
...
14
15
16
 
 
 
 
17
18
19
20
...
4
5
6
 
7
8
9
10
...
14
15
16
17
18
19
20
21
22
23
24
0
@@ -4,7 +4,7 @@ module Treetop
0
       def compile(address, builder, parent_expression = nil)
0
         super
0
         
0
- builder.if__ "input.index(/#{text_value.gsub('/', '\/')}/, index) == index" do
0
+ builder.if__ "input.index(/#{escaped_text_value}/, index) == index" do
0
           assign_result "(#{node_class_name}).new(input, index...(index + 1))"
0
           extend_result_with_inline_module
0
           builder << "@index += 1"
0
@@ -14,6 +14,10 @@ module Treetop
0
           assign_result 'nil'
0
         end
0
       end
0
+
0
+ def escaped_text_value
0
+ text_value.gsub(/\/|#(@|\$)/) {|match| "\\#{match}"}
0
+ end
0
     end
0
   end
0
 end
0
\ No newline at end of file
...
19
20
21
22
 
23
24
25
26
27
 
28
29
30
31
 
32
33
34
...
36
37
38
39
 
40
41
42
43
 
44
45
46
...
53
54
55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
57
...
19
20
21
 
22
23
24
25
26
 
27
28
29
30
 
31
32
33
34
...
36
37
38
 
39
40
41
42
 
43
44
45
46
...
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
0
@@ -19,16 +19,16 @@ module CharacterClassSpec
0
       result.should be_an_instance_of(Foo)
0
       result.should respond_to(:a_method)
0
     end
0
-
0
+
0
     it "does not match single characters outside of that range" do
0
       parse('8').should be_nil
0
       parse('a').should be_nil
0
     end
0
-
0
+
0
     it "matches a single character within that range at index 1" do
0
       parse(' A', :index => 1).should_not be_nil
0
     end
0
-
0
+
0
     it "fails to match a single character out of that range at index 1" do
0
       parse(' 1', :index => 1).should be_nil
0
     end
0
@@ -36,11 +36,11 @@ module CharacterClassSpec
0
 
0
   describe "A character class containing quotes" do
0
     testing_expression "[\"']"
0
-
0
+
0
     it "matches a quote" do
0
       parse("'").should_not be_nil
0
     end
0
-
0
+
0
     it "matches a double-quote" do
0
       parse('"').should_not be_nil
0
     end
0
@@ -53,4 +53,24 @@ module CharacterClassSpec
0
       parse("/").should_not be_nil
0
     end
0
   end
0
+
0
+ describe "A character class containing a # followed by what looks like a Ruby instance variable" do
0
+ testing_expression '[#@a]'
0
+
0
+ it "matches a any character in the class" do
0
+ parse("a").should_not be_nil
0
+ parse("@").should_not be_nil
0
+ parse("#").should_not be_nil
0
+ end
0
+ end
0
+
0
+ describe "A character class containing a # followed by what looks like a Ruby global variable" do
0
+ testing_expression '[#$%]'
0
+
0
+ it "matches a any character in the class" do
0
+ parse("#").should_not be_nil
0
+ parse("$").should_not be_nil
0
+ parse("%").should_not be_nil
0
+ end
0
+ end
0
 end
0
\ No newline at end of file

Comments

    No one has commented yet.