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

Side by Side Diff: pkg/compiler/lib/src/parser/parser.dart

Issue 2385643003: Fixes in dart2js parser to be able to parse files without the diet-parser (Closed)
Patch Set: Created 4 years, 2 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 dart2js.parser; 5 library dart2js.parser;
6 6
7 import '../common.dart'; 7 import '../common.dart';
8 import '../options.dart' show ParserOptions; 8 import '../options.dart' show ParserOptions;
9 import '../tokens/keyword.dart' show Keyword; 9 import '../tokens/keyword.dart' show Keyword;
10 import '../tokens/precedence.dart' show PrecedenceInfo; 10 import '../tokens/precedence.dart' show PrecedenceInfo;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 Parser(this.listener, ParserOptions parserOptions, 105 Parser(this.listener, ParserOptions parserOptions,
106 {this.asyncAwaitKeywordsEnabled: false}) 106 {this.asyncAwaitKeywordsEnabled: false})
107 : parserOptions = parserOptions, 107 : parserOptions = parserOptions,
108 enableGenericMethodSyntax = parserOptions.enableGenericMethodSyntax; 108 enableGenericMethodSyntax = parserOptions.enableGenericMethodSyntax;
109 109
110 Token parseUnit(Token token) { 110 Token parseUnit(Token token) {
111 listener.beginCompilationUnit(token); 111 listener.beginCompilationUnit(token);
112 int count = 0; 112 int count = 0;
113 while (!identical(token.kind, EOF_TOKEN)) { 113 while (!identical(token.kind, EOF_TOKEN)) {
114 token = parseTopLevelDeclaration(token); 114 token = parseTopLevelDeclaration(token);
115 listener.endTopLevelDeclaration(token);
116 count++; 115 count++;
117 } 116 }
118 listener.endCompilationUnit(count, token); 117 listener.endCompilationUnit(count, token);
119 return token; 118 return token;
120 } 119 }
121 120
122 Token parseTopLevelDeclaration(Token token) { 121 Token parseTopLevelDeclaration(Token token) {
122 token = _parseTopLevelDeclaration(token);
123 listener.endTopLevelDeclaration(token);
Siggi Cherem (dart-lang) 2016/09/30 22:28:07 note: this moved down here because when we parse a
124 return token;
125 }
126
127 Token _parseTopLevelDeclaration(Token token) {
123 token = parseMetadataStar(token); 128 token = parseMetadataStar(token);
124 final String value = token.stringValue; 129 final String value = token.stringValue;
125 if ((identical(value, 'abstract') && optional('class', token.next)) || 130 if ((identical(value, 'abstract') && optional('class', token.next)) ||
126 identical(value, 'class')) { 131 identical(value, 'class')) {
127 return parseClassOrNamedMixinApplication(token); 132 return parseClassOrNamedMixinApplication(token);
128 } else if (identical(value, 'enum')) { 133 } else if (identical(value, 'enum')) {
129 return parseEnum(token); 134 return parseEnum(token);
130 } else if (identical(value, 'typedef')) { 135 } else if (identical(value, 'typedef')) {
131 return parseTypedef(token); 136 return parseTypedef(token);
132 } else if (identical(value, 'library')) { 137 } else if (identical(value, 'library')) {
(...skipping 1217 matching lines...) Expand 10 before | Expand all | Expand 10 after
1350 } 1355 }
1351 1356
1352 bool isFactoryDeclaration(Token token) { 1357 bool isFactoryDeclaration(Token token) {
1353 if (optional('external', token)) token = token.next; 1358 if (optional('external', token)) token = token.next;
1354 if (optional('const', token)) token = token.next; 1359 if (optional('const', token)) token = token.next;
1355 return optional('factory', token); 1360 return optional('factory', token);
1356 } 1361 }
1357 1362
1358 Token parseMember(Token token) { 1363 Token parseMember(Token token) {
1359 token = parseMetadataStar(token); 1364 token = parseMetadataStar(token);
1360 if (isFactoryDeclaration(token)) {
1361 return parseFactoryMethod(token);
1362 }
1363 Token start = token; 1365 Token start = token;
1364 listener.beginMember(token); 1366 listener.beginMember(token);
1367 if (isFactoryDeclaration(token)) {
1368 token = parseFactoryMethod(token);
1369 listener.endMember();
1370 assert (token != null);
1371 return token;
1372 }
1365 1373
1366 Link<Token> identifiers = findMemberName(token); 1374 Link<Token> identifiers = findMemberName(token);
1367 if (identifiers.isEmpty) { 1375 if (identifiers.isEmpty) {
1368 return listener.expectedDeclaration(start); 1376 return listener.expectedDeclaration(start);
1369 } 1377 }
1370 Token afterName = identifiers.head; 1378 Token afterName = identifiers.head;
1371 identifiers = identifiers.tail; 1379 identifiers = identifiers.tail;
1372 1380
1373 if (identifiers.isEmpty) { 1381 if (identifiers.isEmpty) {
1374 return listener.expectedDeclaration(start); 1382 return listener.expectedDeclaration(start);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1420 } 1428 }
1421 break; 1429 break;
1422 } else if ((identical(value, '=')) || (identical(value, ','))) { 1430 } else if ((identical(value, '=')) || (identical(value, ','))) {
1423 isField = true; 1431 isField = true;
1424 break; 1432 break;
1425 } else { 1433 } else {
1426 token = listener.unexpected(token); 1434 token = listener.unexpected(token);
1427 if (identical(token.kind, EOF_TOKEN)) { 1435 if (identical(token.kind, EOF_TOKEN)) {
1428 // TODO(ahe): This is a hack, see parseTopLevelMember. 1436 // TODO(ahe): This is a hack, see parseTopLevelMember.
1429 listener.endFields(1, start, token); 1437 listener.endFields(1, start, token);
1438 listener.endMember();
1430 return token; 1439 return token;
1431 } 1440 }
1432 } 1441 }
1433 } 1442 }
1434 1443
1435 var modifiers = identifiers.reverse(); 1444 var modifiers = identifiers.reverse();
1436 return isField 1445 token = isField
1437 ? parseFields(start, modifiers, type, getOrSet, name, false) 1446 ? parseFields(start, modifiers, type, getOrSet, name, false)
1438 : parseMethod(start, modifiers, type, getOrSet, name); 1447 : parseMethod(start, modifiers, type, getOrSet, name);
1448 listener.endMember();
1449 return token;
1439 } 1450 }
1440 1451
1441 Token parseMethod(Token start, Link<Token> modifiers, Token type, 1452 Token parseMethod(Token start, Link<Token> modifiers, Token type,
1442 Token getOrSet, Token name) { 1453 Token getOrSet, Token name) {
1443 Token externalModifier; 1454 Token externalModifier;
1444 Token staticModifier; 1455 Token staticModifier;
1445 Token constModifier; 1456 Token constModifier;
1446 int modifierCount = 0; 1457 int modifierCount = 0;
1447 int allowedModifierCount = 1; 1458 int allowedModifierCount = 1;
1448 // TODO(johnniwinther): Move error reporting to resolution to give more 1459 // TODO(johnniwinther): Move error reporting to resolution to give more
(...skipping 1547 matching lines...) Expand 10 before | Expand all | Expand 10 after
2996 } 3007 }
2997 listener.handleContinueStatement(hasTarget, continueKeyword, token); 3008 listener.handleContinueStatement(hasTarget, continueKeyword, token);
2998 return expectSemicolon(token); 3009 return expectSemicolon(token);
2999 } 3010 }
3000 3011
3001 Token parseEmptyStatement(Token token) { 3012 Token parseEmptyStatement(Token token) {
3002 listener.handleEmptyStatement(token); 3013 listener.handleEmptyStatement(token);
3003 return expectSemicolon(token); 3014 return expectSemicolon(token);
3004 } 3015 }
3005 } 3016 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698