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 # AST nodes of the Nit language
16 # Was previously based on parser_abs.nit.
21 # Root of the AST class-hierarchy
23 # Location is set during AST building. Once built, location cannon be null.
24 # However, manual instantiated nodes may need more care.
25 var location
: Location is writable, noinit
27 # The location of the important part of the node (identifier or whatever)
28 fun hot_location
: Location do return location
30 # Display a message for the colored location of the node
31 fun debug
(message
: String)
33 sys
.stderr
.write
"{hot_location} {self.class_name}: {message}\n{hot_location.colored_line("0;32")}\n"
36 # Parent of the node in the AST
37 var parent
: nullable ANode = null
39 # The topmost ancestor of the element
40 # This just apply `parent` until the first one
46 if p
== null then return res
51 # The most specific common parent between `self` and `other`
52 # Return null if the two node are unrelated (distinct root)
53 fun common_parent
(other
: ANode): nullable ANode
55 # First, get the same depth
56 var s
: nullable ANode = self
57 var o
: nullable ANode = other
58 var d
= s
.depth
- o
.depth
67 assert o
.depth
== s
.depth
68 # Second, go up until same in found
76 # Number of nodes between `self` and the `root` of the AST
77 # ENSURE `self == self.root implies result == 0 `
78 # ENSURE `self != self.root implies result == self.parent.depth + 1`
85 if p
== null then return res
91 # Replace a child with an other node in the AST
92 private fun replace_child
(old_child
: ANode, new_child
: nullable ANode) is abstract
94 # Detach a node from its parent
95 # Aborts if the node is not detachable. use `replace_with` instead
96 # REQUIRE: parent != null
97 # REQUIRE: is_detachable
98 # ENDURE: parent == null
101 assert parent
!= null
102 parent
.replace_child
(self, null)
106 # Replace itself with an other node in the AST
107 # REQUIRE: parent != null
108 # ENSURE: node.parent == old(parent)
109 # ENSURE: parent == null
110 fun replace_with
(node
: ANode)
112 assert parent
!= null
113 parent
.replace_child
(self, node
)
117 # Visit all nodes in order.
118 # Thus, call `v.enter_visit(e)` for each child `e`
119 fun visit_all
(v
: Visitor) is abstract
121 # Do a deep search and return an array of tokens that match a given text
122 fun collect_tokens_by_text
(text
: String): Array[Token]
124 var v
= new CollectTokensByTextVisitor(text
)
129 # Do a deep search and return an array of node that are annotated
130 # The attached node can be retrieved by two invocations of parent
131 fun collect_annotations_by_name
(name
: String): Array[AAnnotation]
133 var v
= new CollectAnnotationsByNameVisitor(name
)
139 private class CollectTokensByTextVisitor
142 var result
= new Array[Token]
143 redef fun visit
(node
)
146 if node
isa Token and node
.text
== text
then result
.add
(node
)
150 private class CollectAnnotationsByNameVisitor
153 var result
= new Array[AAnnotation]
154 redef fun visit
(node
)
157 if node
isa AAnnotation and node
.n_atid
.n_id
.text
== name
then result
.add
(node
)
162 # A sequence of nodes
163 # It is a specific class (instead of using a Array) to track the parent/child relation when nodes are added or removed
164 class ANodes[E
: ANode]
166 private var parent
: ANode
167 private var items
= new Array[E
]
168 redef fun iterator
do return items
.iterator
169 redef fun length
do return items
.length
170 redef fun is_empty
do return items
.is_empty
189 var res
= items
.shift
201 redef fun []=(index
, e
)
203 hook_remove
(self[index
])
207 redef fun remove_at
(index
)
209 hook_remove
(items
[index
])
210 items
.remove_at
(index
)
212 private fun hook_add
(e
: E
)
214 #assert e.parent == null
217 private fun hook_remove
(e
: E
)
219 assert e
.parent
== parent
223 # Used in parent constructor to fill elements
224 private fun unsafe_add_all
(nodes
: Collection[Object])
226 var parent
= self.parent
234 private fun replace_child
(old_child
: ANode, new_child
: nullable ANode): Bool
236 var parent
= self.parent
237 for i
in [0..length
[ do
238 if self[i
] == old_child
then
239 if new_child
!= null then
240 assert new_child
isa E
242 new_child
.parent
= parent
252 private fun visit_all
(v
: Visitor)
254 for n
in self do v
.enter_visit
(n
)
258 # Ancestor of all tokens
259 # A token is a node that has a `text` but no children.
263 # The raw content on the token
264 fun text
: String is abstract
266 # The raw content on the token
267 fun text
=(text
: String) is abstract
269 # The previous token in the Lexer.
270 # May have disappeared in the AST
271 var prev_token
: nullable Token = null
273 # The next token in the Lexer.
274 # May have disappeared in the AST
275 var next_token
: nullable Token = null
277 # The verbatim blank text between `prev_token` and `self`
278 fun blank_before
: String
280 if prev_token
== null then return ""
281 var from
= prev_token
.location
.pend
+1
282 var to
= location
.pstart
283 return location
.file
.string
.substring
(from
,to-from
)
286 redef fun to_s
: String do
290 redef fun visit_all
(v
: Visitor) do end
291 redef fun replace_child
(old_child
: ANode, new_child
: nullable ANode) do end
294 redef class SourceFile
295 # The first token parser by the lexer
296 # May have disappeared in the final AST
297 var first_token
: nullable Token = null
299 # The first token parser by the lexer
300 # May have disappeared in the final AST
301 var last_token
: nullable Token = null
304 # Ancestor of all productions
305 # A production is a node without text but that usually has children.
309 # All the annotations attached directly to the node
310 var n_annotations
: nullable AAnnotations = null is writable
312 # Return all its annotations of a given name in the order of their declaration
313 # Retun an empty array if no such an annotation.
314 fun get_annotations
(name
: String): Array[AAnnotation]
316 var res
= new Array[AAnnotation]
317 var nas
= n_annotations
318 if nas
== null then return res
319 for na
in nas
.n_items
do
320 if na
.name
!= name
then continue
326 redef fun replace_with
(n
: ANode)
330 if not isset n
._location
and isset _location
then n
._location
= _location
334 # Abstract standard visitor on the AST
335 abstract class Visitor
336 # What the visitor do when a node is visited
337 # Concrete visitors should implement this method.
339 protected fun visit
(e
: ANode) is abstract
341 # Ask the visitor to visit a given node.
342 # Usually automatically called by visit_all* methods.
343 # This method should not be redefined
344 fun enter_visit
(e
: nullable ANode)
346 if e
== null then return
347 var old
= _current_node
353 # The current visited node
354 var current_node
: nullable ANode = null is writable
357 # Token of end of line (basically `\n`)
366 # Token of a line of comments
367 # Starts with the `#` and contains the final end-of-line (if any)
372 # A token associated with a keyword
373 abstract class TokenKeyword
377 return "keyword '{text}'"
381 # The deprecated keyword `package`.
386 # The keyword `module`
391 # The keyword `import`
396 # The keyword `class`
401 # The keyword `abstract`
406 # The keyword `interface`
411 # The keywords `enum` ane `universal`
436 # The keyword `redef`
456 # The keyword `extern`
461 # The keyword `public`
466 # The keyword `protected`
471 # The keyword `private`
476 # The keyword `intrude`
496 # The keyword `while`
526 # The keyword `implies`
536 # The keyword `return`
541 # The keyword `continue`
546 # The keyword `break`
551 # The keyword `abort`
556 # The keyword `assert`
576 # The keyword `super`
591 # The keyword `false`
606 # The keyword `nullable`
611 # The keyword `isset`
616 # The keyword `label`
621 # The special keyword `__DEBUG__`
666 # A token associated with an operator (and other lookalike symbols)
667 abstract class TokenOperator
671 return "operator '{text}'"
785 # A class (or formal type) identifier. They start with an uppercase.
790 do return "type identifier '{text}'"
794 # A standard identifier (variable, method...). They start with a lowercase.
799 do return "identifier '{text}'"
803 # An attribute identifier. They start with an underscore.
808 do return "attribute '{text}'"
812 # A token of a literal value (string, integer, etc).
813 abstract class TokenLiteral
817 do return "literal value '{text}'"
821 # A literal decimal integer
826 # A literal hexadecimal integer
831 # A literal floating point number
836 # A literal character
846 # The starting part of a super string (between `"` and `{`)
851 # The middle part of a super string (between `}` and `{`)
856 # The final part of a super string (between `}` and `"`)
866 do return "malformed string {text}"
875 do return "malformed character {text}"
879 # A extern code block
880 class TExternCodeSegment
897 # A lexical error (unexpected character)
901 # A syntactic error (unexpected token)
906 # The main node of a Nit source-file
910 # The declaration part of the module
911 var n_moduledecl
: nullable AModuledecl = null is writable
913 # List of importation clauses
914 var n_imports
= new ANodes[AImport](self)
916 # List of extern blocks
917 var n_extern_code_blocks
= new ANodes[AExternCodeBlock](self)
919 # List of class definition (including top-level methods and the main)
920 var n_classdefs
= new ANodes[AClassdef](self)
923 # Abstract class for definition of entities
924 abstract class ADefinition
927 var n_doc
: nullable ADoc = null is writable
929 # The `redef` keyword
930 var n_kwredef
: nullable TKwredef = null is writable
932 # The declared visibility
933 var n_visibility
: nullable AVisibility = null is writable
936 # The declaration of the module with the documentation, name, and annotations
940 # The `module` keyword
941 var n_kwmodule
: TKwmodule is writable, noinit
943 # The declared module name
944 var n_name
: AModuleName is writable, noinit
947 # A import clause of a module
948 abstract class AImport
951 # The declared visibility
952 var n_visibility
: AVisibility is writable, noinit
954 # The `import` keyword
955 var n_kwimport
: TKwimport is writable, noinit
958 # A standard import clause. eg `import x`
961 # The imported module name
962 var n_name
: AModuleName is writable, noinit
965 # The special import clause of the kernel module. eg `import end`
968 # The `end` keyword, that indicate the root module
969 var n_kwend
: TKwend is writable, noinit
972 # A visibility modifier
974 # The public visibility is an empty production (no keyword).
976 # Note: even if some visibilities are only valid on some placse (for instance, no `protected` class or no `intrude` method)
977 # the parser has no such a restriction, therefore the semantic phases has to check that the visibilities make sense.
978 abstract class AVisibility
982 # An implicit or explicit public visibility modifier
983 class APublicVisibility
985 # The `public` keyword, if any
986 var n_kwpublic
: nullable TKwpublic is writable
988 # An explicit private visibility modifier
989 class APrivateVisibility
991 # The `private` keyword
992 var n_kwprivate
: TKwprivate is writable, noinit
994 # An explicit protected visibility modifier
995 class AProtectedVisibility
997 # The `protected` keyword
998 var n_kwprotected
: TKwprotected is writable, noinit
1000 # An explicit intrude visibility modifier
1001 class AIntrudeVisibility
1003 # The `intrude` keyword
1004 var n_kwintrude
: TKwintrude is writable, noinit
1007 # A class definition
1008 # While most definition are `AStdClassdef`
1009 # There is tow special case of class definition
1010 abstract class AClassdef
1012 # All the declared properties (including the main method)
1013 var n_propdefs
= new ANodes[APropdef](self)
1016 # A standard class definition with a name, superclasses and properties
1021 # The class kind (interface, abstract class, etc.)
1022 var n_classkind
: AClasskind is writable, noinit
1024 # The name of the class
1025 var n_id
: nullable TClassid = null is writable
1027 # The list of formal parameter types
1028 var n_formaldefs
= new ANodes[AFormaldef](self)
1030 # The extern block code
1031 var n_extern_code_block
: nullable AExternCodeBlock = null is writable
1033 # The list of super-classes
1034 var n_superclasses
= new ANodes[ASuperclass](self)
1037 var n_kwend
: TKwend is writable, noinit
1039 redef fun hot_location
do return n_id
.location
1042 # The implicit class definition of the implicit main method
1047 # The implicit class definition of the top-level methods
1052 # The modifier for the kind of class (abstract, interface, etc.)
1053 abstract class AClasskind
1057 # A default, or concrete class modifier (just `class`)
1058 class AConcreteClasskind
1061 # The `class` keyword.
1062 var n_kwclass
: TKwclass is writable, noinit
1065 # An abstract class modifier (`abstract class`)
1066 class AAbstractClasskind
1069 # The `abstract` keyword.
1070 var n_kwabstract
: TKwabstract is writable, noinit
1072 # The `class` keyword.
1073 var n_kwclass
: TKwclass is writable, noinit
1076 # An interface class modifier (`interface`)
1077 class AInterfaceClasskind
1080 # The `interface` keyword.
1081 var n_kwinterface
: TKwinterface is writable, noinit
1084 # An enum/universal class modifier (`enum class`)
1085 class AEnumClasskind
1088 # The `enum` keyword.
1089 var n_kwenum
: TKwenum is writable, noinit
1092 # An extern class modifier (`extern class`)
1093 class AExternClasskind
1096 # The `extern` keyword.
1097 var n_kwextern
: TKwextern is writable, noinit
1099 # The `class` keyword.
1100 var n_kwclass
: nullable TKwclass = null is writable
1103 # The definition of a formal generic parameter type. eg `X: Y`
1107 # The name of the parameter type
1108 var n_id
: TClassid is writable, noinit
1110 # The bound of the parameter type
1111 var n_type
: nullable AType = null is writable
1114 # A super-class. eg `super X`
1119 var n_kwsuper
: TKwsuper is writable, noinit
1121 # The super-class (indicated as a type)
1122 var n_type
: AType is writable, noinit
1125 # The definition of a property
1126 abstract class APropdef
1130 # A definition of an attribute
1131 # For historical reason, old-syle and new-style attributes use the same `ANode` sub-class
1135 # The identifier for a old-style attribute (null if new-style)
1136 var n_kwvar
: TKwvar is writable, noinit
1138 # The identifier for a new-style attribute (null if old-style)
1139 var n_id2
: TId is writable, noinit
1141 # The declared type of the attribute
1142 var n_type
: nullable AType = null is writable
1144 # The initial value, if any (set with `=`)
1145 var n_expr
: nullable AExpr = null is writable
1147 # The initial value, if any (set with `do return`)
1148 var n_block
: nullable AExpr = null is writable
1150 redef fun hot_location
1152 return n_id2
.location
1156 # A definition of all kind of method (including constructors)
1160 # The `fun` keyword, if any
1161 var n_kwmeth
: nullable TKwmeth = null is writable
1163 # The `init` keyword, if any
1164 var n_kwinit
: nullable TKwinit = null is writable
1166 # The `new` keyword, if any
1167 var n_kwnew
: nullable TKwnew = null is writable
1169 # The name of the method, if any
1170 var n_methid
: nullable AMethid = null is writable
1172 # The signature of the method, if any
1173 var n_signature
: nullable ASignature = null is writable
1175 # The body (in Nit) of the method, if any
1176 var n_block
: nullable AExpr = null is writable
1178 # The list of declared callbacks (for extern methods)
1179 var n_extern_calls
: nullable AExternCalls = null is writable
1181 # The body (in extern code) of the method, if any
1182 var n_extern_code_block
: nullable AExternCodeBlock = null is writable
1184 redef fun hot_location
1186 if n_methid
!= null then
1187 return n_methid
.location
1188 else if n_kwinit
!= null then
1189 return n_kwinit
.location
1190 else if n_kwnew
!= null then
1191 return n_kwnew
.location
1198 # The implicit main method
1199 class AMainMethPropdef
1203 # Declaration of callbacks for extern methods
1207 # The `import` keyword
1208 var n_kwimport
: TKwimport is writable, noinit
1210 # The list of declared callbacks
1211 var n_extern_calls
: ANodes[AExternCall] = new ANodes[AExternCall](self)
1214 # A single callback declaration
1215 abstract class AExternCall
1219 # A single callback declaration on a method
1220 abstract class APropExternCall
1224 # A single callback declaration on a method on the current receiver
1225 class ALocalPropExternCall
1226 super APropExternCall
1228 # The name of the called-back method
1229 var n_methid
: AMethid is writable, noinit
1232 # A single callback declaration on a method on an explicit receiver type.
1233 class AFullPropExternCall
1234 super APropExternCall
1236 # The type of the receiver of the called-back method
1237 var n_type
: AType is writable, noinit
1240 var n_dot
: nullable TDot = null is writable
1242 # The name of the called-back method
1243 var n_methid
: AMethid is writable, noinit
1246 # A single callback declaration on a method on a constructor
1247 class AInitPropExternCall
1248 super APropExternCall
1250 # The allocated type
1251 var n_type
: AType is writable, noinit
1254 # A single callback declaration on a `super` call
1255 class ASuperExternCall
1258 # The `super` keyword
1259 var n_kwsuper
: TKwsuper is writable, noinit
1262 # A single callback declaration on a cast
1263 abstract class ACastExternCall
1267 # A single callback declaration on a cast to a given type
1268 class ACastAsExternCall
1269 super ACastExternCall
1271 # The origin type of the cast
1272 var n_from_type
: AType is writable, noinit
1275 var n_dot
: nullable TDot = null is writable
1278 var n_kwas
: TKwas is writable, noinit
1280 # The destination of the cast
1281 var n_to_type
: AType is writable, noinit
1284 # A single callback declaration on a cast to a nullable type
1285 class AAsNullableExternCall
1286 super ACastExternCall
1288 # The origin type to cast as nullable
1289 var n_type
: AType is writable, noinit
1292 var n_kwas
: TKwas is writable, noinit
1294 # The `nullable` keyword
1295 var n_kwnullable
: TKwnullable is writable, noinit
1298 # A single callback declaration on a cast to a non-nullable type
1299 class AAsNotNullableExternCall
1300 super ACastExternCall
1302 # The destination type on a cast to not nullable
1303 var n_type
: AType is writable, noinit
1306 var n_kwas
: TKwas is writable, noinit
1309 var n_kwnot
: TKwnot is writable, noinit
1311 # The `nullable` keyword
1312 var n_kwnullable
: TKwnullable is writable, noinit
1315 # A definition of a virtual type
1319 # The `type` keyword
1320 var n_kwtype
: TKwtype is writable, noinit
1322 # The name of the virtual type
1323 var n_id
: TClassid is writable, noinit
1325 # The bound of the virtual type
1326 var n_type
: AType is writable, noinit
1329 # The identifier of a method in a method declaration.
1330 # There is a specific class because of operator and setters.
1331 abstract class AMethid
1335 # A method name with a simple identifier
1339 # The simple identifier
1340 var n_id
: TId is writable, noinit
1348 var n_plus
: TPlus is writable, noinit
1356 var n_minus
: TMinus is writable, noinit
1364 var n_star
: TStar is writable, noinit
1367 # A method name `**`
1368 class AStarstarMethid
1372 var n_starstar
: TStarstar is writable, noinit
1380 var n_slash
: TSlash is writable, noinit
1384 class APercentMethid
1388 var n_percent
: TPercent is writable, noinit
1391 # A method name `==`
1396 var n_eq
: TEq is writable, noinit
1399 # A method name `!=`
1404 var n_ne
: TNe is writable, noinit
1407 # A method name `<=`
1412 var n_le
: TLe is writable, noinit
1415 # A method name `>=`
1420 var n_ge
: TGe is writable, noinit
1428 var n_lt
: TLt is writable, noinit
1436 var n_gt
: TGt is writable, noinit
1439 # A method name `<<`
1444 var n_ll
: TLl is writable, noinit
1447 # A method name `>>`
1452 var n_gg
: TGg is writable, noinit
1455 # A method name `[]`
1460 var n_obra
: TObra is writable, noinit
1463 var n_cbra
: TCbra is writable, noinit
1466 # A method name `<=>`
1467 class AStarshipMethid
1471 var n_starship
: TStarship is writable, noinit
1474 # A setter method name with a simple identifier (with a `=`)
1478 # The base identifier
1479 var n_id
: TId is writable, noinit
1482 var n_assign
: TAssign is writable, noinit
1485 # A method name `[]=`
1486 class ABraassignMethid
1490 var n_obra
: TObra is writable, noinit
1493 var n_cbra
: TCbra is writable, noinit
1496 var n_assign
: TAssign is writable, noinit
1499 # A signature in a method definition. eg `(x,y:X,z:Z):T`
1504 var n_opar
: nullable TOpar = null is writable
1506 # The list of parameters
1507 var n_params
= new ANodes[AParam](self)
1510 var n_cpar
: nullable TCpar = null is writable
1513 var n_type
: nullable AType = null is writable
1516 # A parameter definition in a signature. eg `x:X`
1520 # The name of the parameter
1521 var n_id
: TId is writable, noinit
1523 # The type of the parameter, if any
1524 var n_type
: nullable AType = null is writable
1526 # The `...` symbol to indicate varargs
1527 var n_dotdotdot
: nullable TDotdotdot = null is writable
1530 # A static type. eg `nullable X[Y]`
1533 # The `nullable` keyword
1534 var n_kwnullable
: nullable TKwnullable = null is writable
1536 # The name of the class or of the formal type
1537 var n_id
: TClassid is writable, noinit
1539 # Type arguments for a generic type
1540 var n_types
= new ANodes[AType](self)
1543 # A label at the end of a block or in a break/continue statement. eg `label x`
1547 # The `label` keyword
1548 var n_kwlabel
: TKwlabel is writable, noinit
1550 # The name of the label, if any
1551 var n_id
: nullable TId is writable
1554 # Expression and statements
1555 # From a AST point of view there is no distinction between statement and expressions (even if the parser has to distinguish them)
1556 abstract class AExpr
1560 # A sequence of `AExpr` (usually statements)
1561 # The last `AExpr` gives the value of the whole block
1565 # The list of statements in the bloc.
1566 # The last element is often considered as an expression that give the value of the whole block.
1567 var n_expr
= new ANodes[AExpr](self)
1570 var n_kwend
: nullable TKwend = null is writable
1573 # A declaration of a local variable. eg `var x: X = y`
1578 var n_kwvar
: TKwvar is writable, noinit
1580 # The name of the local variable
1581 var n_id
: TId is writable, noinit
1583 # The declaration type of the local variable
1584 var n_type
: nullable AType = null is writable
1586 # The `=` symbol (for the initial value)
1587 var n_assign
: nullable TAssign = null is writable
1589 # The initial value, if any
1590 var n_expr
: nullable AExpr = null is writable
1593 # A `return` statement. eg `return x`
1597 # The `return` keyword
1598 var n_kwreturn
: nullable TKwreturn = null is writable
1600 # The return value, if any
1601 var n_expr
: nullable AExpr = null is writable
1604 # Something that has a label.
1605 abstract class ALabelable
1608 # The associated label declatation
1609 var n_label
: nullable ALabel = null is writable
1612 # A `break` or a `continue`
1613 abstract class AEscapeExpr
1617 # The return value, if nay (unused currently)
1618 var n_expr
: nullable AExpr = null is writable
1621 # A `break` statement.
1625 # The `break` keyword
1626 var n_kwbreak
: TKwbreak is writable, noinit
1629 # An `abort` statement
1633 # The `abort` keyword
1634 var n_kwabort
: TKwabort is writable, noinit
1637 # A `continue` statement
1641 # The `continue` keyword.
1642 var n_kwcontinue
: nullable TKwcontinue = null is writable
1651 var n_kwdo
: TKwdo is writable, noinit
1653 # The list of statements of the `do`.
1654 var n_block
: nullable AExpr = null is writable
1662 var n_kwif
: TKwif is writable, noinit
1664 # The expression used as the condition of the `if`
1665 var n_expr
: AExpr is writable, noinit
1667 # The body of the `then` part
1668 var n_then
: nullable AExpr = null is writable
1670 # The body of the `else` part
1671 var n_else
: nullable AExpr = null is writable
1674 # A `if` expression (ternary conditional). eg. `if true then 1 else 0`
1679 var n_kwif
: TKwif is writable, noinit
1681 # The expression used as the condition of the `if`
1682 var n_expr
: AExpr is writable, noinit
1684 # The `then` keyword
1685 var n_kwthen
: TKwthen is writable, noinit
1687 # The expression in the `then` part
1688 var n_then
: AExpr is writable, noinit
1690 # The `else` keyword
1691 var n_kwelse
: TKwelse is writable, noinit
1693 # The expression in the `else` part
1694 var n_else
: AExpr is writable, noinit
1697 # A `while` statement
1702 # The `while` keyword
1703 var n_kwwhile
: TKwwhile is writable, noinit
1705 # The expression used as the condition of the `while`
1706 var n_expr
: AExpr is writable, noinit
1709 var n_kwdo
: TKwdo is writable, noinit
1711 # The body of the loop
1712 var n_block
: nullable AExpr = null is writable
1715 # A `loop` statement
1720 # The `loop` keyword
1721 var n_kwloop
: TKwloop is writable, noinit
1723 # The body of the loop
1724 var n_block
: nullable AExpr = null is writable
1733 var n_kwfor
: TKwfor is writable, noinit
1735 # The list of name of the automatic variables
1736 var n_ids
= new ANodes[TId](self)
1738 # The expression used as the collection to iterate on
1739 var n_expr
: AExpr is writable, noinit
1742 var n_kwdo
: TKwdo is writable, noinit
1744 # The body of the loop
1745 var n_block
: nullable AExpr = null is writable
1748 # An `assert` statement
1752 # The `assert` keyword
1753 var n_kwassert
: TKwassert is writable, noinit
1755 # The name of the assert, if any
1756 var n_id
: nullable TId = null is writable
1758 # The expression used as the condition of the `assert`
1759 var n_expr
: AExpr is writable, noinit
1761 # The body to execute when the assert fails
1762 var n_else
: nullable AExpr = null is writable
1765 # Whatever is a simple assignment. eg `= something`
1766 abstract class AAssignFormExpr
1770 var n_assign
: TAssign is writable, noinit
1772 # The right-value to assign.
1773 var n_value
: AExpr is writable, noinit
1776 # Whatever is a combined assignment. eg `+= something`
1777 abstract class AReassignFormExpr
1780 # The combined operator (eg. `+=`)
1781 var n_assign_op
: AAssignOp is writable, noinit
1783 # The right-value to apply on the combined operator.
1784 var n_value
: AExpr is writable, noinit
1787 # A `once` expression. eg `once x`
1791 # The `once` keyword
1792 var n_kwonce
: TKwonce is writable, noinit
1794 # The expression to evaluate only one time
1795 var n_expr
: AExpr is writable, noinit
1798 # A polymorphic invocation of a method
1799 # The form of the invocation (name, arguments, etc.) are specific
1800 abstract class ASendExpr
1802 # The receiver of the method invocation
1803 var n_expr
: AExpr is writable, noinit
1806 # A binary operation on a method
1807 abstract class ABinopExpr
1809 # The second operand of the operation
1810 # Note: the receiver (`n_expr`) is the first operand
1811 var n_expr2
: AExpr is writable, noinit
1814 # Something that is boolean expression
1815 abstract class ABoolExpr
1819 # Something that is binary boolean expression
1820 abstract class ABinBoolExpr
1823 # The first boolean operand
1824 var n_expr
: AExpr is writable, noinit
1826 # The second boolean operand
1827 var n_expr2
: AExpr is writable, noinit
1835 # A `and` expression
1840 # A `or else` expression
1845 # A `implies` expression
1850 # A `not` expression
1855 var n_kwnot
: TKwnot is writable, noinit
1857 # The boolean operand of the `not`
1858 var n_expr
: AExpr is writable, noinit
1901 # A type-ckeck expression. eg `x isa T`
1905 # The expression to check
1906 var n_expr
: AExpr is writable, noinit
1908 # The destination type to check to
1909 var n_type
: AType is writable, noinit
1922 # A `<=>` expression
1947 # A unary minus expression. eg `-x`
1952 var n_minus
: TMinus is writable, noinit
1955 # An explicit instantiation. eg `new T`
1960 var n_kwnew
: TKwnew is writable, noinit
1962 # The `type` keyword
1963 var n_type
: AType is writable, noinit
1965 # The name of the named-constructor, if any
1966 var n_id
: nullable TId = null is writable
1968 # The arguments of the `new`
1969 var n_args
: AExprs is writable, noinit
1972 # Whatever is a old-style attribute access
1973 abstract class AAttrFormExpr
1976 # The receiver of the attribute
1977 var n_expr
: AExpr is writable, noinit
1979 # The name of the attribute
1980 var n_id
: TAttrid is writable, noinit
1984 # The read of an attribute. eg `x._a`
1989 # The assignment of an attribute. eg `x._a=y`
1990 class AAttrAssignExpr
1992 super AAssignFormExpr
1995 # Whatever looks-like a call with a standard method and any number of arguments.
1996 abstract class ACallFormExpr
1999 # The name of the method
2000 var n_id
: TId is writable, noinit
2002 # The arguments of the call
2003 var n_args
: AExprs is writable, noinit
2006 # A complex setter call (standard or brackets)
2007 abstract class ASendReassignFormExpr
2009 super AReassignFormExpr
2012 # A complex attribute assignment. eg `x._a+=y`
2013 class AAttrReassignExpr
2015 super AReassignFormExpr
2018 # A call with a standard method-name and any number of arguments. eg `x.m(y)`. OR just a simple id
2019 # Note: because the parser cannot distinguish a variable read with a method call with an implicit receiver and no arguments, it always returns a `ACallExpr`.
2020 # Semantic analysis have to transform them to instance of `AVarExpr`.
2025 # A setter call with a standard method-name and any number of arguments. eg `x.m(y)=z`. OR just a simple assignment.
2026 # Note: because the parser cannot distinguish a variable write with a setter call with an implicit receiver and no arguments, it always returns a `ACallAssignExpr`.
2027 # Semantic analysis have to transform them to instance of `AVarAssignExpr`.
2028 class ACallAssignExpr
2030 super AAssignFormExpr
2033 # A complex setter call with a standard method-name and any number of arguments. eg `x.m(y)+=z`. OR just a simple complex assignment.
2034 # Note: because the parser cannot distinguish a variable write with a complex setter call with an implicit receiver and no arguments, it always returns a `ACallReassignExpr`.
2035 # Semantic analysis have to transform them to instance of `AVarReassignExpr`.
2036 class ACallReassignExpr
2038 super ASendReassignFormExpr
2041 # A call to `super`. OR a call of a super-constructor
2045 # The qualifier part before the super (currenlty unused)
2046 var n_qualified
: nullable AQualified = null is writable
2048 # The `super` keyword
2049 var n_kwsuper
: TKwsuper is writable, noinit
2051 # The arguments of the super
2052 var n_args
: AExprs is writable, noinit
2055 # A call to the `init` constructor.
2056 # Note: because `init` is a keyword and not a `TId`, the explicit call to init cannot be a `ACallFormExpr`.
2060 # The `init` keyword
2061 var n_kwinit
: TKwinit is writable, noinit
2063 # The arguments of the init
2064 var n_args
: AExprs is writable, noinit
2067 # Whatever looks-like a call of the brackets `[]` operator.
2068 abstract class ABraFormExpr
2071 # The arguments inside the brackets
2072 var n_args
: AExprs is writable, noinit
2075 # A call of the brackets operator. eg `x[y,z]`
2080 # A setter call of the bracket operator. eg `x[y,z]=t`
2081 class ABraAssignExpr
2083 super AAssignFormExpr
2086 # Whatever is an access to a local variable
2087 abstract class AVarFormExpr
2090 # The name of the attribute
2091 var n_id
: TId is writable, noinit
2094 # A complex setter call of the bracket operator. eg `x[y,z]+=t`
2095 class ABraReassignExpr
2097 super ASendReassignFormExpr
2100 # A local variable read access.
2101 # The parser cannot instantiate them, see `ACallExpr`.
2106 # A local variable simple assignment access
2107 # The parser cannot instantiate them, see `ACallAssignExpr`.
2108 class AVarAssignExpr
2110 super AAssignFormExpr
2113 # A local variable complex assignment access
2114 # The parser cannot instantiate them, see `ACallReassignExpr`.
2115 class AVarReassignExpr
2117 super AReassignFormExpr
2120 # A literal range, open or closed
2121 abstract class ARangeExpr
2124 # The left (lower) element of the range
2125 var n_expr
: AExpr is writable, noinit
2127 # The right (uppr) element of the range
2128 var n_expr2
: AExpr is writable, noinit
2131 # A closed literal range. eg `[x..y]`
2135 # The opening bracket `[`
2136 var n_obra
: TObra is writable, noinit
2138 # The closing bracket `]`
2139 var n_cbra
: TCbra is writable, noinit
2142 # An open literal range. eg `[x..y[`
2146 # The opening bracket `[`
2147 var n_obra
: TObra is writable, noinit
2149 # The closing bracket `[` (because open range)
2150 var n_cbra
: TObra is writable, noinit
2153 # A literal array. eg. `[x,y,z]`
2157 # The opening bracket `[`
2158 var n_obra
: TObra is writable, noinit
2160 # The elements of the array
2161 var n_exprs
= new ANodes[AExpr](self)
2163 # The type of the element of the array (if any)
2164 var n_type
: nullable AType = null is writable
2166 # The closing bracket `]`
2167 var n_cbra
: TCbra is writable, noinit
2174 # The `self` keyword
2175 var n_kwself
: nullable TKwself is writable
2178 # When there is no explicit receiver, `self` is implicit
2179 class AImplicitSelfExpr
2183 # A `true` boolean literal constant
2187 # The `true` keyword
2188 var n_kwtrue
: TKwtrue is writable, noinit
2191 # A `false` boolean literal constant
2195 # The `false` keyword
2196 var n_kwfalse
: TKwfalse is writable, noinit
2199 # A `null` literal constant
2203 # The `null` keyword
2204 var n_kwnull
: TKwnull is writable, noinit
2207 # An integer literal
2212 # An integer literal in decimal format
2217 var n_number
: TNumber is writable, noinit
2220 # An integer literal in hexadecimal format
2224 # The hexadecimal token
2225 var n_hex_number
: THexNumber is writable, noinit
2233 var n_float
: TFloat is writable, noinit
2236 # A character literal
2240 # The character token
2241 var n_char
: TChar is writable, noinit
2245 abstract class AStringFormExpr
2249 var n_string
: Token is writable, noinit
2252 # A simple string. eg. `"abc"`
2254 super AStringFormExpr
2257 # The start of a superstring. eg `"abc{`
2258 class AStartStringExpr
2259 super AStringFormExpr
2262 # The middle of a superstring. eg `}abc{`
2263 class AMidStringExpr
2264 super AStringFormExpr
2267 # The end of a superstrng. eg `}abc"`
2268 class AEndStringExpr
2269 super AStringFormExpr
2272 # A superstring literal. eg `"a{x}b{y}c"`
2273 # Each part is modeled a sequence of expression. eg. `["a{, x, }b{, y, }c"]`
2274 class ASuperstringExpr
2277 # The list of the expressions of the superstring
2278 var n_exprs
= new ANodes[AExpr](self)
2281 # A simple parenthesis. eg `(x)`
2285 # The opening parenthesis
2286 var n_opar
: TOpar is writable, noinit
2288 # The inner expression
2289 var n_expr
: AExpr is writable, noinit
2291 # The closing parenthesis
2292 var n_cpar
: TCpar is writable, noinit
2295 # A cast, against a type or `not null`
2299 # The expression to cast
2300 var n_expr
: AExpr is writable, noinit
2303 var n_kwas
: TKwas is writable, noinit
2305 # The opening parenthesis
2306 var n_opar
: nullable TOpar = null is writable
2308 # The closing parenthesis
2309 var n_cpar
: nullable TCpar = null is writable
2312 # A type cast. eg `x.as(T)`
2316 # The target type to cast to
2317 var n_type
: AType is writable, noinit
2320 # A as-not-null cast. eg `x.as(not null)`
2321 class AAsNotnullExpr
2325 var n_kwnot
: TKwnot is writable, noinit
2327 # The `null` keyword
2328 var n_kwnull
: TKwnull is writable, noinit
2331 # A is-set check of old-style attributes. eg `isset x._a`
2332 class AIssetAttrExpr
2335 # The `isset` keyword
2336 var n_kwisset
: TKwisset is writable, noinit
2339 # An ellipsis notation used to pass an expression as it, in a vararg parameter
2343 # The passed expression
2344 var n_expr
: AExpr is writable, noinit
2347 var n_dotdotdot
: TDotdotdot is writable, noinit
2350 # A list of expression separated with commas (arguments for instance)
2354 # The list of expressions
2355 var n_exprs
= new ANodes[AExpr](self)
2358 # A special expression that encapsulates a static type
2359 # Can only be found in special construction like arguments of annotations.
2363 # The encapsulated type
2364 var n_type
: AType is writable, noinit
2367 # A special expression that encapsulates a method identifier
2368 # Can only be found in special construction like arguments of annotations.
2373 var n_expr
: AExpr is writable, noinit
2375 # The encapsulated method identifier
2376 var n_id
: AMethid is writable, noinit
2379 # A special expression that encapsulate an annotation
2380 # Can only be found in special construction like arguments of annotations.
2382 # The encapsulated annotations are in `n_annotations`
2387 # A special expression to debug types
2388 class ADebugTypeExpr
2391 # The `debug` keyword
2392 var n_kwdebug
: TKwdebug is writable, noinit
2394 # The `type` keyword
2395 var n_kwtype
: TKwtype is writable, noinit
2397 # The expression to check
2398 var n_expr
: AExpr is writable, noinit
2401 var n_type
: AType is writable, noinit
2404 # A list of expression separated with commas (arguments for instance)
2405 abstract class AExprs
2408 # The list of expressions
2409 var n_exprs
= new ANodes[AExpr](self)
2412 # A simple list of expressions
2417 # A list of expressions enclosed in parentheses
2421 # The opening parenthesis
2422 var n_opar
: TOpar is writable, noinit
2424 # The closing parenthesis
2425 var n_cpar
: TCpar is writable, noinit
2428 # A list of expressions enclosed in brackets
2432 # The opening bracket
2433 var n_obra
: TObra is writable, noinit
2435 # The closing bracket
2436 var n_cbra
: TCbra is writable, noinit
2439 # A complex assignment operator. (`+=` and `-=`)
2440 abstract class AAssignOp
2444 # The `+=` assignment operation
2449 var n_pluseq
: TPluseq is writable, noinit
2452 # The `-=` assignment operator
2453 class AMinusAssignOp
2457 var n_minuseq
: TMinuseq is writable, noinit
2460 # A possibly fully-qualified module identifier
2464 # The starting quad (`::`)
2465 var n_quad
: nullable TQuad = null is writable
2467 # The list of quad-separated project/group identifiers
2468 var n_path
= new ANodes[TId](self)
2470 # The final module identifier
2471 var n_id
: TId is writable, noinit
2474 # A language declaration for an extern block
2479 var n_kwin
: TKwin is writable, noinit
2482 var n_string
: TString is writable, noinit
2485 # An full extern block
2486 class AExternCodeBlock
2489 # The language declration
2490 var n_in_language
: nullable AInLanguage = null is writable
2492 # The block of extern code
2493 var n_extern_code_segment
: TExternCodeSegment is writable, noinit
2496 # A possible full method qualifier.
2500 # The starting quad (`::`)
2501 var n_quad
: nullable TQuad = null is writable
2503 # The list of quad-separated project/group/module identifiers
2504 var n_id
= new ANodes[TId](self)
2506 # A class identifier
2507 var n_classid
: nullable TClassid = null is writable
2510 # A documentation of a definition
2511 # It contains the block of comments just above the declaration
2515 # A list of lines of comment
2516 var n_comment
= new ANodes[TComment](self)
2519 # A group of annotation on a node
2521 # This same class is used for the 3 kind of annotations:
2523 # * *is* annotations. eg `module foo is bar`.
2524 # * *at* annotations. eg `foo@bar` or `foo@(bar,baz)`.
2525 # * *class* annotations, defined in classes.
2529 # The `@` symbol, for *at* annotations
2530 var n_at
: nullable TAt = null is writable
2532 # The opening parenthesis in *at* annotations
2533 var n_opar
: nullable TOpar = null is writable
2535 # The list of annotations
2536 var n_items
= new ANodes[AAnnotation](self)
2538 # The closing parenthesis in *at* annotations
2539 var n_cpar
: nullable TCpar = null is writable
2542 # A single annotation
2546 # The name of the annotation
2547 var n_atid
: AAtid is writable, noinit
2549 # The opening parenthesis of the arguments
2550 var n_opar
: nullable TOpar = null is writable
2552 # The list of arguments
2553 var n_args
= new ANodes[AExpr](self)
2555 # The closing parenthesis
2556 var n_cpar
: nullable TCpar = null is writable
2558 # The name of the annotation
2561 return n_atid
.n_id
.text
2565 # An annotation name
2566 abstract class AAtid
2569 # The identifier of the annotation.
2570 # Can be a TId of a keyword
2571 var n_id
: Token is writable, noinit
2574 # An annotation name based on an identifier
2579 # An annotation name based on the keyword `extern`
2584 # An annotation name based on the keyword `import`
2589 # An annotation name based on the keyword `abstract`
2590 class AKwabstractAtid
2594 # The root of the AST
2599 var n_base
: nullable AModule is writable
2601 # The end of file (or error) token
2602 var n_eof
: EOF is writable