diff --git a/lib/src/ast/sass/expression.dart b/lib/src/ast/sass/expression.dart index 1c1c4e0e..a261a0ec 100644 --- a/lib/src/ast/sass/expression.dart +++ b/lib/src/ast/sass/expression.dart @@ -5,6 +5,7 @@ import '../../visitor/expression.dart'; import 'node.dart'; +export 'expression/boolean.dart'; export 'expression/identifier.dart'; export 'expression/interpolation.dart'; export 'expression/list.dart'; diff --git a/lib/src/ast/sass/expression/boolean.dart b/lib/src/ast/sass/expression/boolean.dart new file mode 100644 index 00000000..dbf51928 --- /dev/null +++ b/lib/src/ast/sass/expression/boolean.dart @@ -0,0 +1,21 @@ +// 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 'package:source_span/source_span.dart'; + +import '../../../visitor/expression.dart'; +import '../expression.dart'; + +class BooleanExpression implements Expression { + final bool value; + + final SourceSpan span; + + BooleanExpression(this.value, {this.span}); + + /*=T*/ visit/**/(ExpressionVisitor/**/ visitor) => + visitor.visitBooleanExpression(this); + + String toString() => value.toString(); +} diff --git a/lib/src/parser.dart b/lib/src/parser.dart index 9854c47a..fe1407c3 100644 --- a/lib/src/parser.dart +++ b/lib/src/parser.dart @@ -394,12 +394,17 @@ class Parser { Expression _identifierLike() { // TODO: url(), functions var identifier = _interpolatedIdentifier(); - if (identifier.asPlain == "not") { - _ignoreComments(); - return new UnaryOperatorExpression( - UnaryOperator.not, _singleExpression()); - } else { - return new IdentifierExpression(identifier); + switch (identifier.asPlain) { + case "not": + _ignoreComments(); + return new UnaryOperatorExpression( + UnaryOperator.not, _singleExpression(), span: identifier.span); + + case "true": return new BooleanExpression(true, span: identifier.span); + case "false": return new BooleanExpression(false, span: identifier.span); + + default: + return new IdentifierExpression(identifier); } } diff --git a/lib/src/visitor/expression.dart b/lib/src/visitor/expression.dart index 69edf2ec..880e4b51 100644 --- a/lib/src/visitor/expression.dart +++ b/lib/src/visitor/expression.dart @@ -8,6 +8,7 @@ class ExpressionVisitor { T visit(Expression expression) => expression.visit(this); T visitVariableExpression(VariableExpression node) => null; + T visitBooleanExpression(BooleanExpression node) => null; T visitUnaryOperatorExpression(UnaryOperatorExpression node) { node.operand.visit(this); @@ -19,13 +20,6 @@ class ExpressionVisitor { return null; } - T visitInterpolationExpression(InterpolationExpression node) { - for (var value in node.contents) { - if (value is Expression) value.visit(this); - } - return null; - } - T visitListExpression(ListExpression node) { for (var expression in node.contents) { expression.visit(this); @@ -37,4 +31,11 @@ class ExpressionVisitor { visitInterpolationExpression(node.text); return null; } + + T visitInterpolationExpression(InterpolationExpression node) { + for (var value in node.contents) { + if (value is Expression) value.visit(this); + } + return null; + } } diff --git a/lib/src/visitor/expression/perform.dart b/lib/src/visitor/expression/perform.dart index c0aeec63..e8b83822 100644 --- a/lib/src/visitor/expression/perform.dart +++ b/lib/src/visitor/expression/perform.dart @@ -36,6 +36,9 @@ class PerformExpressionVisitor extends ExpressionVisitor { Identifier visitIdentifierExpression(IdentifierExpression node) => new Identifier(visitInterpolationExpression(node.text).text); + Boolean visitBooleanExpression(BooleanExpression node) => + new Boolean(node.value); + SassString visitInterpolationExpression(InterpolationExpression node) { return new SassString(node.contents.map((value) { if (value is String) return value;