Lexing of explicit negative/positive XPath numbers
This commit is contained in:
parent
8295fa5783
commit
bcd138a15a
|
@ -178,8 +178,8 @@ module Oga
|
||||||
# instead lexes them separately so that we can convert the values to
|
# instead lexes them separately so that we can convert the values to
|
||||||
# the corresponding Ruby types (Fixnum and Float).
|
# the corresponding Ruby types (Fixnum and Float).
|
||||||
|
|
||||||
integer = digit+;
|
integer = ('-' | '+')* digit+;
|
||||||
float = digit+ ('.' digit+)*;
|
float = ('-' | '+')* digit+ ('.' digit+)*;
|
||||||
|
|
||||||
action emit_integer {
|
action emit_integer {
|
||||||
value = slice_input(ts, te).to_i
|
value = slice_input(ts, te).to_i
|
||||||
|
|
|
@ -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
|
|
@ -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
|
Loading…
Reference in New Issue