public abstract class Target extends Object
Modifier and Type | Field and Description |
---|---|
protected CodeGenerator |
gen |
protected String[] |
targetCharValueEscape
For pure strings of Java 16-bit Unicode char, how can we display
it in the target language as a literal.
|
Modifier | Constructor and Description |
---|---|
protected |
Target(CodeGenerator gen,
String language) |
Modifier and Type | Method and Description |
---|---|
protected abstract void |
appendUnicodeEscapedCodePoint(int codePoint,
StringBuilder sb)
Escape the Unicode code point appropriately for this language
and append the escaped value to
sb . |
String |
encodeIntAsCharEscape(int v)
Assume 16-bit char
|
protected void |
genFile(Grammar g,
org.stringtemplate.v4.ST outputFileST,
String fileName) |
String |
getAltLabelContextStructName(String label) |
String |
getBaseListenerFileName(boolean header)
A given grammar T, return a blank listener implementation
such as TBaseListener.java, if we're using the Java target.
|
String |
getBaseVisitorFileName(boolean header)
A given grammar T, return a blank listener implementation
such as TBaseListener.java, if we're using the Java target.
|
CodeGenerator |
getCodeGenerator() |
String |
getElementListName(String name) |
String |
getElementName(String name) |
String |
getImplicitRuleLabel(String ruleName) |
String |
getImplicitSetLabel(String id) |
String |
getImplicitTokenLabel(String tokenName) |
int |
getInlineTestSetWordSize()
How many bits should be used to do inline token type tests? Java assumes
a 64-bit word for bitsets.
|
String |
getLanguage() |
String |
getListenerFileName(boolean header)
A given grammar T, return the listener name such as
TListener.java, if we're using the Java target.
|
String |
getListLabel(String label) |
String |
getLoopCounter(GrammarAST ast) |
String |
getLoopLabel(GrammarAST ast) |
String |
getRecognizerFileName(boolean header)
Generate TParser.java and TLexer.java from T.g4 if combined, else
just use T.java as output regardless of type.
|
String |
getRuleFunctionContextStructName(Rule r) |
String |
getRuleFunctionContextStructName(RuleFunction function)
If we know which actual function, we can provide the actual ctx type.
|
int |
getSerializedATNSegmentLimit()
Gets the maximum number of 16-bit unsigned integers that can be encoded
in a single segment of the serialized ATN.
|
String |
getTargetStringLiteralFromANTLRStringLiteral(CodeGenerator generator,
String literal,
boolean addQuotes)
Convert from an ANTLR string literal found in a grammar file to an
equivalent string literal in the target language.
|
String |
getTargetStringLiteralFromString(String s) |
String |
getTargetStringLiteralFromString(String s,
boolean quoted)
Given a random string of Java unicode chars, return a new string with
optionally appropriate quote characters for target language and possibly
with some escaped characters.
|
org.stringtemplate.v4.STGroup |
getTemplates() |
String |
getTokenTypeAsTargetLabel(Grammar g,
int ttype)
Get a meaningful name for a token type useful during code generation.
|
String[] |
getTokenTypesAsTargetLabels(Grammar g,
int[] ttypes) |
abstract String |
getVersion()
ANTLR tool should check output templates / target are compatible with tool code generation.
|
String |
getVisitorFileName(boolean header)
A given grammar T, return the visitor name such as
TVisitor.java, if we're using the Java target.
|
boolean |
grammarSymbolCausesIssueInGeneratedCode(GrammarAST idNode) |
protected org.stringtemplate.v4.STGroup |
loadTemplates() |
boolean |
needsHeader() |
boolean |
supportsOverloadedMethods() |
boolean |
templatesExist() |
protected abstract boolean |
visibleGrammarSymbolCausesIssueInGeneratedCode(GrammarAST idNode) |
boolean |
wantsBaseListener() |
boolean |
wantsBaseVisitor() |
protected String[] targetCharValueEscape
I have defined (via the constructor) the set of typical escapes,
but your Target
subclass is free to alter the translated chars
or add more definitions. This is non-static so each target can have
a different set in memory at same time.
protected final CodeGenerator gen
protected Target(CodeGenerator gen, String language)
public CodeGenerator getCodeGenerator()
public String getLanguage()
public abstract String getVersion()
public org.stringtemplate.v4.STGroup getTemplates()
public String getTokenTypeAsTargetLabel(Grammar g, int ttype)
public String getTargetStringLiteralFromString(String s, boolean quoted)
protected abstract void appendUnicodeEscapedCodePoint(int codePoint, StringBuilder sb)
sb
.public String getTargetStringLiteralFromANTLRStringLiteral(CodeGenerator generator, String literal, boolean addQuotes)
Convert from an ANTLR string literal found in a grammar file to an equivalent string literal in the target language.
For Java, this is the translation 'a\n"'
→ "a\n\""
.
Expect single quotes around the incoming literal. Just flip the quotes
and replace double quotes with \"
.
Note that we have decided to allow people to use '\"' without penalty, so
we must build the target string in a loop as String.replace(char, char)
cannot handle both \"
and "
without a lot of messing
around.
public String encodeIntAsCharEscape(int v)
public String getLoopLabel(GrammarAST ast)
public String getLoopCounter(GrammarAST ast)
public String getRuleFunctionContextStructName(RuleFunction function)
public String getRecognizerFileName(boolean header)
public String getListenerFileName(boolean header)
public String getVisitorFileName(boolean header)
public String getBaseListenerFileName(boolean header)
public String getBaseVisitorFileName(boolean header)
public int getSerializedATNSegmentLimit()
SerializedATN.getSegments()
public int getInlineTestSetWordSize()
public boolean grammarSymbolCausesIssueInGeneratedCode(GrammarAST idNode)
protected abstract boolean visibleGrammarSymbolCausesIssueInGeneratedCode(GrammarAST idNode)
public boolean templatesExist()
protected org.stringtemplate.v4.STGroup loadTemplates()
public boolean wantsBaseListener()
public boolean wantsBaseVisitor()
public boolean supportsOverloadedMethods()
public boolean needsHeader()
Copyright © 1992–2020 ANTLR. All rights reserved.