| Index: pkg/dart_parser/lib/src/class_member_parser.dart
|
| diff --git a/pkg/dart_parser/lib/src/class_member_parser.dart b/pkg/dart_parser/lib/src/class_member_parser.dart
|
| index 5ac801a635404bf003de3a752dbd9ca591d71a94..792468bf91d832eed194f354925d423589a883b9 100644
|
| --- a/pkg/dart_parser/lib/src/class_member_parser.dart
|
| +++ b/pkg/dart_parser/lib/src/class_member_parser.dart
|
| @@ -5,22 +5,13 @@
|
| library dart_parser.class_member_parser;
|
|
|
| import 'package:dart_scanner/src/token.dart' show
|
| - BeginGroupToken,
|
| - ErrorToken,
|
| Token;
|
|
|
| -import 'package:dart_scanner/src/token_constants.dart' show
|
| - EOF_TOKEN;
|
| -
|
| import 'listener.dart' show
|
| Listener;
|
|
|
| -import 'error_kind.dart' show
|
| - ErrorKind;
|
| -
|
| import 'parser.dart' show
|
| - Parser,
|
| - optional;
|
| + Parser;
|
|
|
| /// Parser similar to [TopLevelParser] but also parses class members (excluding
|
| /// their bodies).
|
| @@ -33,125 +24,12 @@ class ClassMemberParser extends Parser {
|
|
|
| Token parseExpression(Token token) => skipExpression(token);
|
|
|
| - Token parseArgumentsOpt(Token token) {
|
| - // This method is overridden for two reasons:
|
| - // 1. Avoid generating events for arguments.
|
| - // 2. Avoid calling skip expression for each argument (which doesn't work).
|
| - listener.handleNoArguments(token);
|
| - if (optional('(', token)) {
|
| - BeginGroupToken begin = token;
|
| - return begin.endGroup.next;
|
| - } else {
|
| - return token;
|
| - }
|
| - }
|
| -
|
| - Token skipExpression(Token token) {
|
| - while (true) {
|
| - final kind = token.kind;
|
| - final value = token.stringValue;
|
| - if ((identical(kind, EOF_TOKEN)) ||
|
| - (identical(value, ';')) ||
|
| - (identical(value, ',')) ||
|
| - (identical(value, '}')) ||
|
| - (identical(value, ')')) ||
|
| - (identical(value, ']'))) {
|
| - break;
|
| - }
|
| - if (identical(value, '=') ||
|
| - identical(value, '?') ||
|
| - identical(value, ':') ||
|
| - identical(value, '??')) {
|
| - var nextValue = token.next.stringValue;
|
| - if (identical(nextValue, 'const')) {
|
| - token = token.next;
|
| - nextValue = token.next.stringValue;
|
| - }
|
| - if (identical(nextValue, '{')) {
|
| - // Handle cases like this:
|
| - // class Foo {
|
| - // var map;
|
| - // Foo() : map = {};
|
| - // Foo.x() : map = true ? {} : {};
|
| - // }
|
| - BeginGroupToken begin = token.next;
|
| - token = (begin.endGroup != null) ? begin.endGroup : token;
|
| - token = token.next;
|
| - continue;
|
| - }
|
| - if (identical(nextValue, '<')) {
|
| - // Handle cases like this:
|
| - // class Foo {
|
| - // var map;
|
| - // Foo() : map = <String, Foo>{};
|
| - // Foo.x() : map = true ? <String, Foo>{} : <String, Foo>{};
|
| - // }
|
| - BeginGroupToken begin = token.next;
|
| - token = (begin.endGroup != null) ? begin.endGroup : token;
|
| - token = token.next;
|
| - if (identical(token.stringValue, '{')) {
|
| - begin = token;
|
| - token = (begin.endGroup != null) ? begin.endGroup : token;
|
| - token = token.next;
|
| - }
|
| - continue;
|
| - }
|
| - }
|
| - if (!mayParseFunctionExpressions && identical(value, '{')) {
|
| - break;
|
| - }
|
| - if (token is BeginGroupToken) {
|
| - BeginGroupToken begin = token;
|
| - token = (begin.endGroup != null) ? begin.endGroup : token;
|
| - } else if (token is ErrorToken) {
|
| - listener.reportErrorToken(token);
|
| - }
|
| - token = token.next;
|
| - }
|
| - return token;
|
| - }
|
| -
|
| - Token skipAsyncModifier(Token token) {
|
| - String value = token.stringValue;
|
| - if (identical(value, 'async')) {
|
| - token = token.next;
|
| - value = token.stringValue;
|
| -
|
| - if (identical(value, '*')) {
|
| - token = token.next;
|
| - }
|
| - } else if (identical(value, 'sync')) {
|
| - token = token.next;
|
| - value = token.stringValue;
|
| -
|
| - if (identical(value, '*')) {
|
| - token = token.next;
|
| - }
|
| - }
|
| - return token;
|
| - }
|
| + // This method is overridden for two reasons:
|
| + // 1. Avoid generating events for arguments.
|
| + // 2. Avoid calling skip expression for each argument (which doesn't work).
|
| + Token parseArgumentsOpt(Token token) => skipArgumentsOpt(token);
|
|
|
| Token parseFunctionBody(Token token, bool isExpression, bool allowAbstract) {
|
| - assert(!isExpression);
|
| - token = skipAsyncModifier(token);
|
| - String value = token.stringValue;
|
| - if (identical(value, ';')) {
|
| - if (!allowAbstract) {
|
| - listener.reportError(token, ErrorKind.EXPECTED_BODY);
|
| - }
|
| - listener.handleNoFunctionBody(token);
|
| - } else {
|
| - if (identical(value, '=>')) {
|
| - token = parseExpression(token.next);
|
| - expectSemicolon(token);
|
| - } else if (value == '=') {
|
| - token = parseRedirectingFactoryBody(token);
|
| - expectSemicolon(token);
|
| - } else {
|
| - token = skipBlock(token);
|
| - }
|
| - listener.skippedFunctionBody(token);
|
| - }
|
| - return token;
|
| + return skipFunctionBody(token, isExpression, allowAbstract);
|
| }
|
| }
|
|
|