Support for lexing/parsing XPath type tests.

Unlike what I thought before syntax such as "node()" is not a function call.
Instead this is a special node test that tests the *types* of nodes, not their
names.
This commit is contained in:
Yorick Peterse committed 2014-08-14 21:51:58 +02:00
1 parent 23441bb5a4
commit 6ad5170476
7 files changed
+77 -25

No files matched your search

+4 -12
View File
@@ -120,9 +120,7 @@ describe Oga::XPath::Lexer do
lex_xpath('//A').should == [
[:T_SLASH, nil],
[:T_AXIS, 'descendant-or-self'],
[:T_IDENT, 'node'],
[:T_LPAREN, nil],
[:T_RPAREN, nil],
[:T_NODE_TYPE, 'node'],
[:T_SLASH, nil],
[:T_IDENT, 'A']
]
@@ -132,9 +130,7 @@ describe Oga::XPath::Lexer do
lex_xpath('/..').should == [
[:T_SLASH, nil],
[:T_AXIS, 'parent'],
[:T_IDENT, 'node'],
[:T_LPAREN, nil],
[:T_RPAREN, nil],
[:T_NODE_TYPE, 'node']
]
end
@@ -142,18 +138,14 @@ describe Oga::XPath::Lexer do
lex_xpath('/.').should == [
[:T_SLASH, nil],
[:T_AXIS, 'self'],
[:T_IDENT, 'node'],
[:T_LPAREN, nil],
[:T_RPAREN, nil],
[:T_NODE_TYPE, 'node']
]
end
example 'lex the . axis followed by a path' do
lex_xpath('./foo').should == [
[:T_AXIS, 'self'],
[:T_IDENT, 'node'],
[:T_LPAREN, nil],
[:T_RPAREN, nil],
[:T_NODE_TYPE, 'node'],
[:T_SLASH, nil],
[:T_IDENT, 'foo']
]
+2 -6
View File
@@ -37,9 +37,7 @@ describe Oga::XPath::Lexer do
[:T_IDENT, 'wikimedia'],
[:T_SLASH, nil],
[:T_AXIS, 'descendant-or-self'],
[:T_IDENT, 'node'],
[:T_LPAREN, nil],
[:T_RPAREN, nil],
[:T_NODE_TYPE, 'node'],
[:T_SLASH, nil],
[:T_IDENT, 'editions']
]
@@ -66,9 +64,7 @@ describe Oga::XPath::Lexer do
[:T_SLASH, nil],
[:T_IDENT, 'edition'],
[:T_SLASH, nil],
[:T_IDENT, 'text'],
[:T_LPAREN, nil],
[:T_RPAREN, nil]
[:T_NODE_TYPE, 'text']
]
end
end
+23
View File
@@ -0,0 +1,23 @@
require 'spec_helper'
describe Oga::XPath::Lexer do
context 'node types' do
example 'lex the "node" type' do
lex_xpath('node()').should == [[:T_NODE_TYPE, 'node']]
end
example 'lex the "comment" type' do
lex_xpath('comment()').should == [[:T_NODE_TYPE, 'comment']]
end
example 'lex the "text" type' do
lex_xpath('text()').should == [[:T_NODE_TYPE, 'text']]
end
example 'lex the "processing-instruction" type' do
lex_xpath('processing-instruction()').should == [
[:T_NODE_TYPE, 'processing-instruction']
]
end
end
end
+3 -3
View File
@@ -105,7 +105,7 @@ describe Oga::XPath::Parser do
example 'parse the // axis' do
parse_xpath('//A').should == s(
:absolute_path,
s(:axis, 'descendant-or-self', s(:call, 'node')),
s(:axis, 'descendant-or-self', s(:node_type, 'node')),
s(:axis, 'child', s(:test, nil, 'A'))
)
end
@@ -113,14 +113,14 @@ describe Oga::XPath::Parser do
example 'parse the .. axis' do
parse_xpath('/..').should == s(
:absolute_path,
s(:axis, 'parent', s(:call, 'node'))
s(:axis, 'parent', s(:node_type, 'node'))
)
end
example 'parse the . axis' do
parse_xpath('/.').should == s(
:absolute_path,
s(:axis, 'self', s(:call, 'node'))
s(:axis, 'self', s(:node_type, 'node'))
)
end
end
+23
View File
@@ -0,0 +1,23 @@
require 'spec_helper'
describe Oga::XPath::Parser do
context 'node types' do
example 'parse the "node" type' do
parse_xpath('node()').should == s(:axis, 'child', s(:node_type, 'node'))
end
example 'parse the "comment" type' do
parse_xpath('comment()')
.should == s(:axis, 'child', s(:node_type, 'comment'))
end
example 'parse the "text" type' do
parse_xpath('text()').should == s(:axis, 'child', s(:node_type, 'text'))
end
example 'parse the "processing-instruction" type' do
parse_xpath('processing-instruction()')
.should == s(:axis, 'child', s(:node_type, 'processing-instruction'))
end
end
end