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

Side by Side Diff: dart/sdk/lib/_internal/compiler/implementation/tree/nodes.dart

Issue 324293002: Improve parser error recovery. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed Johnni's comments Created 6 years, 6 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) 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 part of tree; 5 part of tree;
6 6
7 abstract class Visitor<R> { 7 abstract class Visitor<R> {
8 const Visitor(); 8 const Visitor();
9 9
10 R visitNode(Node node); 10 R visitNode(Node node);
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 TypeAnnotation asTypeAnnotation() => null; 201 TypeAnnotation asTypeAnnotation() => null;
202 TypeVariable asTypeVariable() => null; 202 TypeVariable asTypeVariable() => null;
203 Typedef asTypedef() => null; 203 Typedef asTypedef() => null;
204 VariableDefinitions asVariableDefinitions() => null; 204 VariableDefinitions asVariableDefinitions() => null;
205 While asWhile() => null; 205 While asWhile() => null;
206 206
207 bool isValidBreakTarget() => false; 207 bool isValidBreakTarget() => false;
208 bool isValidContinueTarget() => false; 208 bool isValidContinueTarget() => false;
209 bool isThis() => false; 209 bool isThis() => false;
210 bool isSuper() => false; 210 bool isSuper() => false;
211
212 bool get isErroneous => false;
211 } 213 }
212 214
213 class ClassNode extends Node { 215 class ClassNode extends Node {
214 final Modifiers modifiers; 216 final Modifiers modifiers;
215 final Identifier name; 217 final Identifier name;
216 final Node superclass; 218 final Node superclass;
217 final NodeList interfaces; 219 final NodeList interfaces;
218 final NodeList typeParameters; 220 final NodeList typeParameters;
219 final NodeList body; 221 final NodeList body;
220 222
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 Statement(); 314 Statement();
313 315
314 Statement asStatement() => this; 316 Statement asStatement() => this;
315 317
316 // TODO(ahe): make class abstract instead of adding an abstract method. 318 // TODO(ahe): make class abstract instead of adding an abstract method.
317 accept(Visitor visitor); 319 accept(Visitor visitor);
318 320
319 bool isValidBreakTarget() => true; 321 bool isValidBreakTarget() => true;
320 } 322 }
321 323
322 /// Errorneous expression that behaves as a literal null. 324 /// Erroneous expression that behaves as a literal null.
323 class ErrorExpression extends LiteralNull { 325 class ErrorExpression extends LiteralNull {
324 ErrorExpression(token) 326 ErrorExpression(token)
325 : super(token); 327 : super(token);
326 328
327 ErrorExpression asErrorExpression() => this; 329 ErrorExpression asErrorExpression() => this;
330
331 bool get isErroneous => true;
328 } 332 }
329 333
330 /** 334 /**
331 * A message send aka method invocation. In Dart, most operations can 335 * A message send aka method invocation. In Dart, most operations can
332 * (and should) be considered as message sends. Getters and setters 336 * (and should) be considered as message sends. Getters and setters
333 * are just methods with a special syntax. Consequently, we model 337 * are just methods with a special syntax. Consequently, we model
334 * property access, assignment, operators, and method calls with this 338 * property access, assignment, operators, and method calls with this
335 * one node. 339 * one node.
336 */ 340 */
337 class Send extends Expression { 341 class Send extends Expression {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 return firstBeginToken(receiver, selector); 412 return firstBeginToken(receiver, selector);
409 } 413 }
410 414
411 Token getEndToken() { 415 Token getEndToken() {
412 if (isPrefix) { 416 if (isPrefix) {
413 if (receiver != null) return receiver.getEndToken(); 417 if (receiver != null) return receiver.getEndToken();
414 if (selector != null) return selector.getEndToken(); 418 if (selector != null) return selector.getEndToken();
415 return null; 419 return null;
416 } 420 }
417 if (!isPostfix && argumentsNode != null) { 421 if (!isPostfix && argumentsNode != null) {
418 return argumentsNode.getEndToken(); 422 Token token = argumentsNode.getEndToken();
423 if (token != null) return token;
419 } 424 }
420 if (selector != null) return selector.getEndToken(); 425 if (selector != null) return selector.getEndToken();
421 return receiver.getBeginToken(); 426 return getBeginToken();
422 } 427 }
423 428
424 Send copyWithReceiver(Node newReceiver) { 429 Send copyWithReceiver(Node newReceiver) {
425 assert(receiver == null); 430 assert(receiver == null);
426 return new Send(newReceiver, selector, argumentsNode); 431 return new Send(newReceiver, selector, argumentsNode);
427 } 432 }
428 } 433 }
429 434
430 class Postfix extends NodeList { 435 class Postfix extends NodeList {
431 Postfix() : super(null, const Link<Node>()); 436 Postfix() : super(null, const Link<Node>());
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 } 556 }
552 return endToken; 557 return endToken;
553 } 558 }
554 559
555 Token getEndToken() { 560 Token getEndToken() {
556 if (endToken != null) return endToken; 561 if (endToken != null) return endToken;
557 if (nodes != null) { 562 if (nodes != null) {
558 Link<Node> link = nodes; 563 Link<Node> link = nodes;
559 if (link.isEmpty) return beginToken; 564 if (link.isEmpty) return beginToken;
560 while (!link.tail.isEmpty) link = link.tail; 565 while (!link.tail.isEmpty) link = link.tail;
561 if (link.head.getEndToken() != null) return link.head.getEndToken(); 566 Node lastNode = link.head;
562 if (link.head.getBeginToken() != null) return link.head.getBeginToken(); 567 if (lastNode != null) {
568 if (lastNode.getEndToken() != null) return lastNode.getEndToken();
569 if (lastNode.getBeginToken() != null) return lastNode.getBeginToken();
570 }
563 } 571 }
564 return beginToken; 572 return beginToken;
565 } 573 }
566 } 574 }
567 575
568 class Block extends Statement { 576 class Block extends Statement {
569 final NodeList statements; 577 final NodeList statements;
570 578
571 Block(this.statements); 579 Block(this.statements);
572 580
(...skipping 1534 matching lines...) Expand 10 before | Expand all | Expand 10 after
2107 } 2115 }
2108 2116
2109 class IsInterpolationVisitor extends Visitor<bool> { 2117 class IsInterpolationVisitor extends Visitor<bool> {
2110 const IsInterpolationVisitor(); 2118 const IsInterpolationVisitor();
2111 bool visitNode(Node node) => false; 2119 bool visitNode(Node node) => false;
2112 bool visitStringInterpolation(StringInterpolation node) => true; 2120 bool visitStringInterpolation(StringInterpolation node) => true;
2113 bool visitStringJuxtaposition(StringJuxtaposition node) 2121 bool visitStringJuxtaposition(StringJuxtaposition node)
2114 => node.isInterpolation; 2122 => node.isInterpolation;
2115 } 2123 }
2116 2124
2125 /// Erroneous node used to recover from parser errors. Implements various
2126 /// interfaces and provides bare minimum of implementation to avoid unnecessary
2127 /// messages.
2128 class ErrorNode
2129 extends Node
2130 implements FunctionExpression, VariableDefinitions, Typedef {
2131 final Token token;
2132 final String reason;
2133 final Identifier name;
2134 final NodeList definitions;
2135
2136 ErrorNode.internal(this.token, this.reason, this.name, this.definitions);
2137
2138 factory ErrorNode(Token token, String reason) {
2139 Identifier name = new Identifier(token);
2140 NodeList definitions = new NodeList(
2141 null, const Link<Node>().prepend(name), null, null);
2142 return new ErrorNode.internal(token, reason, name, definitions);
2143 }
2144
2145 Token get beginToken => token;
2146 Token get endToken => token;
2147
2148 Token getBeginToken() => token;
2149
2150 Token getEndToken() => token;
2151
2152 accept(Visitor visitor) {}
2153
2154 visitChildren(Visitor visitor) {}
2155
2156 bool get isErroneous => true;
2157
2158 // FunctionExpression.
2159 get parameters => null;
2160 get body => null;
2161 get returnType => null;
2162 get modifiers => Modifiers.EMPTY;
2163 get initializers => null;
2164 get getOrSet => null;
2165 get isRedirectingFactory => false;
2166 bool hasBody() => false;
2167 bool hasEmptyBody() => false;
2168
2169 // VariableDefinitions.
2170 get metadata => null;
2171 get type => null;
2172
2173 // Typedef.
2174 get typeParameters => null;
2175 get formals => null;
2176 get typedefKeyword => null;
2177 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698