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

Side by Side Diff: pkg/front_end/lib/src/fasta/parser/parser.dart

Issue 2723883002: Add AstBuilder support for fields. (Closed)
Patch Set: Created 3 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 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 fasta.parser.parser; 5 library fasta.parser.parser;
6 6
7 import '../scanner.dart' show ErrorToken; 7 import '../scanner.dart' show ErrorToken;
8 8
9 import '../scanner/recover.dart' show closeBraceFor, skipToEof; 9 import '../scanner/recover.dart' show closeBraceFor, skipToEof;
10 10
(...skipping 1147 matching lines...) Expand 10 before | Expand all | Expand 10 after
1158 return modifiers; 1158 return modifiers;
1159 } 1159 }
1160 } 1160 }
1161 return modifiers.tail; 1161 return modifiers.tail;
1162 } 1162 }
1163 1163
1164 Token parseFields(Token start, Link<Token> modifiers, Token type, 1164 Token parseFields(Token start, Link<Token> modifiers, Token type,
1165 Token getOrSet, Token name, bool isTopLevel) { 1165 Token getOrSet, Token name, bool isTopLevel) {
1166 bool hasType = type != null; 1166 bool hasType = type != null;
1167 1167
1168 Token covariantKeyword;
1168 if (getOrSet == null && !isTopLevel) { 1169 if (getOrSet == null && !isTopLevel) {
1169 modifiers = removeOptCovariantTokenIfNotStatic(modifiers); 1170 Link<Token> newModifiers = removeOptCovariantTokenIfNotStatic(modifiers);
ahe 2017/03/01 15:20:31 This is horrible. But that's not your fault. Would
Paul Berry 2017/03/01 21:08:22 Done.
1171 if (!identical(newModifiers, modifiers)) {
1172 covariantKeyword = modifiers.first;
1173 modifiers = newModifiers;
1174 }
1170 } 1175 }
1171 1176
1172 Token varFinalOrConst = 1177 Token varFinalOrConst =
1173 expectVarFinalOrConst(modifiers, hasType, !isTopLevel); 1178 expectVarFinalOrConst(modifiers, hasType, !isTopLevel);
1174 bool isVar = false; 1179 bool isVar = false;
1175 bool hasModifier = false; 1180 bool hasModifier = false;
1176 if (varFinalOrConst != null) { 1181 if (varFinalOrConst != null) {
1177 hasModifier = true; 1182 hasModifier = true;
1178 isVar = optional('var', varFinalOrConst); 1183 isVar = optional('var', varFinalOrConst);
1179 } 1184 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1212 while (optional(',', token)) { 1217 while (optional(',', token)) {
1213 token = parseIdentifier(token.next, context); 1218 token = parseIdentifier(token.next, context);
1214 token = parseFieldInitializerOpt(token); 1219 token = parseFieldInitializerOpt(token);
1215 ++fieldCount; 1220 ++fieldCount;
1216 } 1221 }
1217 Token semicolon = token; 1222 Token semicolon = token;
1218 token = expectSemicolon(token); 1223 token = expectSemicolon(token);
1219 if (isTopLevel) { 1224 if (isTopLevel) {
1220 listener.endTopLevelFields(fieldCount, start, semicolon); 1225 listener.endTopLevelFields(fieldCount, start, semicolon);
1221 } else { 1226 } else {
1222 listener.endFields(fieldCount, start, semicolon); 1227 listener.endFields(fieldCount, covariantKeyword, start, semicolon);
1223 } 1228 }
1224 return token; 1229 return token;
1225 } 1230 }
1226 1231
1227 Token parseTopLevelMethod(Token start, Link<Token> modifiers, Token type, 1232 Token parseTopLevelMethod(Token start, Link<Token> modifiers, Token type,
1228 Token getOrSet, Token name) { 1233 Token getOrSet, Token name) {
1229 listener.beginTopLevelMethod(start, name); 1234 listener.beginTopLevelMethod(start, name);
1230 Token externalModifier; 1235 Token externalModifier;
1231 // TODO(johnniwinther): Move error reporting to resolution to give more 1236 // TODO(johnniwinther): Move error reporting to resolution to give more
1232 // specific error messages. 1237 // specific error messages.
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
1709 isField = true; 1714 isField = true;
1710 } 1715 }
1711 break; 1716 break;
1712 } else if ((identical(value, '=')) || (identical(value, ','))) { 1717 } else if ((identical(value, '=')) || (identical(value, ','))) {
1713 isField = true; 1718 isField = true;
1714 break; 1719 break;
1715 } else { 1720 } else {
1716 token = reportUnrecoverableError(token, ErrorKind.UnexpectedToken); 1721 token = reportUnrecoverableError(token, ErrorKind.UnexpectedToken);
1717 if (identical(token.kind, EOF_TOKEN)) { 1722 if (identical(token.kind, EOF_TOKEN)) {
1718 // TODO(ahe): This is a hack, see parseTopLevelMember. 1723 // TODO(ahe): This is a hack, see parseTopLevelMember.
1719 listener.endFields(1, start, token); 1724 listener.endFields(1, null, start, token);
1720 listener.endMember(); 1725 listener.endMember();
1721 return token; 1726 return token;
1722 } 1727 }
1723 } 1728 }
1724 } 1729 }
1725 1730
1726 var modifiers = identifiers.reverse(); 1731 var modifiers = identifiers.reverse();
1727 token = isField 1732 token = isField
1728 ? parseFields(start, modifiers, type, getOrSet, name, false) 1733 ? parseFields(start, modifiers, type, getOrSet, name, false)
1729 : parseMethod(start, modifiers, type, getOrSet, name); 1734 : parseMethod(start, modifiers, type, getOrSet, name);
(...skipping 1811 matching lines...) Expand 10 before | Expand all | Expand 10 after
3541 break; 3546 break;
3542 } 3547 }
3543 if (isRecoverable) { 3548 if (isRecoverable) {
3544 listener.handleRecoverableError(token, kind, arguments); 3549 listener.handleRecoverableError(token, kind, arguments);
3545 return null; 3550 return null;
3546 } else { 3551 } else {
3547 return listener.handleUnrecoverableError(token, kind, arguments); 3552 return listener.handleUnrecoverableError(token, kind, arguments);
3548 } 3553 }
3549 } 3554 }
3550 } 3555 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698