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

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

Issue 2282233002: Add support for parsing, but not capturing, assers in constructor initializer lists (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: add flag Created 4 years, 4 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
« no previous file with comments | « pkg/analyzer/lib/src/generated/engine.dart ('k') | pkg/analyzer/lib/src/task/dart.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 fcf9b0132a2d4265d7527c05f679a4c09e57fd81..d3f747517b61ae2e1f002434f72d482c97e7f9f7 100644
--- a/pkg/analyzer/lib/src/generated/parser.dart
+++ b/pkg/analyzer/lib/src/generated/parser.dart
@@ -2135,6 +2135,12 @@ class Parser {
int _errorListenerLock = 0;
/**
+ * A flag indicating whether the parser is to parse asserts in the initializer
+ * list of a constructor.
+ */
+ bool _enableAssertInitializer = false;
+
+ /**
* A flag indicating whether the parser is to parse the async support.
*/
bool _parseAsync = true;
@@ -2202,6 +2208,20 @@ class Parser {
}
/**
+ * Return `true` if the parser is to parse asserts in the initializer list of
+ * a constructor.
+ */
+ bool get enableAssertInitializer => _enableAssertInitializer;
+
+ /**
+ * Set whether the parser is to parse asserts in the initializer list of a
+ * constructor to match the given [enable] flag.
+ */
+ void set enableAssertInitializer(bool enable) {
+ _enableAssertInitializer = enable;
+ }
+
+ /**
* Return `true` if the current token is the first token of a return type that
* is followed by an identifier, possibly followed by a list of type
* parameters, followed by a left-parenthesis. This is used by
@@ -2862,6 +2882,7 @@ class Parser {
"parseDirective invoked in an invalid state (currentToken = $_currentToken)");
}
}
+
Directive directive = parseDirective();
if (declarations.length > 0 && !directiveFoundAfterDeclaration) {
_reportErrorForToken(ParserErrorCode.DIRECTIVE_AFTER_DECLARATION,
@@ -4346,6 +4367,31 @@ class Parser {
}
/**
+ * Parse an assert within a constructor's initializer list. Return the assert.
+ *
+ * This method assumes that the current token matches `Keyword.ASSERT`.
+ *
+ * assertInitializer ::=
+ * 'assert' '(' expression [',' expression] ')'
+ */
+ void _parseAssertInitializer() {
+ // TODO(brianwilkerson) Capture the syntax in the AST using a new class,
+ // such as AssertInitializer
+ Token keyword = getAndAdvance();
+ Token leftParen = _expect(TokenType.OPEN_PAREN);
+ Expression expression = parseExpression2();
+ Token comma;
+ Expression message;
+ if (_matches(TokenType.COMMA)) {
+ comma = getAndAdvance();
+ message = parseExpression2();
+ }
+ Token rightParen = _expect(TokenType.CLOSE_PAREN);
+// return new AssertInitializer(
+// keyword, leftParen, expression, comma, message, rightParen);
+ }
+
+ /**
* Parse an assert statement. Return the assert statement.
*
* This method assumes that the current token matches `Keyword.ASSERT`.
@@ -5502,6 +5548,9 @@ class Parser {
} else if (_matches(TokenType.OPEN_CURLY_BRACKET) ||
_matches(TokenType.FUNCTION)) {
_reportErrorForCurrentToken(ParserErrorCode.MISSING_INITIALIZER);
+ } else if (_enableAssertInitializer &&
+ _matchesKeyword(Keyword.ASSERT)) {
+ _parseAssertInitializer();
} else {
initializers.add(_parseConstructorFieldInitializer(false));
}
@@ -8282,6 +8331,7 @@ class Parser {
Keyword keyword = _currentToken.keyword;
return keyword == Keyword.CASE || keyword == Keyword.DEFAULT;
}
+
while (!atEndOrNextMember()) {
_advance();
}
@@ -8625,6 +8675,7 @@ class Parser {
type == TokenType.INT ||
type == TokenType.DOUBLE;
}
+
while ((_tokenMatchesIdentifier(token) && !isKeywordAfterUri(token)) ||
isValidInUri(token)) {
token = token.next;
« no previous file with comments | « pkg/analyzer/lib/src/generated/engine.dart ('k') | pkg/analyzer/lib/src/task/dart.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698