antlr-ng Tool Class Hierarchy / codegen/ITargetGenerator / ITargetGeneratorCallables
Interface: ITargetGeneratorCallables
This interface contains all callable members of the target generator, which generate code. They all take an output model object (aka OMO) as first argument. The generator will use the information in the model object to generate the target code.
Extended by
Methods
escapeIfNeeded()
escapeIfNeeded(identifier): string;
Parameters
identifier
string
Returns
string
renderBaseListenerFile()
renderBaseListenerFile(file, declaration): string;
Renders a base version of a ListenerFile
output model. This base class implements all methods of the listener interface as empty methods. This is useful for the user to create a custom listener class by extending this base class and overriding only the methods of interest.
Languages that support optional methods (e.g. TypeSricpt) don't need such a base class. Custom listeners can simply implement the interface and override only the methods of interest. The code generator has to insert code to test if the method is implemented or not.
Parameters
file
ListenerFile
The model object for details.
declaration
boolean
If true, render the declaration file for the base listener file.
Returns
string
The generated code as a string.
renderBaseVisitorFile()
renderBaseVisitorFile(file, declaration): string;
Renders a base version of a VisitorFile
output model. This base class implements all methods of the visitor interface as empty methods. This is useful for the user to create a custom vistitors class by extending this base class and overriding only the methods of interest.
Languages that support optional methods (e.g. TypeSricpt) don't need such a base class. Custom listeners can simply implement the interface and override only the methods of interest. The code generator has to insert code to test if the method is implemented or not.
Parameters
file
VisitorFile
The model object for details.
declaration
boolean
If true, render the declaration file for the base visitor file.
Returns
string
The generated code as a string.
renderImplicitRuleLabel()
renderImplicitRuleLabel(ruleName): string;
Parameters
ruleName
string
Returns
string
renderImplicitSetLabel()
renderImplicitSetLabel(id): string;
Parameters
id
string
Returns
string
renderImplicitTokenLabel()
renderImplicitTokenLabel(tokenName): string;
Should be same for all refs to same token like ctx.ID within single rule function for literals like 'while', we gen _s<ttype>
Parameters
tokenName
string
Returns
string
renderLexerFile()
renderLexerFile(file, declaration): string;
Renders a LexerFile
output model.
Parameters
file
LexerFile
The model object for details.
declaration
boolean
If true, render the declaration file for the lexer file.
Returns
string
The generated code as a string.
renderListenerFile()
renderListenerFile(file, declaration): string;
Renders a ListenerFile
output model.
Parameters
file
ListenerFile
The model object for details.
declaration
boolean
If true, render the declaration file for the listener file.
Returns
string
The generated code as a string.
renderListLabelName()
renderListLabelName(label): string;
Parameters
label
string
Returns
string
renderParserFile()
renderParserFile(file, declaration): string;
Renders a ParserFile
output model.
Parameters
file
ParserFile
The model object for details.
declaration
boolean
If true, render the declaration file for the parser file.
Returns
string
The generated code as a string.
renderTestFile()
renderTestFile(
grammarName,
lexerName,
parserName,
parserStartRuleName,
showDiagnosticErrors,
traceATN,
profile,
showDFA,
useListener,
useVisitor,
predictionMode,
buildParseTree): string;
Renders the content of the unit test file with the given parameters. The test file is used to execute a single unit test for a grammar. It contains the necessary imports, the test function and the code to parse a given input string with the specified parser and lexer.
Parameters
grammarName
string
The name of the grammar to be tested.
lexerName
string
The name of the lexer to be used in the test.
parserName
The name of the parser to be used in the test.
undefined
| string
parserStartRuleName
The start rule of the parser to be used in the test.
undefined
| string
showDiagnosticErrors
boolean
If true, the test will show diagnostic errors in the output.
traceATN
boolean
If true, the test will print ATN tracing information.
profile
boolean
If true, the test will profile the parsing process.
showDFA
boolean
If true, the test will show the DFA state information from the lexer.
useListener
boolean
If true, the test will use a listener to print processing information.
useVisitor
boolean
If true, the test will use a visitor. This is used mostly to test importing the generated visitor class.
predictionMode
string
The prediction mode to be used in the test. This can be one of the following: "LL", "SLL", "LL_EXACT_AMBIG_DETECTION". If undefined, the default prediction mode of the parser will be used.
buildParseTree
boolean
If true, the test will build a parse tree from the input string and print it.
Returns
string
renderVisitorFile()
renderVisitorFile(file, declaration): string;
Renders a VistiorFile
output model.
Parameters
file
VisitorFile
The model object for details.
declaration
boolean
If true, render the declaration file for the visitor file.
Returns
string
The generated code as a string.