Package org.antlr.v4.codegen.target
Class JavaTarget
java.lang.Object
org.antlr.v4.codegen.Target
org.antlr.v4.codegen.target.JavaTarget
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionAvoid grammar symbols in this set to prevent conflicts in gen'd code.protected static final String[]private static final ThreadLocal<org.stringtemplate.v4.STGroup>The Java target can cache the code generation templates.Fields inherited from class org.antlr.v4.codegen.Target
gen, targetCharValueEscape -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidprivate voidappendJavaStringCodePoint(int codePoint, StringBuilder sb) Append one code point inside a Java double-quoted literal.private voidappendJavaStringLiteralText(String text, StringBuilder sb) Append grammar text that is not a Unicode scalar.protected voidappendUnicodeEscapedCodePoint(int codePoint, StringBuilder sb) Escape the Unicode code point appropriately for this language and append the escaped value tosb.encodeIntAsCharEscape(int v) Assume 16-bit charintGets the maximum number of 16-bit unsigned integers that can be encoded in a single segment of the serialized ATN.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.private static booleanisHexDigit(char c) protected org.stringtemplate.v4.STGroupprotected booleanMethods inherited from class org.antlr.v4.codegen.Target
genFile, getAltLabelContextStructName, getBaseListenerFileName, getBaseVisitorFileName, getCodeGenerator, getElementListName, getElementName, getImplicitRuleLabel, getImplicitSetLabel, getImplicitTokenLabel, getInlineTestSetWordSize, getLanguage, getListenerFileName, getListLabel, getLoopCounter, getLoopLabel, getRecognizerFileName, getRuleFunctionContextStructName, getRuleFunctionContextStructName, getTargetStringLiteralFromString, getTargetStringLiteralFromString, getTemplates, getTokenTypeAsTargetLabel, getTokenTypesAsTargetLabels, getVisitorFileName, grammarSymbolCausesIssueInGeneratedCode, needsHeader, shouldUseUnicodeEscapeForCodePointInDoubleQuotedString, supportsOverloadedMethods, wantsBaseListener, wantsBaseVisitor
-
Field Details
-
targetTemplates
The Java target can cache the code generation templates. -
javaKeywords
-
badWords
Avoid grammar symbols in this set to prevent conflicts in gen'd code.
-
-
Constructor Details
-
JavaTarget
-
-
Method Details
-
getBadWords
-
addBadWords
protected void addBadWords() -
getTargetStringLiteralFromANTLRStringLiteral
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.- Specified by:
getTargetStringLiteralFromANTLRStringLiteralin classTarget
-
encodeIntAsCharEscape
Description copied from class:TargetAssume 16-bit char- Specified by:
encodeIntAsCharEscapein classTarget
-
getSerializedATNSegmentLimit
public int getSerializedATNSegmentLimit()Description copied from class:TargetGets the maximum number of 16-bit unsigned integers that can be encoded in a single segment of the serialized ATN.- Overrides:
getSerializedATNSegmentLimitin classTarget- Returns:
- the serialized ATN segment limit
- See Also:
-
visibleGrammarSymbolCausesIssueInGeneratedCode
- Specified by:
visibleGrammarSymbolCausesIssueInGeneratedCodein classTarget
-
loadTemplates
protected org.stringtemplate.v4.STGroup loadTemplates()- Overrides:
loadTemplatesin classTarget
-
appendJavaStringLiteralText
Append grammar text that is not a Unicode scalar. Backslash and quote are escaped so javac does not treat a later quote or unicode escape as syntax. -
isHexDigit
private static boolean isHexDigit(char c) -
appendJavaStringCodePoint
Append one code point inside a Java double-quoted literal. Code points that javac treats as raw characters even inside a\\uescape use a short escape instead.- Parameters:
codePoint- a Unicode scalar value,0..Character.MAX_CODE_POINT- Throws:
IllegalArgumentException- whencodePointis not a scalar. Callers preserve an undecodable grammar escape as source text instead.
-
appendUnicodeEscapedCodePoint
Description copied from class:TargetEscape the Unicode code point appropriately for this language and append the escaped value tosb.- Specified by:
appendUnicodeEscapedCodePointin classTarget
-