diff --git a/lib/oga/xpath/lexer.rl b/lib/oga/xpath/lexer.rl index cf7d688..5d29fa2 100644 --- a/lib/oga/xpath/lexer.rl +++ b/lib/oga/xpath/lexer.rl @@ -212,11 +212,7 @@ module Oga | 'parent' | 'preceding' | 'preceding-sibling' - | 'self') '::'; - - action emit_axis_full { - emit(:T_AXIS, ts, te - 2) - } + | 'self'); # Short Axes # @@ -285,10 +281,13 @@ module Oga '[' => { add_token(:T_LBRACK) }; ']' => { add_token(:T_RBRACK) }; - string => emit_string; - integer => emit_integer; - float => emit_float; - axis_full => emit_axis_full; + string => emit_string; + integer => emit_integer; + float => emit_float; + + axis_full => { emit(:T_AXIS, ts, te) }; + axis_full '::' => { emit(:T_AXIS, ts, te - 2) }; + axis_short => emit_axis_short; identifier => emit_identifier; *|; diff --git a/spec/oga/xpath/parser/axes_spec.rb b/spec/oga/xpath/parser/axes_spec.rb index 9cd43f9..623bad3 100644 --- a/spec/oga/xpath/parser/axes_spec.rb +++ b/spec/oga/xpath/parser/axes_spec.rb @@ -44,6 +44,21 @@ describe Oga::XPath::Parser do ) end + example 'parse the descendant-or-self axis without a test' do + parse_xpath('/descendant-or-self').should == s( + :absolute_path, + s(:axis, 'descendant-or-self') + ) + end + + example 'parse the descendant-or-self axis followed by an attribute axis' do + parse_xpath('/descendant-or-self/attribute::foo').should == s( + :absolute_path, + s(:axis, 'descendant-or-self'), + s(:axis, 'attribute', s(:test, nil, 'foo')) + ) + end + example 'parse the following axis' do parse_xpath('/following::A').should == s( :absolute_path,