| OLD | NEW |
| 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 dart_parser; | 5 library dart_parser; |
| 6 | 6 |
| 7 import 'package:dart_scanner/src/keyword.dart' show | 7 import 'package:dart_scanner/src/keyword.dart' show |
| 8 Keyword; | 8 Keyword; |
| 9 | 9 |
| 10 import 'package:dart_scanner/src/precedence.dart' show | 10 import 'package:dart_scanner/src/precedence.dart' show |
| (...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 thisKeyword = token; | 460 thisKeyword = token; |
| 461 // TODO(ahe): Validate field initializers are only used in | 461 // TODO(ahe): Validate field initializers are only used in |
| 462 // constructors, and not for function-typed arguments. | 462 // constructors, and not for function-typed arguments. |
| 463 token = expect('.', token.next); | 463 token = expect('.', token.next); |
| 464 } | 464 } |
| 465 token = parseIdentifier(token); | 465 token = parseIdentifier(token); |
| 466 if (optional('(', token)) { | 466 if (optional('(', token)) { |
| 467 listener.beginFunctionTypedFormalParameter(token); | 467 listener.beginFunctionTypedFormalParameter(token); |
| 468 listener.handleNoTypeVariables(token); | 468 listener.handleNoTypeVariables(token); |
| 469 token = parseFormalParameters(token); | 469 token = parseFormalParameters(token); |
| 470 listener.handleFunctionTypedFormalParameter(token); | 470 listener.endFunctionTypedFormalParameter(token); |
| 471 } else if (optional('<', token)) { | 471 } else if (optional('<', token)) { |
| 472 listener.beginFunctionTypedFormalParameter(token); | 472 listener.beginFunctionTypedFormalParameter(token); |
| 473 token = parseTypeVariablesOpt(token); | 473 token = parseTypeVariablesOpt(token); |
| 474 token = parseFormalParameters(token); | 474 token = parseFormalParameters(token); |
| 475 listener.handleFunctionTypedFormalParameter(token); | 475 listener.endFunctionTypedFormalParameter(token); |
| 476 } | 476 } |
| 477 String value = token.stringValue; | 477 String value = token.stringValue; |
| 478 if ((identical('=', value)) || (identical(':', value))) { | 478 if ((identical('=', value)) || (identical(':', value))) { |
| 479 // TODO(ahe): Validate that these are only used for optional parameters. | 479 // TODO(ahe): Validate that these are only used for optional parameters. |
| 480 Token equal = token; | 480 Token equal = token; |
| 481 token = parseExpression(token.next); | 481 token = parseExpression(token.next); |
| 482 listener.handleValuedFormalParameter(equal, token); | 482 listener.handleValuedFormalParameter(equal, token); |
| 483 if (type.isRequired) { | 483 if (type.isRequired) { |
| 484 listener.reportError( | 484 listener.reportError( |
| 485 equal, ErrorKind.RequiredParameterWithDefault); | 485 equal, ErrorKind.RequiredParameterWithDefault); |
| (...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1060 parseType(type); | 1060 parseType(type); |
| 1061 if (isVar) { | 1061 if (isVar) { |
| 1062 listener.reportError(modifiers.head, ErrorKind.ExtraneousModifier, | 1062 listener.reportError(modifiers.head, ErrorKind.ExtraneousModifier, |
| 1063 {'modifier': modifiers.head}); | 1063 {'modifier': modifiers.head}); |
| 1064 } | 1064 } |
| 1065 } | 1065 } |
| 1066 | 1066 |
| 1067 Token token = parseIdentifier(name); | 1067 Token token = parseIdentifier(name); |
| 1068 | 1068 |
| 1069 int fieldCount = 1; | 1069 int fieldCount = 1; |
| 1070 token = parseVariableInitializerOpt(token); | 1070 token = parseFieldInitializerOpt(token); |
| 1071 while (optional(',', token)) { | 1071 while (optional(',', token)) { |
| 1072 token = parseIdentifier(token.next); | 1072 token = parseIdentifier(token.next); |
| 1073 token = parseVariableInitializerOpt(token); | 1073 token = parseFieldInitializerOpt(token); |
| 1074 ++fieldCount; | 1074 ++fieldCount; |
| 1075 } | 1075 } |
| 1076 Token semicolon = token; | 1076 Token semicolon = token; |
| 1077 token = expectSemicolon(token); | 1077 token = expectSemicolon(token); |
| 1078 if (isTopLevel) { | 1078 if (isTopLevel) { |
| 1079 listener.endTopLevelFields(fieldCount, start, semicolon); | 1079 listener.endTopLevelFields(fieldCount, start, semicolon); |
| 1080 } else { | 1080 } else { |
| 1081 listener.endFields(fieldCount, start, semicolon); | 1081 listener.endFields(fieldCount, start, semicolon); |
| 1082 } | 1082 } |
| 1083 return token; | 1083 return token; |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1204 } | 1204 } |
| 1205 token = beginGroup.endGroup; | 1205 token = beginGroup.endGroup; |
| 1206 } | 1206 } |
| 1207 } | 1207 } |
| 1208 } | 1208 } |
| 1209 token = token.next; | 1209 token = token.next; |
| 1210 } | 1210 } |
| 1211 return const Link<Token>(); | 1211 return const Link<Token>(); |
| 1212 } | 1212 } |
| 1213 | 1213 |
| 1214 Token parseFieldInitializerOpt(Token token) { |
| 1215 if (optional('=', token)) { |
| 1216 Token assignment = token; |
| 1217 listener.beginFieldInitializer(token); |
| 1218 token = parseExpression(token.next); |
| 1219 listener.endFieldInitializer(assignment); |
| 1220 } |
| 1221 return token; |
| 1222 } |
| 1223 |
| 1214 Token parseVariableInitializerOpt(Token token) { | 1224 Token parseVariableInitializerOpt(Token token) { |
| 1215 if (optional('=', token)) { | 1225 if (optional('=', token)) { |
| 1216 Token assignment = token; | 1226 Token assignment = token; |
| 1217 // TODO(ahe): Rename this to beginVariableInitializer. | 1227 listener.beginVariableInitializer(token); |
| 1218 listener.beginInitializer(token); | |
| 1219 token = parseExpression(token.next); | 1228 token = parseExpression(token.next); |
| 1220 // TODO(ahe): Rename this to endVariableInitializer. | 1229 listener.endVariableInitializer(assignment); |
| 1221 listener.endInitializer(assignment); | |
| 1222 } | 1230 } |
| 1223 return token; | 1231 return token; |
| 1224 } | 1232 } |
| 1225 | 1233 |
| 1226 Token parseInitializersOpt(Token token) { | 1234 Token parseInitializersOpt(Token token) { |
| 1227 if (optional(':', token)) { | 1235 if (optional(':', token)) { |
| 1228 return parseInitializers(token); | 1236 return parseInitializers(token); |
| 1229 } else { | 1237 } else { |
| 1230 listener.handleNoInitializers(); | 1238 listener.handleNoInitializers(); |
| 1231 return token; | 1239 return token; |
| 1232 } | 1240 } |
| 1233 } | 1241 } |
| 1234 | 1242 |
| 1235 Token parseInitializers(Token token) { | 1243 Token parseInitializers(Token token) { |
| 1236 Token begin = token; | 1244 Token begin = token; |
| 1237 listener.beginInitializers(begin); | 1245 listener.beginInitializers(begin); |
| 1238 expect(':', token); | 1246 expect(':', token); |
| 1239 int count = 0; | 1247 int count = 0; |
| 1240 bool old = mayParseFunctionExpressions; | 1248 bool old = mayParseFunctionExpressions; |
| 1241 mayParseFunctionExpressions = false; | 1249 mayParseFunctionExpressions = false; |
| 1242 do { | 1250 do { |
| 1243 token = token.next; | 1251 token = token.next; |
| 1244 listener.beginConstructorInitializer(token); | 1252 listener.beginInitializer(token); |
| 1245 token = parseExpression(token); | 1253 token = parseExpression(token); |
| 1246 listener.endConstructorInitializer(token); | 1254 listener.endInitializer(token); |
| 1247 ++count; | 1255 ++count; |
| 1248 } while (optional(',', token)); | 1256 } while (optional(',', token)); |
| 1249 mayParseFunctionExpressions = old; | 1257 mayParseFunctionExpressions = old; |
| 1250 listener.endInitializers(count, begin, token); | 1258 listener.endInitializers(count, begin, token); |
| 1251 return token; | 1259 return token; |
| 1252 } | 1260 } |
| 1253 | 1261 |
| 1254 Token parseLiteralStringOrRecoverExpression(Token token) { | 1262 Token parseLiteralStringOrRecoverExpression(Token token) { |
| 1255 if (identical(token.kind, STRING_TOKEN)) { | 1263 if (identical(token.kind, STRING_TOKEN)) { |
| 1256 return parseLiteralString(token); | 1264 return parseLiteralString(token); |
| (...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1723 } else { | 1731 } else { |
| 1724 if (identical(value, '=>')) { | 1732 if (identical(value, '=>')) { |
| 1725 token = parseExpression(token.next); | 1733 token = parseExpression(token.next); |
| 1726 expectSemicolon(token); | 1734 expectSemicolon(token); |
| 1727 } else if (value == '=') { | 1735 } else if (value == '=') { |
| 1728 token = parseRedirectingFactoryBody(token); | 1736 token = parseRedirectingFactoryBody(token); |
| 1729 expectSemicolon(token); | 1737 expectSemicolon(token); |
| 1730 } else { | 1738 } else { |
| 1731 token = skipBlock(token); | 1739 token = skipBlock(token); |
| 1732 } | 1740 } |
| 1733 listener.skippedFunctionBody(token); | 1741 listener.handleFunctionBodySkipped(token); |
| 1734 } | 1742 } |
| 1735 return token; | 1743 return token; |
| 1736 } | 1744 } |
| 1737 | 1745 |
| 1738 Token parseFunctionBody(Token token, bool isExpression, bool allowAbstract) { | 1746 Token parseFunctionBody(Token token, bool isExpression, bool allowAbstract) { |
| 1739 if (optional(';', token)) { | 1747 if (optional(';', token)) { |
| 1740 if (!allowAbstract) { | 1748 if (!allowAbstract) { |
| 1741 listener.reportError(token, ErrorKind.ExpectedBody); | 1749 listener.reportError(token, ErrorKind.ExpectedBody); |
| 1742 } | 1750 } |
| 1743 listener.endFunctionBody(0, null, token); | 1751 listener.endFunctionBody(0, null, token); |
| (...skipping 1426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3170 } | 3178 } |
| 3171 listener.handleContinueStatement(hasTarget, continueKeyword, token); | 3179 listener.handleContinueStatement(hasTarget, continueKeyword, token); |
| 3172 return expectSemicolon(token); | 3180 return expectSemicolon(token); |
| 3173 } | 3181 } |
| 3174 | 3182 |
| 3175 Token parseEmptyStatement(Token token) { | 3183 Token parseEmptyStatement(Token token) { |
| 3176 listener.handleEmptyStatement(token); | 3184 listener.handleEmptyStatement(token); |
| 3177 return expectSemicolon(token); | 3185 return expectSemicolon(token); |
| 3178 } | 3186 } |
| 3179 } | 3187 } |
| OLD | NEW |