From: Alexis Laferrière Date: Tue, 1 Sep 2015 21:43:27 +0000 (-0400) Subject: lib/nit: extract Nit keywords from jwrapper to a support module for Nit code generators X-Git-Tag: v0.7.8~42^2~6 X-Git-Url: http://nitlanguage.org lib/nit: extract Nit keywords from jwrapper to a support module for Nit code generators Signed-off-by: Alexis Laferrière --- diff --git a/contrib/jwrapper/src/code_generator.nit b/contrib/jwrapper/src/code_generator.nit index e716a2e..fda1a57 100644 --- a/contrib/jwrapper/src/code_generator.nit +++ b/contrib/jwrapper/src/code_generator.nit @@ -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 index 0000000..ea410a2 --- /dev/null +++ b/lib/gen_nit.nit @@ -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