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/plugins/css | |
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/plugins/css')
-rw-r--r-- | src/plugins/css/CSSParser.cpp | 11 | ||||
-rw-r--r-- | src/plugins/css/CSSParser.hpp | 3 |
2 files changed, 11 insertions, 3 deletions
diff --git a/src/plugins/css/CSSParser.cpp b/src/plugins/css/CSSParser.cpp index 40179bf..a09a69f 100644 --- a/src/plugins/css/CSSParser.cpp +++ b/src/plugins/css/CSSParser.cpp @@ -74,15 +74,22 @@ static const std::map<int, CodeTokenDescriptor> CSS_DESCRIPTORS = { {ESCAPE, {CodeTokenMode::ESCAPE, ESCAPE}}, {LINEBREAK, {CodeTokenMode::LINEBREAK, LINEBREAK}}}; -Rooted<Node> CSSParser::doParse(CharReader &reader, ParserContext &ctx) +void CSSParser::doParse(CharReader &reader, ParserContext &ctx) { CodeTokenizer tokenizer{reader, CSS_ROOT, CSS_DESCRIPTORS}; tokenizer.ignoreComments = true; tokenizer.ignoreLinebreaks = true; + + // Create the root node and push it onto the parser scope Rooted<model::SelectorNode> root = { new model::SelectorNode{ctx.getManager(), "root"}}; + ctx.getScope().push(root); + + // Parse the document into the root node parseDocument(root, tokenizer, ctx); - return root; + + // Remove the element from the parser scope + ctx.getScope().pop(); } void CSSParser::parseDocument(Rooted<model::SelectorNode> root, diff --git a/src/plugins/css/CSSParser.hpp b/src/plugins/css/CSSParser.hpp index 2f37e6a..b2a760f 100644 --- a/src/plugins/css/CSSParser.hpp +++ b/src/plugins/css/CSSParser.hpp @@ -35,6 +35,7 @@ #include <core/common/CharReader.hpp> #include <core/model/Style.hpp> #include <core/parser/Parser.hpp> +#include <core/parser/ParserScope.hpp> namespace ousia { @@ -158,7 +159,7 @@ protected: * @return returns the root node of the resulting SelectorTree. For more * information on the return conventions consult the Parser.hpp. */ - Rooted<Node> doParse(CharReader &reader, ParserContext &ctx) override; + void doParse(CharReader &reader, ParserContext &ctx) override; }; } |