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

Unified Diff: compiler/java/com/google/dart/compiler/parser/DartParser.java

Issue 10012012: Error recovery for unsupported operator overloads (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 'got rid of syntax test' Created 8 years, 8 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
« no previous file with comments | « no previous file | compiler/java/com/google/dart/compiler/parser/ParserErrorCode.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compiler/java/com/google/dart/compiler/parser/DartParser.java
diff --git a/compiler/java/com/google/dart/compiler/parser/DartParser.java b/compiler/java/com/google/dart/compiler/parser/DartParser.java
index 2cf601c0cf9abf477c1e7cd3a07ee393803a6993..dddcdab6c9e1f270a9fc362bffbd41211732b84c 100644
--- a/compiler/java/com/google/dart/compiler/parser/DartParser.java
+++ b/compiler/java/com/google/dart/compiler/parser/DartParser.java
@@ -1178,7 +1178,7 @@ public class DartParser extends CompletionHooksParserBase {
}
private DartMethodDefinition parseMethod(Modifiers modifiers, DartTypeNode returnType) {
- DartExpression name = null;
+ DartExpression name = new DartIdentifier("");
zundel 2012/04/05 18:45:36 @Brian, this is a failsafe to make sure we never g
if (modifiers.isFactory()) {
if (modifiers.isAbstract()) {
@@ -1219,8 +1219,30 @@ public class DartParser extends CompletionHooksParserBase {
&& ctx.getTokenString().equals(CALL_KEYWORD)) {
name = done(new DartIdentifier(CALL_KEYWORD));
} else {
- reportUnexpectedToken(position(), Token.COMMENT, operation);
- done(null);
+ // Not a valid operator. Try to recover.
+ boolean found = false;
+ for (int i = 0; i < 4; ++i) {
+ if (peek(i).equals(Token.LPAREN)) {
+ found = true;
+ break;
+ }
+ }
+ StringBuilder buf = new StringBuilder();
+ buf.append(operation.getSyntax());
+ if (found) {
+ reportError(position(), ParserErrorCode.OPERATOR_IS_NOT_USER_DEFINABLE);
+ while(true) {
+ Token token = peek(0);
+ if (token.equals(Token.LPAREN)) {
+ break;
+ }
+ buf.append(next().getSyntax());
+ }
+ name = done(new DartIdentifier(buf.toString()));
zundel 2012/04/05 18:45:36 This works hard to get a meaningful name for the m
+ } else {
+ reportUnexpectedToken(position(), Token.COMMENT, operation);
+ done(null);
+ }
}
} else {
beginMethodName();
« no previous file with comments | « no previous file | compiler/java/com/google/dart/compiler/parser/ParserErrorCode.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698