forked from jasder/antlr
rm generic parameter from ANTLRErrorListener, ripple effect.
This commit is contained in:
parent
bb5790d6a9
commit
3ad87ba12c
|
@ -36,7 +36,7 @@ import org.antlr.v4.runtime.misc.NotNull;
|
|||
import org.antlr.v4.runtime.misc.Nullable;
|
||||
|
||||
/** How to emit recognition errors */
|
||||
public interface ANTLRErrorListener<Symbol> {
|
||||
public interface ANTLRErrorListener {
|
||||
/** Upon syntax error, notify any interested parties. This is not how to
|
||||
* recover from errors or compute error messages. The parser
|
||||
* ANTLRErrorStrategy specifies how to recover from syntax errors
|
||||
|
@ -70,12 +70,12 @@ public interface ANTLRErrorListener<Symbol> {
|
|||
* the parser was able to recover in line without exiting the
|
||||
* surrounding rule.
|
||||
*/
|
||||
public <T extends Symbol> void syntaxError(Recognizer<T, ?> recognizer,
|
||||
@Nullable T offendingSymbol,
|
||||
int line,
|
||||
int charPositionInLine,
|
||||
String msg,
|
||||
@Nullable RecognitionException e);
|
||||
public void syntaxError(Recognizer<?, ?> recognizer,
|
||||
@Nullable Object offendingSymbol,
|
||||
int line,
|
||||
int charPositionInLine,
|
||||
String msg,
|
||||
@Nullable RecognitionException e);
|
||||
|
||||
/** Called when the parser detects a true ambiguity: an input sequence can be matched
|
||||
* literally by two or more pass through the grammar. ANTLR resolves the ambiguity in
|
||||
|
|
|
@ -36,15 +36,14 @@ import org.antlr.v4.runtime.misc.IntervalSet;
|
|||
*
|
||||
* @author Sam Harwell
|
||||
*/
|
||||
public class BaseErrorListener<Symbol> implements ANTLRErrorListener<Symbol> {
|
||||
|
||||
public class BaseErrorListener implements ANTLRErrorListener {
|
||||
@Override
|
||||
public <T extends Symbol> void syntaxError(Recognizer<T, ?> recognizer,
|
||||
T offendingSymbol,
|
||||
int line,
|
||||
int charPositionInLine,
|
||||
String msg,
|
||||
RecognitionException e)
|
||||
public void syntaxError(Recognizer<?, ?> recognizer,
|
||||
Object offendingSymbol,
|
||||
int line,
|
||||
int charPositionInLine,
|
||||
String msg,
|
||||
RecognitionException e)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -32,16 +32,16 @@ package org.antlr.v4.runtime;
|
|||
*
|
||||
* @author Sam Harwell
|
||||
*/
|
||||
public class ConsoleErrorListener extends BaseErrorListener<Object> {
|
||||
public class ConsoleErrorListener extends BaseErrorListener {
|
||||
public static final ConsoleErrorListener INSTANCE = new ConsoleErrorListener();
|
||||
|
||||
@Override
|
||||
public <T extends Object> void syntaxError(Recognizer<T, ?> recognizer,
|
||||
T offendingSymbol,
|
||||
int line,
|
||||
int charPositionInLine,
|
||||
String msg,
|
||||
RecognitionException e)
|
||||
public void syntaxError(Recognizer<?, ?> recognizer,
|
||||
Object offendingSymbol,
|
||||
int line,
|
||||
int charPositionInLine,
|
||||
String msg,
|
||||
RecognitionException e)
|
||||
{
|
||||
System.err.println("line " + line + ":" + charPositionInLine + " " + msg);
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ import org.antlr.v4.runtime.misc.Interval;
|
|||
import org.antlr.v4.runtime.misc.IntervalSet;
|
||||
import org.antlr.v4.runtime.misc.NotNull;
|
||||
|
||||
public class DiagnosticErrorListener extends BaseErrorListener<Token> {
|
||||
public class DiagnosticErrorListener extends BaseErrorListener {
|
||||
@Override
|
||||
public void reportAmbiguity(@NotNull Parser recognizer,
|
||||
DFA dfa, int startIndex, int stopIndex, @NotNull IntervalSet ambigAlts,
|
||||
|
|
|
@ -360,7 +360,7 @@ public abstract class Lexer extends Recognizer<Integer, LexerATNSimulator>
|
|||
String msg = "token recognition error at: '"+
|
||||
_input.getText(Interval.of(_tokenStartCharIndex, _input.index()))+"'";
|
||||
|
||||
ANTLRErrorListener<? super Integer> listener = getErrorListenerDispatch();
|
||||
ANTLRErrorListener listener = getErrorListenerDispatch();
|
||||
listener.syntaxError(this, null, _tokenStartLine, _tokenStartCharPositionInLine, msg, e);
|
||||
}
|
||||
|
||||
|
|
|
@ -316,7 +316,7 @@ public abstract class Parser extends Recognizer<Token, ParserATNSimulator<Token>
|
|||
charPositionInLine = ((Token) offendingToken).getCharPositionInLine();
|
||||
}
|
||||
|
||||
ANTLRErrorListener<? super Token> listener = getErrorListenerDispatch();
|
||||
ANTLRErrorListener listener = getErrorListenerDispatch();
|
||||
listener.syntaxError(this, offendingToken, line, charPositionInLine, msg, e);
|
||||
}
|
||||
|
||||
|
|
|
@ -38,22 +38,22 @@ import java.util.Collection;
|
|||
*
|
||||
* @author Sam Harwell
|
||||
*/
|
||||
public class ProxyErrorListener<Symbol> implements ANTLRErrorListener<Symbol> {
|
||||
private final Collection<? extends ANTLRErrorListener<? super Symbol>> delegates;
|
||||
public class ProxyErrorListener implements ANTLRErrorListener {
|
||||
private final Collection<? extends ANTLRErrorListener> delegates;
|
||||
|
||||
public ProxyErrorListener(Collection<? extends ANTLRErrorListener<? super Symbol>> delegates) {
|
||||
public ProxyErrorListener(Collection<? extends ANTLRErrorListener> delegates) {
|
||||
this.delegates = delegates;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends Symbol> void syntaxError(Recognizer<T, ?> recognizer,
|
||||
T offendingSymbol,
|
||||
int line,
|
||||
int charPositionInLine,
|
||||
String msg,
|
||||
RecognitionException e)
|
||||
public void syntaxError(Recognizer<?, ?> recognizer,
|
||||
Object offendingSymbol,
|
||||
int line,
|
||||
int charPositionInLine,
|
||||
String msg,
|
||||
RecognitionException e)
|
||||
{
|
||||
for (ANTLRErrorListener<? super Symbol> listener : delegates) {
|
||||
for (ANTLRErrorListener listener : delegates) {
|
||||
listener.syntaxError(recognizer, offendingSymbol, line, charPositionInLine, msg, e);
|
||||
}
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ public class ProxyErrorListener<Symbol> implements ANTLRErrorListener<Symbol> {
|
|||
IntervalSet ambigAlts,
|
||||
ATNConfigSet configs)
|
||||
{
|
||||
for (ANTLRErrorListener<? super Symbol> listener : delegates) {
|
||||
for (ANTLRErrorListener listener : delegates) {
|
||||
listener.reportAmbiguity(recognizer, dfa, startIndex, stopIndex, ambigAlts, configs);
|
||||
}
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ public class ProxyErrorListener<Symbol> implements ANTLRErrorListener<Symbol> {
|
|||
int stopIndex,
|
||||
ATNConfigSet configs)
|
||||
{
|
||||
for (ANTLRErrorListener<? super Symbol> listener : delegates) {
|
||||
for (ANTLRErrorListener listener : delegates) {
|
||||
listener.reportAttemptingFullContext(recognizer, dfa, startIndex, stopIndex, configs);
|
||||
}
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ public class ProxyErrorListener<Symbol> implements ANTLRErrorListener<Symbol> {
|
|||
int stopIndex,
|
||||
ATNConfigSet configs)
|
||||
{
|
||||
for (ANTLRErrorListener<? super Symbol> listener : delegates) {
|
||||
for (ANTLRErrorListener listener : delegates) {
|
||||
listener.reportContextSensitivity(recognizer, dfa, startIndex, stopIndex, configs);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,8 +42,10 @@ public abstract class Recognizer<Symbol, ATNInterpreter extends ATNSimulator> {
|
|||
public static final int EOF=-1;
|
||||
|
||||
@NotNull
|
||||
private List<ANTLRErrorListener<? super Symbol>> _listeners =
|
||||
new CopyOnWriteArrayList<ANTLRErrorListener<? super Symbol>>() {{ add(ConsoleErrorListener.INSTANCE); }};
|
||||
private List<ANTLRErrorListener> _listeners =
|
||||
new CopyOnWriteArrayList<ANTLRErrorListener>() {{
|
||||
add(ConsoleErrorListener.INSTANCE);
|
||||
}};
|
||||
|
||||
protected ATNInterpreter _interp;
|
||||
|
||||
|
@ -99,7 +101,7 @@ public abstract class Recognizer<Symbol, ATNInterpreter extends ATNSimulator> {
|
|||
/**
|
||||
* @throws NullPointerException if {@code listener} is {@code null}.
|
||||
*/
|
||||
public void addErrorListener(@NotNull ANTLRErrorListener<? super Symbol> listener) {
|
||||
public void addErrorListener(@NotNull ANTLRErrorListener listener) {
|
||||
if (listener == null) {
|
||||
throw new NullPointerException("listener cannot be null.");
|
||||
}
|
||||
|
@ -107,7 +109,7 @@ public abstract class Recognizer<Symbol, ATNInterpreter extends ATNSimulator> {
|
|||
_listeners.add(listener);
|
||||
}
|
||||
|
||||
public void removeErrorListener(@NotNull ANTLRErrorListener<? super Symbol> listener) {
|
||||
public void removeErrorListener(@NotNull ANTLRErrorListener listener) {
|
||||
_listeners.remove(listener);
|
||||
}
|
||||
|
||||
|
@ -116,12 +118,12 @@ public abstract class Recognizer<Symbol, ATNInterpreter extends ATNSimulator> {
|
|||
}
|
||||
|
||||
@NotNull
|
||||
public List<? extends ANTLRErrorListener<? super Symbol>> getErrorListeners() {
|
||||
return new ArrayList<ANTLRErrorListener<? super Symbol>>(_listeners);
|
||||
public List<? extends ANTLRErrorListener> getErrorListeners() {
|
||||
return new ArrayList<ANTLRErrorListener>(_listeners);
|
||||
}
|
||||
|
||||
public ANTLRErrorListener<? super Symbol> getErrorListenerDispatch() {
|
||||
return new ProxyErrorListener<Symbol>(getErrorListeners());
|
||||
public ANTLRErrorListener getErrorListenerDispatch() {
|
||||
return new ProxyErrorListener(getErrorListeners());
|
||||
}
|
||||
|
||||
// subclass needs to override these if there are sempreds or actions
|
||||
|
|
|
@ -539,11 +539,14 @@ public class TestPerformance extends BaseTest {
|
|||
void parseFile(CharStream input);
|
||||
}
|
||||
|
||||
private static class DescriptiveErrorListener extends BaseErrorListener<Token> {
|
||||
private static class DescriptiveErrorListener extends BaseErrorListener {
|
||||
public static DescriptiveErrorListener INSTANCE = new DescriptiveErrorListener();
|
||||
|
||||
@Override
|
||||
public <T extends Token> void syntaxError(Recognizer<T, ?> recognizer, T offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) {
|
||||
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol,
|
||||
int line, int charPositionInLine,
|
||||
String msg, RecognitionException e)
|
||||
{
|
||||
String sourceName = recognizer.getInputStream().getSourceName();
|
||||
sourceName = sourceName != null && !sourceName.isEmpty() ? sourceName+": " : "";
|
||||
System.err.println(sourceName+"line "+line+":"+charPositionInLine+" "+msg);
|
||||
|
|
Loading…
Reference in New Issue