Package antlr
Class CppCharFormatter
- java.lang.Object
-
- antlr.CppCharFormatter
-
- All Implemented Interfaces:
CharFormatter
class CppCharFormatter extends java.lang.Object implements CharFormatter
-
-
Constructor Summary
Constructors Constructor Description CppCharFormatter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
escapeChar(int c, boolean forCharLiteral)
Given a character value, return a string representing the character that can be embedded inside a string literal or character literal This works for Java/C/C++ code-generation and languages with compatible special-character-escapment.java.lang.String
escapeString(java.lang.String s)
Converts a String into a representation that can be use as a literal when surrounded by double-quotes.java.lang.String
literalChar(int c)
Given a character value, return a string representing the character literal that can be recognized by the target language compiler.java.lang.String
literalString(java.lang.String s)
Converts a String into a string literal This works for languages that use double-quotes for string literals.
-
-
-
Method Detail
-
escapeChar
public java.lang.String escapeChar(int c, boolean forCharLiteral)
Given a character value, return a string representing the character that can be embedded inside a string literal or character literal This works for Java/C/C++ code-generation and languages with compatible special-character-escapment. Used internally in CppCharFormatter and in CppCodeGenerator.converJavaToCppString.- Specified by:
escapeChar
in interfaceCharFormatter
- Parameters:
c
- The character of interest.forCharLiteral
- true to escape for char literal, false for string literal IGNORED!!
-
escapeString
public java.lang.String escapeString(java.lang.String s)
Converts a String into a representation that can be use as a literal when surrounded by double-quotes. Used for escaping semantic predicate strings for exceptions.- Specified by:
escapeString
in interfaceCharFormatter
- Parameters:
s
- The String to be changed into a literal
-
literalChar
public java.lang.String literalChar(int c)
Given a character value, return a string representing the character literal that can be recognized by the target language compiler. This works for languages that use single-quotes for character literals.- Specified by:
literalChar
in interfaceCharFormatter
- Parameters:
c
- The character of interest.
-
literalString
public java.lang.String literalString(java.lang.String s)
Converts a String into a string literal This works for languages that use double-quotes for string literals. Code-generators for languages should override this method. Used for the generation of the tables with token names- Specified by:
literalString
in interfaceCharFormatter
- Parameters:
s
- The String to be changed into a literal
-
-