diff options
-rw-r--r-- | src/core/CSS.hpp | 12 | ||||
-rw-r--r-- | src/plugins/css/CSSParser.cpp | 29 | ||||
-rw-r--r-- | src/plugins/css/CSSParser.hpp | 2 | ||||
-rw-r--r-- | test/plugins/css/CSSParserTest.cpp | 2 |
4 files changed, 23 insertions, 22 deletions
diff --git a/src/core/CSS.hpp b/src/core/CSS.hpp index aa701b5..1510f3a 100644 --- a/src/core/CSS.hpp +++ b/src/core/CSS.hpp @@ -70,7 +70,7 @@ struct Specificity { */ class RuleSet : public Managed { private: - std::map<std::string, variant::Variant> rules; + std::map<std::string, Variant> rules; public: /** @@ -78,9 +78,9 @@ public: */ RuleSet(Manager &mgr) : Managed(mgr), rules() {} - std::map<std::string, variant::Variant> &getRules() { return rules; } + std::map<std::string, Variant> &getRules() { return rules; } - const std::map<std::string, variant::Variant> &getRules() const + const std::map<std::string, Variant> &getRules() const { return rules; } @@ -127,11 +127,11 @@ public: class PseudoSelector { private: const std::string name; - const std::vector<std::string> args; + const Variant::arrayType args; const bool generative; public: - PseudoSelector(std::string name, std::vector<std::string> args, + PseudoSelector(std::string name, Variant::arrayType args, bool generative) : name(std::move(name)), args(std::move(args)), generative(generative) { @@ -144,7 +144,7 @@ public: const std::string &getName() const { return name; } - const std::vector<std::string> &getArgs() const { return args; } + const Variant::arrayType &getArgs() const { return args; } const bool &isGenerative() const { return generative; } }; diff --git a/src/plugins/css/CSSParser.cpp b/src/plugins/css/CSSParser.cpp index 51b2fd2..4bbcc18 100644 --- a/src/plugins/css/CSSParser.cpp +++ b/src/plugins/css/CSSParser.cpp @@ -122,8 +122,7 @@ void CSSParser::parseSelectors(Rooted<SelectorNode> root, { auto tuple = parseSelector(tokenizer, ctx); // append the SelectorPath to the root node. - std::vector<Rooted<SelectorNode>> unmergedLeafs = - root->append(tuple.first); + std::vector<Rooted<SelectorNode>> unmergedLeafs = root->append(tuple.first); // append the leaf to the leafList. switch (unmergedLeafs.size()) { case 0: @@ -167,8 +166,8 @@ std::pair<Rooted<SelectorNode>, Rooted<SelectorNode>> CSSParser::parseSelector( // so we parse the rest of the subsequent SelectorPath auto tuple = parseSelector(tokenizer, ctx); // then we establish the DESCENDANT relationship - s->getEdges().push_back(new SelectorNode::SelectorEdge( - ctx.manager, tuple.first)); + s->getEdges().push_back( + new SelectorNode::SelectorEdge(ctx.manager, tuple.first)); // and we return this node as well as the leaf. return std::make_pair(s, tuple.second); } @@ -226,14 +225,16 @@ Rooted<SelectorNode> CSSParser::parsePrimitiveSelector(CodeTokenizer &tokenizer, return n; } // parse the argument list. - std::vector<std::string> args; + Variant::arrayType args; // we require at least one argument, if parantheses are used - expect(TOKEN_TEXT, tokenizer, t, true, ctx); - args.push_back(t.content); + args.push_back(variant::Reader::parseGeneric(tokenizer.getInput(), + ctx.logger, + {',', ')'}).second); while (expect(COMMA, tokenizer, t, false, ctx)) { // as long as we find commas we expect new arguments. - expect(TOKEN_TEXT, tokenizer, t, true, ctx); - args.push_back(t.content); + args.push_back( + variant::Reader::parseGeneric( + tokenizer.getInput(), ctx.logger, {',', ')'}).second); } expect(PAREN_CLOSE, tokenizer, t, true, ctx); // and we return with the finished Selector. @@ -247,7 +248,7 @@ Rooted<SelectorNode> CSSParser::parsePrimitiveSelector(CodeTokenizer &tokenizer, // so we expect an ID now. Token t; expect(TOKEN_TEXT, tokenizer, t, true, ctx); - std::vector<std::string> args{t.content}; + Variant::arrayType args{Variant(t.content.c_str())}; // and we return the finished Selector Rooted<SelectorNode> n{ new SelectorNode(ctx.manager, name, {"has_id", args, false})}; @@ -262,7 +263,7 @@ Rooted<SelectorNode> CSSParser::parsePrimitiveSelector(CodeTokenizer &tokenizer, // in both cases the attribute name comes first. Token t; expect(TOKEN_TEXT, tokenizer, t, true, ctx); - std::vector<std::string> args{t.content}; + Variant::arrayType args{Variant(t.content.c_str())}; if (!expect(EQUALS, tokenizer, t, false, ctx)) { // if no equals sign follows we have a has_attribute // PseudoSelector @@ -276,7 +277,7 @@ Rooted<SelectorNode> CSSParser::parsePrimitiveSelector(CodeTokenizer &tokenizer, // with an equals sign we have a has_value PseudoSelector and // expect the value next. expect(STRING, tokenizer, t, true, ctx); - args.push_back(t.content); + args.push_back(Variant(t.content.c_str())); // then we expect a closing bracket. expect(BRACKET_CLOSE, tokenizer, t, true, ctx); // and then we can return the result. @@ -313,14 +314,14 @@ void CSSParser::parseRules(CodeTokenizer &tokenizer, Rooted<RuleSet> ruleSet, ParserContext &ctx) { std::string key; - variant::Variant value; + Variant value; while (parseRule(tokenizer, ctx, key, value)) { ruleSet->getRules().insert({key, value}); } } bool CSSParser::parseRule(CodeTokenizer &tokenizer, ParserContext &ctx, - std::string &key, variant::Variant &value) + std::string &key, Variant &value) { Token t; if (!expect(TOKEN_TEXT, tokenizer, t, false, ctx)) { diff --git a/src/plugins/css/CSSParser.hpp b/src/plugins/css/CSSParser.hpp index a4d8cdc..82f0cd1 100644 --- a/src/plugins/css/CSSParser.hpp +++ b/src/plugins/css/CSSParser.hpp @@ -112,7 +112,7 @@ private: * @return true if a rule was found. */ bool parseRule(CodeTokenizer &tokenizer, ParserContext &ctx, - std::string &key, variant::Variant &value); + std::string &key, Variant &value); /** * A convenience function to wrap around the tokenizer peek() function that diff --git a/test/plugins/css/CSSParserTest.cpp b/test/plugins/css/CSSParserTest.cpp index 8873673..6499375 100644 --- a/test/plugins/css/CSSParserTest.cpp +++ b/test/plugins/css/CSSParserTest.cpp @@ -120,7 +120,7 @@ TEST(CSSParser, testParseSelectors) Rooted<SelectorNode> Ag = children[1]; ASSERT_EQ("A", Ag->getName()); { - PseudoSelector select{"g", {"4", "2", "3"}, true}; + PseudoSelector select{"g", {Variant(4), Variant(2), Variant(3)}, true}; ASSERT_EQ(select, Ag->getPseudoSelector()); } ASSERT_EQ(0, Ag->getEdges().size()); |