Skip to content

Commit

Permalink
Case-insensitive compiler handling was switched
Browse files Browse the repository at this point in the history
  • Loading branch information
cjheath committed Mar 12, 2014
1 parent 88ec58a commit 10c14c4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/treetop/compiler/node_classes/terminal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Terminal < AtomicExpression
def compile(address, builder, parent_expression = nil)
super
insensitive = insens.text_value.length > 0
str = insensitive ? string : string.downcase
str = insensitive ? string.downcase : string
string_length = eval(str).length

builder.if__ "has_terminal?(#{str}, #{insensitive ? ':insens' : false}, index)" do
Expand Down
2 changes: 1 addition & 1 deletion lib/treetop/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Treetop #:nodoc:
module VERSION #:nodoc:
MAJOR = 1
MINOR = 5
TINY = 0
TINY = 1

STRING = [MAJOR, MINOR, TINY].join('.')
end
Expand Down
20 changes: 10 additions & 10 deletions spec/compiler/terminal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,45 @@ class Foo < Treetop::Runtime::SyntaxNode
end

describe "a terminal symbol" do
testing_expression "'foo'"
testing_expression "'Foo'"

it "matches the input string" do
parse "foo", :index => 0 do |result|
parse "Foo", :index => 0 do |result|
result.should_not be_nil
result.interval.should == (0...3)
result.text_value.should == 'foo'
result.text_value.should == 'Foo'
end
end

it "fails to match the input string other than at the start" do
parse " foo", :index => 0 do |result|
parse " Foo", :index => 0 do |result|
result.should be_nil
end
end

it "fails to match the input string in the wrong case" do
parse "Foo", :index => 0 do |result|
parse "foo", :index => 0 do |result|
result.should be_nil
end
end
end

describe "a terminal symbol with case-insensitive matching" do
testing_expression "'foo'i"
testing_expression "'Foo'i"

it "matches the input string in the same case" do
parse "foo", :index => 0 do |result|
parse "Foo", :index => 0 do |result|
result.should_not be_nil
result.interval.should == (0...3)
result.text_value.should == 'foo'
result.text_value.should == 'Foo'
end
end

it "matches the input string in varied case" do
parse "FoO", :index => 0 do |result|
parse "foO", :index => 0 do |result|
result.should_not be_nil
result.interval.should == (0...3)
result.text_value.should == 'FoO'
result.text_value.should == 'foO'
end
end
end
Expand Down

0 comments on commit 10c14c4

Please sign in to comment.