1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # Support to generate and otherwise manipulate Nit code
21 # Reserved keywords in the Nit language
22 var keywords
: Set[String] is lazy
do return new HashSet[String].from
([
23 "abort", "abstract", "and", "assert", "break", "class", "continue",
24 "do", "else", "end", "enum", "extern", "false", "implies", "import",
25 "init", "interface", "intrude", "if", "in", "is", "isa", "isset",
26 "for", "label", "loop", "module", "new", "not", "null", "nullable",
27 "or", "package", "private", "protected", "public", "return", "self",
28 "super", "then", "true", "type", "var", "while"])
30 # Top-level methods from the `Object` class
32 # This is a non-exaustive list that targets conflict-prone names.
33 var methods_in_object
: Array[String] is lazy
do return [
34 "class_name", "get_time", "hash", "inspect", "inspect_head",
35 "is_same_type", "is_same_instance", "object_id", "output",
36 "output_class_name", "sys", "to_s"]
38 # Methods in the `Pointer` class
40 # This is a non-exaustive list that targets conflict-prone names.
41 var methods_in_pointer
: Array[String] is lazy
do return methods_in_object
+ [
45 # Template of a Nit module to generate Nit code
49 # Header on top of the module, usually the documentation
50 var header
: nullable Writable = null is writable
53 var name
: Writable is writable
55 # Annotations on the module declaration
56 var annotations
= new Array[Writable]
58 # Imports from this module
59 var imports
= new Array[Writable]
61 # Main content of this module
62 var content
= new Array[Writable]
67 if header
!= null then add header
70 if annotations
.is_empty
then
71 add
"module {name}\n\n"
73 add
"module {name} is\n"
74 for annotation
in annotations
do add
"\t{annotation}\n"
78 for i
in imports
do add
"import {i}\n"