Skip to content

Commit

Permalink
Cleanup duplicate SwiftTarget code
Browse files Browse the repository at this point in the history
Signed-off-by: tison <wander4096@gmail.com>
  • Loading branch information
tisonkun authored and parrt committed Sep 4, 2023
1 parent dae2d27 commit 1a96b1c
Showing 1 changed file with 15 additions and 24 deletions.
39 changes: 15 additions & 24 deletions tool/src/org/antlr/v4/codegen/target/SwiftTarget.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

public class SwiftTarget extends Target {
protected static final Map<Character, String> targetCharValueEscape;

static {
// https://docs.swift.org/swift-book/LanguageGuide/StringsAndCharacters.html
HashMap<Character, String> map = new HashMap<>();
Expand All @@ -32,23 +33,23 @@ public class SwiftTarget extends Target {
targetCharValueEscape = map;
}

protected static final HashSet<String> reservedWords = new HashSet<>(Arrays.asList(
"associatedtype", "class", "deinit", "enum", "extension", "func", "import", "init", "inout", "internal",
"let", "operator", "private", "protocol", "public", "static", "struct", "subscript", "typealias", "var",
"break", "case", "continue", "default", "defer", "do", "else", "fallthrough", "for", "guard", "if",
"in", "repeat", "return", "switch", "where", "while",
"as", "catch", "dynamicType", "false", "is", "nil", "rethrows", "super", "self", "Self", "throw", "throws",
"true", "try", "__COLUMN__", "__FILE__", "__FUNCTION__","__LINE__", "#column", "#file", "#function", "#line", "_" , "#available", "#else", "#elseif", "#endif", "#if", "#selector",
"associativity", "convenience", "dynamic", "didSet", "final", "get", "infix", "indirect", "lazy",
"left", "mutating", "none", "nonmutating", "optional", "override", "postfix", "precedence",
"prefix", "Protocol", "required", "right", "set", "Type", "unowned", "weak", "willSet",
protected static final HashSet<String> reservedWords = new HashSet<>(Arrays.asList(
"associatedtype", "class", "deinit", "enum", "extension", "func", "import", "init", "inout", "internal",
"let", "operator", "private", "protocol", "public", "static", "struct", "subscript", "typealias", "var",
"break", "case", "continue", "default", "defer", "do", "else", "fallthrough", "for", "guard", "if",
"in", "repeat", "return", "switch", "where", "while",
"as", "catch", "dynamicType", "false", "is", "nil", "rethrows", "super", "self", "Self", "throw", "throws",
"true", "try", "__COLUMN__", "__FILE__", "__FUNCTION__", "__LINE__", "#column", "#file", "#function", "#line", "_", "#available", "#else", "#elseif", "#endif", "#if", "#selector",
"associativity", "convenience", "dynamic", "didSet", "final", "get", "infix", "indirect", "lazy",
"left", "mutating", "none", "nonmutating", "optional", "override", "postfix", "precedence",
"prefix", "Protocol", "required", "right", "set", "Type", "unowned", "weak", "willSet",

"rule", "parserRule"
"rule", "parserRule"
));

public SwiftTarget(CodeGenerator gen) {
super(gen);
}
public SwiftTarget(CodeGenerator gen) {
super(gen);
}

@Override
public Map<Character, String> getTargetCharValueEscape() {
Expand All @@ -65,16 +66,6 @@ protected String escapeWord(String word) {
return "`" + word + "`";
}

@Override
protected void genFile(Grammar g, ST outputFileST, String fileName) {
super.genFile(g,outputFileST,fileName);
}

@Override
public boolean isATNSerializedAsInts() {
return true;
}

@Override
protected String escapeChar(int v) {
return String.format("\\u{%X}", v);
Expand Down

0 comments on commit 1a96b1c

Please sign in to comment.