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

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

Issue 8913016: Issue 839: Bad code leading to top level methods being something other than identifier (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Nits Created 9 years 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: 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 85e54bf233d968aeb3ba567714bd926568e0b44c..368b4cf8f91bcc60941f218d8e38d0814f374008 100644
--- a/compiler/java/com/google/dart/compiler/parser/DartParser.java
+++ b/compiler/java/com/google/dart/compiler/parser/DartParser.java
@@ -112,6 +112,7 @@ public class DartParser extends CompletionHooksParserBase {
private boolean isDietParse;
private boolean isParsingInterface;
private boolean isParsingAbstract;
+ private boolean isParsingClass;
/**
* Determines the maximum number of errors before terminating the parser. See
@@ -253,7 +254,7 @@ public class DartParser extends CompletionHooksParserBase {
try {
DartNode node = null;
beginTopLevelElement();
- isParsingInterface = false;
+ isParsingClass = isParsingInterface = false;
// Check for ABSTRACT_KEYWORD.
isParsingAbstract = false;
if (optionalPseudoKeyword(ABSTRACT_KEYWORD)) {
@@ -261,6 +262,7 @@ public class DartParser extends CompletionHooksParserBase {
}
// Parse top level element.
if (optionalPseudoKeyword(CLASS_KEYWORD)) {
+ isParsingClass = true;
node = done(parseClass());
} else if (optionalPseudoKeyword(INTERFACE_KEYWORD)) {
isParsingInterface = true;
@@ -1113,7 +1115,10 @@ public class DartParser extends CompletionHooksParserBase {
// Check for named constructor.
if (optional(Token.PERIOD)) {
name = doneWithoutConsuming(new DartPropertyAccess(name, parseIdentifier()));
-
+ if(currentlyParsingToplevel()) {
+ // TODO: Error recovery could find a missing brace and treat this as an expression
+ reportError(name, ParserErrorCode.FUNCTION_NAME_EXPECTED_IDENTIFIER);
+ }
if (optional(Token.PERIOD)) {
name = doneWithoutConsuming(new DartPropertyAccess(name, parseIdentifier()));
}
@@ -1229,7 +1234,6 @@ public class DartParser extends CompletionHooksParserBase {
* | THIS ('.' identifier)? arguments
* ;
* </pre>
- * @return true if initializer is a redirected constructor, false otherwise.
*/
private void parseInitializers(List<DartInitializer> initializers) {
expect(Token.COLON);
@@ -3746,4 +3750,8 @@ public class DartParser extends CompletionHooksParserBase {
private void reportError(DartNode node, ErrorCode errorCode, Object... arguments) {
reportError(new DartCompilationError(node, errorCode, arguments));
}
+
+ private boolean currentlyParsingToplevel() {
+ return !(isParsingInterface || isParsingAbstract || isParsingClass);
+ }
}

Powered by Google App Engine
This is Rietveld 408576698