diff options
author | Eevee (Alex Munroe) <eevee.git@veekun.com> | 2014-09-01 21:38:43 -0700 |
---|---|---|
committer | Eevee (Alex Munroe) <eevee.git@veekun.com> | 2014-09-01 21:38:43 -0700 |
commit | 9733a04e016980515976196b45e54c426ed918ff (patch) | |
tree | 6504db8cdffd2d25ea1f0ab120054e9a41b4a716 /scss/blockast.py | |
parent | e51ab4d3c8d52604b5f2fbc83d2c1f235941fa94 (diff) | |
download | pyscss-separate-block-evaluation.tar.gz |
Parse assignment flags, though they're not used yet.separate-block-evaluation
Diffstat (limited to 'scss/blockast.py')
-rw-r--r-- | scss/blockast.py | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/scss/blockast.py b/scss/blockast.py index bc8eea1..b3e9bd0 100644 --- a/scss/blockast.py +++ b/scss/blockast.py @@ -49,22 +49,40 @@ class Declaration(Node): class Assignment(Declaration): - def __init__(self, name, value_expression): + KNOWN_FLAGS = frozenset(('!default', '!global')) + + def __init__(self, name, value_expression, flags): self.name = name self.value_expression = value_expression + self.flags = flags @classmethod def parse(cls, name, value): - # TODO pull off !default, !global + # Pull off flags: default, global + flags = set() + while True: + value__flag = value.rsplit(None, 1) + if len(value__flag) < 2: + break + if not value__flag[1].startswith('!'): + break + + value, flag = value__flag + if flag not in cls.KNOWN_FLAGS: + raise ValueError("Unrecognized flag: {0}".format(flag)) + + flags.add(flag) + # TODO interp-parse the name? is that a thing? # TODO this is a bit naughty, but uses no state except the ast_cache -- # which should maybe be in the Compiler anyway...? value_expression = Calculator().parse_expression(value) - return cls(name, value_expression) + return cls(name, value_expression, flags) def evaluate(self, compilation): + # TODO actually make use of the flags value = self.value_expression.evaluate(compilation.current_calculator) compilation.current_namespace.set_variable(self.name, value) |