Fix variables.

This commit is contained in:
Natalie Weizenbaum 2016-05-24 15:53:41 -07:00
parent 86fa4cf068
commit b88d0158ec
2 changed files with 12 additions and 5 deletions

View File

@ -14,7 +14,9 @@ class Environment {
_variables[_variableIndices[name] ?? 0][name];
void setVariable(String name, Value value, {bool global}) {
var index = global ? 0 : _variableIndices[name] ?? _variables.length - 1;
var index = global || _variables.length == 1
? 0
: _variableIndices.putIfAbsent(name, () => _variables.length - 1);
_variables[index][name] = value;
}
@ -24,7 +26,9 @@ class Environment {
try {
return callback();
} finally {
_variables.removeLast();
for (var name in _variables.removeLast().keys) {
_variableIndices.remove(name);
}
}
}
}

View File

@ -36,8 +36,9 @@ class Parser {
Stylesheet parse() {
var start = _scanner.state;
var children = <Statement>[];
do {
while (true) {
children.addAll(_comments());
if (_scanner.isDone) break;
switch (_scanner.peekChar()) {
case $dollar:
children.add(_variableDeclaration());
@ -47,13 +48,15 @@ class Parser {
children.add(_atRule());
break;
case $semicolon: break;
case $semicolon:
_scanner.readChar();
break;
default:
children.add(_styleRule());
break;
}
} while (_scanChar($semicolon));
}
_scanner.expectDone();
return new Stylesheet(children, span: _scanner.spanFrom(start));