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

Unified Diff: pkg/front_end/lib/src/fasta/parser/parser.dart

Issue 2985703002: new handleInvalidTopLevelDeclaration event in fasta parser (Closed)
Patch Set: cleanup forwarding listener - enclosingEvent Created 3 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: pkg/front_end/lib/src/fasta/parser/parser.dart
diff --git a/pkg/front_end/lib/src/fasta/parser/parser.dart b/pkg/front_end/lib/src/fasta/parser/parser.dart
index 8ff84bbd67275d6faad324a2b93e364b48d592c8..4a56814a2753f74c3b62154467a3d5cf4f15a1c6 100644
--- a/pkg/front_end/lib/src/fasta/parser/parser.dart
+++ b/pkg/front_end/lib/src/fasta/parser/parser.dart
@@ -224,46 +224,51 @@ class Parser {
Token parseUnit(Token token) {
listener.beginCompilationUnit(token);
- int count = 0;
+ _topLevelDeclarationCount = 0;
while (!identical(token.kind, EOF_TOKEN)) {
token = parseTopLevelDeclaration(token);
- count++;
}
- listener.endCompilationUnit(count, token);
+ listener.endCompilationUnit(_topLevelDeclarationCount, token);
return token;
}
- Token parseTopLevelDeclaration(Token token) {
- token = _parseTopLevelDeclaration(token);
- listener.endTopLevelDeclaration(token);
- return token;
- }
+ 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
- Token _parseTopLevelDeclaration(Token token) {
- if (identical(token.type, TokenType.SCRIPT_TAG)) {
- return parseScript(token);
- }
- token = parseMetadataStar(token);
- final String value = token.stringValue;
- if ((identical(value, 'abstract') && optional('class', token.next)) ||
- identical(value, 'class')) {
- return parseClassOrNamedMixinApplication(token);
- } else if (identical(value, 'enum')) {
- return parseEnum(token);
- } else if (identical(value, 'typedef') &&
- (token.next.isIdentifier || optional("void", token.next))) {
- return parseTypedef(token);
- } else if (identical(value, 'library')) {
- return parseLibraryName(token);
- } else if (identical(value, 'import')) {
- return parseImport(token);
- } else if (identical(value, 'export')) {
- return parseExport(token);
- } else if (identical(value, 'part')) {
- return parsePartOrPartOf(token);
+ Token parseTopLevelDeclaration(Token token) {
+ Token start = token;
+ if (token.type == TokenType.SCRIPT_TAG) {
+ token = parseScript(token);
} else {
- return parseTopLevelMember(token);
+ token = parseMetadataStar(token);
+ final String value = token.stringValue;
+ if ((identical(value, 'abstract') && optional('class', token.next)) ||
+ identical(value, 'class')) {
+ token = parseClassOrNamedMixinApplication(token);
+ } else if (identical(value, 'enum')) {
+ token = parseEnum(token);
+ } else if (identical(value, 'typedef') &&
+ (token.next.isIdentifier || optional("void", token.next))) {
+ token = parseTypedef(token);
+ } else if (identical(value, 'library')) {
+ token = parseLibraryName(token);
+ } else if (identical(value, 'import')) {
+ token = parseImport(token);
+ } else if (identical(value, 'export')) {
+ token = parseExport(token);
+ } else if (identical(value, 'part')) {
+ token = parsePartOrPartOf(token);
+ } else if (token.type == TokenType.IDENTIFIER || token.keyword != null) {
+ token = parseTopLevelMember(token);
+ } else {
+ reportRecoverableErrorWithToken(
+ token, fasta.templateExpectedDeclaration);
+ listener.handleInvalidTopLevelDeclaration(start, token);
+ return token.next;
+ }
}
+ listener.endTopLevelDeclaration(token);
+ ++_topLevelDeclarationCount;
+ return token;
}
/// library qualified ';'

Powered by Google App Engine
This is Rietveld 408576698