lib/nit: extract Nit keywords from jwrapper to a support module for Nit code generators
authorAlexis Laferrière <alexis.laf@xymus.net>
Tue, 1 Sep 2015 21:43:27 +0000 (17:43 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Thu, 3 Sep 2015 14:32:31 +0000 (10:32 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

contrib/jwrapper/src/code_generator.nit
lib/gen_nit.nit [new file with mode: 0644]

index e716a2e..fda1a57 100644 (file)
@@ -18,6 +18,8 @@
 # Services to generate extern class `in "Java"`
 module code_generator
 
+import gen_nit
+
 intrude import model
 
 class CodeGenerator
@@ -417,18 +419,12 @@ redef class Sys
        # List of Nit keywords
        #
        # These may also be keywords in Java, but there they would be used capitalized.
-       private var nit_keywords = new HashSet[String].from(["abort", "abstract", "and", "assert",
-               "break", "class", "continue", "do", "else", "end", "enum", "extern", "false", "implies",
-               "import", "init", "interface", "intrude", "if", "in", "is", "isa", "isset", "for", "label",
-               "loop", "module", "new", "not", "null", "nullable", "or", "package", "private",
-               "protected", "public", "return", "self", "super", "then", "true", "type", "var", "while",
-
-       # Top-level methods
-               "class_name", "get_time", "hash", "inspect", "inspect_head", "is_same_type",
-               "is_same_instance", "object_id", "output", "output_class_name", "sys", "to_s",
-
-       # Pointer or JavaObject methods
-               "free"])
+       private var nit_keywords: Set[String] is lazy do
+               var set = new HashSet[String]
+               set.add_all keywords
+               set.add_all methods_in_pointer
+               return set
+       end
 
        # Name of methods used at the top-level
        #
diff --git a/lib/gen_nit.nit b/lib/gen_nit.nit
new file mode 100644 (file)
index 0000000..ea410a2
--- /dev/null
@@ -0,0 +1,41 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Support to generate and otherwise manipulate Nit code
+module gen_nit
+
+redef class Sys
+       # Reserved keywords in the Nit language
+       var keywords: Set[String] is lazy do return new HashSet[String].from([
+               "abort", "abstract", "and", "assert", "break", "class", "continue",
+               "do", "else", "end", "enum", "extern", "false", "implies", "import",
+               "init", "interface", "intrude", "if", "in", "is", "isa", "isset",
+               "for", "label", "loop", "module", "new", "not", "null", "nullable",
+               "or", "package", "private", "protected", "public", "return", "self",
+               "super", "then", "true", "type", "var", "while"])
+
+       # Top-level methods from the `Object` class
+       #
+       # This is a non-exaustive list that targets conflict-prone names.
+       var methods_in_object: Array[String] is lazy do return [
+               "class_name", "get_time", "hash", "inspect", "inspect_head",
+               "is_same_type", "is_same_instance", "object_id", "output",
+               "output_class_name", "sys", "to_s"]
+
+       # Methods in the `Pointer` class
+       #
+       # This is a non-exaustive list that targets conflict-prone names.
+       var methods_in_pointer: Array[String] is lazy do return methods_in_object + [
+               "free"]
+end