Package org.antlr.v4
Class Tool
java.lang.Object
org.antlr.v4.Tool
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionfinal String[]
boolean
boolean
boolean
boolean
boolean
boolean
static final String
protected boolean
static boolean
static boolean
boolean
static final String
boolean
boolean
static Tool.Option[]
protected boolean
boolean
static final String
boolean
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
boolean
Important enough to avoid multiple definitions that we do very early, right after AST construction.Given the raw AST of a grammar, create a grammar object associated with the AST.void
error
(ANTLRMessage msg) void
exit
(int e) static GrammarAST
findOptionValueAST
(GrammarRootAST root, String option) Manually get option node from tree; return null if no defined.void
getImportedGrammarFile
(Grammar g, String fileName) int
getOutputDirectory
(String fileNameWithPath) Return the location where ANTLR will generate output files for a given file.getOutputFileWriter
(Grammar g, String fileName) This method is used by all code generators to create new output files.protected void
protected void
handleOptionSetArg
(String arg) void
help()
void
loadGrammar
(String fileName) Convenience method to load and process an ANTLR grammar.loadImportedGrammar
(Grammar g, GrammarAST nameNode) Try current dir then dir of g then lib dirvoid
void
static void
new_getOutputDirectory
(String fileNameWithPath) void
panic()
parseGrammar
(String fileName) parseGrammarFromString
(String grammar) void
To process a grammar, we load all of its imported grammars into subordinate grammar objects.void
void
processNonCombinedGrammar
(Grammar g, boolean gencode) void
void
sortGrammarByTokenVocab
(List<String> fileNames) void
version()
void
warning
(ANTLRMessage msg) protected void
writeDOTFile
(Grammar g, String name, String dot) protected void
writeDOTFile
(Grammar g, Rule r, String dot)
-
Field Details
-
VERSION
-
GRAMMAR_EXTENSION
- See Also:
-
LEGACY_GRAMMAR_EXTENSION
- See Also:
-
ALL_GRAMMAR_EXTENSIONS
-
inputDirectory
-
outputDirectory
-
libDirectory
-
generate_ATN_dot
public boolean generate_ATN_dot -
grammarEncoding
-
msgFormat
-
launch_ST_inspector
public boolean launch_ST_inspector -
ST_inspector_wait_for_close
public boolean ST_inspector_wait_for_close -
force_atn
public boolean force_atn -
log
public boolean log -
gen_listener
public boolean gen_listener -
gen_visitor
public boolean gen_visitor -
gen_dependencies
public boolean gen_dependencies -
genPackage
-
grammarOptions
-
warnings_are_errors
public boolean warnings_are_errors -
longMessages
public boolean longMessages -
exact_output_dir
public boolean exact_output_dir -
optionDefs
-
haveOutputDir
protected boolean haveOutputDir -
return_dont_exit
protected boolean return_dont_exit -
internalOption_PrintGrammarTree
public static boolean internalOption_PrintGrammarTree -
internalOption_ShowATNConfigsInDFA
public static boolean internalOption_ShowATNConfigsInDFA -
args
-
grammarFiles
-
errMgr
-
logMgr
-
-
Constructor Details
-
Tool
public Tool() -
Tool
-
-
Method Details
-
main
-
handleArgs
protected void handleArgs() -
handleOptionSetArg
-
processGrammarsOnCommandLine
public void processGrammarsOnCommandLine() -
process
To process a grammar, we load all of its imported grammars into subordinate grammar objects. Then we merge the imported rules into the root grammar. If a root grammar is a combined grammar, we have to extract the implicit lexer. Once all this is done, we process the lexer first, if present, and then the parser grammar -
processNonCombinedGrammar
-
checkForRuleIssues
Important enough to avoid multiple definitions that we do very early, right after AST construction. Also check for undefined rules in parser/lexer to avoid exceptions later. Return true if we find multiple definitions of the same rule or a reference to an undefined rule or parser rule ref in lexer rule. -
sortGrammarByTokenVocab
-
findOptionValueAST
Manually get option node from tree; return null if no defined. -
createGrammar
Given the raw AST of a grammar, create a grammar object associated with the AST. Once we have the grammar object, ensure that all nodes in tree referred to this grammar. Later, we will use it for error handling and generally knowing from where a rule comes from. -
parseGrammar
-
loadGrammar
Convenience method to load and process an ANTLR grammar. Useful when creating interpreters. If you need to access to the lexer grammar created while processing a combined grammar, use getImplicitLexer() on returned grammar. -
loadImportedGrammar
Try current dir then dir of g then lib dir- Parameters:
g
-nameNode
- The node associated with the imported grammar name.- Throws:
IOException
-
parseGrammarFromString
-
parse
-
generateATNs
-
getOutputFileWriter
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. The final filename is sensitive to the output directory and the directory where the grammar file was found. If -o is /tmp and the original grammar file was foo/t.g4 then output files go in /tmp/foo. The output dir -o spec takes precedence if it's absolute. E.g., if the grammar file dir is absolute the output dir is given precedence. "-o /tmp /usr/lib/t.g4" results in "/tmp/T.java" as output (assuming t.g4 holds T.java). If no -o is specified, then just write to the directory where the grammar file was found. If outputDirectory==null then write a String.- Throws:
IOException
-
getImportedGrammarFile
-
getOutputDirectory
Return the location where ANTLR will generate output files for a given file. This is a base directory and output files will be relative to here in some cases such as when -o option is used and input files are given relative to the input directory.- Parameters:
fileNameWithPath
- path to input source
-
new_getOutputDirectory
- Since:
- 4.7.1 in response to -Xexact-output-dir
-
writeDOTFile
- Throws:
IOException
-
writeDOTFile
- Throws:
IOException
-
help
public void help() -
log
-
log
-
getNumErrors
public int getNumErrors() -
addListener
-
removeListener
-
removeListeners
public void removeListeners() -
getListeners
-
info
-
error
-
warning
-
version
public void version() -
exit
public void exit(int e) -
panic
public void panic()
-