Basic parser setup for XPath function calls.

This commit is contained in:
Yorick Peterse 2014-06-17 19:57:17 +02:00
parent 894de7f909
commit 497f57ccd2
2 changed files with 39 additions and 0 deletions

View File

@ -32,6 +32,7 @@ rule
| axis
| string
| number
| call
;
node_test
@ -61,6 +62,16 @@ rule
| 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
: T_STRING { s(:string, val[0]) }
;

View File

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