diff --git a/CSharpTranslator/antlr3/src/cs2j/CSharp/JavaMaker.g b/CSharpTranslator/antlr3/src/cs2j/CSharp/JavaMaker.g index 90c40a1..17cefd9 100644 --- a/CSharpTranslator/antlr3/src/cs2j/CSharp/JavaMaker.g +++ b/CSharpTranslator/antlr3/src/cs2j/CSharp/JavaMaker.g @@ -65,6 +65,22 @@ scope NSContext { } return stripped; } + + // TODO: Read reserved words from a file so that they can be extended by customer + private readonly static string[] javaReserved = new string[] { "int", "protected", "package" }; + + protected string fixBrokenId(string id) + { + // Console.WriteLine(id); + foreach (string k in javaReserved) + { + if (k == id) + { + return "__" + id; + } + } + return id; + } } /******************************************************************************************** @@ -1191,7 +1207,11 @@ predefined_type returns [string thetext]: | 'ushort' { $thetext = "System.UInt16"; } ; -identifier: +identifier +@after { + string fixedId = fixBrokenId($identifier.tree.Token.Text); + $identifier.tree.Token.Text = fixedId; +}: IDENTIFIER | also_keyword; keyword: