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:
Yorick Peterse 2014-10-26 22:38:05 +01:00
parent 39c0f7147c
commit 46646e2ace
2 changed files with 46 additions and 0 deletions

View File

@ -35,6 +35,11 @@ rule
;
expression
: expression_members
| T_LPAREN expression_members T_RPAREN { val[1] }
;
expression_members
: node_test_as_axis
| operator
| axis

View File

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