Top Description Inners Fields Constructors Methods
org.antlr.tool

public Class ErrorManager

extends Object
Class Inheritance
Imports
org.antlr.Tool, org.antlr.analysis.DFAState, .DecisionProbe, .NFAState, org.antlr.misc.BitSet, org.antlr.runtime.RecognitionException, .Token, org.stringtemplate.v4.ST, .STErrorListener, .STGroup, .STGroupFile, org.stringtemplate.v4.misc.STMessage, java.lang.reflect.Field, java.util.Collection, .HashMap, .HashSet, .List, .Locale, .Map, .Set, .WeakHashMap

Defines all the errors ANTLR can generator for both the tool and for issues with a grammar. Here is a list of language names: http://ftp.ics.uci.edu/pub/ietf/http/related/iso639.txt Here is a list of country names: http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html I use constants not strings to identify messages as the compiler will find any errors/mismatches rather than leaving a mistyped string in the code to be found randomly in the future. Further, Intellij can do field name expansion to save me some typing. I have to map int constants to template names, however, which could introduce a mismatch. Someone could provide a .stg file that had a template name wrong. When I load the group, then, I must verify that all messages are there. This is essentially the functionality of the resource bundle stuff Java has, but I don't want to load a property file--I want to load a template group file and this is so simple, why mess with their junk. I use the default Locale as defined by java to compute a group file name in the org/antlr/tool/templates/messages dir called en_US.stg and so on. Normally we want to use the default locale, but often a message file will not exist for it so we must fall back on the US local. During initialization of this class, all errors go straight to System.err. There is no way around this. If I have not set up the error system, how can I do errors properly? For example, if the string template group file full of messages has an error, how could I print to anything but System.err? TODO: how to map locale to a file encoding for the stringtemplate group file? ST knows how to pay attention to the default encoding so it should probably just work unless a GUI sets the local to some chinese variation but System.getProperty("file.encoding") is US. Hmm...

Todo

get antlr.g etc.. parsing errors to come here.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
pack-priv static STErrorListener
blankSTListener

During verification of the messages group file, don't gen errors.

public static final Map<String, Set<String>>
emitSingleError

Only one error can be emitted for any entry in this table.

public static final BitSet
ERRORS_FORCING_NO_ANALYSIS

Do not do perform analysis if one of these happens

public static final BitSet
ERRORS_FORCING_NO_CODEGEN

Do not do code gen if one of these happens

private static STGroup
format

The group of templates that represent the current message format.

private static String
private static final String[]
idToMessageTemplateName

From a msgID how can I get the name of the template that describes the error or warning?

pack-priv static STErrorListener
initSTListener

Handle all ST error listeners here (code gen, Grammar, and this class use templates.

private static Locale
locale

Messages should be sensitive to the locale.

public static final int
private static STGroup
messages

The group of templates that represent all possible ANTLR errors.

public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
pack-priv static ANTLRErrorListener
pack-priv static STErrorListener
theDefaultSTListener

Errors during initialization related to ST must all go to System.err.

private static final Map<Thread, ErrorManager.ErrorState>
threadToErrorStateMap

Track the number of errors regardless of the listener but track per thread.

private static final Map<Thread, ANTLRErrorListener>
threadToListenerMap

Each thread might need it's own error listener; e.g., a GUI with multiple window frames holding multiple grammars.

private static final Map<Thread, Tool>
threadToToolMap

Each thread has its own ptr to a Tool object, which knows how to panic, for example.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static void
public static void
assertTrue(boolean condition, String message)

public static void
public static boolean
public static boolean
public static void
error(int msgID)

public static void
error(int msgID, Throwable e)

public static void
error(int msgID, Object arg)

public static void
error(int msgID, Object arg, Object arg2)

public static void
error(int msgID, Object arg, Throwable e)

public static boolean
public static ANTLRErrorListener
public static ErrorManager.ErrorState
private static StackTraceElement
getLastNonErrorManagerCodeLocation(Throwable e)

Return first non ErrorManager code location for generating messages

public static ST
getLocationFormat()

Return a ST that refers to the current format used for emitting messages.

public static ST
getMessage(int msgID)

Given a message ID, return a ST that somebody can fill with data.

public static ST
public static String
getMessageType(int msgID)

public static int
public static ST
public static STErrorListener
public static void
grammarError(int msgID, Grammar g, Token token, Object arg, Object arg2)

public static void
grammarError(int msgID, Grammar g, Token token, Object arg)

public static void
grammarError(int msgID, Grammar g, Token token)

public static void
grammarWarning(int msgID, Grammar g, Token token, Object arg, Object arg2)

public static void
grammarWarning(int msgID, Grammar g, Token token, Object arg)

public static void
grammarWarning(int msgID, Grammar g, Token token)

public static void
info(String msg)

protected static boolean
public static void
insufficientPredicates(DecisionProbe probe, DFAState d, Map<Integer, Set<Token>> altToUncoveredLocations)

public static void
public static void
public static void
leftRecursionCycles(Collection<? extends Set<? extends Rule>> cycles)

public static void
public static void
public static void
panic()

I *think* this will allow Tool subclasses to exit gracefully for GUIs etc...

pack-priv static void
rawError(String msg)

If there are errors during ErrorManager init, we have no choice but to go to System.err.

pack-priv static void
public static void
recursionOverflow(DecisionProbe probe, DFAState sampleBadState, int alt, Collection<String> targetRules, Collection<? extends Collection<? extends NFAState>> callSiteStates)

public static void
public static void
public static void
setErrorListener(ANTLRErrorListener listener)

In general, you'll want all errors to go to a single spot.

public static void
setFormat(String formatName)

The format gets reset either from the Tool if the user supplied a command line option to that effect Otherwise we just use the default "antlr".

public static void
setLocale(Locale locale)

We really only need a single locale for entire running ANTLR code in a single VM.

public static void
setTool(Tool tool)

public static void
syntaxError(int msgID, Grammar grammar, Token token, Object arg, RecognitionException re)

public static void
protected static boolean
verifyFormat()

Verify the message format template group

protected static boolean
verifyMessages()

Use reflection to find list of MSG_ fields and then verify a template exists for each one from the locale's group.

public static void
warning(int msgID, Object arg)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait