public class Target extends Object
Modifier and Type | Field and Description |
---|---|
Set<String> |
badWords
Avoid grammar symbols in this set to prevent conflicts in gen'd code.
|
CodeGenerator |
gen |
static String[] |
javaKeywords |
protected String[] |
targetCharValueEscape
For pure strings of Java 16-bit Unicode char, how can we display
it in the target language as a literal.
|
Constructor and Description |
---|
Target(CodeGenerator gen) |
Modifier and Type | Method and Description |
---|---|
void |
addBadWords() |
String |
encodeIntAsCharEscape(int v)
Assume 16-bit char
|
protected void |
genFile(Grammar g,
org.stringtemplate.v4.ST outputFileST,
String fileName) |
protected void |
genListenerFile(Grammar g,
org.stringtemplate.v4.ST outputFileST) |
protected void |
genRecognizerHeaderFile(Grammar g,
org.stringtemplate.v4.ST headerFileST,
String extName) |
String |
getAltLabelContextStructName(String label) |
String |
getElementListName(String name) |
String |
getElementName(String name) |
String |
getImplicitRuleLabel(String ruleName) |
String |
getImplicitSetLabel(String id) |
String |
getImplicitTokenLabel(String tokenName) |
String |
getListLabel(String label) |
String |
getLoopCounter(GrammarAST ast) |
String |
getLoopLabel(GrammarAST ast) |
String |
getRuleFunctionContextStructName(Rule r) |
String |
getRuleFunctionContextStructName(RuleFunction function)
If we know which actual function, we can provide the actual ctx type.
|
String |
getTarget64BitStringFromValue(long word)
Convert long to 0xNNNNNNNNNNNNNNNN by default for spitting out
with bitsets.
|
String |
getTargetCharLiteralCharValue(int c)
Convert from an ANTLR char literal found in a grammar file to
an equivalent char literal in the target language.
|
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.
|
String |
getTokenTypeAsTargetLabel(Grammar g,
int ttype)
Get a meaningful name for a token type useful during code generation.
|
String[] |
getTokenTypesAsTargetLabels(Grammar g,
int[] ttypes) |
boolean |
grammarSymbolCausesIssueInGeneratedCode(GrammarAST idNode) |
protected String[] targetCharValueEscape
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.public CodeGenerator gen
public Set<String> badWords
public static String[] javaKeywords
public Target(CodeGenerator gen)
public void addBadWords()
protected void genListenerFile(Grammar g, org.stringtemplate.v4.ST outputFileST)
protected void genRecognizerHeaderFile(Grammar g, org.stringtemplate.v4.ST headerFileST, String extName)
public String getTokenTypeAsTargetLabel(Grammar g, int ttype)
public String getTargetCharLiteralCharValue(int c)
public String getTarget64BitStringFromValue(long word)
public String getTargetStringLiteralFromString(String s, boolean quoted)
public String getTargetStringLiteralFromANTLRStringLiteral(CodeGenerator generator, String literal, boolean addQuotes)
'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 Utils.replace(java.lang.String, java.lang.String, java.lang.String)
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 boolean grammarSymbolCausesIssueInGeneratedCode(GrammarAST idNode)
Copyright © 1992-2013 ANTLR. All Rights Reserved.