-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a ParenthesizedExpression class (#503)
This allows us to accurately track the source spans for parenthesized expressions, which in turn allows us to print accurate error indications. Adding a new class for this more accurately represents the structure of the expression, but it also involves an extra allocation during parsing and an extra level of nesting during evaluation which could have a small but real performance impact. We could alternatively add a package-internal setter for Expression.span, and update the source span for parenthesized expressions after they're initially parsed. However, this has its own downsides: it adds complexity and mutability to the object model; and many expression classes currently use lazily-generated spans, so making them settable would require adding extra slots on those classes. I decided to go with the extra class because it only adds overhead when parentheses are actually used in practice, as opposed to adding overhead to every list/color/etc. The runtime overhead is also likely to be mitigated if at any point we add a constant-folding step.
- Loading branch information
Showing
9 changed files
with
56 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright 2018 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 '../../../value.dart'; | ||
import '../../../visitor/interface/expression.dart'; | ||
import '../expression.dart'; | ||
|
||
/// An expression wrapped in parentheses. | ||
class ParenthesizedExpression implements Expression { | ||
/// The internal expression. | ||
final Expression expression; | ||
|
||
final FileSpan span; | ||
|
||
ParenthesizedExpression(this.expression, this.span); | ||
|
||
T accept<T>(ExpressionVisitor<T> visitor) => | ||
visitor.visitParenthesizedExpression(this); | ||
|
||
String toString() => expression.toString(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name: sass | ||
version: 1.14.3-dev | ||
version: 1.14.3 | ||
description: A Sass implementation in Dart. | ||
author: Dart Team <[email protected]> | ||
homepage: https://github.com/sass/dart-sass | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters