Lexing of explicit negative/positive XPath numbers

This commit is contained in:
Yorick Peterse 2014-08-26 20:21:30 +02:00
parent 8295fa5783
commit bcd138a15a
3 changed files with 28 additions and 2 deletions

View File

@ -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

View File

@ -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

View File

@ -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