diff --git a/XPath/impl/xpath_ast.hpp b/XPath/impl/xpath_ast.hpp index d0735596..68ac1c97 100644 --- a/XPath/impl/xpath_ast.hpp +++ b/XPath/impl/xpath_ast.hpp @@ -10,6 +10,8 @@ namespace Arabica { namespace XPath { +namespace impl +{ template class types @@ -38,6 +40,7 @@ typename types::node_iter_t& skipWhitespace(typename types struct xpath_grammar_definition @@ -185,107 +187,107 @@ struct xpath_grammar_definition UnaryMinusOperator = ch_p('-'); } // xpath_grammar_definition - boost::spirit::rule > QName; - boost::spirit::rule > Prefix; - boost::spirit::rule > LocalPart; - boost::spirit::rule > NCName; - boost::spirit::rule > NCNameChar; + boost::spirit::rule > QName; + boost::spirit::rule > Prefix; + boost::spirit::rule > LocalPart; + boost::spirit::rule > NCName; + boost::spirit::rule > NCNameChar; - boost::spirit::rule > AxisName; - boost::spirit::rule > NodeType; + boost::spirit::rule > AxisName; + boost::spirit::rule > NodeType; - boost::spirit::rule > LocationPath; - boost::spirit::rule > AbsoluteLocationPath; - boost::spirit::rule > RelativeLocationPath; + boost::spirit::rule > LocationPath; + boost::spirit::rule > AbsoluteLocationPath; + boost::spirit::rule > RelativeLocationPath; - boost::spirit::rule > Step; - boost::spirit::rule > AxisSpecifier; + boost::spirit::rule > Step; + boost::spirit::rule > AxisSpecifier; - boost::spirit::rule > NodeTest; + boost::spirit::rule > NodeTest; - boost::spirit::rule > Predicate; - boost::spirit::rule > PredicateExpr; + boost::spirit::rule > Predicate; + boost::spirit::rule > PredicateExpr; - boost::spirit::rule > AbbreviatedAbsoluteLocationPath; - boost::spirit::rule > AbbreviatedStep; - boost::spirit::rule > AbbreviatedAxisSpecifier; + boost::spirit::rule > AbbreviatedAbsoluteLocationPath; + boost::spirit::rule > AbbreviatedStep; + boost::spirit::rule > AbbreviatedAxisSpecifier; - boost::spirit::rule > Expr; - boost::spirit::rule > PrimaryExpr; + boost::spirit::rule > Expr; + boost::spirit::rule > PrimaryExpr; - boost::spirit::rule > FunctionCall; - boost::spirit::rule > Argument; + boost::spirit::rule > FunctionCall; + boost::spirit::rule > Argument; - boost::spirit::rule > UnionExpr; - boost::spirit::rule > PathExpr; - boost::spirit::rule > FilterExpr; + boost::spirit::rule > UnionExpr; + boost::spirit::rule > PathExpr; + boost::spirit::rule > FilterExpr; - boost::spirit::rule > OrExpr; - boost::spirit::rule > AndExpr; - boost::spirit::rule > EqualityExpr; - boost::spirit::rule > RelationalExpr; + boost::spirit::rule > OrExpr; + boost::spirit::rule > AndExpr; + boost::spirit::rule > EqualityExpr; + boost::spirit::rule > RelationalExpr; - boost::spirit::rule > AdditiveExpr; - boost::spirit::rule > MultiplicativeExpr; - boost::spirit::rule > UnaryExpr; + boost::spirit::rule > AdditiveExpr; + boost::spirit::rule > MultiplicativeExpr; + boost::spirit::rule > UnaryExpr; - boost::spirit::rule > Literal; - boost::spirit::rule > Number; - boost::spirit::rule > Digits; - boost::spirit::rule > MultiplyOperator; - boost::spirit::rule > FunctionName; - boost::spirit::rule > VariableReference; - boost::spirit::rule > NameTest; - boost::spirit::rule > S; // ExprWhitespace + boost::spirit::rule > Literal; + boost::spirit::rule > Number; + boost::spirit::rule > Digits; + boost::spirit::rule > MultiplyOperator; + boost::spirit::rule > FunctionName; + boost::spirit::rule > VariableReference; + boost::spirit::rule > NameTest; + boost::spirit::rule > S; // ExprWhitespace // bonus bits - boost::spirit::rule > Slash; - boost::spirit::rule > SlashSlash; + boost::spirit::rule > Slash; + boost::spirit::rule > SlashSlash; - boost::spirit::rule > AncestorOrSelf; - boost::spirit::rule > Ancestor; - boost::spirit::rule > Attribute; - boost::spirit::rule > Child; - boost::spirit::rule > DescendantOrSelf; - boost::spirit::rule > Descendant; - boost::spirit::rule > FollowingSibling; - boost::spirit::rule > Following; - boost::spirit::rule > Namespace; - boost::spirit::rule > Parent; - boost::spirit::rule > PrecedingSibling; - boost::spirit::rule > Preceding; - boost::spirit::rule > Self; + boost::spirit::rule > AncestorOrSelf; + boost::spirit::rule > Ancestor; + boost::spirit::rule > Attribute; + boost::spirit::rule > Child; + boost::spirit::rule > DescendantOrSelf; + boost::spirit::rule > Descendant; + boost::spirit::rule > FollowingSibling; + boost::spirit::rule > Following; + boost::spirit::rule > Namespace; + boost::spirit::rule > Parent; + boost::spirit::rule > PrecedingSibling; + boost::spirit::rule > Preceding; + boost::spirit::rule > Self; - boost::spirit::rule > Comment; - boost::spirit::rule > Text; - boost::spirit::rule > ProcessingInstruction; - boost::spirit::rule > Node; - boost::spirit::rule > AnyName; + boost::spirit::rule > Comment; + boost::spirit::rule > Text; + boost::spirit::rule > ProcessingInstruction; + boost::spirit::rule > Node; + boost::spirit::rule > AnyName; - boost::spirit::rule > SelfSelect; - boost::spirit::rule > ParentSelect; + boost::spirit::rule > SelfSelect; + boost::spirit::rule > ParentSelect; - boost::spirit::rule > LeftSquare; - boost::spirit::rule > RightSquare; + boost::spirit::rule > LeftSquare; + boost::spirit::rule > RightSquare; - boost::spirit::rule > LeftBracket; - boost::spirit::rule > RightBracket; + boost::spirit::rule > LeftBracket; + boost::spirit::rule > RightBracket; - boost::spirit::rule > PlusOperator; - boost::spirit::rule > MinusOperator; - boost::spirit::rule > ModOperator; - boost::spirit::rule > DivOperator; - boost::spirit::rule > EqualsOperator; - boost::spirit::rule > NotEqualsOperator; - boost::spirit::rule > LessThanOperator; - boost::spirit::rule > LessThanEqualsOperator; - boost::spirit::rule > GreaterThanOperator; - boost::spirit::rule > GreaterThanEqualsOperator; + boost::spirit::rule > PlusOperator; + boost::spirit::rule > MinusOperator; + boost::spirit::rule > ModOperator; + boost::spirit::rule > DivOperator; + boost::spirit::rule > EqualsOperator; + boost::spirit::rule > NotEqualsOperator; + boost::spirit::rule > LessThanOperator; + boost::spirit::rule > LessThanEqualsOperator; + boost::spirit::rule > GreaterThanOperator; + boost::spirit::rule > GreaterThanEqualsOperator; - boost::spirit::rule > OrOperator; - boost::spirit::rule > AndOperator; - boost::spirit::rule > UnionOperator; - boost::spirit::rule > UnaryMinusOperator; + boost::spirit::rule > OrOperator; + boost::spirit::rule > AndOperator; + boost::spirit::rule > UnionOperator; + boost::spirit::rule > UnaryMinusOperator; }; // xpath_grammar_definition @@ -298,7 +300,7 @@ struct xpath_grammar : public boost::spirit::grammar { } // definition - boost::spirit::rule > const& + boost::spirit::rule > const& start() const { return xpath_grammar_definition::LocationPath; @@ -315,7 +317,7 @@ struct xpath_grammar_expr : public boost::spirit::grammar { } // definition - boost::spirit::rule > const& + boost::spirit::rule > const& start() const { return xpath_grammar_definition::Expr; @@ -323,6 +325,7 @@ struct xpath_grammar_expr : public boost::spirit::grammar }; // definition }; // xpath_grammar +} // namespace impl } // namespace XPath } // namespace Arabica diff --git a/XPath/impl/xpath_parser.hpp b/XPath/impl/xpath_parser.hpp index a0f72c9a..f1ac0d00 100644 --- a/XPath/impl/xpath_parser.hpp +++ b/XPath/impl/xpath_parser.hpp @@ -104,9 +104,9 @@ public: private: XPathExpressionPtr do_compile(const string_type& xpath, - typename types::tree_info_t(XPath::*fn)(const string_type& str) const) const + typename impl::types::tree_info_t(XPath::*fn)(const string_type& str) const) const { - typename types::tree_info_t ast; + typename impl::types::tree_info_t ast; try { ast = (this->*fn)(xpath); if(!ast.full) @@ -125,20 +125,20 @@ private: } // catch } // do_compile - typename types::tree_info_t parse_xpath(const string_type& str) const + typename impl::types::tree_info_t parse_xpath(const string_type& str) const { - typename types::str_iter_t first = str.begin(), last = str.end(); + typename impl::types::str_iter_t first = str.begin(), last = str.end(); return ast_parse(first, last, xpathg_); } // parse_xpath - typename types::tree_info_t parse_xpath_expr(const string_type& str) const + typename impl::types::tree_info_t parse_xpath_expr(const string_type& str) const { - typename types::str_iter_t first = str.begin(), last = str.end(); + typename impl::types::str_iter_t first = str.begin(), last = str.end(); return ast_parse(first, last, xpathge_); } // parse_xpath - xpath_grammar xpathg_; - xpath_grammar_expr xpathge_; + impl::xpath_grammar xpathg_; + impl::xpath_grammar_expr xpathge_; impl::ResolverHolder > namespaceContext_; impl::ResolverHolder > variableResolver_; @@ -146,10 +146,10 @@ private: ///////////////////////////////////////////////////////////////////////////////// public: - static XPathExpression* compile_expression(typename types::node_iter_t const& i, + static XPathExpression* compile_expression(typename impl::types::node_iter_t const& i, impl::CompilationContext& context) { - long id = getNodeId(i); + long id = impl::getNodeId(i); if(XPath::factory().find(id) == XPath::factory().end()) { @@ -161,22 +161,22 @@ public: } // compile_expression private: - static XPathExpression* createAbsoluteLocationPath(typename types::node_iter_t const& i, impl::CompilationContext& context); - static XPathExpression* createRelativeLocationPath(typename types::node_iter_t const& i, impl::CompilationContext& context); - static XPathExpression* createSingleStepRelativeLocationPath(typename types::node_iter_t const& i, impl::CompilationContext& context); - static XPathExpression* createExpression(typename types::node_iter_t const& i, impl::CompilationContext& context); - static XPathExpression* createFunction(typename types::node_iter_t const& i, impl::CompilationContext& context); - static XPathExpression* createBinaryExpression(typename types::node_iter_t const& i, impl::CompilationContext& context); - static XPathExpression* createLiteral(typename types::node_iter_t const& i, impl::CompilationContext& context); - static XPathExpression* createNumber(typename types::node_iter_t const& i, impl::CompilationContext& context); - static XPathExpression* createVariable(typename types::node_iter_t const& i, impl::CompilationContext& context); - static XPathExpression* createSingleStepAbsoluteLocationPath(typename types::node_iter_t const& i, impl::CompilationContext& context); - static XPathExpression* createUnaryExpression(typename types::node_iter_t const& i, impl::CompilationContext& context); - static XPathExpression* createUnaryNegativeExpr(typename types::node_iter_t const& i, impl::CompilationContext& context); + static XPathExpression* createAbsoluteLocationPath(typename impl::types::node_iter_t const& i, impl::CompilationContext& context); + static XPathExpression* createRelativeLocationPath(typename impl::types::node_iter_t const& i, impl::CompilationContext& context); + static XPathExpression* createSingleStepRelativeLocationPath(typename impl::types::node_iter_t const& i, impl::CompilationContext& context); + static XPathExpression* createExpression(typename impl::types::node_iter_t const& i, impl::CompilationContext& context); + static XPathExpression* createFunction(typename impl::types::node_iter_t const& i, impl::CompilationContext& context); + static XPathExpression* createBinaryExpression(typename impl::types::node_iter_t const& i, impl::CompilationContext& context); + static XPathExpression* createLiteral(typename impl::types::node_iter_t const& i, impl::CompilationContext& context); + static XPathExpression* createNumber(typename impl::types::node_iter_t const& i, impl::CompilationContext& context); + static XPathExpression* createVariable(typename impl::types::node_iter_t const& i, impl::CompilationContext& context); + static XPathExpression* createSingleStepAbsoluteLocationPath(typename impl::types::node_iter_t const& i, impl::CompilationContext& context); + static XPathExpression* createUnaryExpression(typename impl::types::node_iter_t const& i, impl::CompilationContext& context); + static XPathExpression* createUnaryNegativeExpr(typename impl::types::node_iter_t const& i, impl::CompilationContext& context); - static impl::StepList createStepList(typename types::node_iter_t const& from, typename types::node_iter_t const& to, impl::CompilationContext& context); + static impl::StepList createStepList(typename impl::types::node_iter_t const& from, typename impl::types::node_iter_t const& to, impl::CompilationContext& context); - typedef XPathExpression* (*compileFn)(typename types::node_iter_t const& i, impl::CompilationContext& context); + typedef XPathExpression* (*compileFn)(typename impl::types::node_iter_t const& i, impl::CompilationContext& context); static std::map& factory() { static std::map f = init_createFunctions(); @@ -334,7 +334,7 @@ private: } // init_debugNames /* - static void dump(typename types::node_iter_t const& i, int depth) + static void dump(typename impl::types::node_iter_t const& i, int depth) { long id = static_cast(i->value.id().to_long()); @@ -342,7 +342,7 @@ private: std::cerr << ' '; std::cerr << names()[id] << " - " << std::string(i->value.begin(), i->value.end()) << std::endl; - for(typename types::node_iter_t c = i->children.begin(); c != i->children.end(); ++c) + for(typename impl::types::node_iter_t c = i->children.begin(); c != i->children.end(); ++c) dump(c, depth+2); } // dump */ @@ -374,50 +374,50 @@ namespace XPath { template -XPathExpression* XPath::createAbsoluteLocationPath(typename types::node_iter_t const& i, impl::CompilationContext& context) +XPathExpression* XPath::createAbsoluteLocationPath(typename impl::types::node_iter_t const& i, impl::CompilationContext& context) { return new impl::AbsoluteLocationPath(createStepList(i->children.begin(), i->children.end(), context)); } // createAbsoluteLocationPath template -XPathExpression* XPath::createRelativeLocationPath(typename types::node_iter_t const& i, impl::CompilationContext& context) +XPathExpression* XPath::createRelativeLocationPath(typename impl::types::node_iter_t const& i, impl::CompilationContext& context) { return new impl::RelativeLocationPath(createStepList(i->children.begin(), i->children.end(), context)); } // createRelativeLocationPath template -XPathExpression* XPath::createSingleStepRelativeLocationPath(typename types::node_iter_t const& i, impl::CompilationContext& context) +XPathExpression* XPath::createSingleStepRelativeLocationPath(typename impl::types::node_iter_t const& i, impl::CompilationContext& context) { - typename types::node_iter_t n = i; + typename impl::types::node_iter_t n = i; return new impl::RelativeLocationPath(impl::StepFactory::createStep(n, context)); } // createSingleStepRelativeLocationPath template -XPathExpression* XPath::createExpression(typename types::node_iter_t const& i, impl::CompilationContext& context) +XPathExpression* XPath::createExpression(typename impl::types::node_iter_t const& i, impl::CompilationContext& context) { - typename types::node_iter_t c = i->children.begin(); - skipWhitespace(c); + typename impl::types::node_iter_t c = i->children.begin(); + impl::skipWhitespace(c); return XPath::compile_expression(c, context); } // createExpression template -XPathExpression* XPath::createFunction(typename types::node_iter_t const& i, impl::CompilationContext& context) +XPathExpression* XPath::createFunction(typename impl::types::node_iter_t const& i, impl::CompilationContext& context) { - typename types::node_iter_t c = i->children.begin(); + typename impl::types::node_iter_t c = i->children.begin(); string_type name(c->value.begin(), c->value.end()); ++c; - skipWhitespace(c); - assert(getNodeId(c) == impl::LeftBracket_id); + impl::skipWhitespace(c); + assert(impl::getNodeId(c) == impl::LeftBracket_id); ++c; - skipWhitespace(c); + impl::skipWhitespace(c); std::vector > args; - while(getNodeId(c) != impl::RightBracket_id) + while(impl::getNodeId(c) != impl::RightBracket_id) { XPathExpressionPtr arg(XPath::compile_expression(c++, context)); args.push_back(arg); - skipWhitespace(c); + impl::skipWhitespace(c); } // while ... // maybe trailing whitespace ... @@ -425,15 +425,15 @@ XPathExpression* XPath } // createFunction template -XPathExpression* XPath::createBinaryExpression(typename types::node_iter_t const& i, impl::CompilationContext& context) +XPathExpression* XPath::createBinaryExpression(typename impl::types::node_iter_t const& i, impl::CompilationContext& context) { - typename types::node_iter_t c = i->children.begin(); + typename impl::types::node_iter_t c = i->children.begin(); XPathExpression* p1 = XPath::compile_expression(c, context); ++c; do { - long op = getNodeId(c); + long op = impl::getNodeId(c); ++c; XPathExpression* p2 = XPath::compile_expression(c, context); @@ -491,55 +491,55 @@ XPathExpression* XPath } // createBinaryExpression template -XPathExpression* XPath::createLiteral(typename types::node_iter_t const& i, impl::CompilationContext& context) +XPathExpression* XPath::createLiteral(typename impl::types::node_iter_t const& i, impl::CompilationContext& context) { string_type str(i->value.begin(), i->value.end()); return new StringValue(str); } // createLiteral template -XPathExpression* XPath::createNumber(typename types::node_iter_t const& i, impl::CompilationContext& context) +XPathExpression* XPath::createNumber(typename impl::types::node_iter_t const& i, impl::CompilationContext& context) { return new NumericValue(boost::lexical_cast(string_type(i->value.begin(), i->value.end()))); } // createNumber template -XPathExpression* XPath::createVariable(typename types::node_iter_t const& i, impl::CompilationContext& context) +XPathExpression* XPath::createVariable(typename impl::types::node_iter_t const& i, impl::CompilationContext& context) { return new Variable(string_type(i->value.begin()+1, i->value.end())); // skip $ } // createVariable template -XPathExpression* XPath::createSingleStepAbsoluteLocationPath(typename types::node_iter_t const& i, impl::CompilationContext& context) +XPathExpression* XPath::createSingleStepAbsoluteLocationPath(typename impl::types::node_iter_t const& i, impl::CompilationContext& context) { - typename types::node_iter_t n = i; + typename impl::types::node_iter_t n = i; return new impl::AbsoluteLocationPath(impl::StepFactory::createStep(n, context)); } // createSingleStepAbsoluteLocationPath template -XPathExpression* XPath::createUnaryExpression(typename types::node_iter_t const& i, impl::CompilationContext& context) +XPathExpression* XPath::createUnaryExpression(typename impl::types::node_iter_t const& i, impl::CompilationContext& context) { return XPath::compile_expression(i->children.begin(), context); } // createUnaryExpression template -XPathExpression* XPath::createUnaryNegativeExpr(typename types::node_iter_t const& i, impl::CompilationContext& context) +XPathExpression* XPath::createUnaryNegativeExpr(typename impl::types::node_iter_t const& i, impl::CompilationContext& context) { return new impl::UnaryNegative(XPath::compile_expression(i+1, context)); } // createUnaryNegativeExpr template -impl::StepList XPath::createStepList(typename types::node_iter_t const& from, - typename types::node_iter_t const& to, +impl::StepList XPath::createStepList(typename impl::types::node_iter_t const& from, + typename impl::types::node_iter_t const& to, impl::CompilationContext& context) { impl::StepList steps; - typename types::node_iter_t c = from; - typename types::node_iter_t end = to; + typename impl::types::node_iter_t c = from; + typename impl::types::node_iter_t end = to; while(c != end) - switch(getNodeId(c)) + switch(impl::getNodeId(c)) { case impl::S_id: case impl::Slash_id: @@ -552,14 +552,14 @@ impl::StepList XPath:: break; case impl::Step_id: { - typename types::node_iter_t step = c->children.begin(); + typename impl::types::node_iter_t step = c->children.begin(); steps.push_back(impl::StepFactory::createStep(step, c->children.end(), context)); ++c; } break; default: steps.push_back(impl::StepFactory::createStep(c, end, context)); - } // switch(getNodeId(c)) + } // switch(impl::getNodeId(c)) return steps; } // createStepList