void UnprocessedStatement::process(Ruleset &r) { Extension extension; Mixin mixin; Declaration* declaration; #ifdef WITH_LIBGLOG VLOG(2) << "Statement: " << getTokens()->toString(); #endif // process extends statement if (getExtension(extension.getTarget())) { extension.setExtension(r.getSelector()); getLessRuleset()->getContext()->addExtension(extension); return; } mixin.setStylesheet(getLessRuleset()->getLessStylesheet()); // process mixin if (mixin.parse(*getTokens()) && mixin.insert(*r.getStylesheet(), *getLessRuleset()->getContext(), &r, getLessRuleset())) { } else { declaration = r.createDeclaration(); if (processDeclaration(declaration)) { #ifdef WITH_LIBGLOG VLOG(2) << "Declaration: " << declaration->getProperty() << ": " << declaration->getValue().toString(); #endif getLessRuleset()->getContext()->processValue(declaration->getValue()); #ifdef WITH_LIBGLOG VLOG(2) << "Processed declaration: " << declaration->getProperty() << ": " << declaration->getValue().toString(); #endif } else { r.deleteDeclaration(*declaration); throw new ParseException(getTokens()->toString(), "variable, mixin or declaration.", getTokens()->front().line, getTokens()->front().column, getTokens()->front().source); } } #ifdef WITH_LIBGLOG VLOG(3) << "Statement done"; #endif }
// block in value TEST(CssParserTest, BlockValue) { istringstream in("selector {key: {value}}"); CssTokenizer t(&in); CssParser p(&t); Stylesheet s; Declaration* d; p.parseStylesheet(&s); ASSERT_EQ(1, s.getRulesets()->size()); ASSERT_EQ(1, s.getRulesets()->at(0)->getDeclarations()->size()); d = s.getRulesets()->at(0)->getDeclarations()->at(0); ASSERT_STREQ("key", d->getProperty()->c_str()); ASSERT_STREQ("{value}", d->getValue()->toString()->c_str()); }
void LessDeclaration::process(Ruleset &r, void* context) const { Declaration *d = r.createDeclaration(); d->setProperty(property); d->setValue(value); ((ProcessingContext*)context)->interpolate(d->getProperty()); ((ProcessingContext*)context)->processValue(d->getValue()); // If the `important` flag is set, append '!important' if(((ProcessingContext*)context)->isImportant()) { if (d->getValue().size() < 3 || d->getValue().back() == "important") { d->getValue().push_back(Token::BUILTIN_SPACE); d->getValue().push_back(Token::BUILTIN_IMPORTANT); } } }
// Rulesets TEST(CssParserTest, Ruleset) { istringstream in("selector {key: value;}"); CssTokenizer t(&in); CssParser p(&t); Stylesheet s; Ruleset* set; Declaration* d; p.parseStylesheet(&s); ASSERT_EQ(1, s.getRulesets()->size()); set = s.getRulesets()->at(0); ASSERT_STREQ("selector", set->getSelector()->toString()->c_str()); ASSERT_EQ(1, set->getDeclarations()->size()); d = set->getDeclarations()->at(0); ASSERT_STREQ("key", d->getProperty()->c_str()); ASSERT_STREQ("value", d->getValue()->toString()->c_str()); }