antlr

Class Tool

public class Tool extends Object

Field Summary
ToolErrorHandlererrorHandler
Object that handles analysis errors
Readerf
booleangenDiagnostics
Generate diagnostics?
booleangenDocBook
Generate DocBook vs code?
protected booleangenHashLines
booleangenHTML
Generate HTML vs code?
protected StringgrammarFile
protected booleanhasError
Was there an error during parsing or analysis?
protected StringliteralsPrefix
protected StringnamespaceAntlr
protected StringnamespaceStd
protected NameSpacenameSpace
C++ file level options
protected booleannoConstructors
protected StringoutputDir
Current output directory for generated files
protected booleanupperCaseMangledLiterals
static Stringversion
Constructor Summary
Tool()
Construct a new Tool.
Method Summary
protected voidcheckForInvalidArguments(String[] args, BitSet cmdLineArgValid)
voidcopyFile(String source_name, String dest_name)
This example is from the book _Java in a Nutshell_ by David Flanagan.
intdoEverything(String[] args)
Process args and have ANTLR do it's stuff without calling System.exit.
voiddoEverythingWrapper(String[] args)
Perform processing on the grammar file.
voiderror(String s)
Issue an error
voiderror(String s, String file, int line, int column)
Issue an error with line number information
voidfatalError(String message)
An error occured that should stop the Tool from doing any work.
StringfileMinusPath(String f)
booleangetGenHashLines()
StringgetGrammarFile()
ReadergetGrammarReader()
StringgetLanguage(MakeGrammar behavior)
Determine the language used for this run of ANTLR This was made a method so the subclass can override it
StringgetLiteralsPrefix()
StringgetNamespaceAntlr()
StringgetNamespaceStd()
NameSpacegetNameSpace()
StringgetOutputDirectory()
booleangetUpperCaseMangledLiterals()
booleanhasError()
static voidmain(String[] args)
PrintWriteropenOutputFile(String f)
This method is used by all code generators to create new output files.
voidpanic()
Issue an unknown fatal error.
voidpanic(String s)
Issue a fatal error message.
Fileparent(File f)
static VectorparseSeparatedList(String list, char separator)
Parse a list such as "f1.g;f2.g;..." and return a Vector of the elements.
StringpathToFile(String f)
given a filename, strip off the directory prefix (if any) and return it.
protected voidprocessArguments(String[] args)

Process the command-line arguments.

voidreportException(Exception e, String message)
voidreportProgress(String message)
voidsetArgOK(int i)
voidsetFileLineFormatter(FileLineFormatter formatter)
voidsetNameSpace(String name)
Support C++ & C# namespaces (for now).
voidsetOutputDirectory(String o)
voidtoolError(String s)
Issue an error; used for general tool errors not for grammar stuff
voidwarning(String s)
Issue a warning
voidwarning(String s, String file, int line, int column)
Issue a warning with line number information
voidwarning(String[] s, String file, int line, int column)
Issue a warning with line number information

Field Detail

errorHandler

ToolErrorHandler errorHandler
Object that handles analysis errors

f

transient Reader f

genDiagnostics

boolean genDiagnostics
Generate diagnostics? (vs code)

genDocBook

boolean genDocBook
Generate DocBook vs code?

genHashLines

protected boolean genHashLines

genHTML

boolean genHTML
Generate HTML vs code?

grammarFile

protected String grammarFile

hasError

protected boolean hasError
Was there an error during parsing or analysis?

literalsPrefix

protected String literalsPrefix

namespaceAntlr

protected String namespaceAntlr

namespaceStd

protected String namespaceStd

nameSpace

protected NameSpace nameSpace
C++ file level options

noConstructors

protected boolean noConstructors

outputDir

protected String outputDir
Current output directory for generated files

upperCaseMangledLiterals

protected boolean upperCaseMangledLiterals

version

public static String version

Constructor Detail

Tool

public Tool()
Construct a new Tool.

Method Detail

checkForInvalidArguments

protected void checkForInvalidArguments(String[] args, BitSet cmdLineArgValid)

copyFile

public void copyFile(String source_name, String dest_name)
This example is from the book _Java in a Nutshell_ by David Flanagan. Written by David Flanagan. Copyright (c) 1996 O'Reilly & Associates. You may study, use, modify, and distribute this example for any purpose. This example is provided WITHOUT WARRANTY either expressed or implied.

