Skip to content

Parse error on custom property fallback #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tornqvist opened this issue Oct 8, 2018 · 1 comment · Fixed by #68
Closed

Parse error on custom property fallback #50

tornqvist opened this issue Oct 8, 2018 · 1 comment · Fixed by #68
Labels

Comments

@tornqvist
Copy link

The parser will fail if using nested custom properties with fallbacks which themselves are custom properties.

This code:

.my-class {
  width: calc(var(--xxx, var(--yyy)) / 2);
}

Will throw this error:

  Error: Parse error on line 1:
  ...ar(--xxx, var(--yyy)) / 2
  -----------------------^
  Expecting 'EOF', 'ADD', 'SUB', 'MUL', 'DIV', got 'RPAREN'

I tried putting together a PR using recursive rules for the parser but realized someone else with a better understanding of Bison syntax could do a better job than me.

The best I could come up with is a regex which handles two levels of nesting which is enough for my use case but not really fool proof. I figured I should open an issue before submitting a PR with the following change to the parser:

- (var\([^\)]*\))                        return 'CSS_VAR';
+ (var\((?:[^)(]+|\((?:[^)(]+|\([^)(]*\))*\))*\))  return 'CSS_VAR';
@AntonTrollback
Copy link

AntonTrollback commented Oct 16, 2018

This one I want! But I'm not capable of fixing it… Please help us @MoOx ! ^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants