Skip to content

Commit

Permalink
vaev-style: Make style parser a little bit less chatty.
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepy-monax committed Nov 26, 2024
1 parent 8145a33 commit cdde49d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
10 changes: 6 additions & 4 deletions src/vaev-style/decls.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace Vaev::Style {

static bool DEBUG_DECL = false;

template <typename T>
Res<T> parseDeclarationValue(Cursor<Css::Sst> &c) {
if constexpr (requires { T{}.parse(c); }) {
Expand All @@ -15,7 +17,7 @@ Res<T> parseDeclarationValue(Cursor<Css::Sst> &c) {

return Ok(std::move(t));
} else {
logError("missing parser for declaration: {}", T::name());
logErrorIf(DEBUG_DECL, "missing parser for declaration: {}", T::name());
return Error::notImplemented("missing parser for declaration");
}
}
Expand Down Expand Up @@ -102,7 +104,7 @@ Res<P> parseDeclaration(Css::Sst const &sst, bool allowDeferred = true) {
);

if (not resDecl)
logWarn("failed to parse declaration: {} - {}", sst, resDecl);
logWarnIf(DEBUG_DECL, "failed to parse declaration: {} - {}", sst, resDecl);

return resDecl;
}
Expand All @@ -113,14 +115,14 @@ Vec<P> parseDeclarations(Css::Content const &sst, bool allowDeferred = true) {

for (auto const &item : sst) {
if (item != Css::Sst::DECL) {
logWarn("unexpected item in declaration: {}", item.type);
logWarnIf(DEBUG_DECL, "unexpected item in declaration: {}", item.type);
continue;
}

auto prop = parseDeclaration<P>(item, allowDeferred);

if (not prop) {
logWarn("failed to parse declaration: {}", prop.none());
logWarnIf(DEBUG_DECL, "failed to parse declaration: {}", prop.none());
continue;
}
res.pushBack(prop.take());
Expand Down
4 changes: 3 additions & 1 deletion src/vaev-style/rules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Vaev::Style {

static bool DEBUG_RULE = false;

// MARK: StyleRule -------------------------------------------------------------

void StyleRule::repr(Io::Emit &e) const {
Expand Down Expand Up @@ -45,7 +47,7 @@ StyleRule StyleRule::parse(Css::Sst const &sst, Origin origin) {
if (prop)
res.props.pushBack(prop.take());
} else {
logWarn("unexpected item in style rule: {}", item.type);
logWarnIf(DEBUG_RULE, "unexpected item in style rule: {}", item);
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/vaev-style/styles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Vaev::Style {

static bool DEBUG_PROPS = false;

// MARK: DeferredProp ----------------------------------------------------------

bool DeferredProp::_expandVariable(Cursor<Css::Sst> &c, Map<String, Css::Content> const &env, Css::Content &out) {
Expand Down Expand Up @@ -70,7 +72,7 @@ void DeferredProp::apply(Computed &c) const {
// Parse the expanded content
Res<StyleProp> computed = parseDeclaration<StyleProp>(decl, false);
if (not computed) {
logWarn("failed to parse declaration: {}", computed);
logWarnIf(DEBUG_PROPS, "failed to parse declaration: {}", computed);
} else {
computed.unwrap().apply(c);
}
Expand Down

0 comments on commit cdde49d

Please sign in to comment.