Package antlr
Class Tool
- java.lang.Object
-
- antlr.Tool
-
public class Tool extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description (package private) ToolErrorHandler
errorHandler
Object that handles analysis errors(package private) java.io.Reader
f
(package private) boolean
genDiagnostics
Generate diagnostics? (vs code)(package private) boolean
genDocBook
Generate DocBook vs code?protected boolean
genHashLines
(package private) boolean
genHTML
Generate HTML vs code?protected java.lang.String
grammarFile
protected boolean
hasError
Was there an error during parsing or analysis?protected java.lang.String
literalsPrefix
protected NameSpace
nameSpace
C++ file level optionsprotected java.lang.String
namespaceAntlr
protected java.lang.String
namespaceStd
protected boolean
noConstructors
protected java.lang.String
outputDir
Current output directory for generated filesprotected boolean
upperCaseMangledLiterals
static java.lang.String
version
-
Constructor Summary
Constructors Constructor Description Tool()
Construct a new Tool.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected void
checkForInvalidArguments(java.lang.String[] args, BitSet cmdLineArgValid)
void
copyFile(java.lang.String source_name, java.lang.String dest_name)
This example is from the book _Java in a Nutshell_ by David Flanagan.int
doEverything(java.lang.String[] args)
Process args and have ANTLR do it's stuff without calling System.exit.void
doEverythingWrapper(java.lang.String[] args)
Perform processing on the grammar file.void
error(java.lang.String s)
Issue an errorvoid
error(java.lang.String s, java.lang.String file, int line, int column)
Issue an error with line number informationvoid
fatalError(java.lang.String message)
An error occured that should stop the Tool from doing any work.java.lang.String
fileMinusPath(java.lang.String f)
boolean
getGenHashLines()
java.lang.String
getGrammarFile()
java.io.Reader
getGrammarReader()
java.lang.String
getLanguage(MakeGrammar behavior)
Determine the language used for this run of ANTLR This was made a method so the subclass can override itjava.lang.String
getLiteralsPrefix()
NameSpace
getNameSpace()
java.lang.String
getNamespaceAntlr()
java.lang.String
getNamespaceStd()
java.lang.String
getOutputDirectory()
boolean
getUpperCaseMangledLiterals()
boolean
hasError()
static void
main(java.lang.String[] args)
java.io.PrintWriter
openOutputFile(java.lang.String f)
This method is used by all code generators to create new output files.void
panic()
Deprecated.as of 2.7.2 usefatalError(String)
.void
panic(java.lang.String s)
Deprecated.as of 2.7.2 usefatalError(String)
.java.io.File
parent(java.io.File f)
static Vector
parseSeparatedList(java.lang.String list, char separator)
Parse a list such as "f1.g;f2.g;..." and return a Vector of the elements.java.lang.String
pathToFile(java.lang.String f)
given a filename, strip off the directory prefix (if any) and return it.protected void
processArguments(java.lang.String[] args)
Process the command-line arguments.void
reportException(java.lang.Exception e, java.lang.String message)
void
reportProgress(java.lang.String message)
void
setArgOK(int i)
void
setFileLineFormatter(FileLineFormatter formatter)
void
setNameSpace(java.lang.String name)
Support C++ & C# namespaces (for now).void
setOutputDirectory(java.lang.String o)
void
toolError(java.lang.String s)
Issue an error; used for general tool errors not for grammar stuffvoid
warning(java.lang.String s)
Issue a warningvoid
warning(java.lang.String[] s, java.lang.String file, int line, int column)
Issue a warning with line number informationvoid
warning(java.lang.String s, java.lang.String file, int line, int column)
Issue a warning with line number information
-
-
-
Field Detail
-
version
public static java.lang.String version
-
errorHandler
ToolErrorHandler errorHandler
Object that handles analysis errors
-
hasError
protected boolean hasError
Was there an error during parsing or analysis?
-
genDiagnostics
boolean genDiagnostics
Generate diagnostics? (vs code)
-
genDocBook
boolean genDocBook
Generate DocBook vs code?
-
genHTML
boolean genHTML
Generate HTML vs code?
-
outputDir
protected java.lang.String outputDir
Current output directory for generated files
-
grammarFile
protected java.lang.String grammarFile
-
f
transient java.io.Reader f
-
literalsPrefix
protected java.lang.String literalsPrefix
-
upperCaseMangledLiterals
protected boolean upperCaseMangledLiterals
-
nameSpace
protected NameSpace nameSpace
C++ file level options
-
namespaceAntlr
protected java.lang.String namespaceAntlr
-
namespaceStd
protected java.lang.String namespaceStd
-
genHashLines
protected boolean genHashLines
-
noConstructors
protected boolean noConstructors
-
-
Method Detail
-
getGrammarFile
public java.lang.String getGrammarFile()
-
hasError
public boolean hasError()
-
getNameSpace
public NameSpace getNameSpace()
-
getNamespaceStd
public java.lang.String getNamespaceStd()
-
getNamespaceAntlr
public java.lang.String getNamespaceAntlr()
-
getGenHashLines
public boolean getGenHashLines()
-
getLiteralsPrefix
public java.lang.String getLiteralsPrefix()
-
getUpperCaseMangledLiterals
public boolean getUpperCaseMangledLiterals()
-
setFileLineFormatter
public void setFileLineFormatter(FileLineFormatter formatter)
-
checkForInvalidArguments
protected void checkForInvalidArguments(java.lang.String[] args, BitSet cmdLineArgValid)
-
copyFile
public void copyFile(java.lang.String source_name, java.lang.String dest_name) throws java.io.IOException
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.- Throws:
java.io.IOException
-
doEverythingWrapper
public void doEverythingWrapper(java.lang.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.
-
doEverything
public int doEverything(java.lang.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.
-
error
public void error(java.lang.String s)
Issue an error- Parameters:
s
- The message
-
error
public void error(java.lang.String s, java.lang.String file, int line, int column)
Issue an error with line number information- Parameters:
s
- The messagefile
- 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)
-
fileMinusPath
public java.lang.String fileMinusPath(java.lang.String f)
-
getLanguage
public java.lang.String getLanguage(MakeGrammar behavior)
Determine the language used for this run of ANTLR This was made a method so the subclass can override it
-
getOutputDirectory
public java.lang.String getOutputDirectory()
-
main
public static void main(java.lang.String[] args)
-
openOutputFile
public java.io.PrintWriter openOutputFile(java.lang.String f) throws java.io.IOException
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.- Throws:
java.io.IOException
-
getGrammarReader
public java.io.Reader getGrammarReader()
-
reportException
public void reportException(java.lang.Exception e, java.lang.String message)
- Since:
- 2.7.2
-
reportProgress
public void reportProgress(java.lang.String message)
- Since:
- 2.7.2
-
fatalError
public void fatalError(java.lang.String message)
An error occured that should stop the Tool from doing any work. The default implementation currently exits (via {@link 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 asIllegalStateException
or another subclass ofRuntimeException
. 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
-
panic
public void panic()
Deprecated.as of 2.7.2 usefatalError(String)
. By default this method executesfatalError("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(java.lang.String s)
Deprecated.as of 2.7.2 usefatalError(String)
. By defaykt this method executesfatalError("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 java.io.File parent(java.io.File f)
-
parseSeparatedList
public static Vector parseSeparatedList(java.lang.String list, char separator)
Parse a list such as "f1.g;f2.g;..." and return a Vector of the elements.
-
pathToFile
public java.lang.String pathToFile(java.lang.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(java.lang.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()
-
setArgOK
public void setArgOK(int i)
-
setOutputDirectory
public void setOutputDirectory(java.lang.String o)
-
toolError
public void toolError(java.lang.String s)
Issue an error; used for general tool errors not for grammar stuff- Parameters:
s
- The message
-
warning
public void warning(java.lang.String s)
Issue a warning- Parameters:
s
- the message
-
warning
public void warning(java.lang.String s, java.lang.String file, int line, int column)
Issue a warning with line number information- Parameters:
s
- The messagefile
- 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(java.lang.String[] s, java.lang.String file, int line, int column)
Issue a warning with line number information- Parameters:
s
- The lines of the messagefile
- The file that has the warningline
- The grammar file line number on which the warning occured
-
setNameSpace
public void setNameSpace(java.lang.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
-
-