diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-01-27 16:01:53 +0100 |
---|---|---|
committer | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-01-27 16:01:53 +0100 |
commit | eb6ecdcc85ece4eb84b90f3c9bb920dc1ad2b6d1 (patch) | |
tree | caaaaa969471552a13f5315a3de6e9db15b02a8b /src/core/parser | |
parent | 07d326d02415467ba7f5f238a8e72a9e4b7f1549 (diff) |
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.
Diffstat (limited to 'src/core/parser')
-rw-r--r-- | src/core/parser/Parser.cpp | 8 | ||||
-rw-r--r-- | src/core/parser/Parser.hpp | 27 | ||||
-rw-r--r-- | src/core/parser/ParserContext.cpp | 4 | ||||
-rw-r--r-- | src/core/parser/ParserContext.hpp | 5 |
4 files changed, 20 insertions, 24 deletions
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<Node> Parser::parse(CharReader &reader, ParserContext &ctx) +void Parser::parse(CharReader &reader, ParserContext &ctx) { - return doParse(reader, ctx); + doParse(reader, ctx); } -Rooted<Node> 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 <set> #include <string> -#include <core/managed/Managed.hpp> -#include <core/model/Node.hpp> - 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<Node> 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<Node> 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<Node> 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<Node> ParserContext::link(const std::string &path, +NodeVector<Node> ParserContext::link(const std::string &path, const std::string mimetype, const std::string rel, const RttiSet &supportedTypes) @@ -47,7 +47,7 @@ Rooted<Node> ParserContext::link(const std::string &path, return resourceManager.link(*this, path, mimetype, rel, supportedTypes); } -Rooted<Node> ParserContext::include(const std::string &path, +NodeVector<Node> 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 <core/common/Location.hpp> #include <core/common/Rtti.hpp> +#include <core/model/Node.hpp> #include <core/model/Project.hpp> namespace ousia { @@ -116,7 +117,7 @@ public: * checked, not the actual result. * @return the parsed node or nullptr if something goes wrong. */ - Rooted<Node> link(const std::string &path, const std::string mimetype, + NodeVector<Node> 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<Node> include(const std::string &path, const std::string mimetype, + NodeVector<Node> include(const std::string &path, const std::string mimetype, const std::string rel, const RttiSet &supportedTypes); /** |