Chromium Code Reviews| 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 fasta.parser.parser; | 5 library fasta.parser.parser; |
| 6 | 6 |
| 7 import '../fasta_codes.dart' show Code, Message, Template; | 7 import '../fasta_codes.dart' show Code, Message, Template; |
| 8 | 8 |
| 9 import '../fasta_codes.dart' as fasta; | 9 import '../fasta_codes.dart' as fasta; |
| 10 | 10 |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 217 | 217 |
| 218 bool get inAsync { | 218 bool get inAsync { |
| 219 return asyncState == AsyncModifier.Async || | 219 return asyncState == AsyncModifier.Async || |
| 220 asyncState == AsyncModifier.AsyncStar; | 220 asyncState == AsyncModifier.AsyncStar; |
| 221 } | 221 } |
| 222 | 222 |
| 223 bool get inPlainSync => asyncState == AsyncModifier.Sync; | 223 bool get inPlainSync => asyncState == AsyncModifier.Sync; |
| 224 | 224 |
| 225 Token parseUnit(Token token) { | 225 Token parseUnit(Token token) { |
| 226 listener.beginCompilationUnit(token); | 226 listener.beginCompilationUnit(token); |
| 227 int count = 0; | 227 _topLevelDeclarationCount = 0; |
| 228 while (!identical(token.kind, EOF_TOKEN)) { | 228 while (!identical(token.kind, EOF_TOKEN)) { |
| 229 token = parseTopLevelDeclaration(token); | 229 token = parseTopLevelDeclaration(token); |
| 230 count++; | |
| 231 } | 230 } |
| 232 listener.endCompilationUnit(count, token); | 231 listener.endCompilationUnit(_topLevelDeclarationCount, token); |
| 233 return token; | 232 return token; |
| 234 } | 233 } |
| 235 | 234 |
| 235 int _topLevelDeclarationCount = 0; | |
|
ahe
2017/08/07 13:31:00
Why is this a field now?
danrubel
2017/08/15 20:13:32
Per our discussion, I've reverted this so that inv
| |
| 236 | |
| 236 Token parseTopLevelDeclaration(Token token) { | 237 Token parseTopLevelDeclaration(Token token) { |
| 237 token = _parseTopLevelDeclaration(token); | 238 Token start = token; |
| 239 if (token.type == TokenType.SCRIPT_TAG) { | |
| 240 token = parseScript(token); | |
| 241 } else { | |
| 242 token = parseMetadataStar(token); | |
| 243 final String value = token.stringValue; | |
| 244 if ((identical(value, 'abstract') && optional('class', token.next)) || | |
| 245 identical(value, 'class')) { | |
| 246 token = parseClassOrNamedMixinApplication(token); | |
| 247 } else if (identical(value, 'enum')) { | |
| 248 token = parseEnum(token); | |
| 249 } else if (identical(value, 'typedef') && | |
| 250 (token.next.isIdentifier || optional("void", token.next))) { | |
| 251 token = parseTypedef(token); | |
| 252 } else if (identical(value, 'library')) { | |
| 253 token = parseLibraryName(token); | |
| 254 } else if (identical(value, 'import')) { | |
| 255 token = parseImport(token); | |
| 256 } else if (identical(value, 'export')) { | |
| 257 token = parseExport(token); | |
| 258 } else if (identical(value, 'part')) { | |
| 259 token = parsePartOrPartOf(token); | |
| 260 } else if (token.type == TokenType.IDENTIFIER || token.keyword != null) { | |
| 261 token = parseTopLevelMember(token); | |
| 262 } else { | |
| 263 reportRecoverableErrorWithToken( | |
| 264 token, fasta.templateExpectedDeclaration); | |
| 265 listener.handleInvalidTopLevelDeclaration(start, token); | |
| 266 return token.next; | |
| 267 } | |
| 268 } | |
| 238 listener.endTopLevelDeclaration(token); | 269 listener.endTopLevelDeclaration(token); |
| 270 ++_topLevelDeclarationCount; | |
| 239 return token; | 271 return token; |
| 240 } | 272 } |
| 241 | 273 |
| 242 Token _parseTopLevelDeclaration(Token token) { | |
| 243 if (identical(token.type, TokenType.SCRIPT_TAG)) { | |
| 244 return parseScript(token); | |
| 245 } | |
| 246 token = parseMetadataStar(token); | |
| 247 final String value = token.stringValue; | |
| 248 if ((identical(value, 'abstract') && optional('class', token.next)) || | |
| 249 identical(value, 'class')) { | |
| 250 return parseClassOrNamedMixinApplication(token); | |
| 251 } else if (identical(value, 'enum')) { | |
| 252 return parseEnum(token); | |
| 253 } else if (identical(value, 'typedef') && | |
| 254 (token.next.isIdentifier || optional("void", token.next))) { | |
| 255 return parseTypedef(token); | |
| 256 } else if (identical(value, 'library')) { | |
| 257 return parseLibraryName(token); | |
| 258 } else if (identical(value, 'import')) { | |
| 259 return parseImport(token); | |
| 260 } else if (identical(value, 'export')) { | |
| 261 return parseExport(token); | |
| 262 } else if (identical(value, 'part')) { | |
| 263 return parsePartOrPartOf(token); | |
| 264 } else { | |
| 265 return parseTopLevelMember(token); | |
| 266 } | |
| 267 } | |
| 268 | |
| 269 /// library qualified ';' | 274 /// library qualified ';' |
| 270 Token parseLibraryName(Token token) { | 275 Token parseLibraryName(Token token) { |
| 271 Token libraryKeyword = token; | 276 Token libraryKeyword = token; |
| 272 listener.beginLibraryName(libraryKeyword); | 277 listener.beginLibraryName(libraryKeyword); |
| 273 assert(optional('library', token)); | 278 assert(optional('library', token)); |
| 274 token = parseQualified(token.next, IdentifierContext.libraryName, | 279 token = parseQualified(token.next, IdentifierContext.libraryName, |
| 275 IdentifierContext.libraryNameContinuation); | 280 IdentifierContext.libraryNameContinuation); |
| 276 Token semicolon = token; | 281 Token semicolon = token; |
| 277 token = expect(';', token); | 282 token = expect(';', token); |
| 278 listener.endLibraryName(libraryKeyword, semicolon); | 283 listener.endLibraryName(libraryKeyword, semicolon); |
| (...skipping 3724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4003 } | 4008 } |
| 4004 | 4009 |
| 4005 Token reportUnexpectedToken(Token token) { | 4010 Token reportUnexpectedToken(Token token) { |
| 4006 return reportUnrecoverableErrorWithToken( | 4011 return reportUnrecoverableErrorWithToken( |
| 4007 token, fasta.templateUnexpectedToken); | 4012 token, fasta.templateUnexpectedToken); |
| 4008 } | 4013 } |
| 4009 } | 4014 } |
| 4010 | 4015 |
| 4011 // TODO(ahe): Remove when analyzer supports generalized function syntax. | 4016 // TODO(ahe): Remove when analyzer supports generalized function syntax. |
| 4012 typedef _MessageWithArgument<T> = Message Function(T); | 4017 typedef _MessageWithArgument<T> = Message Function(T); |
| OLD | NEW |