Skip to content

Commit

Permalink
Don't throw a ParseException when the lookahead parser produces a war…
Browse files Browse the repository at this point in the history
…ning.

Also simplify the ErrorReporter interface.
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=91028868
  • Loading branch information
tbreisacher authored and blickly committed Apr 13, 2015
1 parent dc63eeb commit 0039676
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 40 deletions.
34 changes: 10 additions & 24 deletions src/com/google/javascript/jscomp/parsing/ParserRunner.java
Expand Up @@ -26,7 +26,6 @@
import com.google.javascript.jscomp.parsing.parser.trees.Comment; import com.google.javascript.jscomp.parsing.parser.trees.Comment;
import com.google.javascript.jscomp.parsing.parser.trees.ProgramTree; import com.google.javascript.jscomp.parsing.parser.trees.ProgramTree;
import com.google.javascript.jscomp.parsing.parser.util.SourcePosition; import com.google.javascript.jscomp.parsing.parser.util.SourcePosition;
import com.google.javascript.jscomp.parsing.parser.util.format.SimpleFormat;
import com.google.javascript.rhino.ErrorReporter; import com.google.javascript.rhino.ErrorReporter;
import com.google.javascript.rhino.Node; import com.google.javascript.rhino.Node;
import com.google.javascript.rhino.StaticSourceFile; import com.google.javascript.rhino.StaticSourceFile;
Expand Down Expand Up @@ -129,33 +128,20 @@ private static class Es6ErrorReporter
} }


@Override @Override
protected void reportMessage( protected void reportError(SourcePosition location, String message) {
SourcePosition location, String kind, String format, if (isIdeMode || !errorSeen) {
Object... arguments) { errorSeen = true;
String message = SimpleFormat.format("%s", this.reporter.error(
SimpleFormat.format(format, arguments)); message, location.source.name,
switch (kind) { location.line + 1, location.column);
case "Error":
if (isIdeMode || !errorSeen) {
errorSeen = true;
this.reporter.error(
message, location.source.name,
location.line + 1, location.column);
}
break;
case "Warning":
this.reporter.warning(
message, location.source.name,
location.line + 1, location.column);
break;
default:
throw new IllegalStateException("Unexpected:" + kind);
} }
} }


@Override @Override
protected void reportMessage(SourcePosition location, String message) { protected void reportWarning(SourcePosition location, String message) {
throw new IllegalStateException("Not called directly"); this.reporter.warning(
message, location.source.name,
location.line + 1, location.column);
} }
} }


Expand Down
Expand Up @@ -24,23 +24,17 @@
public abstract class ErrorReporter { public abstract class ErrorReporter {
public final void reportError(SourcePosition location, String format, Object... arguments) { public final void reportError(SourcePosition location, String format, Object... arguments) {
hadError = true; hadError = true;
reportMessage(location, "Error", format, arguments); String message = SimpleFormat.format(format, arguments);
reportError(location, message);
} }


public final void reportWarning(SourcePosition location, String format, Object... arguments) { public final void reportWarning(SourcePosition location, String format, Object... arguments) {
reportMessage(location, "Warning", format, arguments); String message = SimpleFormat.format(format, arguments);
reportWarning(location, message);
} }


protected void reportMessage( protected abstract void reportError(SourcePosition location, String message);
SourcePosition location, String kind, String format, Object... arguments) { protected abstract void reportWarning(SourcePosition location, String message);
String message = SimpleFormat.format("%s: %s", kind, SimpleFormat.format(format, arguments));
if (location != null) {
message = SimpleFormat.format("%s: %s", location, message);
}
reportMessage(location, message);
}

protected abstract void reportMessage(SourcePosition location, String message);


public final boolean hadError() { public final boolean hadError() {
return hadError; return hadError;
Expand Down
Expand Up @@ -24,13 +24,12 @@ public class LookaheadErrorReporter extends ErrorReporter {
public static class ParseException extends RuntimeException {} public static class ParseException extends RuntimeException {}


@Override @Override
protected void reportMessage( public void reportError(SourcePosition location, String message) {
SourcePosition location, String kind, String format, Object... arguments) {
throw new ParseException(); throw new ParseException();
} }


@Override @Override
protected void reportMessage(SourcePosition location, String message) { public void reportWarning(SourcePosition location, String message) {
throw new ParseException(); // Don't report a failed parse for a warning.
} }
} }

0 comments on commit 0039676

Please sign in to comment.