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/resource | |
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/resource')
-rw-r--r-- | src/core/resource/ResourceManager.cpp | 39 | ||||
-rw-r--r-- | src/core/resource/ResourceManager.hpp | 15 |
2 files changed, 25 insertions, 29 deletions
diff --git a/src/core/resource/ResourceManager.cpp b/src/core/resource/ResourceManager.cpp index 610176b..2e15c85 100644 --- a/src/core/resource/ResourceManager.cpp +++ b/src/core/resource/ResourceManager.cpp @@ -70,11 +70,9 @@ void ResourceManager::purgeResource(SourceId sourceId) contextReaders.erase(sourceId); } -Rooted<Node> ResourceManager::parse(ParserContext &ctx, const std::string &path, - const std::string &mimetype, - const std::string &rel, - const RttiSet &supportedTypes, - ParseMode mode) +NodeVector<Node> ResourceManager::parse( + ParserContext &ctx, const std::string &path, const std::string &mimetype, + const std::string &rel, const RttiSet &supportedTypes, ParseMode mode) { // Some references used for convenience Registry ®istry = ctx.getRegistry(); @@ -88,7 +86,7 @@ Rooted<Node> ResourceManager::parse(ParserContext &ctx, const std::string &path, Resource resource; if (!req.deduce(registry, logger) || !req.locate(registry, logger, resource, relativeTo)) { - return nullptr; + return NodeVector<Node>{}; } // Allocate a new SourceId handle for this Resource @@ -104,7 +102,7 @@ Rooted<Node> ResourceManager::parse(ParserContext &ctx, const std::string &path, // Fetch the input stream and create a char reader std::unique_ptr<std::istream> is = resource.stream(); - CharReader reader(*is, sourceId); + CharReader reader(*is, sourceId); // Actually parse the input stream, distinguish the LINK and the // INCLUDE mode @@ -165,13 +163,12 @@ Rooted<Node> ResourceManager::parse(ParserContext &ctx, const std::string &path, catch (LoggableException ex) { // Log the exception and return nullptr logger.log(ex); - return nullptr; - // return NodeVector<Node>{}; + return NodeVector<Node>{}; } // Make sure the parsed nodes fulfill the "supportedTypes" constraint, // remove nodes that do not the result - for (auto it = parsedNodes.begin(); it != parsedNodes.end(); ) { + for (auto it = parsedNodes.begin(); it != parsedNodes.end();) { const Rtti &type = (*it)->type(); if (!type.isOneOf(supportedTypes)) { logger.error(std::string("Node of internal type ") + type.name + @@ -183,23 +180,23 @@ Rooted<Node> ResourceManager::parse(ParserContext &ctx, const std::string &path, } } - // TODO: Return parsed nodes - return nullptr; + return parsedNodes; } -Rooted<Node> ResourceManager::link(ParserContext &ctx, const std::string &path, - const std::string &mimetype, - const std::string &rel, - const RttiSet &supportedTypes) +NodeVector<Node> ResourceManager::link(ParserContext &ctx, + const std::string &path, + const std::string &mimetype, + const std::string &rel, + const RttiSet &supportedTypes) { return parse(ctx, path, mimetype, rel, supportedTypes, ParseMode::LINK); } -Rooted<Node> ResourceManager::include(ParserContext &ctx, - const std::string &path, - const std::string &mimetype, - const std::string &rel, - const RttiSet &supportedTypes) +NodeVector<Node> ResourceManager::include(ParserContext &ctx, + const std::string &path, + const std::string &mimetype, + const std::string &rel, + const RttiSet &supportedTypes) { return parse(ctx, path, mimetype, rel, supportedTypes, ParseMode::INCLUDE); } diff --git a/src/core/resource/ResourceManager.hpp b/src/core/resource/ResourceManager.hpp index e98e8f4..559112b 100644 --- a/src/core/resource/ResourceManager.hpp +++ b/src/core/resource/ResourceManager.hpp @@ -35,14 +35,13 @@ #include <core/common/Location.hpp> #include <core/common/Rtti.hpp> #include <core/common/SourceContextReader.hpp> -#include <core/managed/Managed.hpp> +#include <core/model/Node.hpp> #include "Resource.hpp" namespace ousia { // Forward declarations -class Node; class Parser; class ParserContext; class ResourceRequest; @@ -130,9 +129,9 @@ private: * can deal with. Note that only the types the parser claims to return are * checked, not the actual result. * @param mode describes whether the file should be included or linked. - * @return the parsed node or nullptr if something goes wrong. + * @return the parsed nodes or an empty list if something went wrong. */ - Rooted<Node> parse(ParserContext &ctx, const std::string &path, + NodeVector<Node> parse(ParserContext &ctx, const std::string &path, const std::string &mimetype, const std::string &rel, const RttiSet &supportedTypes, ParseMode mode); @@ -159,9 +158,9 @@ public: * @param supportedTypes contains the types of the returned Node the caller * can deal with. Note that only the types the parser claims to return are * checked, not the actual result. - * @return the parsed node or nullptr if something goes wrong. + * @return the parsed nodes or an empty list if something went wrong. */ - Rooted<Node> link(ParserContext &ctx, const std::string &path, + NodeVector<Node> link(ParserContext &ctx, const std::string &path, const std::string &mimetype, const std::string &rel, const RttiSet &supportedTypes); @@ -190,9 +189,9 @@ public: * @param supportedTypes contains the types of the returned Node the caller * can deal with. Note that only the types the parser claims to return are * checked, not the actual result. - * @return the parsed node or nullptr if something goes wrong. + * @return the parsed nodes or an empty list if something went wrong. */ - Rooted<Node> include(ParserContext &ctx, const std::string &path, + NodeVector<Node> include(ParserContext &ctx, const std::string &path, const std::string &mimetype, const std::string &rel, const RttiSet &supportedTypes); |