Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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