diff --git a/lib/oga/xpath/lexer.rl b/lib/oga/xpath/lexer.rl index 5cdf58e..c2e7064 100644 --- a/lib/oga/xpath/lexer.rl +++ b/lib/oga/xpath/lexer.rl @@ -178,8 +178,8 @@ module Oga # instead lexes them separately so that we can convert the values to # the corresponding Ruby types (Fixnum and Float). - integer = digit+; - float = digit+ ('.' digit+)*; + integer = ('-' | '+')* digit+; + float = ('-' | '+')* digit+ ('.' digit+)*; action emit_integer { value = slice_input(ts, te).to_i diff --git a/spec/oga/xpath/lexer/floats_spec.rb b/spec/oga/xpath/lexer/floats_spec.rb new file mode 100644 index 0000000..3ff0999 --- /dev/null +++ b/spec/oga/xpath/lexer/floats_spec.rb @@ -0,0 +1,13 @@ +require 'spec_helper' + +describe Oga::XPath::Lexer do + context 'floats' do + example 'lex a float' do + lex_xpath('10.0').should == [[:T_FLOAT, 10.0]] + end + + example 'lex a negative float' do + lex_xpath('-10.0').should == [[:T_FLOAT, -10.0]] + end + end +end diff --git a/spec/oga/xpath/lexer/integers_spec.rb b/spec/oga/xpath/lexer/integers_spec.rb new file mode 100644 index 0000000..9a6d8e0 --- /dev/null +++ b/spec/oga/xpath/lexer/integers_spec.rb @@ -0,0 +1,13 @@ +require 'spec_helper' + +describe Oga::XPath::Lexer do + context 'integers' do + example 'lex an integer' do + lex_xpath('10').should == [[:T_INT, 10]] + end + + example 'lex a negative integer' do + lex_xpath('-10').should == [[:T_INT, -10]] + end + end +end