2016-05-24 23:01:41 +02:00
|
|
|
// Copyright 2016 Google Inc. Use of this source code is governed by an
|
|
|
|
// MIT-style license that can be found in the LICENSE file or at
|
|
|
|
// https://opensource.org/licenses/MIT.
|
|
|
|
|
|
|
|
import '../../ast/sass/expression.dart';
|
2016-05-25 00:36:44 +02:00
|
|
|
import '../../environment.dart';
|
2016-05-24 23:01:41 +02:00
|
|
|
import '../../value.dart';
|
|
|
|
import '../expression.dart';
|
|
|
|
|
|
|
|
class PerformExpressionVisitor extends ExpressionVisitor<Value> {
|
2016-05-25 00:36:44 +02:00
|
|
|
final Environment _environment;
|
|
|
|
|
|
|
|
PerformExpressionVisitor(this._environment);
|
|
|
|
|
2016-05-24 23:01:41 +02:00
|
|
|
Value visit(Expression expression) => expression.visit(this);
|
|
|
|
|
2016-05-25 00:36:44 +02:00
|
|
|
Value visitVariableExpression(VariableExpression node) {
|
|
|
|
var result = _environment.getVariable(node.name);
|
|
|
|
if (result != null) return result;
|
|
|
|
|
|
|
|
// TODO: real exception
|
|
|
|
throw node.span.message("undefined variable");
|
|
|
|
}
|
|
|
|
|
2016-05-24 23:01:41 +02:00
|
|
|
Identifier visitIdentifierExpression(IdentifierExpression node) =>
|
|
|
|
new Identifier(visitInterpolationExpression(node.text).text);
|
|
|
|
|
|
|
|
SassString visitInterpolationExpression(InterpolationExpression node) {
|
|
|
|
return new SassString(node.contents.map((value) {
|
|
|
|
if (value is String) return value;
|
|
|
|
return (value as Expression).visit(this);
|
|
|
|
}).join());
|
|
|
|
}
|
|
|
|
|
|
|
|
SassList visitListExpression(ListExpression node) => new SassList(
|
|
|
|
node.contents.map((expression) => expression.visit(this)),
|
|
|
|
node.separator);
|
|
|
|
|
|
|
|
SassString visitStringExpression(StringExpression node) =>
|
|
|
|
visitInterpolationExpression(node.text);
|
|
|
|
}
|