doEverything

public int doEverything(String[] args)
Process args and have ANTLR do it's stuff without calling System.exit. Just return the result code. Makes it easy for ANT build tool.

doEverythingWrapper

public void doEverythingWrapper(String[] args)
Perform processing on the grammar file. Can only be called from main() @param args The command-line arguments passed to main(). This wrapper does the System.exit for use with command-line.

error

public void error(String s)
Issue an error

Parameters: s The message

error

public void error(String s, String file, int line, int column)
Issue an error with line number information

Parameters: s The message file The file that has the error (or null) line The grammar file line number on which the error occured (or -1) column The grammar file column number on which the error occured (or -1)

fatalError

public void fatalError(String message)
An error occured that should stop the Tool from doing any work. The default implementation currently exits (via java.lang.System.exit(int) after printing an error message to stderr. However, the tools should expect that a subclass will override this to throw an unchecked exception such as java.lang.IllegalStateException or another subclass of java.lang.RuntimeException. If this method is overriden, it must never return normally; i.e. it must always throw an exception or call System.exit.

Parameters: s The message

Since: 2.7.2

fileMinusPath

public String fileMinusPath(String f)

getGenHashLines

public boolean getGenHashLines()

getGrammarFile

public String getGrammarFile()

getGrammarReader

public Reader getGrammarReader()

getLanguage

public String getLanguage(MakeGrammar behavior)
Determine the language used for this run of ANTLR This was made a method so the subclass can override it

getLiteralsPrefix

public String getLiteralsPrefix()

getNamespaceAntlr

public String getNamespaceAntlr()

getNamespaceStd

public String getNamespaceStd()

getNameSpace

public NameSpace getNameSpace()

getOutputDirectory

public String getOutputDirectory()

getUpperCaseMangledLiterals

public boolean getUpperCaseMangledLiterals()

hasError

public boolean hasError()

main

public static void main(String[] args)

openOutputFile

public PrintWriter openOutputFile(String f)
This method is used by all code generators to create new output files. If the outputDir set by -o is not present it will be created here.

panic

public void panic()

Deprecated: as of 2.7.2 use fatalError. By default this method executes fatalError("panic");.

Issue an unknown fatal error. If this method is overriden, it must never return normally; i.e. it must always throw an exception or call System.exit.

panic

public void panic(String s)

Deprecated: as of 2.7.2 use fatalError. By defaykt this method executes fatalError("panic: " + s);.

Issue a fatal error message. If this method is overriden, it must never return normally; i.e. it must always throw an exception or call System.exit.

Parameters: s The message

parent

public File parent(File f)

parseSeparatedList

public static Vector parseSeparatedList(String list, char separator)
Parse a list such as "f1.g;f2.g;..." and return a Vector of the elements.

pathToFile

public String pathToFile(String f)
given a filename, strip off the directory prefix (if any) and return it. Return "./" if f has no dir prefix.

processArguments

protected void processArguments(String[] args)

Process the command-line arguments. Can only be called by Tool. A bitset is collected of all correct arguments via setArgOk.

Parameters: args The command-line arguments passed to main()

reportException

public void reportException(Exception e, String message)

Since: 2.7.2

reportProgress

public void reportProgress(String message)

Since: 2.7.2

setArgOK

public void setArgOK(int i)

setFileLineFormatter

public void setFileLineFormatter(FileLineFormatter formatter)

setNameSpace

public void setNameSpace(String name)
Support C++ & C# namespaces (for now). C++: Add a nested namespace name to the current namespace. C# : Specify an enclosing namespace for the generated code. DAW: David Wagner -- C# support by kunle odutola

setOutputDirectory

public void setOutputDirectory(String o)

toolError

public void toolError(String s)
Issue an error; used for general tool errors not for grammar stuff

Parameters: s The message

warning

public void warning(String s)
Issue a warning

Parameters: s the message

warning

public void warning(String s, String file, int line, int column)
Issue a warning with line number information

Parameters: s The message file The file that has the warning (or null) line The grammar file line number on which the warning occured (or -1) column The grammar file line number on which the warning occured (or -1)

warning

public void warning(String[] s, String file, int line, int column)
Issue a warning with line number information

Parameters: s The lines of the message file The file that has the warning line The grammar file line number on which the warning occured