antlr-ng Tool Class Hierarchy / index / Tool
Class: Tool
The main class in antlr-ng, which is used to do full grammar processing and output generation.
Implements
ITool
Constructors
Constructor
new Tool(): Tool;
Returns
Tool
Properties
errorManager
readonly errorManager: ErrorManager;
Implementation of
ITool.errorManager
toolConfiguration
toolConfiguration: IToolConfiguration;
Implementation of
ITool.toolConfiguration
Methods
checkForRuleIssues()
checkForRuleIssues(g): boolean;
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.
Parameters
g
The grammar to check.
Returns
boolean
true if there are issues with the rules.
Implementation of
ITool.checkForRuleIssues
createGrammar()
createGrammar(grammarAST): IGrammar;
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.
Parameters
grammarAST
The raw AST of the grammar.
Returns
IGrammar
The grammar object.
Implementation of
ITool.createGrammar
exit()
exit(e): void;
Parameters
e
number
Returns
void
Implementation of
ITool.exit
exportATNDotFiles()
exportATNDotFiles(g): void;
Parameters
g
Returns
void
Implementation of
ITool.exportATNDotFiles
generate()
generate(parameters): boolean;
Initiates a full generation process with the given parameters.
Parameters
parameters
IToolConfiguration
Details about the generation process (source + target files, options, etc.).
Returns
boolean
true if the run was successful, false otherwise.
Implementation of
ITool.generate
getImportedGrammarFile()
getImportedGrammarFile(g, fileName): undefined | string;
Parameters
g
fileName
string
Returns
undefined
| string
Implementation of
ITool.getImportedGrammarFile
getNumErrors()
getNumErrors(): number;
Returns
number
Implementation of
ITool.getNumErrors
getOutputDirectory()
getOutputDirectory(fileNameWithPath): string;
Parameters
fileNameWithPath
string
path to input source.
Returns
string
the location where antlr-ng will generate output files for a given grammar. This is either the output directory specified in the configuration or the directory of the input file.
Implementation of
ITool.getOutputDirectory
getOutputFile()
getOutputFile(g, fileName): string;
This method is used by all code generators that create output files. If the specificed outputDir is not present it will be created (recursively).
If the output path is relative, it will be resolved relative to the current working directory.
If no output dir is specified, then just write to the directory where the grammar file was found.
Parameters
g
The grammar for which we are generating a file.
fileName
string
The name of the file to generate.
Returns
string
The full path to the output file.
Implementation of
ITool.getOutputFile
loadGrammar()
loadGrammar(fileName): Grammar;
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.
Parameters
fileName
string
The name of the grammar file to load.
Returns
The grammar object.
Implementation of
ITool.loadGrammar
loadImportedGrammar()
loadImportedGrammar(g, nameNode): null | Grammar;
Try current dir then dir of g then lib dir.
Parameters
g
The grammar to import.
nameNode
The node associated with the imported grammar name.
Returns
null
| Grammar
The imported grammar or null if not found.
Implementation of
ITool.loadImportedGrammar
logInfo()
logInfo(info): void;
Parameters
info
component?
string
msg
string
Returns
void
Implementation of
ITool.logInfo
panic()
panic(): void;
Returns
void
Implementation of
ITool.panic
parse()
parse(input): undefined | GrammarRootAST;
Parameters
input
CharStream
Returns
undefined
| GrammarRootAST
Implementation of
ITool.parse
parseGrammar()
parseGrammar(fileName): undefined | GrammarRootAST;
Parameters
fileName
string
Returns
undefined
| GrammarRootAST
Implementation of
ITool.parseGrammar
parseGrammarFromString()
parseGrammarFromString(grammar): undefined | GrammarRootAST;
Parameters
grammar
string
Returns
undefined
| GrammarRootAST
Implementation of
ITool.parseGrammarFromString
process()
process(
g,
configuration,
genCode): void;
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
Parameters
g
The grammar to process.
configuration
IToolConfiguration
Details about the generation process (source + target files, options, etc.).
genCode
boolean
Whether to generate code or not.
Returns
void
Implementation of
ITool.process
processNonCombinedGrammar()
processNonCombinedGrammar(g, genCode): void;
Parameters
g
genCode
boolean
Returns
void
Implementation of
ITool.processNonCombinedGrammar
sortGrammarByTokenVocab()
sortGrammarByTokenVocab(fileNames): GrammarRootAST[];
Parameters
fileNames
string
[]
Returns
Implementation of
ITool.sortGrammarByTokenVocab
writeDOTFile()
protected writeDOTFile(
g,
rulOrName,
dot): void;
Parameters
g
rulOrName
string
| Rule
dot
string
Returns
void
Implementation of
ITool.writeDOTFile