public class DumpBitSet
extends java.lang.Object
antlr.collections.BitSet
and its associated token type name.
This is a helper class that is very useful for diagnosing logic problems
with ANTLR based lexers or parsers. ANTLR implements a large number of
decisions based on its own BitSet
class and the
member
method. Without being able to dump the contents of
such a bitset, such decision logic is obscured. With this tool, one can
easily print any BitSet
to STDOUT
.
For command line syntax, see main(java.lang.String[])
.
Modifier and Type | Field and Description |
---|---|
private static java.lang.String[] |
syntax
Help text for command line users.
|
private java.text.NumberFormat |
tfmt
Formats a token type (integer) padded on left with zeros.
|
Constructor and Description |
---|
DumpBitSet() |
Modifier and Type | Method and Description |
---|---|
private void |
dumpWorker(antlr.collections.impl.BitSet testSet,
java.lang.String[] tokenNames)
Core worker routine that dumps the
BitSet to
STDOUT . |
static antlr.collections.impl.BitSet |
lookupBitSet(java.lang.String className,
java.lang.String setName)
Uses reflection to obtain a reference to the
BitSet
that is to be dumped. |
static java.lang.String[] |
lookupTokenNames(java.lang.String className)
Uses reflection to obtain a reference to the
_tokenNames
String[] that maps integer token types to the symbolic
names used in the ANTLR grammars. |
static void |
main(java.lang.String[] args)
Provides a command line interface for an end user to dump an arbitrary
public static
BitSet field of an arbitrary public parser
or lexer created by ANTLR. |
private static void |
printSyntax()
Helper method to print out syntax help messages for the command line
user.
|
private java.text.NumberFormat tfmt
private static java.lang.String[] syntax
public static java.lang.String[] lookupTokenNames(java.lang.String className) throws java.lang.ClassNotFoundException, java.lang.NoSuchFieldException, java.lang.IllegalAccessException, java.lang.SecurityException
_tokenNames
String[]
that maps integer token types to the symbolic
names used in the ANTLR grammars.
Note that this field is public static
and is always named
the same, so it is hard coded into this method for convenience.
className
- Fully qualified (incuding package) classname of the parser
or lexer in which to find the array.String[]
.java.lang.ClassNotFoundException
- If an respective error occurs.java.lang.NoSuchFieldException
- If an respective error occurs.java.lang.IllegalAccessException
- If an respective error occurs.java.lang.SecurityException
- If an respective error occurs.public static antlr.collections.impl.BitSet lookupBitSet(java.lang.String className, java.lang.String setName) throws java.lang.ClassNotFoundException, java.lang.NoSuchFieldException, java.lang.IllegalAccessException, java.lang.SecurityException
BitSet
that is to be dumped. These
Note that such BitSet
fields are public static
so all that is needed is the name of the field.
className
- Fully qualified (incuding package) classname of the parser
or lexer in which to find the bit set.setName
- The name of the BitSet
field to dump.BitSet
field reference.java.lang.ClassNotFoundException
- If an respective error occurs.java.lang.NoSuchFieldException
- If an respective error occurs.java.lang.IllegalAccessException
- If an respective error occurs.java.lang.SecurityException
- If an respective error occurs.private void dumpWorker(antlr.collections.impl.BitSet testSet, java.lang.String[] tokenNames)
BitSet
to
STDOUT
.testSet
- The BitSet
to dump.tokenNames
- The array of associated token names.private static void printSyntax()
public static void main(java.lang.String[] args)
BitSet
field of an arbitrary public parser
or lexer created by ANTLR.
Syntax:
java DumpBitSet <bitsetclass> <setname>Where:
public static BitSet
public static BitSet
to
dump
args
- List of command line arguments.