Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1507)

Unified Diff: pkg/analyzer/lib/src/generated/parser.dart

Issue 1043583002: Scanner/parser support for DEP 9 (null-aware operators). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer/lib/src/generated/parser.dart
diff --git a/pkg/analyzer/lib/src/generated/parser.dart b/pkg/analyzer/lib/src/generated/parser.dart
index 47c1774921c034749cbf31bf2db93b918e0f1b9a..d5755436d2602ddb0de4b8595137ef23aee53c45 100644
--- a/pkg/analyzer/lib/src/generated/parser.dart
+++ b/pkg/analyzer/lib/src/generated/parser.dart
@@ -694,7 +694,7 @@ class IncrementalParseDispatcher implements AstVisitor<AstNode> {
@override
AstNode visitConditionalExpression(ConditionalExpression node) {
if (identical(_oldNode, node.condition)) {
- return _parser.parseLogicalOrExpression();
+ return _parser.parseIfNullExpression();
} else if (identical(_oldNode, node.thenExpression)) {
return _parser.parseExpressionWithoutCascade();
} else if (identical(_oldNode, node.elseExpression)) {
@@ -2715,10 +2715,10 @@ class Parser {
* parsed.
*
* conditionalExpression ::=
- * logicalOrExpression ('?' expressionWithoutCascade ':' expressionWithoutCascade)?
+ * ifNullExpression ('?' expressionWithoutCascade ':' expressionWithoutCascade)?
*/
Expression parseConditionalExpression() {
- Expression condition = parseLogicalOrExpression();
+ Expression condition = parseIfNullExpression();
if (!_matches(TokenType.QUESTION)) {
return condition;
}
@@ -3045,6 +3045,22 @@ class Parser {
}
/**
+ * Parse an if-null expression. Return the if-null expression that was
+ * parsed.
+ *
+ * ifNullExpression ::= logicalOrExpression ('??' logicalOrExpression)*
+ */
+ Expression parseIfNullExpression() {
+ Expression expression = parseLogicalOrExpression();
+ while (_matches(TokenType.QUESTION_QUESTION)) {
+ Token operator = getAndAdvance();
+ expression = new BinaryExpression(
+ expression, operator, parseLogicalOrExpression());
+ }
+ return expression;
+ }
+
+ /**
* Parse an implements clause. Return the implements clause that was parsed.
*
* implementsClause ::=
@@ -4278,9 +4294,9 @@ class Parser {
} finally {
_inInitializer = wasInInitializer;
}
- } else if (_matches(TokenType.PERIOD)) {
- Token period = getAndAdvance();
- return new PropertyAccess(prefix, period, parseSimpleIdentifier());
+ } else if (_matches(TokenType.PERIOD) || _matches(TokenType.QUESTION_PERIOD)) {
+ Token operator = getAndAdvance();
+ return new PropertyAccess(prefix, operator, parseSimpleIdentifier());
} else {
if (!optional) {
// Report the missing selector.
@@ -6715,6 +6731,7 @@ class Parser {
Expression operand = _parseAssignableExpression(true);
if (_matches(TokenType.OPEN_SQUARE_BRACKET) ||
_matches(TokenType.PERIOD) ||
+ _matches(TokenType.QUESTION_PERIOD) ||
_matches(TokenType.OPEN_PAREN)) {
do {
if (_matches(TokenType.OPEN_PAREN)) {
@@ -6731,6 +6748,7 @@ class Parser {
}
} while (_matches(TokenType.OPEN_SQUARE_BRACKET) ||
_matches(TokenType.PERIOD) ||
+ _matches(TokenType.QUESTION_PERIOD) ||
_matches(TokenType.OPEN_PAREN));
return operand;
}

Powered by Google App Engine
This is Rietveld 408576698