From eb6ecdcc85ece4eb84b90f3c9bb920dc1ad2b6d1 Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Tue, 27 Jan 2015 16:01:53 +0100 Subject: Parsers do no longer return the node they have parsed (as this may be ill-defined -- if a parser only parses a partial document via include, there may be many to no nodes that are returned). Parsers should just use the ParserScope.push funciton. All nodes pushed onto the top-level of the ParserScope are added treated as the nodes the parser has parsed. Adapted all code and all tests accordingly. --- src/core/parser/Parser.cpp | 8 ++++---- src/core/parser/Parser.hpp | 27 +++++++++++---------------- src/core/parser/ParserContext.cpp | 4 ++-- src/core/parser/ParserContext.hpp | 5 +++-- 4 files changed, 20 insertions(+), 24 deletions(-) (limited to 'src/core/parser') diff --git a/src/core/parser/Parser.cpp b/src/core/parser/Parser.cpp index 2978669..4e5016d 100644 --- a/src/core/parser/Parser.cpp +++ b/src/core/parser/Parser.cpp @@ -24,15 +24,15 @@ namespace ousia { /* Class Parser */ -Rooted Parser::parse(CharReader &reader, ParserContext &ctx) +void Parser::parse(CharReader &reader, ParserContext &ctx) { - return doParse(reader, ctx); + doParse(reader, ctx); } -Rooted Parser::parse(const std::string &str, ParserContext &ctx) +void Parser::parse(const std::string &str, ParserContext &ctx) { CharReader reader{str}; - return doParse(reader, ctx); + doParse(reader, ctx); } } diff --git a/src/core/parser/Parser.hpp b/src/core/parser/Parser.hpp index e4419f5..54c5bfc 100644 --- a/src/core/parser/Parser.hpp +++ b/src/core/parser/Parser.hpp @@ -32,9 +32,6 @@ #include #include -#include -#include - namespace ousia { // Forward declarations @@ -61,7 +58,7 @@ protected: * calling code will try to resolve these. If no valid node can be produced, * a corresponding LoggableException must be thrown by the parser. */ - virtual Rooted doParse(CharReader &reader, ParserContext &ctx) = 0; + virtual void doParse(CharReader &reader, ParserContext &ctx) = 0; public: /** @@ -82,32 +79,30 @@ public: /** * Parses the given input stream and returns a corresponding node for * inclusion in the document graph. This method should be overridden by - * derived classes. + * derived classes. The created nodes should be placed onto the ParserScope + * using the "push" methods and removed using the "pop" methods. Nodes + * pushed to the top level of the ParserScope are considered as the subgraph + * the parser has created. * * @param reader is a reference to the CharReader that should be used. * @param ctx is a reference to the context that should be used while * parsing the document. - * @return a reference to the node representing the subgraph that has been - * created. The resulting node may point at not yet resolved entities, the - * calling code will try to resolve these. If no valid node can be produced, - * a corresponding ParserException must be thrown by the parser. */ - Rooted parse(CharReader &reader, ParserContext &ctx); + void parse(CharReader &reader, ParserContext &ctx); /** * Parses the given string and returns a corresponding node for * inclusion in the document graph. This method should be overridden by - * derived classes. + * derived classes. The created nodes should be placed onto the ParserScope + * using the "push" methods and removed using the "pop" methods. Nodes + * pushed to the top level of the ParserScope are considered as the subgraph + * the parser has created. * * @param str is the string that should be parsed. * @param ctx is a reference to the context that should be used while * parsing the document. - * @return a reference to the node representing the subgraph that has been - * created. The resulting node may point at not yet resolved entities, the - * calling code will try to resolve these. If no valid node can be produced, - * a corresponding ParserException must be thrown by the parser. */ - Rooted parse(const std::string &str, ParserContext &ctx); + void parse(const std::string &str, ParserContext &ctx); }; } diff --git a/src/core/parser/ParserContext.cpp b/src/core/parser/ParserContext.cpp index 3a651f0..cc09b5e 100644 --- a/src/core/parser/ParserContext.cpp +++ b/src/core/parser/ParserContext.cpp @@ -39,7 +39,7 @@ ParserContext::ParserContext(Registry ®istry, { } -Rooted ParserContext::link(const std::string &path, +NodeVector ParserContext::link(const std::string &path, const std::string mimetype, const std::string rel, const RttiSet &supportedTypes) @@ -47,7 +47,7 @@ Rooted ParserContext::link(const std::string &path, return resourceManager.link(*this, path, mimetype, rel, supportedTypes); } -Rooted ParserContext::include(const std::string &path, +NodeVector ParserContext::include(const std::string &path, const std::string mimetype, const std::string rel, const RttiSet &supportedTypes) diff --git a/src/core/parser/ParserContext.hpp b/src/core/parser/ParserContext.hpp index 9b6eca0..f6ae89c 100644 --- a/src/core/parser/ParserContext.hpp +++ b/src/core/parser/ParserContext.hpp @@ -30,6 +30,7 @@ #include #include +#include #include namespace ousia { @@ -116,7 +117,7 @@ public: * checked, not the actual result. * @return the parsed node or nullptr if something goes wrong. */ - Rooted link(const std::string &path, const std::string mimetype, + NodeVector link(const std::string &path, const std::string mimetype, const std::string rel, const RttiSet &supportedTypes); /** @@ -137,7 +138,7 @@ public: * checked, not the actual result. * @return the parsed node or nullptr if something goes wrong. */ - Rooted include(const std::string &path, const std::string mimetype, + NodeVector include(const std::string &path, const std::string mimetype, const std::string rel, const RttiSet &supportedTypes); /** -- cgit v1.2.3