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

Side by Side Diff: pkg/analyzer/lib/src/generated/parser.dart

Issue 2492633002: Create AST structure for asserts in constructor initializers (Closed)
Patch Set: Created 4 years, 1 month 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analyzer.src.generated.parser; 5 library analyzer.src.generated.parser;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import "dart:math" as math; 8 import "dart:math" as math;
9 9
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
(...skipping 5963 matching lines...) Expand 10 before | Expand all | Expand 10 after
5974 } 5974 }
5975 5975
5976 /** 5976 /**
5977 * Parse an assert within a constructor's initializer list. Return the assert. 5977 * Parse an assert within a constructor's initializer list. Return the assert.
5978 * 5978 *
5979 * This method assumes that the current token matches `Keyword.ASSERT`. 5979 * This method assumes that the current token matches `Keyword.ASSERT`.
5980 * 5980 *
5981 * assertInitializer ::= 5981 * assertInitializer ::=
5982 * 'assert' '(' expression [',' expression] ')' 5982 * 'assert' '(' expression [',' expression] ')'
5983 */ 5983 */
5984 void _parseAssertInitializer() { 5984 AssertInitializer _parseAssertInitializer() {
5985 // TODO(brianwilkerson) Capture the syntax in the AST using a new class,
5986 // such as AssertInitializer
5987 Token keyword = getAndAdvance(); 5985 Token keyword = getAndAdvance();
5988 Token leftParen = _expect(TokenType.OPEN_PAREN); 5986 Token leftParen = _expect(TokenType.OPEN_PAREN);
5989 Expression expression = parseExpression2(); 5987 Expression expression = parseExpression2();
5990 Token comma; 5988 Token comma;
5991 Expression message; 5989 Expression message;
5992 if (_matches(TokenType.COMMA)) { 5990 if (_matches(TokenType.COMMA)) {
5993 comma = getAndAdvance(); 5991 comma = getAndAdvance();
5994 message = parseExpression2(); 5992 message = parseExpression2();
5995 } 5993 }
5996 Token rightParen = _expect(TokenType.CLOSE_PAREN); 5994 Token rightParen = _expect(TokenType.CLOSE_PAREN);
5997 // return new AssertInitializer( 5995 return new AssertInitializer(
5998 // keyword, leftParen, expression, comma, message, rightParen); 5996 keyword, leftParen, expression, comma, message, rightParen);
5999 } 5997 }
6000 5998
6001 /** 5999 /**
6002 * Parse an assignable expression given that the current token is not 'super'. 6000 * Parse an assignable expression given that the current token is not 'super'.
6003 * The [primaryAllowed] is `true` if the expression is allowed to be a primary 6001 * The [primaryAllowed] is `true` if the expression is allowed to be a primary
6004 * without any assignable selector. Return the assignable expression that was 6002 * without any assignable selector. Return the assignable expression that was
6005 * parsed. 6003 * parsed.
6006 */ 6004 */
6007 Expression _parseAssignableExpressionNotStartingWithSuper( 6005 Expression _parseAssignableExpressionNotStartingWithSuper(
6008 bool primaryAllowed) { 6006 bool primaryAllowed) {
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
6223 } else { 6221 } else {
6224 initializers.add(parseConstructorFieldInitializer(true)); 6222 initializers.add(parseConstructorFieldInitializer(true));
6225 } 6223 }
6226 } else if (keyword == Keyword.SUPER) { 6224 } else if (keyword == Keyword.SUPER) {
6227 initializers.add(parseSuperConstructorInvocation()); 6225 initializers.add(parseSuperConstructorInvocation());
6228 } else if (_matches(TokenType.OPEN_CURLY_BRACKET) || 6226 } else if (_matches(TokenType.OPEN_CURLY_BRACKET) ||
6229 _matches(TokenType.FUNCTION)) { 6227 _matches(TokenType.FUNCTION)) {
6230 _reportErrorForCurrentToken(ParserErrorCode.MISSING_INITIALIZER); 6228 _reportErrorForCurrentToken(ParserErrorCode.MISSING_INITIALIZER);
6231 } else if (_enableAssertInitializer && 6229 } else if (_enableAssertInitializer &&
6232 _matchesKeyword(Keyword.ASSERT)) { 6230 _matchesKeyword(Keyword.ASSERT)) {
6233 _parseAssertInitializer(); 6231 initializers.add(_parseAssertInitializer());
6234 } else { 6232 } else {
6235 initializers.add(parseConstructorFieldInitializer(false)); 6233 initializers.add(parseConstructorFieldInitializer(false));
6236 } 6234 }
6237 } while (_optional(TokenType.COMMA)); 6235 } while (_optional(TokenType.COMMA));
6238 if (factoryKeyword != null) { 6236 if (factoryKeyword != null) {
6239 _reportErrorForToken( 6237 _reportErrorForToken(
6240 ParserErrorCode.FACTORY_WITH_INITIALIZERS, factoryKeyword); 6238 ParserErrorCode.FACTORY_WITH_INITIALIZERS, factoryKeyword);
6241 } 6239 }
6242 } 6240 }
6243 ConstructorName redirectedConstructor = null; 6241 ConstructorName redirectedConstructor = null;
(...skipping 1878 matching lines...) Expand 10 before | Expand all | Expand 10 after
8122 */ 8120 */
8123 Parser_SyntheticKeywordToken(Keyword keyword, int offset) 8121 Parser_SyntheticKeywordToken(Keyword keyword, int offset)
8124 : super(keyword, offset); 8122 : super(keyword, offset);
8125 8123
8126 @override 8124 @override
8127 int get length => 0; 8125 int get length => 0;
8128 8126
8129 @override 8127 @override
8130 Token copy() => new Parser_SyntheticKeywordToken(keyword, offset); 8128 Token copy() => new Parser_SyntheticKeywordToken(keyword, offset);
8131 } 8129 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/error_verifier.dart ('k') | pkg/analyzer/lib/src/generated/resolver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698