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/resource/ResourceManager.cpp | 39 ++++++++++++++++------------------- 1 file changed, 18 insertions(+), 21 deletions(-) (limited to 'src/core/resource/ResourceManager.cpp') 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 ResourceManager::parse(ParserContext &ctx, const std::string &path, - const std::string &mimetype, - const std::string &rel, - const RttiSet &supportedTypes, - ParseMode mode) +NodeVector 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 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{}; } // Allocate a new SourceId handle for this Resource @@ -104,7 +102,7 @@ Rooted ResourceManager::parse(ParserContext &ctx, const std::string &path, // Fetch the input stream and create a char reader std::unique_ptr 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 ResourceManager::parse(ParserContext &ctx, const std::string &path, catch (LoggableException ex) { // Log the exception and return nullptr logger.log(ex); - return nullptr; - // return NodeVector{}; + return NodeVector{}; } // 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 ResourceManager::parse(ParserContext &ctx, const std::string &path, } } - // TODO: Return parsed nodes - return nullptr; + return parsedNodes; } -Rooted ResourceManager::link(ParserContext &ctx, const std::string &path, - const std::string &mimetype, - const std::string &rel, - const RttiSet &supportedTypes) +NodeVector 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 ResourceManager::include(ParserContext &ctx, - const std::string &path, - const std::string &mimetype, - const std::string &rel, - const RttiSet &supportedTypes) +NodeVector 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); } -- cgit v1.2.3