From a52aafebd553d9efef775d57d2c81647825eb10d Mon Sep 17 00:00:00 2001 From: jez <> Date: Fri, 26 Oct 2007 23:24:58 +0000 Subject: [PATCH] In XPath node() matches any node of any type. In an XSLT match pattern, node() matches everything except attributes and the document root node. Tweaked that match pattern grammar to introduce a new token in the AST. --- include/XPath/impl/xpath_ast_ids.hpp | 1 + include/XPath/impl/xpath_grammar.hpp | 5 ++++- include/XPath/impl/xpath_parser.hpp | 5 +++-- include/XPath/impl/xpath_step.hpp | 5 +++-- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/include/XPath/impl/xpath_ast_ids.hpp b/include/XPath/impl/xpath_ast_ids.hpp index 51b5d52c..cbe95bfc 100644 --- a/include/XPath/impl/xpath_ast_ids.hpp +++ b/include/XPath/impl/xpath_ast_ids.hpp @@ -106,6 +106,7 @@ enum RelativePathPattern_id, StepPattern_id, ChildOrAttributeAxisSpecifier_id, + NodeMatchPattern_id, AttributeValueTemplate_id, DoubleLeftCurly_id, diff --git a/include/XPath/impl/xpath_grammar.hpp b/include/XPath/impl/xpath_grammar.hpp index 97f45417..5019ad6c 100644 --- a/include/XPath/impl/xpath_grammar.hpp +++ b/include/XPath/impl/xpath_grammar.hpp @@ -357,10 +357,12 @@ struct xpath_grammar_match : public boost::spirit::grammar RelativePathPattern = StepPattern >> *((base::SlashSlash | base::Slash) >> StepPattern); // [5] StepPattern ::= ChildOrAttributeAxisSpecifier NodeTest Predicate* - StepPattern = ChildOrAttributeAxisSpecifier >> base::NodeTest >> *base::Predicate; + StepPattern = ChildOrAttributeAxisSpecifier >> (NodeMatchPattern|base::NodeTest) >> *base::Predicate; // [6] ChildOrAttributeAxisSpecifier ::= AbbreviatedAxisSpecifier | ('child' | 'attribute') '::' ChildOrAttributeAxisSpecifier = ((base::Child | base::Attribute) >> discard_node_d[str_p("::")]) | base::AbbreviatedAxisSpecifier; + + NodeMatchPattern = str_p("node()"); } // definition boost::spirit::rule > const& @@ -375,6 +377,7 @@ struct xpath_grammar_match : public boost::spirit::grammar boost::spirit::rule > RelativePathPattern; boost::spirit::rule > StepPattern; boost::spirit::rule > ChildOrAttributeAxisSpecifier; + boost::spirit::rule > NodeMatchPattern; }; // definition }; // xpath_grammar_match diff --git a/include/XPath/impl/xpath_parser.hpp b/include/XPath/impl/xpath_parser.hpp index 855101c6..14c9b9df 100644 --- a/include/XPath/impl/xpath_parser.hpp +++ b/include/XPath/impl/xpath_parser.hpp @@ -337,8 +337,8 @@ private: factory[impl::NameTest_id] = createSingleMatchStep; factory[impl::QName_id] = createSingleMatchStep; factory[impl::NCName_id] = createSingleMatchStep; + factory[impl::NodeMatchPattern_id] = createSingleMatchStep; factory[impl::AnyName_id] = createSingleMatchStep; - factory[impl::Node_id] = createSingleMatchStep; factory[impl::Text_id] = createSingleMatchStep; factory[impl::Comment_id] = createSingleMatchStep; factory[impl::ProcessingInstruction_id] = createSingleMatchStep; @@ -465,6 +465,7 @@ private: names[impl::RelativePathPattern_id] = SA::construct_from_utf8("RelativePathPattern"); names[impl::StepPattern_id] = SA::construct_from_utf8("StepPattern"); names[impl::ChildOrAttributeAxisSpecifier_id] = SA::construct_from_utf8("ChildOrAttributeAxisSpecifier"); + names[impl::NodeMatchPattern_id] = SA::construct_from_utf8("node()"); names[impl::AttributeValueTemplate_id] = SA::construct_from_utf8("AttributeValueTemplate"); names[impl::DoubleLeftCurly_id] = SA::construct_from_utf8("{{"); @@ -820,8 +821,8 @@ double XPath::defaultPriority(typename impl::types< return 0; } + case impl::NodeMatchPattern_id: case impl::AnyName_id: - case impl::Node_id: case impl::Text_id: case impl::Comment_id: case impl::ProcessingInstruction_id: diff --git a/include/XPath/impl/xpath_step.hpp b/include/XPath/impl/xpath_step.hpp index f6a6b5fe..c3368bca 100644 --- a/include/XPath/impl/xpath_step.hpp +++ b/include/XPath/impl/xpath_step.hpp @@ -399,16 +399,17 @@ private: case impl::SlashSlash_id: case impl::SelfSelect_id: case impl::ParentSelect_id: + case impl::Node_id: { ++node; return new AnyNodeTest(); } // case Node_id - case impl::Node_id: + case impl::NodeMatchPattern_id: { ++node; return new NodeNodeTest(); - } // case Node_id + } // case NodeMatchPattern_id case impl::Slash_id: return new RootNodeTest();