| java.lang.Object org.antlr.codegen.Target
All known Subclasses: org.antlr.codegen.RubyTarget, org.antlr.codegen.JavaTarget, org.antlr.codegen.ObjCTarget, org.antlr.codegen.PythonTarget, org.antlr.codegen.CSharpTarget, org.antlr.codegen.CTarget, org.antlr.codegen.CPPTarget,
Target | public class Target (Code) | | The code generator for ANTLR can usually be retargeted just by providing
a new X.stg file for language X, however, sometimes the files that must
be generated vary enough that some X-specific functionality is required.
For example, in C, you must generate header files whereas in Java you do not.
Other languages may want to keep DFA separate from the main
generated recognizer file.
The notion of a Code Generator target abstracts out the creation
of the various files. As new language targets get added to the ANTLR
system, this target class may have to be altered to handle more
functionality. Eventually, just about all language generation issues
will be expressible in terms of these methods.
If org.antlr.codegen.XTarget class exists, it is used else
Target base class is used. I am using a superclass rather than an
interface for this target concept because I can add functionality
later without breaking previously written targets (extra interface
methods would force adding dummy functions to all code generator
target classes).
|
Field Summary | |
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 Summary | |
public | Target() |
Method Summary | |
protected void | genRecognizerFile(Tool tool, CodeGenerator generator, Grammar grammar, StringTemplate outputFileST) | protected void | genRecognizerHeaderFile(Tool tool, CodeGenerator generator, Grammar grammar, StringTemplate headerFileST, String extName) | public int | getMaxCharValue(CodeGenerator generator) Some targets only support ASCII or 8-bit chars/strings. | public String | getTarget64BitStringFromValue(long word) Convert long to 0xNNNNNNNNNNNNNNNN by default for spitting out
with bitsets. | public String | getTargetCharLiteralFromANTLRCharLiteral(CodeGenerator generator, String literal) Convert from an ANTLR char literal found in a grammar file to
an equivalent char literal in the target language. | public String | getTargetStringLiteralFromANTLRStringLiteral(CodeGenerator generator, String literal) Convert from an ANTLR string literal found in a grammar file to
an equivalent string literal in the target language. | public 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. | public String | getTargetStringLiteralFromString(String s) | public String | getTokenTypeAsTargetLabel(CodeGenerator generator, int ttype) | public boolean | isValidActionScope(int grammarType, String scope) Is scope in @scope::name {action} valid for this kind of grammar?
Targets like C++ may want to allow new scopes like headerfile or
some such. | protected void | performGrammarAnalysis(CodeGenerator generator, Grammar grammar) | public List | postProcessAction(List chunks, antlr.Token actionToken) Give target a chance to do some postprocessing on actions. |
targetCharValueEscape | protected String[] targetCharValueEscape(Code) | | For pure strings of Java 16-bit unicode char, how can we display
it in the target language as a literal. Useful for dumping
predicates and such that may refer to chars that need to be escaped
when represented as strings. Also, templates need to be escaped so
that the target language can hold them as a string.
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 nonstatic so each target can have
a different set in memory at same time.
|
getMaxCharValue | public int getMaxCharValue(CodeGenerator generator)(Code) | | Some targets only support ASCII or 8-bit chars/strings. For example,
C++ will probably want to return 0xFF here.
|
getTarget64BitStringFromValue | public String getTarget64BitStringFromValue(long word)(Code) | | Convert long to 0xNNNNNNNNNNNNNNNN by default for spitting out
with bitsets. I.e., convert bytes to hex string.
|
getTargetCharLiteralFromANTLRCharLiteral | public String getTargetCharLiteralFromANTLRCharLiteral(CodeGenerator generator, String literal)(Code) | | Convert from an ANTLR char literal found in a grammar file to
an equivalent char literal in the target language. For most
languages, this means leaving 'x' as 'x'. Actually, we need
to escape '
' so that it doesn't get converted to \n by
the compiler. Convert the literal to the char value and then
to an appropriate target char literal.
Expect single quotes around the incoming literal.
|
getTargetStringLiteralFromANTLRStringLiteral | public String getTargetStringLiteralFromANTLRStringLiteral(CodeGenerator generator, String literal)(Code) | | 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 \"
|
getTargetStringLiteralFromString | public String getTargetStringLiteralFromString(String s, boolean quoted)(Code) | | 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. For example, if the incoming string has
actual newline characters, the output of this method would convert them
to the two char sequence \n for Java, C, C++, ... The new string has
double-quotes around it as well. Example String in memory:
a"[newlinechar]b'c[carriagereturnchar]d[tab]e\f
would be converted to the valid Java s:
"a\"\nb'c\rd\te\\f"
or
a\"\nb'c\rd\te\\f
depending on the quoted arg.
|
getTargetStringLiteralFromString | public String getTargetStringLiteralFromString(String s)(Code) | | |
getTokenTypeAsTargetLabel | public String getTokenTypeAsTargetLabel(CodeGenerator generator, int ttype)(Code) | | Target must be able to override the labels used for token types
|
isValidActionScope | public boolean isValidActionScope(int grammarType, String scope)(Code) | | Is scope in @scope::name {action} valid for this kind of grammar?
Targets like C++ may want to allow new scopes like headerfile or
some such. The action names themselves are not policed at the
moment so targets can add template actions w/o having to recompile
ANTLR.
|
postProcessAction | public List postProcessAction(List chunks, antlr.Token actionToken)(Code) | | Give target a chance to do some postprocessing on actions.
Python for example will have to fix the indention.
|
|
|