Basic parser setup for XPath function calls.
This commit is contained in:
parent
894de7f909
commit
497f57ccd2
|
@ -32,6 +32,7 @@ rule
|
||||||
| axis
|
| axis
|
||||||
| string
|
| string
|
||||||
| number
|
| number
|
||||||
|
| call
|
||||||
;
|
;
|
||||||
|
|
||||||
node_test
|
node_test
|
||||||
|
@ -61,6 +62,16 @@ rule
|
||||||
| T_AXIS { s(:axis, val[0]) }
|
| T_AXIS { s(:axis, val[0]) }
|
||||||
;
|
;
|
||||||
|
|
||||||
|
call
|
||||||
|
: T_IDENT T_LPAREN T_RPAREN { s(:call, val[0]) }
|
||||||
|
| T_IDENT T_LPAREN call_args T_RPAREN { s(:call, val[0], *val[2]) }
|
||||||
|
;
|
||||||
|
|
||||||
|
call_args
|
||||||
|
: xpath { val }
|
||||||
|
| xpath T_COMMA call_args { [val[0], *val[2]] }
|
||||||
|
;
|
||||||
|
|
||||||
string
|
string
|
||||||
: T_STRING { s(:string, val[0]) }
|
: T_STRING { s(:string, val[0]) }
|
||||||
;
|
;
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Oga::XPath::Parser do
|
||||||
|
context 'function calls' do
|
||||||
|
example 'parse a function call without arguments' do
|
||||||
|
parse_xpath('count()').should == s(:path, s(:call, 'count'))
|
||||||
|
end
|
||||||
|
|
||||||
|
example 'parse a function call with a single argument' do
|
||||||
|
parse_xpath('count(/foo)').should == s(
|
||||||
|
:path,
|
||||||
|
s(:call, 'count', s(:absolute, s(:path, s(:test, nil, 'foo'))))
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
example 'parse a function call with two arguments' do
|
||||||
|
parse_xpath('count(/foo, "bar")').should == s(
|
||||||
|
:path,
|
||||||
|
s(
|
||||||
|
:call,
|
||||||
|
'count',
|
||||||
|
s(:absolute, s(:path, s(:test, nil, 'foo'))),
|
||||||
|
s(:path, s(:string, 'bar'))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue