Skip to content

Commit

Permalink
Fixed more bugs with char classes and interpolation sequences and del…
Browse files Browse the repository at this point in the history
…eted dead code
  • Loading branch information
nathansobo committed Feb 1, 2008
1 parent 386c475 commit 59dc314
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 53 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ end

gemspec = Gem::Specification.new do |s|
s.name = "treetop"
s.version = "1.2.0"
s.version = "1.2.1"
s.author = "Nathan Sobo"
s.email = "nathansobo@gmail.com"
s.homepage = "http://functionalform.blogspot.com"
Expand Down
6 changes: 5 additions & 1 deletion lib/treetop/compiler/node_classes/character_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class CharacterClass < AtomicExpression
def compile(address, builder, parent_expression = nil)
super

builder.if__ "input.index(/#{text_value.gsub('/', '\/')}/, index) == index" do
builder.if__ "input.index(/#{escaped_text_value}/, index) == index" do
assign_result "(#{node_class_name}).new(input, index...(index + 1))"
extend_result_with_inline_module
builder << "@index += 1"
Expand All @@ -14,6 +14,10 @@ def compile(address, builder, parent_expression = nil)
assign_result 'nil'
end
end

def escaped_text_value
text_value.gsub(/\/|#(@|\$)/) {|match| "\\#{match}"}
end
end
end
end
27 changes: 0 additions & 27 deletions lib/treetop/runtime/node_cache.rb

This file was deleted.

19 changes: 0 additions & 19 deletions lib/treetop/runtime/parse_cache.rb

This file was deleted.

30 changes: 25 additions & 5 deletions spec/compiler/character_class_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,28 @@ class Foo < Treetop::Runtime::SyntaxNode
result.should be_an_instance_of(Foo)
result.should respond_to(:a_method)
end

it "does not match single characters outside of that range" do
parse('8').should be_nil
parse('a').should be_nil
end

it "matches a single character within that range at index 1" do
parse(' A', :index => 1).should_not be_nil
end

it "fails to match a single character out of that range at index 1" do
parse(' 1', :index => 1).should be_nil
end
end

describe "A character class containing quotes" do
testing_expression "[\"']"

it "matches a quote" do
parse("'").should_not be_nil
end

it "matches a double-quote" do
parse('"').should_not be_nil
end
Expand All @@ -53,4 +53,24 @@ class Foo < Treetop::Runtime::SyntaxNode
parse("/").should_not be_nil
end
end

describe "A character class containing a # followed by what looks like a Ruby instance variable" do
testing_expression '[#@a]'

it "matches a any character in the class" do
parse("a").should_not be_nil
parse("@").should_not be_nil
parse("#").should_not be_nil
end
end

describe "A character class containing a # followed by what looks like a Ruby global variable" do
testing_expression '[#$%]'

it "matches a any character in the class" do
parse("#").should_not be_nil
parse("$").should_not be_nil
parse("%").should_not be_nil
end
end
end

0 comments on commit 59dc314

Please sign in to comment.