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

Side by Side Diff: dart/pkg/compiler/lib/src/scanner/class_element_parser.dart

Issue 808953004: Recover from fatal parser errors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Merged with r42860. Created 5 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 part of scanner; 5 part of scanner;
6 6
7 class ClassElementParser extends PartialParser { 7 class ClassElementParser extends PartialParser {
8 ClassElementParser(Listener listener) : super(listener); 8 ClassElementParser(Listener listener) : super(listener);
9 9
10 Token parseClassBody(Token token) => fullParseClassBody(token); 10 Token parseClassBody(Token token) => fullParseClassBody(token);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 message: "Node has not been computed for $this.")); 42 message: "Node has not been computed for $this."));
43 return cachedNode; 43 return cachedNode;
44 } 44 }
45 45
46 ClassNode parseNode(Compiler compiler) { 46 ClassNode parseNode(Compiler compiler) {
47 if (cachedNode != null) return cachedNode; 47 if (cachedNode != null) return cachedNode;
48 compiler.withCurrentElement(this, () { 48 compiler.withCurrentElement(this, () {
49 compiler.parser.measure(() { 49 compiler.parser.measure(() {
50 MemberListener listener = new MemberListener(compiler, this); 50 MemberListener listener = new MemberListener(compiler, this);
51 Parser parser = new ClassElementParser(listener); 51 Parser parser = new ClassElementParser(listener);
52 Token token = parser.parseTopLevelDeclaration(beginToken); 52 try {
53 assert(identical(token, endToken.next)); 53 Token token = parser.parseTopLevelDeclaration(beginToken);
54 cachedNode = listener.popNode(); 54 assert(identical(token, endToken.next));
55 assert(invariant(beginToken, listener.nodes.isEmpty, 55 cachedNode = listener.popNode();
56 message: "Non-empty listener stack: ${listener.nodes}")); 56 assert(
57 invariant(
58 beginToken, listener.nodes.isEmpty,
59 message: "Non-empty listener stack: ${listener.nodes}"));
60 } on ParserError catch (e) {
61 // TODO(ahe): Often, a ParserError is thrown while parsing the class
62 // body. This means that the stack actually contains most of the
63 // information synthesized below. Consider rewriting the parser so
64 // endClassDeclaration is called before parsing the class body.
65 Identifier name = new Identifier(findMyName(beginToken));
66 NodeList typeParameters = null;
67 Node supertype = null;
68 NodeList interfaces = listener.makeNodeList(0, null, null, ",");
69 Token extendsKeyword = null;
70 NodeList body = listener.makeNodeList(0, beginToken, endToken, null);
71 cachedNode = new ClassNode(
72 Modifiers.EMPTY, name, typeParameters, supertype, interfaces,
73 beginToken, extendsKeyword, body, endToken);
74 hasParseError = true;
75 }
57 }); 76 });
58 compiler.patchParser.measure(() { 77 compiler.patchParser.measure(() {
59 if (isPatched) { 78 if (isPatched) {
60 // TODO(lrn): Perhaps extract functionality so it doesn't 79 // TODO(lrn): Perhaps extract functionality so it doesn't
61 // need compiler. 80 // need compiler.
62 compiler.patchParser.parsePatchClassNode(patch); 81 compiler.patchParser.parsePatchClassNode(patch);
63 } 82 }
64 }); 83 });
65 }); 84 });
66 return cachedNode; 85 return cachedNode;
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 236
218 void endMetadata(Token beginToken, Token periodBeforeName, Token endToken) { 237 void endMetadata(Token beginToken, Token periodBeforeName, Token endToken) {
219 popNode(); // Discard arguments. 238 popNode(); // Discard arguments.
220 if (periodBeforeName != null) { 239 if (periodBeforeName != null) {
221 popNode(); // Discard name. 240 popNode(); // Discard name.
222 } 241 }
223 popNode(); // Discard node (Send or Identifier). 242 popNode(); // Discard node (Send or Identifier).
224 pushMetadata(new PartialMetadataAnnotation(beginToken, endToken)); 243 pushMetadata(new PartialMetadataAnnotation(beginToken, endToken));
225 } 244 }
226 } 245 }
OLDNEW
« no previous file with comments | « dart/pkg/compiler/lib/src/resolution/members.dart ('k') | dart/pkg/compiler/lib/src/scanner/listener.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698