From 975cca8c20cb030128c104b4060c44a4dca10a89 Mon Sep 17 00:00:00 2001 From: Alex Ott Date: Tue, 6 Oct 2009 12:38:30 +0200 Subject: [PATCH] Use proper boost includes for different boost versions starting from boost 1.38, there is boost.spirit v2 in the repository, older version could be used as 'classic' --- .bzrignore | 12 +++++ include/XPath/impl/xpath_ast.hpp | 9 ++++ include/XPath/impl/xpath_grammar.hpp | 71 +++++++++++++----------- include/XPath/impl/xpath_parser.hpp | 81 +++++++++++++++------------- 4 files changed, 106 insertions(+), 67 deletions(-) diff --git a/.bzrignore b/.bzrignore index 3f7c0898..651b7fd2 100644 --- a/.bzrignore +++ b/.bzrignore @@ -36,3 +36,15 @@ vs9/mangle.sln *.lnk spec gmon.out +examples/DOM/dom2pyx +examples/DOM/domwriter +examples/SAX/pyx +examples/SAX/simple_handler +examples/SAX/writer +examples/SAX/xmlbase +examples/Taggle/taggle +examples/Utils/transcode +examples/XPath/xgrep +examples/XSLT/mangle +m4/lt~obsolete.m4@ + diff --git a/include/XPath/impl/xpath_ast.hpp b/include/XPath/impl/xpath_ast.hpp index 0b8d565d..3211537b 100644 --- a/include/XPath/impl/xpath_ast.hpp +++ b/include/XPath/impl/xpath_ast.hpp @@ -1,8 +1,17 @@ #ifndef ARABICA_XPATHIC_XPATH_AST_HPP #define ARABICA_XPATHIC_XPATH_AST_HPP + +#include + +#if BOOST_VERSION >= 103800 +#define BOOST_SPIRIT_USE_OLD_NAMESPACE 1 +#include +#include +#else #include #include +#endif #include "xpath_ast_ids.hpp" diff --git a/include/XPath/impl/xpath_grammar.hpp b/include/XPath/impl/xpath_grammar.hpp index cb492762..1b42f108 100644 --- a/include/XPath/impl/xpath_grammar.hpp +++ b/include/XPath/impl/xpath_grammar.hpp @@ -5,9 +5,18 @@ #define BOOST_SPIRIT_THREADSAFE #endif +#include + +#if BOOST_VERSION >= 103800 +#define BOOST_SPIRIT_USE_OLD_NAMESPACE 1 +#include +#include +#include +#else #include #include #include +#endif #include "xpath_ast_ids.hpp" @@ -25,7 +34,7 @@ struct xpath_grammar_definition { using namespace boost::spirit; - // [1] + // [1] LocationPath = AbsoluteLocationPath | RelativeLocationPath; // [2] AbsoluteLocationPath = AbbreviatedAbsoluteLocationPath @@ -71,12 +80,12 @@ struct xpath_grammar_definition // [14], [15] Expr = OrExpr; - PrimaryExpr = discard_node_d[S] >> + PrimaryExpr = discard_node_d[S] >> (VariableReference | Number | FunctionCall | discard_node_d[LeftBracket] >> S >> Expr >> S >> discard_node_d[RightBracket] - | Literal) >> + | Literal) >> discard_node_d[S]; // [16], [17] @@ -87,15 +96,15 @@ struct xpath_grammar_definition // UnionExpr ::= PathExpr | UnionExpr '|' PathExpr UnionExpr = PathExpr >> *(UnionOperator >> PathExpr); /* - LocationPath - | FilterExpr - | FilterExpr '/' RelativeLocationPath + LocationPath + | FilterExpr + | FilterExpr '/' RelativeLocationPath | FilterExpr '//' RelativeLocationPath */ - PathExpr = discard_node_d[S] >> - (FilterExpr >> !((SlashSlash | Slash) >> RelativeLocationPath) - | LocationPath) >> + PathExpr = discard_node_d[S] >> + (FilterExpr >> !((SlashSlash | Slash) >> RelativeLocationPath) + | LocationPath) >> discard_node_d[S]; - // FilterExpr ::= PrimaryExpr | FilterExpr Predicate + // FilterExpr ::= PrimaryExpr | FilterExpr Predicate FilterExpr = PrimaryExpr >> *Predicate; // [21], [22], [23], [24] @@ -111,9 +120,9 @@ struct xpath_grammar_definition // [28] ExprToken not actually used - //[29], [30], [31], - Literal = discard_node_d[ch_p('\"')] >> token_node_d[*~ch_p('\"')] >> discard_node_d[ch_p('\"')] - | discard_node_d[ch_p('\'')] >> token_node_d[*~ch_p('\'')] >> discard_node_d[ch_p('\'')]; + //[29], [30], [31], + Literal = discard_node_d[ch_p('\"')] >> token_node_d[*~ch_p('\"')] >> discard_node_d[ch_p('\"')] + | discard_node_d[ch_p('\'')] >> token_node_d[*~ch_p('\'')] >> discard_node_d[ch_p('\'')]; Number = token_node_d[ch_p('.') >> Digits | Digits >> !('.' >> *Digits)]; Digits = token_node_d[+digit_p]; // [32] Operator not actually used @@ -123,7 +132,7 @@ struct xpath_grammar_definition FunctionName = QName - NodeType; VariableReference = ch_p('$') >> QName; NameTest = AnyName - | NCName >> discard_node_d[ch_p(':')] >> AnyName + | NCName >> discard_node_d[ch_p(':')] >> AnyName | QName; NodeType = Comment | Text @@ -161,7 +170,7 @@ struct xpath_grammar_definition ProcessingInstruction = str_p("processing-instruction"); Node = str_p("node"); AnyName = ch_p('*'); - + SelfSelect = ch_p('.'); ParentSelect = str_p(".."); @@ -197,7 +206,7 @@ struct xpath_grammar_definition boost::spirit::rule > AxisName; boost::spirit::rule > NodeType; - boost::spirit::rule > LocationPath; + boost::spirit::rule > LocationPath; boost::spirit::rule > AbsoluteLocationPath; boost::spirit::rule > RelativeLocationPath; @@ -305,7 +314,7 @@ struct xpath_grammar : public boost::spirit::grammar start() const { return xpath_grammar_definition::LocationPath; - } // start + } // start }; // definition }; // xpath_grammar @@ -322,7 +331,7 @@ struct xpath_grammar_expr : public boost::spirit::grammar start() const { return xpath_grammar_definition::Expr; - } // start + } // start }; // definition }; // xpath_grammar_expr @@ -336,27 +345,27 @@ struct xpath_grammar_match : public boost::spirit::grammar using namespace boost::spirit; typedef xpath_grammar_definition base; - // [1] Pattern ::= LocationPathPattern | Pattern '|' LocationPathPattern + // [1] Pattern ::= LocationPathPattern | Pattern '|' LocationPathPattern Pattern = discard_node_d[base::S] >> LocationPathPattern >> discard_node_d[base::S] >> *(base::UnionOperator >> discard_node_d[base::S] >> LocationPathPattern >> discard_node_d[base::S]); - // [2] LocationPathPattern ::= '/' RelativePathPattern? - // | IdKeyPattern (('/' | '//') RelativePathPattern)? - // | '//'? RelativePathPattern + // [2] LocationPathPattern ::= '/' RelativePathPattern? + // | IdKeyPattern (('/' | '//') RelativePathPattern)? + // | '//'? RelativePathPattern LocationPathPattern = IdKeyPattern >> !((base::SlashSlash | base::Slash) >> RelativePathPattern) | !base::SlashSlash >> RelativePathPattern | base::Slash >> !RelativePathPattern; - - // [3] IdKeyPattern ::= 'id' '(' Literal ')' | 'key' '(' Literal ',' Literal ')' + + // [3] IdKeyPattern ::= 'id' '(' Literal ')' | 'key' '(' Literal ',' Literal ')' IdKeyPattern = (str_p("id") >> base::LeftBracket >> discard_node_d[base::S] >> base::Literal >> discard_node_d[base::S] >> base::RightBracket) | (str_p("key") >> base::LeftBracket >> discard_node_d[base::S] >> base::Literal >> discard_node_d[base::S] >> discard_node_d[ch_p(',')] >>discard_node_d[base::S] >> base::Literal >> discard_node_d[base::S] >> base::RightBracket); - // [4] RelativePathPattern ::= StepPattern - // | RelativePathPattern '/' StepPattern + // [4] RelativePathPattern ::= StepPattern + // | RelativePathPattern '/' StepPattern // | RelativePathPattern '//' StepPattern RelativePathPattern = StepPattern >> *((base::SlashSlash | base::Slash) >> StepPattern); - // [5] StepPattern ::= ChildOrAttributeAxisSpecifier NodeTest Predicate* + // [5] StepPattern ::= ChildOrAttributeAxisSpecifier NodeTest Predicate* StepPattern = ChildOrAttributeAxisSpecifier >> (NodeMatchPattern|base::NodeTest) >> *base::Predicate; // [6] ChildOrAttributeAxisSpecifier ::= AbbreviatedAxisSpecifier | ('child' | 'attribute') '::' @@ -369,8 +378,8 @@ struct xpath_grammar_match : public boost::spirit::grammar start() const { return Pattern; - } // start - + } // start + boost::spirit::rule > Pattern; boost::spirit::rule > LocationPathPattern; boost::spirit::rule > IdKeyPattern; @@ -391,14 +400,14 @@ struct xpath_grammar_attribute_value : public boost::spirit::grammar base; - AttributeValueTemplate = (DoubleLeftCurly | DoubleRightCurly | EmbeddedExpr | AttrLiteral) >> + AttributeValueTemplate = (DoubleLeftCurly | DoubleRightCurly | EmbeddedExpr | AttrLiteral) >> *(DoubleLeftCurly | DoubleRightCurly | EmbeddedExpr | AttrLiteral); DoubleLeftCurly = str_p("{{"); DoubleRightCurly = str_p("}}"); LeftCurly = ch_p('{'); RightCurly = ch_p('}'); EmbeddedExpr = LeftCurly >> base::Expr >> RightCurly; - chset<> brackets("{}"); + chset<> brackets("{}"); AttrLiteral = token_node_d[~brackets >> *~brackets]; } // definition diff --git a/include/XPath/impl/xpath_parser.hpp b/include/XPath/impl/xpath_parser.hpp index 58c2f5a5..c3dfb054 100644 --- a/include/XPath/impl/xpath_parser.hpp +++ b/include/XPath/impl/xpath_parser.hpp @@ -1,8 +1,17 @@ #ifndef ARABICA_XPATHIC_XPATH_PARSER_HPP #define ARABICA_XPATHIC_XPATH_PARSER_HPP +#include + +#if BOOST_VERSION >= 103800 +#define BOOST_SPIRIT_USE_OLD_NAMESPACE 1 +#include +#include +#else #include #include +#endif + #include #include #include @@ -40,7 +49,7 @@ public: UnsupportedException(const std::string& thing) : std::runtime_error("Sorry, haven't implemented '" + thing + "' yet") { } }; // class UnsupportedException -namespace impl +namespace impl { template class CompilationContext; @@ -51,7 +60,7 @@ namespace impl } // namespace impl template > -class XPath +class XPath { public: XPath() @@ -116,12 +125,12 @@ public: void resetFunctionResolver() { functionResolver_.set(FunctionResolverPtr(new NullFunctionResolver())); } private: - typedef XPathExpression_impl* (*compileFn)(typename impl::types::node_iter_t const& i, - typename impl::types::node_iter_t const& ie, + typedef XPathExpression_impl* (*compileFn)(typename impl::types::node_iter_t const& i, + typename impl::types::node_iter_t const& ie, impl::CompilationContext& context); typedef typename impl::types::tree_info_t(XPath::*parserFn)(const string_type& str) const; - XPathExpression do_compile(const string_type& xpath, + XPathExpression do_compile(const string_type& xpath, parserFn parser, const std::map& factory) const { @@ -133,16 +142,16 @@ private: impl::CompilationContext context(*this, getNamespaceContext(), getFunctionResolver()); //XPath::dump(ast.trees.begin(), 0); - return XPathExpression(compile_with_factory(ast.trees.begin(), + return XPathExpression(compile_with_factory(ast.trees.begin(), ast.trees.end(), - context, + context, factory)); } // try - catch(const std::exception&) + catch(const std::exception&) { throw; } // catch - catch(...) + catch(...) { throw SyntaxException(string_adaptor().asStdString(xpath)); } // catch @@ -183,29 +192,29 @@ private: ///////////////////////////////////////////////////////////////////////////////// public: - static XPathExpression_impl* compile_expression(typename impl::types::node_iter_t const& i, - typename impl::types::node_iter_t const& ie, + static XPathExpression_impl* compile_expression(typename impl::types::node_iter_t const& i, + typename impl::types::node_iter_t const& ie, impl::CompilationContext& context) { return compile_with_factory(i, ie, context, XPath::expression_factory()); } // compile_expression - static XPathExpression_impl* compile_match(typename impl::types::node_iter_t const& i, - typename impl::types::node_iter_t const& ie, + static XPathExpression_impl* compile_match(typename impl::types::node_iter_t const& i, + typename impl::types::node_iter_t const& ie, impl::CompilationContext& context) { return compile_with_factory(i, ie, context, XPath::match_factory()); } // compile_match - static XPathExpression_impl* compile_attribute_value(typename impl::types::node_iter_t const& i, - typename impl::types::node_iter_t const& ie, + static XPathExpression_impl* compile_attribute_value(typename impl::types::node_iter_t const& i, + typename impl::types::node_iter_t const& ie, impl::CompilationContext& context) { return compile_with_factory(i, ie, context, XPath::attribute_value_factory()); } // compile_attribute_value - static XPathExpression_impl* compile_with_factory(typename impl::types::node_iter_t const& i, - typename impl::types::node_iter_t const& ie, + static XPathExpression_impl* compile_with_factory(typename impl::types::node_iter_t const& i, + typename impl::types::node_iter_t const& ie, impl::CompilationContext& context, const std::map& factory) { @@ -216,7 +225,7 @@ public: //XPath::dump(i, 0); throw UnsupportedException(string_adaptor().asStdString(XPath::names()[id])); } - + try { return (f->second)(i, ie, context); } @@ -367,7 +376,7 @@ private: return factory; } // init_attributeValueCreateFunctions - + static const std::map init_debugNames() { std::map names; @@ -481,7 +490,7 @@ private: return names; } // init_debugNames - + static void dump(typename impl::types::node_iter_t const& i, int depth) { long id = static_cast(i->value.id().to_long()); @@ -569,10 +578,10 @@ XPathExpression_impl* XPathvalue.begin(), n->value.end()));; ++n; name = string_adaptor::construct(n->value.begin(), n->value.end()); - } + } else name = string_adaptor::construct(c->value.begin(), c->value.end()); - + ++c; impl::skipWhitespace(c); assert(impl::getNodeId(c) == impl::LeftBracket_id); @@ -652,7 +661,7 @@ XPathExpression_impl* XPath(op)); } // switch - } + } while(++c != i->children.end()); return p1; @@ -687,7 +696,7 @@ XPathExpression_impl* XPathvalue.begin(), n->value.end()); - return new Variable(namespace_uri, name); + return new Variable(namespace_uri, name); } // createVariable template @@ -710,8 +719,8 @@ XPathExpression_impl* XPath -impl::StepList XPath::createStepList(typename impl::types::node_iter_t const& from, - typename impl::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; @@ -783,13 +792,13 @@ XPathExpression_impl* XPath::node_iter_t n = i->children.begin(), e = i->children.end(); - impl::MatchExpressionWrapper* matches = + impl::MatchExpressionWrapper* matches = new impl::MatchExpressionWrapper(compile_match(n++, e, context)); while(n != e) { ++n; // skip | matches->add_matches(compile_match(n++, e, context)); - } // while + } // while return matches; } // createAlternatePattern @@ -874,7 +883,7 @@ double XPath::defaultPriority(typename impl::types< } // defaultPriority template -Axis getPatternAxis(typename impl::types::node_iter_t const& from, +Axis getPatternAxis(typename impl::types::node_iter_t const& from, typename impl::types::node_iter_t const& to) { typename impl::types::node_iter_t next = from + 1; @@ -885,7 +894,7 @@ Axis getPatternAxis(typename impl::types::node_iter_t const& fro return SELF; int id = impl::getNodeId(next); - + if(id == impl::SlashSlash_id) return ANCESTOR_OR_SELF; if((id == impl::AbbreviatedAxisSpecifier_id) || (id == impl::Attribute_id)) @@ -896,8 +905,8 @@ Axis getPatternAxis(typename impl::types::node_iter_t const& fro template void createStepsFromPattern(impl::StepList& steps, - typename impl::types::node_iter_t const& from, - typename impl::types::node_iter_t const& to, + typename impl::types::node_iter_t const& from, + typename impl::types::node_iter_t const& to, impl::CompilationContext& context, Axis override = static_cast(-1)) { @@ -940,7 +949,7 @@ void createStepsFromPattern(impl::StepList& steps, break; default: { - if(is_attr) + if(is_attr) steps.push_front(new impl::TestStepExpression(SELF, new impl::AttributeNodeTest())); else steps.push_front(new impl::TestStepExpression(SELF, new impl::NotAttributeNodeTest())); @@ -955,8 +964,8 @@ void createStepsFromPattern(impl::StepList& steps, } // createStepsFromPattern template -impl::StepList XPath::createPatternList(typename impl::types::node_iter_t const& from, - typename impl::types::node_iter_t const& to, +impl::StepList XPath::createPatternList(typename impl::types::node_iter_t const& from, + typename impl::types::node_iter_t const& to, impl::CompilationContext& context) { impl::StepList steps; @@ -992,7 +1001,7 @@ XPathExpression_impl* XPath::createFunction(string_adaptor::construct_from_utf8(""), string_adaptor::construct_from_utf8("concat"), - args, + args, context); } // createAttributeValue