Skip to content

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 ​

ts
new Tool(): Tool;

Returns ​

Tool

Properties ​

errorManager ​

ts
readonly errorManager: ErrorManager;

Implementation of ​

ts
ITool.errorManager

toolConfiguration ​

ts
toolConfiguration: IToolConfiguration;

Implementation of ​

ts
ITool.toolConfiguration

Methods ​

checkForRuleIssues() ​

ts
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 ​

Grammar

The grammar to check.

Returns ​

boolean

true if there are issues with the rules.

Implementation of ​

ts
ITool.checkForRuleIssues

createGrammar() ​

ts
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 ​

GrammarRootAST

The raw AST of the grammar.

Returns ​

IGrammar

The grammar object.

Implementation of ​

ts
ITool.createGrammar

exit() ​

ts
exit(e): void;

Parameters ​

e ​

number

Returns ​

void

Implementation of ​

ts
ITool.exit

exportATNDotFiles() ​

ts
exportATNDotFiles(g): void;

Parameters ​

g ​

Grammar

Returns ​

void

Implementation of ​

ts
ITool.exportATNDotFiles

generate() ​

ts
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 ​

ts
ITool.generate

getImportedGrammarFile() ​

ts
getImportedGrammarFile(g, fileName): undefined | string;

Parameters ​

g ​

Grammar

fileName ​

string

Returns ​

undefined | string

Implementation of ​

ts
ITool.getImportedGrammarFile

getNumErrors() ​

ts
getNumErrors(): number;

Returns ​

number

Implementation of ​

ts
ITool.getNumErrors

getOutputDirectory() ​

ts
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 ​

ts
ITool.getOutputDirectory

getOutputFile() ​

ts
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 ​

Grammar

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 ​

ts
ITool.getOutputFile

loadGrammar() ​

ts
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 ​

Grammar

The grammar object.

Implementation of ​

ts
ITool.loadGrammar

loadImportedGrammar() ​

ts
loadImportedGrammar(g, nameNode): null | Grammar;

Try current dir then dir of g then lib dir.

Parameters ​

g ​

Grammar

The grammar to import.

nameNode ​

GrammarAST

The node associated with the imported grammar name.

Returns ​

null | Grammar

The imported grammar or null if not found.

Implementation of ​

ts
ITool.loadImportedGrammar

logInfo() ​

ts
logInfo(info): void;

Parameters ​

info ​
component? ​

string

msg ​

string

Returns ​

void

Implementation of ​

ts
ITool.logInfo

panic() ​

ts
panic(): void;

Returns ​

void

Implementation of ​

ts
ITool.panic

parse() ​

ts
parse(input): undefined | GrammarRootAST;

Parameters ​

input ​

CharStream

Returns ​

undefined | GrammarRootAST

Implementation of ​

ts
ITool.parse

parseGrammar() ​

ts
parseGrammar(fileName): undefined | GrammarRootAST;

Parameters ​

fileName ​

string

Returns ​

undefined | GrammarRootAST

Implementation of ​

ts
ITool.parseGrammar

parseGrammarFromString() ​

ts
parseGrammarFromString(grammar): undefined | GrammarRootAST;

Parameters ​

grammar ​

string

Returns ​

undefined | GrammarRootAST

Implementation of ​

ts
ITool.parseGrammarFromString

process() ​

ts
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 ​

Grammar

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 ​

ts
ITool.process

processNonCombinedGrammar() ​

ts
processNonCombinedGrammar(g, genCode): void;

Parameters ​

g ​

Grammar

genCode ​

boolean

Returns ​

void

Implementation of ​

ts
ITool.processNonCombinedGrammar

sortGrammarByTokenVocab() ​

ts
sortGrammarByTokenVocab(fileNames): GrammarRootAST[];

Parameters ​

fileNames ​

string[]

Returns ​

GrammarRootAST[]

Implementation of ​

ts
ITool.sortGrammarByTokenVocab

writeDOTFile() ​

ts
protected writeDOTFile(
   g, 
   rulOrName, 
   dot): void;

Parameters ​

g ​

Grammar

rulOrName ​

string | Rule

dot ​

string

Returns ​

void

Implementation of ​

ts
ITool.writeDOTFile