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.
22 # Root of the AST class-hierarchy
24 # Location is set during AST building. Once built, location cannon be null.
25 # However, manual instantiated nodes may need more care.
26 var location
: Location is writable, noinit
28 # The location of the important part of the node (identifier or whatever)
29 fun hot_location
: Location do return location
31 # Display a message for the colored location of the node
32 fun debug
(message
: String)
34 sys
.stderr
.write
"{hot_location} {self.class_name}: {message}\n{hot_location.colored_line("0;32")}\n"
37 # Write the subtree on stdout.
43 d
.write_to
(sys
.stdout
)
46 # Parent of the node in the AST
47 var parent
: nullable ANode = null
49 # The topmost ancestor of the element
50 # This just apply `parent` until the first one
56 if p
== null then return res
61 # The most specific common parent between `self` and `other`
62 # Return null if the two node are unrelated (distinct root)
63 fun common_parent
(other
: ANode): nullable ANode
65 # First, get the same depth
66 var s
: nullable ANode = self
67 var o
: nullable ANode = other
68 var d
= s
.depth
- o
.depth
77 assert o
.depth
== s
.depth
78 # Second, go up until same in found
86 # Number of nodes between `self` and the `root` of the AST
87 # ENSURE `self == self.root implies result == 0 `
88 # ENSURE `self != self.root implies result == self.parent.depth + 1`
95 if p
== null then return res
101 # Replace a child with an other node in the AST
102 private fun replace_child
(old_child
: ANode, new_child
: nullable ANode) is abstract
104 # Detach a node from its parent
105 # Aborts if the node is not detachable. use `replace_with` instead
106 # REQUIRE: parent != null
107 # REQUIRE: is_detachable
108 # ENDURE: parent == null
111 assert parent
!= null
112 parent
.replace_child
(self, null)
116 # Replace itself with an other node in the AST
117 # REQUIRE: parent != null
118 # ENSURE: node.parent == old(parent)
119 # ENSURE: parent == null
120 fun replace_with
(node
: ANode)
122 assert parent
!= null
123 parent
.replace_child
(self, node
)
127 # Visit all nodes in order.
128 # Thus, call `v.enter_visit(e)` for each child `e`
129 fun visit_all
(v
: Visitor) is abstract
131 # Do a deep search and return an array of tokens that match a given text
132 fun collect_tokens_by_text
(text
: String): Array[Token]
134 var v
= new CollectTokensByTextVisitor(text
)
139 # Do a deep search and return an array of node that are annotated
140 # The attached node can be retrieved by two invocations of parent
141 fun collect_annotations_by_name
(name
: String): Array[AAnnotation]
143 var v
= new CollectAnnotationsByNameVisitor(name
)
149 private class CollectTokensByTextVisitor
152 var result
= new Array[Token]
153 redef fun visit
(node
)
156 if node
isa Token and node
.text
== text
then result
.add
(node
)
160 private class CollectAnnotationsByNameVisitor
163 var result
= new Array[AAnnotation]
164 redef fun visit
(node
)
167 if node
isa AAnnotation and node
.n_atid
.n_id
.text
== name
then result
.add
(node
)
171 # A helper class to handle (print) Nit AST as an OrderedTree
174 super OrderedTree[ANode]
176 # Reference to the last parent in the Ordered Tree
177 # Is used to handle the initial node parent and workaround possible inconsistent `ANode::parent`
178 private var last_parent
: nullable ANode = null
192 return "{n.class_name} \"{n.text.escape_to_c}\
" @{n.location}"
194 return "{n.class_name} @{n.location}"
199 # A sequence of nodes
200 # It is a specific class (instead of using a Array) to track the parent/child relation when nodes are added or removed
201 class ANodes[E
: ANode]
203 private var parent
: ANode
204 private var items
= new Array[E
]
205 redef fun iterator
do return items
.iterator
206 redef fun length
do return items
.length
207 redef fun is_empty
do return items
.is_empty
226 var res
= items
.shift
238 redef fun []=(index
, e
)
240 hook_remove
(self[index
])
244 redef fun remove_at
(index
)
246 hook_remove
(items
[index
])
247 items
.remove_at
(index
)
249 private fun hook_add
(e
: E
)
251 #assert e.parent == null
254 private fun hook_remove
(e
: E
)
256 assert e
.parent
== parent
260 # Used in parent constructor to fill elements
261 private fun unsafe_add_all
(nodes
: Collection[Object])
263 var parent
= self.parent
271 private fun replace_child
(old_child
: ANode, new_child
: nullable ANode): Bool
273 var parent
= self.parent
274 for i
in [0..length
[ do
275 if self[i
] == old_child
then
276 if new_child
!= null then
277 assert new_child
isa E
279 new_child
.parent
= parent
289 private fun visit_all
(v
: Visitor)
291 for n
in self do v
.enter_visit
(n
)
295 # Ancestor of all tokens
296 # A token is a node that has a `text` but no children.
300 # The raw content on the token
301 fun text
: String is abstract
303 # The raw content on the token
304 fun text
=(text
: String) is abstract
306 # The previous token in the Lexer.
307 # May have disappeared in the AST
308 var prev_token
: nullable Token = null
310 # The next token in the Lexer.
311 # May have disappeared in the AST
312 var next_token
: nullable Token = null
314 # The verbatim blank text between `prev_token` and `self`
315 fun blank_before
: String
317 if prev_token
== null then return ""
318 var from
= prev_token
.location
.pend
+1
319 var to
= location
.pstart
320 return location
.file
.string
.substring
(from
,to-from
)
323 redef fun to_s
: String do
327 redef fun visit_all
(v
: Visitor) do end
328 redef fun replace_child
(old_child
: ANode, new_child
: nullable ANode) do end
331 redef class SourceFile
332 # The first token parser by the lexer
333 # May have disappeared in the final AST
334 var first_token
: nullable Token = null
336 # The first token parser by the lexer
337 # May have disappeared in the final AST
338 var last_token
: nullable Token = null
341 # Ancestor of all productions
342 # A production is a node without text but that usually has children.
346 # All the annotations attached directly to the node
347 var n_annotations
: nullable AAnnotations = null is writable
349 # Return all its annotations of a given name in the order of their declaration
350 # Retun an empty array if no such an annotation.
351 fun get_annotations
(name
: String): Array[AAnnotation]
353 var res
= new Array[AAnnotation]
354 var nas
= n_annotations
355 if nas
!= null then for na
in nas
.n_items
do
356 if na
.name
!= name
then continue
359 if self isa AClassdef then for na
in n_propdefs
do
360 if na
isa AAnnotPropdef then
361 if na
.name
!= name
then continue
369 redef fun replace_with
(n
: ANode)
373 if not isset n
._location
and isset _location
then n
._location
= _location
377 # Abstract standard visitor on the AST
378 abstract class Visitor
379 # What the visitor do when a node is visited
380 # Concrete visitors should implement this method.
382 protected fun visit
(e
: ANode) is abstract
384 # Ask the visitor to visit a given node.
385 # Usually automatically called by visit_all* methods.
386 # This method should not be redefined
387 fun enter_visit
(e
: nullable ANode)
389 if e
== null then return
390 var old
= _current_node
396 # The current visited node
397 var current_node
: nullable ANode = null is writable
400 # Token of end of line (basically `\n`)
409 # Token of a line of comments
410 # Starts with the `#` and contains the final end-of-line (if any)
415 # A token associated with a keyword
416 abstract class TokenKeyword
420 return "keyword '{text}'"
424 # The deprecated keyword `package`.
429 # The keyword `module`
434 # The keyword `import`
439 # The keyword `class`
444 # The keyword `abstract`
449 # The keyword `interface`
454 # The keywords `enum` ane `universal`
479 # The keyword `redef`
499 # The keyword `extern`
504 # The keyword `public`
509 # The keyword `protected`
514 # The keyword `private`
519 # The keyword `intrude`
539 # The keyword `while`
569 # The keyword `implies`
579 # The keyword `return`
584 # The keyword `continue`
589 # The keyword `break`
594 # The keyword `abort`
599 # The keyword `assert`
619 # The keyword `super`
634 # The keyword `false`
649 # The keyword `nullable`
654 # The keyword `isset`
659 # The keyword `label`
669 # The special keyword `__DEBUG__`
714 # A token associated with an operator (and other lookalike symbols)
715 abstract class TokenOperator
719 return "operator '{text}'"
833 # A class (or formal type) identifier. They start with an uppercase.
838 do return "type identifier '{text}'"
842 # A standard identifier (variable, method...). They start with a lowercase.
847 do return "identifier '{text}'"
851 # An attribute identifier. They start with an underscore.
856 do return "attribute '{text}'"
860 # A token of a literal value (string, integer, etc).
861 abstract class TokenLiteral
865 do return "literal value '{text}'"
869 # A literal decimal integer
874 # A literal hexadecimal integer
879 # A literal floating point number
884 # A literal character
894 # The starting part of a super string (between `"` and `{`)
899 # The middle part of a super string (between `}` and `{`)
904 # The final part of a super string (between `}` and `"`)
914 do return "malformed string {text}"
923 do return "malformed character {text}"
927 # A extern code block
928 class TExternCodeSegment
945 # A lexical error (unexpected character)
949 # A syntactic error (unexpected token)
954 # The main node of a Nit source-file
958 # The declaration part of the module
959 var n_moduledecl
: nullable AModuledecl = null is writable
961 # List of importation clauses
962 var n_imports
= new ANodes[AImport](self)
964 # List of extern blocks
965 var n_extern_code_blocks
= new ANodes[AExternCodeBlock](self)
967 # List of class definition (including top-level methods and the main)
968 var n_classdefs
= new ANodes[AClassdef](self)
971 # Abstract class for definition of entities
972 abstract class ADefinition
975 var n_doc
: nullable ADoc = null is writable
977 # The `redef` keyword
978 var n_kwredef
: nullable TKwredef = null is writable
980 # The declared visibility
981 var n_visibility
: nullable AVisibility = null is writable
984 # The declaration of the module with the documentation, name, and annotations
988 # The `module` keyword
989 var n_kwmodule
: TKwmodule is writable, noinit
991 # The declared module name
992 var n_name
: AModuleName is writable, noinit
995 # A import clause of a module
996 abstract class AImport
999 # The declared visibility
1000 var n_visibility
: AVisibility is writable, noinit
1002 # The `import` keyword
1003 var n_kwimport
: TKwimport is writable, noinit
1006 # A standard import clause. eg `import x`
1009 # The imported module name
1010 var n_name
: AModuleName is writable, noinit
1013 # The special import clause of the kernel module. eg `import end`
1016 # The `end` keyword, that indicate the root module
1017 var n_kwend
: TKwend is writable, noinit
1020 # A visibility modifier
1022 # The public visibility is an empty production (no keyword).
1024 # Note: even if some visibilities are only valid on some placse (for instance, no `protected` class or no `intrude` method)
1025 # the parser has no such a restriction, therefore the semantic phases has to check that the visibilities make sense.
1026 abstract class AVisibility
1030 # An implicit or explicit public visibility modifier
1031 class APublicVisibility
1033 # The `public` keyword, if any
1034 var n_kwpublic
: nullable TKwpublic is writable
1036 # An explicit private visibility modifier
1037 class APrivateVisibility
1039 # The `private` keyword
1040 var n_kwprivate
: TKwprivate is writable, noinit
1042 # An explicit protected visibility modifier
1043 class AProtectedVisibility
1045 # The `protected` keyword
1046 var n_kwprotected
: TKwprotected is writable, noinit
1048 # An explicit intrude visibility modifier
1049 class AIntrudeVisibility
1051 # The `intrude` keyword
1052 var n_kwintrude
: TKwintrude is writable, noinit
1055 # A class definition
1056 # While most definition are `AStdClassdef`
1057 # There is tow special case of class definition
1058 abstract class AClassdef
1060 # All the declared properties (including the main method)
1061 var n_propdefs
= new ANodes[APropdef](self)
1064 # A standard class definition with a name, superclasses and properties
1069 # The class kind (interface, abstract class, etc.)
1070 var n_classkind
: AClasskind is writable, noinit
1072 # The name of the class
1073 var n_id
: nullable TClassid = null is writable
1075 # The list of formal parameter types
1076 var n_formaldefs
= new ANodes[AFormaldef](self)
1078 # The extern block code
1079 var n_extern_code_block
: nullable AExternCodeBlock = null is writable
1082 var n_kwend
: TKwend is writable, noinit
1084 fun n_superclasses
: Array[ASuperPropdef] do
1085 return [for d
in n_propdefs
do if d
isa ASuperPropdef then d
]
1088 redef fun hot_location
do return n_id
.location
1091 # The implicit class definition of the implicit main method
1096 # The implicit class definition of the top-level methods
1101 # The modifier for the kind of class (abstract, interface, etc.)
1102 abstract class AClasskind
1106 # A default, or concrete class modifier (just `class`)
1107 class AConcreteClasskind
1110 # The `class` keyword.
1111 var n_kwclass
: TKwclass is writable, noinit
1114 # An abstract class modifier (`abstract class`)
1115 class AAbstractClasskind
1118 # The `abstract` keyword.
1119 var n_kwabstract
: TKwabstract is writable, noinit
1121 # The `class` keyword.
1122 var n_kwclass
: TKwclass is writable, noinit
1125 # An interface class modifier (`interface`)
1126 class AInterfaceClasskind
1129 # The `interface` keyword.
1130 var n_kwinterface
: TKwinterface is writable, noinit
1133 # An enum/universal class modifier (`enum class`)
1134 class AEnumClasskind
1137 # The `enum` keyword.
1138 var n_kwenum
: TKwenum is writable, noinit
1141 # An extern class modifier (`extern class`)
1142 class AExternClasskind
1145 # The `extern` keyword.
1146 var n_kwextern
: TKwextern is writable, noinit
1148 # The `class` keyword.
1149 var n_kwclass
: nullable TKwclass = null is writable
1152 # The definition of a formal generic parameter type. eg `X: Y`
1156 # The name of the parameter type
1157 var n_id
: TClassid is writable, noinit
1159 # The bound of the parameter type
1160 var n_type
: nullable AType = null is writable
1163 # The definition of a property
1164 abstract class APropdef
1168 # A definition of an attribute
1169 # For historical reason, old-syle and new-style attributes use the same `ANode` sub-class
1173 # The identifier for a old-style attribute (null if new-style)
1174 var n_kwvar
: TKwvar is writable, noinit
1176 # The identifier for a new-style attribute (null if old-style)
1177 var n_id2
: TId is writable, noinit
1179 # The declared type of the attribute
1180 var n_type
: nullable AType = null is writable
1182 # The initial value, if any (set with `=`)
1183 var n_expr
: nullable AExpr = null is writable
1185 # The initial value, if any (set with `do return`)
1186 var n_block
: nullable AExpr = null is writable
1188 redef fun hot_location
1190 return n_id2
.location
1194 # A definition of all kind of method (including constructors)
1198 # The `fun` keyword, if any
1199 var n_kwmeth
: nullable TKwmeth = null is writable
1201 # The `init` keyword, if any
1202 var n_kwinit
: nullable TKwinit = null is writable
1204 # The `new` keyword, if any
1205 var n_kwnew
: nullable TKwnew = null is writable
1207 # The name of the method, if any
1208 var n_methid
: nullable AMethid = null is writable
1210 # The signature of the method, if any
1211 var n_signature
: nullable ASignature = null is writable
1213 # The body (in Nit) of the method, if any
1214 var n_block
: nullable AExpr = null is writable
1216 # The list of declared callbacks (for extern methods)
1217 var n_extern_calls
: nullable AExternCalls = null is writable
1219 # The body (in extern code) of the method, if any
1220 var n_extern_code_block
: nullable AExternCodeBlock = null is writable
1222 redef fun hot_location
1224 if n_methid
!= null then
1225 return n_methid
.location
1226 else if n_kwinit
!= null then
1227 return n_kwinit
.location
1228 else if n_kwnew
!= null then
1229 return n_kwnew
.location
1236 # The implicit main method
1237 class AMainMethPropdef
1246 # A super-class. eg `super X`
1251 var n_kwsuper
: TKwsuper is writable, noinit
1253 # The super-class (indicated as a type)
1254 var n_type
: AType is writable, noinit
1258 # Declaration of callbacks for extern methods
1262 # The `import` keyword
1263 var n_kwimport
: TKwimport is writable, noinit
1265 # The list of declared callbacks
1266 var n_extern_calls
: ANodes[AExternCall] = new ANodes[AExternCall](self)
1269 # A single callback declaration
1270 abstract class AExternCall
1274 # A single callback declaration on a method
1275 abstract class APropExternCall
1279 # A single callback declaration on a method on the current receiver
1280 class ALocalPropExternCall
1281 super APropExternCall
1283 # The name of the called-back method
1284 var n_methid
: AMethid is writable, noinit
1287 # A single callback declaration on a method on an explicit receiver type.
1288 class AFullPropExternCall
1289 super APropExternCall
1291 # The type of the receiver of the called-back method
1292 var n_type
: AType is writable, noinit
1295 var n_dot
: nullable TDot = null is writable
1297 # The name of the called-back method
1298 var n_methid
: AMethid is writable, noinit
1301 # A single callback declaration on a method on a constructor
1302 class AInitPropExternCall
1303 super APropExternCall
1305 # The allocated type
1306 var n_type
: AType is writable, noinit
1309 # A single callback declaration on a `super` call
1310 class ASuperExternCall
1313 # The `super` keyword
1314 var n_kwsuper
: TKwsuper is writable, noinit
1317 # A single callback declaration on a cast
1318 abstract class ACastExternCall
1322 # A single callback declaration on a cast to a given type
1323 class ACastAsExternCall
1324 super ACastExternCall
1326 # The origin type of the cast
1327 var n_from_type
: AType is writable, noinit
1330 var n_dot
: nullable TDot = null is writable
1333 var n_kwas
: TKwas is writable, noinit
1335 # The destination of the cast
1336 var n_to_type
: AType is writable, noinit
1339 # A single callback declaration on a cast to a nullable type
1340 class AAsNullableExternCall
1341 super ACastExternCall
1343 # The origin type to cast as nullable
1344 var n_type
: AType is writable, noinit
1347 var n_kwas
: TKwas is writable, noinit
1349 # The `nullable` keyword
1350 var n_kwnullable
: TKwnullable is writable, noinit
1353 # A single callback declaration on a cast to a non-nullable type
1354 class AAsNotNullableExternCall
1355 super ACastExternCall
1357 # The destination type on a cast to not nullable
1358 var n_type
: AType is writable, noinit
1361 var n_kwas
: TKwas is writable, noinit
1364 var n_kwnot
: TKwnot is writable, noinit
1366 # The `nullable` keyword
1367 var n_kwnullable
: TKwnullable is writable, noinit
1370 # A definition of a virtual type
1374 # The `type` keyword
1375 var n_kwtype
: TKwtype is writable, noinit
1377 # The name of the virtual type
1378 var n_id
: TClassid is writable, noinit
1380 # The bound of the virtual type
1381 var n_type
: AType is writable, noinit
1384 # The identifier of a method in a method declaration.
1385 # There is a specific class because of operator and setters.
1386 abstract class AMethid
1390 # A method name with a simple identifier
1394 # The simple identifier
1395 var n_id
: TId is writable, noinit
1403 var n_plus
: TPlus is writable, noinit
1411 var n_minus
: TMinus is writable, noinit
1419 var n_star
: TStar is writable, noinit
1422 # A method name `**`
1423 class AStarstarMethid
1427 var n_starstar
: TStarstar is writable, noinit
1435 var n_slash
: TSlash is writable, noinit
1439 class APercentMethid
1443 var n_percent
: TPercent is writable, noinit
1446 # A method name `==`
1451 var n_eq
: TEq is writable, noinit
1454 # A method name `!=`
1459 var n_ne
: TNe is writable, noinit
1462 # A method name `<=`
1467 var n_le
: TLe is writable, noinit
1470 # A method name `>=`
1475 var n_ge
: TGe is writable, noinit
1483 var n_lt
: TLt is writable, noinit
1491 var n_gt
: TGt is writable, noinit
1494 # A method name `<<`
1499 var n_ll
: TLl is writable, noinit
1502 # A method name `>>`
1507 var n_gg
: TGg is writable, noinit
1510 # A method name `[]`
1515 var n_obra
: TObra is writable, noinit
1518 var n_cbra
: TCbra is writable, noinit
1521 # A method name `<=>`
1522 class AStarshipMethid
1526 var n_starship
: TStarship is writable, noinit
1529 # A setter method name with a simple identifier (with a `=`)
1533 # The base identifier
1534 var n_id
: TId is writable, noinit
1537 var n_assign
: TAssign is writable, noinit
1540 # A method name `[]=`
1541 class ABraassignMethid
1545 var n_obra
: TObra is writable, noinit
1548 var n_cbra
: TCbra is writable, noinit
1551 var n_assign
: TAssign is writable, noinit
1554 # A signature in a method definition. eg `(x,y:X,z:Z):T`
1559 var n_opar
: nullable TOpar = null is writable
1561 # The list of parameters
1562 var n_params
= new ANodes[AParam](self)
1565 var n_cpar
: nullable TCpar = null is writable
1568 var n_type
: nullable AType = null is writable
1571 # A parameter definition in a signature. eg `x:X`
1575 # The name of the parameter
1576 var n_id
: TId is writable, noinit
1578 # The type of the parameter, if any
1579 var n_type
: nullable AType = null is writable
1581 # The `...` symbol to indicate varargs
1582 var n_dotdotdot
: nullable TDotdotdot = null is writable
1585 # A static type. eg `nullable X[Y]`
1588 # The `nullable` keyword
1589 var n_kwnullable
: nullable TKwnullable = null is writable
1591 # The name of the class or of the formal type
1592 var n_id
: TClassid is writable, noinit
1594 # Type arguments for a generic type
1595 var n_types
= new ANodes[AType](self)
1598 # A label at the end of a block or in a break/continue statement. eg `label x`
1602 # The `label` keyword
1603 var n_kwlabel
: TKwlabel is writable, noinit
1605 # The name of the label, if any
1606 var n_id
: nullable TId is writable, noinit
1609 # Expression and statements
1610 # From a AST point of view there is no distinction between statement and expressions (even if the parser has to distinguish them)
1611 abstract class AExpr
1615 # A sequence of `AExpr` (usually statements)
1616 # The last `AExpr` gives the value of the whole block
1620 # The list of statements in the bloc.
1621 # The last element is often considered as an expression that give the value of the whole block.
1622 var n_expr
= new ANodes[AExpr](self)
1625 var n_kwend
: nullable TKwend = null is writable
1628 # A declaration of a local variable. eg `var x: X = y`
1633 var n_kwvar
: nullable TKwvar = null is writable
1635 # The name of the local variable
1636 var n_id
: TId is writable, noinit
1638 # The declaration type of the local variable
1639 var n_type
: nullable AType = null is writable
1641 # The `=` symbol (for the initial value)
1642 var n_assign
: nullable TAssign = null is writable
1644 # The initial value, if any
1645 var n_expr
: nullable AExpr = null is writable
1648 # A `return` statement. eg `return x`
1652 # The `return` keyword
1653 var n_kwreturn
: nullable TKwreturn = null is writable
1655 # The return value, if any
1656 var n_expr
: nullable AExpr = null is writable
1659 # Something that has a label.
1660 abstract class ALabelable
1663 # The associated label declatation
1664 var n_label
: nullable ALabel = null is writable
1667 # A `break` or a `continue`
1668 abstract class AEscapeExpr
1672 # The return value, if nay (unused currently)
1673 var n_expr
: nullable AExpr = null is writable
1676 # A `break` statement.
1680 # The `break` keyword
1681 var n_kwbreak
: TKwbreak is writable, noinit
1684 # An `abort` statement
1688 # The `abort` keyword
1689 var n_kwabort
: TKwabort is writable, noinit
1692 # A `continue` statement
1696 # The `continue` keyword.
1697 var n_kwcontinue
: nullable TKwcontinue = null is writable
1706 var n_kwdo
: TKwdo is writable, noinit
1708 # The list of statements of the `do`.
1709 var n_block
: nullable AExpr = null is writable
1717 var n_kwif
: TKwif is writable, noinit
1719 # The expression used as the condition of the `if`
1720 var n_expr
: AExpr is writable, noinit
1722 # The body of the `then` part
1723 var n_then
: nullable AExpr = null is writable
1725 # The body of the `else` part
1726 var n_else
: nullable AExpr = null is writable
1729 # A `if` expression (ternary conditional). eg. `if true then 1 else 0`
1734 var n_kwif
: TKwif is writable, noinit
1736 # The expression used as the condition of the `if`
1737 var n_expr
: AExpr is writable, noinit
1739 # The `then` keyword
1740 var n_kwthen
: TKwthen is writable, noinit
1742 # The expression in the `then` part
1743 var n_then
: AExpr is writable, noinit
1745 # The `else` keyword
1746 var n_kwelse
: TKwelse is writable, noinit
1748 # The expression in the `else` part
1749 var n_else
: AExpr is writable, noinit
1752 # A `while` statement
1757 # The `while` keyword
1758 var n_kwwhile
: TKwwhile is writable, noinit
1760 # The expression used as the condition of the `while`
1761 var n_expr
: AExpr is writable, noinit
1764 var n_kwdo
: TKwdo is writable, noinit
1766 # The body of the loop
1767 var n_block
: nullable AExpr = null is writable
1770 # A `loop` statement
1775 # The `loop` keyword
1776 var n_kwloop
: TKwloop is writable, noinit
1778 # The body of the loop
1779 var n_block
: nullable AExpr = null is writable
1788 var n_kwfor
: TKwfor is writable, noinit
1790 # The list of name of the automatic variables
1791 var n_ids
= new ANodes[TId](self)
1793 # The expression used as the collection to iterate on
1794 var n_expr
: AExpr is writable, noinit
1797 var n_kwdo
: TKwdo is writable, noinit
1799 # The body of the loop
1800 var n_block
: nullable AExpr = null is writable
1803 # A `with` statement
1808 # The `with` keyword
1809 var n_kwwith
: TKwwith is writable, noinit
1811 # The expression used to get the value to control
1812 var n_expr
: AExpr is writable, noinit
1815 var n_kwdo
: TKwdo is writable, noinit
1817 # The body of the loop
1818 var n_block
: nullable AExpr = null is writable
1821 # An `assert` statement
1825 # The `assert` keyword
1826 var n_kwassert
: TKwassert is writable, noinit
1828 # The name of the assert, if any
1829 var n_id
: nullable TId = null is writable
1831 # The expression used as the condition of the `assert`
1832 var n_expr
: AExpr is writable, noinit
1834 # The body to execute when the assert fails
1835 var n_else
: nullable AExpr = null is writable
1838 # Whatever is a simple assignment. eg `= something`
1839 abstract class AAssignFormExpr
1843 var n_assign
: TAssign is writable, noinit
1845 # The right-value to assign.
1846 var n_value
: AExpr is writable, noinit
1849 # Whatever is a combined assignment. eg `+= something`
1850 abstract class AReassignFormExpr
1853 # The combined operator (eg. `+=`)
1854 var n_assign_op
: AAssignOp is writable, noinit
1856 # The right-value to apply on the combined operator.
1857 var n_value
: AExpr is writable, noinit
1860 # A `once` expression. eg `once x`
1864 # The `once` keyword
1865 var n_kwonce
: TKwonce is writable, noinit
1867 # The expression to evaluate only one time
1868 var n_expr
: AExpr is writable, noinit
1871 # A polymorphic invocation of a method
1872 # The form of the invocation (name, arguments, etc.) are specific
1873 abstract class ASendExpr
1875 # The receiver of the method invocation
1876 var n_expr
: AExpr is writable, noinit
1879 # A binary operation on a method
1880 abstract class ABinopExpr
1882 # The second operand of the operation
1883 # Note: the receiver (`n_expr`) is the first operand
1884 var n_expr2
: AExpr is writable, noinit
1887 # Something that is boolean expression
1888 abstract class ABoolExpr
1892 # Something that is binary boolean expression
1893 abstract class ABinBoolExpr
1896 # The first boolean operand
1897 var n_expr
: AExpr is writable, noinit
1899 # The second boolean operand
1900 var n_expr2
: AExpr is writable, noinit
1908 # A `and` expression
1913 # A `or else` expression
1918 # A `implies` expression
1923 # A `not` expression
1928 var n_kwnot
: TKwnot is writable, noinit
1930 # The boolean operand of the `not`
1931 var n_expr
: AExpr is writable, noinit
1974 # A type-ckeck expression. eg `x isa T`
1978 # The expression to check
1979 var n_expr
: AExpr is writable, noinit
1981 # The destination type to check to
1982 var n_type
: AType is writable, noinit
1995 # A `<=>` expression
2020 # A unary minus expression. eg `-x`
2025 var n_minus
: TMinus is writable, noinit
2028 # An explicit instantiation. eg `new T`
2033 var n_kwnew
: TKwnew is writable, noinit
2035 # The `type` keyword
2036 var n_type
: AType is writable, noinit
2038 # The name of the named-constructor, if any
2039 var n_id
: nullable TId = null is writable
2041 # The arguments of the `new`
2042 var n_args
: AExprs is writable, noinit
2045 # Whatever is a old-style attribute access
2046 abstract class AAttrFormExpr
2049 # The receiver of the attribute
2050 var n_expr
: AExpr is writable, noinit
2052 # The name of the attribute
2053 var n_id
: TAttrid is writable, noinit
2057 # The read of an attribute. eg `x._a`
2062 # The assignment of an attribute. eg `x._a=y`
2063 class AAttrAssignExpr
2065 super AAssignFormExpr
2068 # Whatever looks-like a call with a standard method and any number of arguments.
2069 abstract class ACallFormExpr
2072 # The name of the method
2073 var n_id
: TId is writable, noinit
2075 # The arguments of the call
2076 var n_args
: AExprs is writable, noinit
2079 # A complex setter call (standard or brackets)
2080 abstract class ASendReassignFormExpr
2082 super AReassignFormExpr
2085 # A complex attribute assignment. eg `x._a+=y`
2086 class AAttrReassignExpr
2088 super AReassignFormExpr
2091 # A call with a standard method-name and any number of arguments. eg `x.m(y)`. OR just a simple id
2092 # 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`.
2093 # Semantic analysis have to transform them to instance of `AVarExpr`.
2098 # A setter call with a standard method-name and any number of arguments. eg `x.m(y)=z`. OR just a simple assignment.
2099 # 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`.
2100 # Semantic analysis have to transform them to instance of `AVarAssignExpr`.
2101 class ACallAssignExpr
2103 super AAssignFormExpr
2106 # 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.
2107 # 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`.
2108 # Semantic analysis have to transform them to instance of `AVarReassignExpr`.
2109 class ACallReassignExpr
2111 super ASendReassignFormExpr
2114 # A call to `super`. OR a call of a super-constructor
2118 # The qualifier part before the super (currenlty unused)
2119 var n_qualified
: nullable AQualified = null is writable
2121 # The `super` keyword
2122 var n_kwsuper
: TKwsuper is writable, noinit
2124 # The arguments of the super
2125 var n_args
: AExprs is writable, noinit
2128 # A call to the `init` constructor.
2129 # Note: because `init` is a keyword and not a `TId`, the explicit call to init cannot be a `ACallFormExpr`.
2133 # The `init` keyword
2134 var n_kwinit
: TKwinit is writable, noinit
2136 # The arguments of the init
2137 var n_args
: AExprs is writable, noinit
2140 # Whatever looks-like a call of the brackets `[]` operator.
2141 abstract class ABraFormExpr
2144 # The arguments inside the brackets
2145 var n_args
: AExprs is writable, noinit
2148 # A call of the brackets operator. eg `x[y,z]`
2153 # A setter call of the bracket operator. eg `x[y,z]=t`
2154 class ABraAssignExpr
2156 super AAssignFormExpr
2159 # Whatever is an access to a local variable
2160 abstract class AVarFormExpr
2163 # The name of the attribute
2164 var n_id
: TId is writable, noinit
2167 # A complex setter call of the bracket operator. eg `x[y,z]+=t`
2168 class ABraReassignExpr
2170 super ASendReassignFormExpr
2173 # A local variable read access.
2174 # The parser cannot instantiate them, see `ACallExpr`.
2179 # A local variable simple assignment access
2180 # The parser cannot instantiate them, see `ACallAssignExpr`.
2181 class AVarAssignExpr
2183 super AAssignFormExpr
2186 # A local variable complex assignment access
2187 # The parser cannot instantiate them, see `ACallReassignExpr`.
2188 class AVarReassignExpr
2190 super AReassignFormExpr
2193 # A literal range, open or closed
2194 abstract class ARangeExpr
2197 # The left (lower) element of the range
2198 var n_expr
: AExpr is writable, noinit
2200 # The right (uppr) element of the range
2201 var n_expr2
: AExpr is writable, noinit
2204 # A closed literal range. eg `[x..y]`
2208 # The opening bracket `[`
2209 var n_obra
: TObra is writable, noinit
2211 # The closing bracket `]`
2212 var n_cbra
: TCbra is writable, noinit
2215 # An open literal range. eg `[x..y[`
2219 # The opening bracket `[`
2220 var n_obra
: TObra is writable, noinit
2222 # The closing bracket `[` (because open range)
2223 var n_cbra
: TObra is writable, noinit
2226 # A literal array. eg. `[x,y,z]`
2230 # The opening bracket `[`
2231 var n_obra
: TObra is writable, noinit
2233 # The elements of the array
2234 var n_exprs
= new ANodes[AExpr](self)
2236 # The type of the element of the array (if any)
2237 var n_type
: nullable AType = null is writable
2239 # The closing bracket `]`
2240 var n_cbra
: TCbra is writable, noinit
2247 # The `self` keyword
2248 var n_kwself
: nullable TKwself = null is writable
2251 # When there is no explicit receiver, `self` is implicit
2252 class AImplicitSelfExpr
2256 # A `true` boolean literal constant
2260 # The `true` keyword
2261 var n_kwtrue
: TKwtrue is writable, noinit
2264 # A `false` boolean literal constant
2268 # The `false` keyword
2269 var n_kwfalse
: TKwfalse is writable, noinit
2272 # A `null` literal constant
2276 # The `null` keyword
2277 var n_kwnull
: TKwnull is writable, noinit
2280 # An integer literal
2285 # An integer literal in decimal format
2290 var n_number
: TNumber is writable, noinit
2293 # An integer literal in hexadecimal format
2297 # The hexadecimal token
2298 var n_hex_number
: THexNumber is writable, noinit
2306 var n_float
: TFloat is writable, noinit
2309 # A character literal
2313 # The character token
2314 var n_char
: TChar is writable, noinit
2318 abstract class AStringFormExpr
2322 var n_string
: Token is writable, noinit
2325 # A simple string. eg. `"abc"`
2327 super AStringFormExpr
2330 # The start of a superstring. eg `"abc{`
2331 class AStartStringExpr
2332 super AStringFormExpr
2335 # The middle of a superstring. eg `}abc{`
2336 class AMidStringExpr
2337 super AStringFormExpr
2340 # The end of a superstrng. eg `}abc"`
2341 class AEndStringExpr
2342 super AStringFormExpr
2345 # A superstring literal. eg `"a{x}b{y}c"`
2346 # Each part is modeled a sequence of expression. eg. `["a{, x, }b{, y, }c"]`
2347 class ASuperstringExpr
2350 # The list of the expressions of the superstring
2351 var n_exprs
= new ANodes[AExpr](self)
2354 # A simple parenthesis. eg `(x)`
2358 # The opening parenthesis
2359 var n_opar
: TOpar is writable, noinit
2361 # The inner expression
2362 var n_expr
: AExpr is writable, noinit
2364 # The closing parenthesis
2365 var n_cpar
: TCpar is writable, noinit
2368 # A cast, against a type or `not null`
2372 # The expression to cast
2373 var n_expr
: AExpr is writable, noinit
2376 var n_kwas
: TKwas is writable, noinit
2378 # The opening parenthesis
2379 var n_opar
: nullable TOpar = null is writable
2381 # The closing parenthesis
2382 var n_cpar
: nullable TCpar = null is writable
2385 # A type cast. eg `x.as(T)`
2389 # The target type to cast to
2390 var n_type
: AType is writable, noinit
2393 # A as-not-null cast. eg `x.as(not null)`
2394 class AAsNotnullExpr
2398 var n_kwnot
: TKwnot is writable, noinit
2400 # The `null` keyword
2401 var n_kwnull
: TKwnull is writable, noinit
2404 # A is-set check of old-style attributes. eg `isset x._a`
2405 class AIssetAttrExpr
2408 # The `isset` keyword
2409 var n_kwisset
: TKwisset is writable, noinit
2412 # An ellipsis notation used to pass an expression as it, in a vararg parameter
2416 # The passed expression
2417 var n_expr
: AExpr is writable, noinit
2420 var n_dotdotdot
: TDotdotdot is writable, noinit
2423 # A list of expression separated with commas (arguments for instance)
2427 # The list of expressions
2428 var n_exprs
= new ANodes[AExpr](self)
2431 # A special expression that encapsulates a static type
2432 # Can only be found in special construction like arguments of annotations.
2436 # The encapsulated type
2437 var n_type
: AType is writable, noinit
2440 # A special expression that encapsulates a method identifier
2441 # Can only be found in special construction like arguments of annotations.
2446 var n_expr
: AExpr is writable, noinit
2448 # The encapsulated method identifier
2449 var n_id
: AMethid is writable, noinit
2452 # A special expression that encapsulate an annotation
2453 # Can only be found in special construction like arguments of annotations.
2455 # The encapsulated annotations are in `n_annotations`
2460 # A special expression to debug types
2461 class ADebugTypeExpr
2464 # The `debug` keyword
2465 var n_kwdebug
: TKwdebug is writable, noinit
2467 # The `type` keyword
2468 var n_kwtype
: TKwtype is writable, noinit
2470 # The expression to check
2471 var n_expr
: AExpr is writable, noinit
2474 var n_type
: AType is writable, noinit
2477 # A list of expression separated with commas (arguments for instance)
2478 abstract class AExprs
2481 # The list of expressions
2482 var n_exprs
= new ANodes[AExpr](self)
2485 # A simple list of expressions
2490 # A list of expressions enclosed in parentheses
2494 # The opening parenthesis
2495 var n_opar
: TOpar is writable, noinit
2497 # The closing parenthesis
2498 var n_cpar
: TCpar is writable, noinit
2501 # A list of expressions enclosed in brackets
2505 # The opening bracket
2506 var n_obra
: TObra is writable, noinit
2508 # The closing bracket
2509 var n_cbra
: TCbra is writable, noinit
2512 # A complex assignment operator. (`+=` and `-=`)
2513 abstract class AAssignOp
2517 # The `+=` assignment operation
2522 var n_pluseq
: TPluseq is writable, noinit
2525 # The `-=` assignment operator
2526 class AMinusAssignOp
2530 var n_minuseq
: TMinuseq is writable, noinit
2533 # A possibly fully-qualified module identifier
2537 # The starting quad (`::`)
2538 var n_quad
: nullable TQuad = null is writable
2540 # The list of quad-separated project/group identifiers
2541 var n_path
= new ANodes[TId](self)
2543 # The final module identifier
2544 var n_id
: TId is writable, noinit
2547 # A language declaration for an extern block
2552 var n_kwin
: TKwin is writable, noinit
2555 var n_string
: TString is writable, noinit
2558 # An full extern block
2559 class AExternCodeBlock
2562 # The language declration
2563 var n_in_language
: nullable AInLanguage = null is writable
2565 # The block of extern code
2566 var n_extern_code_segment
: TExternCodeSegment is writable, noinit
2569 # A possible full method qualifier.
2573 # The starting quad (`::`)
2574 var n_quad
: nullable TQuad = null is writable
2576 # The list of quad-separated project/group/module identifiers
2577 var n_id
= new ANodes[TId](self)
2579 # A class identifier
2580 var n_classid
: nullable TClassid = null is writable
2583 # A documentation of a definition
2584 # It contains the block of comments just above the declaration
2588 # A list of lines of comment
2589 var n_comment
= new ANodes[TComment](self)
2592 # A group of annotation on a node
2594 # This same class is used for the 3 kind of annotations:
2596 # * *is* annotations. eg `module foo is bar`.
2597 # * *at* annotations. eg `foo@bar` or `foo@(bar,baz)`.
2598 # * *class* annotations, defined in classes.
2602 # The `@` symbol, for *at* annotations
2603 var n_at
: nullable TAt = null is writable
2605 # The opening parenthesis in *at* annotations
2606 var n_opar
: nullable TOpar = null is writable
2608 # The list of annotations
2609 var n_items
= new ANodes[AAnnotation](self)
2611 # The closing parenthesis in *at* annotations
2612 var n_cpar
: nullable TCpar = null is writable
2615 # A single annotation
2619 # The name of the annotation
2620 var n_atid
: AAtid is writable, noinit
2622 # The opening parenthesis of the arguments
2623 var n_opar
: nullable TOpar = null is writable
2625 # The list of arguments
2626 var n_args
= new ANodes[AExpr](self)
2628 # The closing parenthesis
2629 var n_cpar
: nullable TCpar = null is writable
2631 # The name of the annotation
2634 return n_atid
.n_id
.text
2638 # An annotation name
2639 abstract class AAtid
2642 # The identifier of the annotation.
2643 # Can be a TId of a keyword
2644 var n_id
: Token is writable, noinit
2647 # An annotation name based on an identifier
2652 # An annotation name based on the keyword `extern`
2657 # An annotation name based on the keyword `import`
2662 # An annotation name based on the keyword `abstract`
2663 class AKwabstractAtid
2667 # The root of the AST
2672 var n_base
: nullable AModule is writable
2674 # The end of file (or error) token
2675 var n_eof
: EOF is writable