diff options
author | Benjamin Paassen <bpaassen@techfak.uni-bielefeld.de> | 2014-12-09 14:41:28 +0100 |
---|---|---|
committer | Benjamin Paassen <bpaassen@techfak.uni-bielefeld.de> | 2014-12-09 14:41:28 +0100 |
commit | 98c4f90d3e34bd4d536ee6c84b4d79b71cde3998 (patch) | |
tree | cf49120e122d15bf7199eda7b3914dd73dcf30fe /src/plugins/css/CSSParser.cpp | |
parent | 37fc54402744b84b65ba87178387d7f6009d50df (diff) |
made CSSParser full compatible (including pseudo selector arguments) with type system parsing.
Diffstat (limited to 'src/plugins/css/CSSParser.cpp')
-rw-r--r-- | src/plugins/css/CSSParser.cpp | 29 |
1 files changed, 15 insertions, 14 deletions
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)) { |