Class ErrorListener
java.lang.Object
org.antlr.v4.runtime.BaseErrorListener
org.ek9lang.compiler.common.ErrorListener
- All Implemented Interfaces:
Serializable, org.antlr.v4.runtime.ANTLRErrorListener, SemanticErrorReporter
public class ErrorListener
extends org.antlr.v4.runtime.BaseErrorListener
implements Serializable, SemanticErrorReporter
We need an error listener for the lexing parsing and also our own tree
visiting. So our own tree visiting will be able to use additional methods we
add on to this; so we can report semantic errors and warnings.
Why? Because we need to gather-up all the errors on a per-file processing
basis. This is needed because we are going to multi-thread the various stages
of compilation based on a thread per source file. So, we would not want the
error information being interleaved in the console output. Plus eventually
there will be a UI over the compiler, and we will need very focused sets of
errors on a per source code basis.
This is not designed to be thread safe, only one thread should be parsing/processing
a source or one a specific phase.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classFine detail of the error.static enumThe type of the error.static classThe details of an error, position, etc.static enumWhat is the semantic nature of the error. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddirectiveError(IToken offendingToken, String msg, ErrorListener.SemanticClassification classification) Create a new error based on the directive.intGet the current error verbosity level.Get all Errors.getShortNameOfSourceFile(IToken token) Get the filename (but not full path) of the source file.getSourceLine(String fileName, int lineNumber) Get a source line for error display.Get the current source line provider.booleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanCheck if fuzzy matching suggestions are computed (level >= 2, or forced by the caller).booleanThe raw forced flag, as set - NOT the level's contribution.booleantrue if has no warnings.voidraiseReturningNotRequired(IToken token, String msg) Create new semantic error.voidraiseReturningRequired(IToken token, String msg) Create new semantic error.voidreset()Remove all errors and warnings.voidsemanticError(org.antlr.v4.runtime.Token offendingToken, String msg, ErrorListener.SemanticClassification classification) Create new semantic error.voidsemanticError(IToken offendingToken, String msg, ErrorListener.SemanticClassification classification) Create new semantic error.voidsemanticError(IToken offendingToken, String msg, ErrorListener.SemanticClassification classification, List<String> declaredParameterNames) A semantic error ABOUT A CALL'S ARGUMENT LIST, carrying the parameter names the called method declares, in order - seeErrorListener.ErrorDetails.getDeclaredParameterNames().voidsemanticError(IToken offendingToken, String msg, ErrorListener.SemanticClassification classification, MatchResults results) Create new semantic error.voidsemanticWarning(IToken offendingToken, String msg, ErrorListener.SemanticClassification classification) Issue a semantic warning.voidsetErrorLevel(int errorLevel) Set the error verbosity level from CompilerFlags.voidsetExceptionOnAmbiguity(boolean exceptionOnAmbiguity) voidsetExceptionOnContextSensitive(boolean exceptionOnContextSensitive) voidsetExceptionOnFullContext(boolean exceptionOnFullContext) voidsetSourceLineProvider(SourceLineProvider provider) Set the source line provider for visual error display.voidsetSuggestionsForced(boolean suggestionsForced) Compute "did you mean" candidates whatever the error level - for a programmatic consumer that wants the candidates but not the boxed visual rendering level 1+ brings with it.voidFrom now on, ignore syntax errors.voidsyntaxError(org.antlr.v4.runtime.Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, org.antlr.v4.runtime.RecognitionException e) Methods inherited from class org.antlr.v4.runtime.BaseErrorListener
reportAmbiguity, reportAttemptingFullContext, reportContextSensitivityMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface SemanticErrorReporter
semanticErrorWithSuggestions
-
Constructor Details
-
ErrorListener
Create new error listener.
-
-
Method Details
-
getGeneralIdentifierOfSource
-
setErrorLevel
public void setErrorLevel(int errorLevel) Set the error verbosity level from CompilerFlags. Called before compilation starts.- Parameters:
errorLevel- 0=minimal, 1=visual, 2=visual+fuzzy, 3=rich explanations, 4=rich+forAI.json dump
-
getErrorLevel
public int getErrorLevel()Get the current error verbosity level.- Returns:
- The error level (0-4)
-
setSourceLineProvider
Set the source line provider for visual error display. Called before compilation starts when visual errors are enabled. -
getSourceLineProvider
Get the current source line provider. May be null if not configured or after deserialization. -
isFuzzySuggestionsEnabled
public boolean isFuzzySuggestionsEnabled()Check if fuzzy matching suggestions are computed (level >= 2, or forced by the caller). SeeCompilerFlags.isFuzzySuggestionsEnabled()for why the two are separable.- Specified by:
isFuzzySuggestionsEnabledin interfaceSemanticErrorReporter
-
setSuggestionsForced
public void setSuggestionsForced(boolean suggestionsForced) Compute "did you mean" candidates whatever the error level - for a programmatic consumer that wants the candidates but not the boxed visual rendering level 1+ brings with it. -
isSuggestionsForced
public boolean isSuggestionsForced()The raw forced flag, as set - NOT the level's contribution. Read when re-creating a listener. -
getSourceLine
-
reset
public void reset()Remove all errors and warnings. -
suppressSyntaxErrors
public void suppressSyntaxErrors()From now on, ignore syntax errors. Called by the lexer when a source is nested beyond its limit (E11011): the lexer ends the input there, so every syntax error the parser then reports is only a consequence of that cut, and would bury the one error that says what is wrong. -
getShortNameOfSourceFile
Get the filename (but not full path) of the source file.- Specified by:
getShortNameOfSourceFilein interfaceSemanticErrorReporter
-
isExceptionOnAmbiguity
public boolean isExceptionOnAmbiguity() -
setExceptionOnAmbiguity
public void setExceptionOnAmbiguity(boolean exceptionOnAmbiguity) -
isExceptionOnContextSensitive
public boolean isExceptionOnContextSensitive() -
setExceptionOnContextSensitive
public void setExceptionOnContextSensitive(boolean exceptionOnContextSensitive) -
isExceptionOnFullContext
public boolean isExceptionOnFullContext() -
setExceptionOnFullContext
public void setExceptionOnFullContext(boolean exceptionOnFullContext) -
getErrors
Get all Errors. See other methods (yet to come to get specific types of errors/warnings). Marks duplicate rich messages for suppression (first-occurrence-only per error code). -
getDirectiveErrors
-
hasDirectiveErrors
public boolean hasDirectiveErrors() -
hasErrors
public boolean hasErrors() -
isErrorFree
public boolean isErrorFree() -
getWarnings
-
hasWarnings
public boolean hasWarnings() -
isWarningFree
public boolean isWarningFree()true if has no warnings. -
raiseReturningNotRequired
-
raiseReturningRequired
-
semanticError
public void semanticError(IToken offendingToken, String msg, ErrorListener.SemanticClassification classification, MatchResults results) Create new semantic error.- Specified by:
semanticErrorin interfaceSemanticErrorReporter
-
semanticError
public void semanticError(IToken offendingToken, String msg, ErrorListener.SemanticClassification classification, List<String> declaredParameterNames) A semantic error ABOUT A CALL'S ARGUMENT LIST, carrying the parameter names the called method declares, in order - seeErrorListener.ErrorDetails.getDeclaredParameterNames().- Specified by:
semanticErrorin interfaceSemanticErrorReporter
-
semanticError
public void semanticError(IToken offendingToken, String msg, ErrorListener.SemanticClassification classification) Create new semantic error.- Specified by:
semanticErrorin interfaceSemanticErrorReporter
-
semanticError
public void semanticError(org.antlr.v4.runtime.Token offendingToken, String msg, ErrorListener.SemanticClassification classification) Create new semantic error.- Specified by:
semanticErrorin interfaceSemanticErrorReporter
-
directiveError
public void directiveError(IToken offendingToken, String msg, ErrorListener.SemanticClassification classification) Create a new error based on the directive. This means that if a directive was present or was missing against an actual compiler error - we can raise this specific type of error to indicate something that the EK9 developer was checking for (via a directive) is in error. -
semanticWarning
public void semanticWarning(IToken offendingToken, String msg, ErrorListener.SemanticClassification classification) Issue a semantic warning.- Specified by:
semanticWarningin interfaceSemanticErrorReporter
-
syntaxError
public void syntaxError(org.antlr.v4.runtime.Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, org.antlr.v4.runtime.RecognitionException e) - Specified by:
syntaxErrorin interfaceorg.antlr.v4.runtime.ANTLRErrorListener- Overrides:
syntaxErrorin classorg.antlr.v4.runtime.BaseErrorListener
-