Support for custom grouping of XPath expressions.
This allows the use of expressions such as "(A or B) and C". This fixes #59.
This commit is contained in:
parent
39c0f7147c
commit
46646e2ace
|
@ -35,6 +35,11 @@ rule
|
|||
;
|
||||
|
||||
expression
|
||||
: expression_members
|
||||
| T_LPAREN expression_members T_RPAREN { val[1] }
|
||||
;
|
||||
|
||||
expression_members
|
||||
: node_test_as_axis
|
||||
| operator
|
||||
| axis
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Oga::XPath::Parser do
|
||||
context 'grouping of expressions' do
|
||||
example 'parse "A + (B + C)"' do
|
||||
parse_xpath('A + (B + C)').should == s(
|
||||
:add,
|
||||
s(:axis, 'child', s(:test, nil, 'A')),
|
||||
s(
|
||||
:add,
|
||||
s(:axis, 'child', s(:test, nil, 'B')),
|
||||
s(:axis, 'child', s(:test, nil, 'C'))
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
example 'parse "A or (B or C)"' do
|
||||
parse_xpath('A or (B or C)').should == s(
|
||||
:or,
|
||||
s(:axis, 'child', s(:test, nil, 'A')),
|
||||
s(
|
||||
:or,
|
||||
s(:axis, 'child', s(:test, nil, 'B')),
|
||||
s(:axis, 'child', s(:test, nil, 'C'))
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
example 'parse "(A or B) and C"' do
|
||||
parse_xpath('(A or B) and C').should == s(
|
||||
:and,
|
||||
s(
|
||||
:or,
|
||||
s(:axis, 'child', s(:test, nil, 'A')),
|
||||
s(:axis, 'child', s(:test, nil, 'B'))
|
||||
),
|
||||
s(:axis, 'child', s(:test, nil, 'C'))
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue