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 return res
356 for na
in nas
.n_items
do
357 if na
.name
!= name
then continue
363 redef fun replace_with
(n
: ANode)
367 if not isset n
._location
and isset _location
then n
._location
= _location
371 # Abstract standard visitor on the AST
372 abstract class Visitor
373 # What the visitor do when a node is visited
374 # Concrete visitors should implement this method.
376 protected fun visit
(e
: ANode) is abstract
378 # Ask the visitor to visit a given node.
379 # Usually automatically called by visit_all* methods.
380 # This method should not be redefined
381 fun enter_visit
(e
: nullable ANode)
383 if e
== null then return
384 var old
= _current_node
390 # The current visited node
391 var current_node
: nullable ANode = null is writable
394 # Token of end of line (basically `\n`)
403 # Token of a line of comments
404 # Starts with the `#` and contains the final end-of-line (if any)
409 # A token associated with a keyword
410 abstract class TokenKeyword
414 return "keyword '{text}'"
418 # The deprecated keyword `package`.
423 # The keyword `module`
428 # The keyword `import`
433 # The keyword `class`
438 # The keyword `abstract`
443 # The keyword `interface`
448 # The keywords `enum` ane `universal`
473 # The keyword `redef`
493 # The keyword `extern`
498 # The keyword `public`
503 # The keyword `protected`
508 # The keyword `private`
513 # The keyword `intrude`
533 # The keyword `while`
563 # The keyword `implies`
573 # The keyword `return`
578 # The keyword `continue`
583 # The keyword `break`
588 # The keyword `abort`
593 # The keyword `assert`
613 # The keyword `super`
628 # The keyword `false`
643 # The keyword `nullable`
648 # The keyword `isset`
653 # The keyword `label`
658 # The special keyword `__DEBUG__`
703 # A token associated with an operator (and other lookalike symbols)
704 abstract class TokenOperator
708 return "operator '{text}'"
822 # A class (or formal type) identifier. They start with an uppercase.
827 do return "type identifier '{text}'"
831 # A standard identifier (variable, method...). They start with a lowercase.
836 do return "identifier '{text}'"
840 # An attribute identifier. They start with an underscore.
845 do return "attribute '{text}'"
849 # A token of a literal value (string, integer, etc).
850 abstract class TokenLiteral
854 do return "literal value '{text}'"
858 # A literal decimal integer
863 # A literal hexadecimal integer
868 # A literal floating point number
873 # A literal character
883 # The starting part of a super string (between `"` and `{`)
888 # The middle part of a super string (between `}` and `{`)
893 # The final part of a super string (between `}` and `"`)
903 do return "malformed string {text}"
912 do return "malformed character {text}"
916 # A extern code block
917 class TExternCodeSegment
934 # A lexical error (unexpected character)
938 # A syntactic error (unexpected token)
943 # The main node of a Nit source-file
947 # The declaration part of the module
948 var n_moduledecl
: nullable AModuledecl = null is writable
950 # List of importation clauses
951 var n_imports
= new ANodes[AImport](self)
953 # List of extern blocks
954 var n_extern_code_blocks
= new ANodes[AExternCodeBlock](self)
956 # List of class definition (including top-level methods and the main)
957 var n_classdefs
= new ANodes[AClassdef](self)
960 # Abstract class for definition of entities
961 abstract class ADefinition
964 var n_doc
: nullable ADoc = null is writable
966 # The `redef` keyword
967 var n_kwredef
: nullable TKwredef = null is writable
969 # The declared visibility
970 var n_visibility
: nullable AVisibility = null is writable
973 # The declaration of the module with the documentation, name, and annotations
977 # The `module` keyword
978 var n_kwmodule
: TKwmodule is writable, noinit
980 # The declared module name
981 var n_name
: AModuleName is writable, noinit
984 # A import clause of a module
985 abstract class AImport
988 # The declared visibility
989 var n_visibility
: AVisibility is writable, noinit
991 # The `import` keyword
992 var n_kwimport
: TKwimport is writable, noinit
995 # A standard import clause. eg `import x`
998 # The imported module name
999 var n_name
: AModuleName is writable, noinit
1002 # The special import clause of the kernel module. eg `import end`
1005 # The `end` keyword, that indicate the root module
1006 var n_kwend
: TKwend is writable, noinit
1009 # A visibility modifier
1011 # The public visibility is an empty production (no keyword).
1013 # Note: even if some visibilities are only valid on some placse (for instance, no `protected` class or no `intrude` method)
1014 # the parser has no such a restriction, therefore the semantic phases has to check that the visibilities make sense.
1015 abstract class AVisibility
1019 # An implicit or explicit public visibility modifier
1020 class APublicVisibility
1022 # The `public` keyword, if any
1023 var n_kwpublic
: nullable TKwpublic is writable
1025 # An explicit private visibility modifier
1026 class APrivateVisibility
1028 # The `private` keyword
1029 var n_kwprivate
: TKwprivate is writable, noinit
1031 # An explicit protected visibility modifier
1032 class AProtectedVisibility
1034 # The `protected` keyword
1035 var n_kwprotected
: TKwprotected is writable, noinit
1037 # An explicit intrude visibility modifier
1038 class AIntrudeVisibility
1040 # The `intrude` keyword
1041 var n_kwintrude
: TKwintrude is writable, noinit
1044 # A class definition
1045 # While most definition are `AStdClassdef`
1046 # There is tow special case of class definition
1047 abstract class AClassdef
1049 # All the declared properties (including the main method)
1050 var n_propdefs
= new ANodes[APropdef](self)
1053 # A standard class definition with a name, superclasses and properties
1058 # The class kind (interface, abstract class, etc.)
1059 var n_classkind
: AClasskind is writable, noinit
1061 # The name of the class
1062 var n_id
: nullable TClassid = null is writable
1064 # The list of formal parameter types
1065 var n_formaldefs
= new ANodes[AFormaldef](self)
1067 # The extern block code
1068 var n_extern_code_block
: nullable AExternCodeBlock = null is writable
1070 # The list of super-classes
1071 var n_superclasses
= new ANodes[ASuperclass](self)
1074 var n_kwend
: TKwend is writable, noinit
1076 redef fun hot_location
do return n_id
.location
1079 # The implicit class definition of the implicit main method
1084 # The implicit class definition of the top-level methods
1089 # The modifier for the kind of class (abstract, interface, etc.)
1090 abstract class AClasskind
1094 # A default, or concrete class modifier (just `class`)
1095 class AConcreteClasskind
1098 # The `class` keyword.
1099 var n_kwclass
: TKwclass is writable, noinit
1102 # An abstract class modifier (`abstract class`)
1103 class AAbstractClasskind
1106 # The `abstract` keyword.
1107 var n_kwabstract
: TKwabstract is writable, noinit
1109 # The `class` keyword.
1110 var n_kwclass
: TKwclass is writable, noinit
1113 # An interface class modifier (`interface`)
1114 class AInterfaceClasskind
1117 # The `interface` keyword.
1118 var n_kwinterface
: TKwinterface is writable, noinit
1121 # An enum/universal class modifier (`enum class`)
1122 class AEnumClasskind
1125 # The `enum` keyword.
1126 var n_kwenum
: TKwenum is writable, noinit
1129 # An extern class modifier (`extern class`)
1130 class AExternClasskind
1133 # The `extern` keyword.
1134 var n_kwextern
: TKwextern is writable, noinit
1136 # The `class` keyword.
1137 var n_kwclass
: nullable TKwclass = null is writable
1140 # The definition of a formal generic parameter type. eg `X: Y`
1144 # The name of the parameter type
1145 var n_id
: TClassid is writable, noinit
1147 # The bound of the parameter type
1148 var n_type
: nullable AType = null is writable
1151 # A super-class. eg `super X`
1156 var n_kwsuper
: TKwsuper is writable, noinit
1158 # The super-class (indicated as a type)
1159 var n_type
: AType is writable, noinit
1162 # The definition of a property
1163 abstract class APropdef
1167 # A definition of an attribute
1168 # For historical reason, old-syle and new-style attributes use the same `ANode` sub-class
1172 # The identifier for a old-style attribute (null if new-style)
1173 var n_kwvar
: TKwvar is writable, noinit
1175 # The identifier for a new-style attribute (null if old-style)
1176 var n_id2
: TId is writable, noinit
1178 # The declared type of the attribute
1179 var n_type
: nullable AType = null is writable
1181 # The initial value, if any (set with `=`)
1182 var n_expr
: nullable AExpr = null is writable
1184 # The initial value, if any (set with `do return`)
1185 var n_block
: nullable AExpr = null is writable
1187 redef fun hot_location
1189 return n_id2
.location
1193 # A definition of all kind of method (including constructors)
1197 # The `fun` keyword, if any
1198 var n_kwmeth
: nullable TKwmeth = null is writable
1200 # The `init` keyword, if any
1201 var n_kwinit
: nullable TKwinit = null is writable
1203 # The `new` keyword, if any
1204 var n_kwnew
: nullable TKwnew = null is writable
1206 # The name of the method, if any
1207 var n_methid
: nullable AMethid = null is writable
1209 # The signature of the method, if any
1210 var n_signature
: nullable ASignature = null is writable
1212 # The body (in Nit) of the method, if any
1213 var n_block
: nullable AExpr = null is writable
1215 # The list of declared callbacks (for extern methods)
1216 var n_extern_calls
: nullable AExternCalls = null is writable
1218 # The body (in extern code) of the method, if any
1219 var n_extern_code_block
: nullable AExternCodeBlock = null is writable
1221 redef fun hot_location
1223 if n_methid
!= null then
1224 return n_methid
.location
1225 else if n_kwinit
!= null then
1226 return n_kwinit
.location
1227 else if n_kwnew
!= null then
1228 return n_kwnew
.location
1235 # The implicit main method
1236 class AMainMethPropdef
1240 # Declaration of callbacks for extern methods
1244 # The `import` keyword
1245 var n_kwimport
: TKwimport is writable, noinit
1247 # The list of declared callbacks
1248 var n_extern_calls
: ANodes[AExternCall] = new ANodes[AExternCall](self)
1251 # A single callback declaration
1252 abstract class AExternCall
1256 # A single callback declaration on a method
1257 abstract class APropExternCall
1261 # A single callback declaration on a method on the current receiver
1262 class ALocalPropExternCall
1263 super APropExternCall
1265 # The name of the called-back method
1266 var n_methid
: AMethid is writable, noinit
1269 # A single callback declaration on a method on an explicit receiver type.
1270 class AFullPropExternCall
1271 super APropExternCall
1273 # The type of the receiver of the called-back method
1274 var n_type
: AType is writable, noinit
1277 var n_dot
: nullable TDot = null is writable
1279 # The name of the called-back method
1280 var n_methid
: AMethid is writable, noinit
1283 # A single callback declaration on a method on a constructor
1284 class AInitPropExternCall
1285 super APropExternCall
1287 # The allocated type
1288 var n_type
: AType is writable, noinit
1291 # A single callback declaration on a `super` call
1292 class ASuperExternCall
1295 # The `super` keyword
1296 var n_kwsuper
: TKwsuper is writable, noinit
1299 # A single callback declaration on a cast
1300 abstract class ACastExternCall
1304 # A single callback declaration on a cast to a given type
1305 class ACastAsExternCall
1306 super ACastExternCall
1308 # The origin type of the cast
1309 var n_from_type
: AType is writable, noinit
1312 var n_dot
: nullable TDot = null is writable
1315 var n_kwas
: TKwas is writable, noinit
1317 # The destination of the cast
1318 var n_to_type
: AType is writable, noinit
1321 # A single callback declaration on a cast to a nullable type
1322 class AAsNullableExternCall
1323 super ACastExternCall
1325 # The origin type to cast as nullable
1326 var n_type
: AType is writable, noinit
1329 var n_kwas
: TKwas is writable, noinit
1331 # The `nullable` keyword
1332 var n_kwnullable
: TKwnullable is writable, noinit
1335 # A single callback declaration on a cast to a non-nullable type
1336 class AAsNotNullableExternCall
1337 super ACastExternCall
1339 # The destination type on a cast to not nullable
1340 var n_type
: AType is writable, noinit
1343 var n_kwas
: TKwas is writable, noinit
1346 var n_kwnot
: TKwnot is writable, noinit
1348 # The `nullable` keyword
1349 var n_kwnullable
: TKwnullable is writable, noinit
1352 # A definition of a virtual type
1356 # The `type` keyword
1357 var n_kwtype
: TKwtype is writable, noinit
1359 # The name of the virtual type
1360 var n_id
: TClassid is writable, noinit
1362 # The bound of the virtual type
1363 var n_type
: AType is writable, noinit
1366 # The identifier of a method in a method declaration.
1367 # There is a specific class because of operator and setters.
1368 abstract class AMethid
1372 # A method name with a simple identifier
1376 # The simple identifier
1377 var n_id
: TId is writable, noinit
1385 var n_plus
: TPlus is writable, noinit
1393 var n_minus
: TMinus is writable, noinit
1401 var n_star
: TStar is writable, noinit
1404 # A method name `**`
1405 class AStarstarMethid
1409 var n_starstar
: TStarstar is writable, noinit
1417 var n_slash
: TSlash is writable, noinit
1421 class APercentMethid
1425 var n_percent
: TPercent is writable, noinit
1428 # A method name `==`
1433 var n_eq
: TEq is writable, noinit
1436 # A method name `!=`
1441 var n_ne
: TNe is writable, noinit
1444 # A method name `<=`
1449 var n_le
: TLe is writable, noinit
1452 # A method name `>=`
1457 var n_ge
: TGe is writable, noinit
1465 var n_lt
: TLt is writable, noinit
1473 var n_gt
: TGt is writable, noinit
1476 # A method name `<<`
1481 var n_ll
: TLl is writable, noinit
1484 # A method name `>>`
1489 var n_gg
: TGg is writable, noinit
1492 # A method name `[]`
1497 var n_obra
: TObra is writable, noinit
1500 var n_cbra
: TCbra is writable, noinit
1503 # A method name `<=>`
1504 class AStarshipMethid
1508 var n_starship
: TStarship is writable, noinit
1511 # A setter method name with a simple identifier (with a `=`)
1515 # The base identifier
1516 var n_id
: TId is writable, noinit
1519 var n_assign
: TAssign is writable, noinit
1522 # A method name `[]=`
1523 class ABraassignMethid
1527 var n_obra
: TObra is writable, noinit
1530 var n_cbra
: TCbra is writable, noinit
1533 var n_assign
: TAssign is writable, noinit
1536 # A signature in a method definition. eg `(x,y:X,z:Z):T`
1541 var n_opar
: nullable TOpar = null is writable
1543 # The list of parameters
1544 var n_params
= new ANodes[AParam](self)
1547 var n_cpar
: nullable TCpar = null is writable
1550 var n_type
: nullable AType = null is writable
1553 # A parameter definition in a signature. eg `x:X`
1557 # The name of the parameter
1558 var n_id
: TId is writable, noinit
1560 # The type of the parameter, if any
1561 var n_type
: nullable AType = null is writable
1563 # The `...` symbol to indicate varargs
1564 var n_dotdotdot
: nullable TDotdotdot = null is writable
1567 # A static type. eg `nullable X[Y]`
1570 # The `nullable` keyword
1571 var n_kwnullable
: nullable TKwnullable = null is writable
1573 # The name of the class or of the formal type
1574 var n_id
: TClassid is writable, noinit
1576 # Type arguments for a generic type
1577 var n_types
= new ANodes[AType](self)
1580 # A label at the end of a block or in a break/continue statement. eg `label x`
1584 # The `label` keyword
1585 var n_kwlabel
: TKwlabel is writable, noinit
1587 # The name of the label, if any
1588 var n_id
: nullable TId is writable
1591 # Expression and statements
1592 # From a AST point of view there is no distinction between statement and expressions (even if the parser has to distinguish them)
1593 abstract class AExpr
1597 # A sequence of `AExpr` (usually statements)
1598 # The last `AExpr` gives the value of the whole block
1602 # The list of statements in the bloc.
1603 # The last element is often considered as an expression that give the value of the whole block.
1604 var n_expr
= new ANodes[AExpr](self)
1607 var n_kwend
: nullable TKwend = null is writable
1610 # A declaration of a local variable. eg `var x: X = y`
1615 var n_kwvar
: TKwvar is writable, noinit
1617 # The name of the local variable
1618 var n_id
: TId is writable, noinit
1620 # The declaration type of the local variable
1621 var n_type
: nullable AType = null is writable
1623 # The `=` symbol (for the initial value)
1624 var n_assign
: nullable TAssign = null is writable
1626 # The initial value, if any
1627 var n_expr
: nullable AExpr = null is writable
1630 # A `return` statement. eg `return x`
1634 # The `return` keyword
1635 var n_kwreturn
: nullable TKwreturn = null is writable
1637 # The return value, if any
1638 var n_expr
: nullable AExpr = null is writable
1641 # Something that has a label.
1642 abstract class ALabelable
1645 # The associated label declatation
1646 var n_label
: nullable ALabel = null is writable
1649 # A `break` or a `continue`
1650 abstract class AEscapeExpr
1654 # The return value, if nay (unused currently)
1655 var n_expr
: nullable AExpr = null is writable
1658 # A `break` statement.
1662 # The `break` keyword
1663 var n_kwbreak
: TKwbreak is writable, noinit
1666 # An `abort` statement
1670 # The `abort` keyword
1671 var n_kwabort
: TKwabort is writable, noinit
1674 # A `continue` statement
1678 # The `continue` keyword.
1679 var n_kwcontinue
: nullable TKwcontinue = null is writable
1688 var n_kwdo
: TKwdo is writable, noinit
1690 # The list of statements of the `do`.
1691 var n_block
: nullable AExpr = null is writable
1699 var n_kwif
: TKwif is writable, noinit
1701 # The expression used as the condition of the `if`
1702 var n_expr
: AExpr is writable, noinit
1704 # The body of the `then` part
1705 var n_then
: nullable AExpr = null is writable
1707 # The body of the `else` part
1708 var n_else
: nullable AExpr = null is writable
1711 # A `if` expression (ternary conditional). eg. `if true then 1 else 0`
1716 var n_kwif
: TKwif is writable, noinit
1718 # The expression used as the condition of the `if`
1719 var n_expr
: AExpr is writable, noinit
1721 # The `then` keyword
1722 var n_kwthen
: TKwthen is writable, noinit
1724 # The expression in the `then` part
1725 var n_then
: AExpr is writable, noinit
1727 # The `else` keyword
1728 var n_kwelse
: TKwelse is writable, noinit
1730 # The expression in the `else` part
1731 var n_else
: AExpr is writable, noinit
1734 # A `while` statement
1739 # The `while` keyword
1740 var n_kwwhile
: TKwwhile is writable, noinit
1742 # The expression used as the condition of the `while`
1743 var n_expr
: AExpr is writable, noinit
1746 var n_kwdo
: TKwdo is writable, noinit
1748 # The body of the loop
1749 var n_block
: nullable AExpr = null is writable
1752 # A `loop` statement
1757 # The `loop` keyword
1758 var n_kwloop
: TKwloop is writable, noinit
1760 # The body of the loop
1761 var n_block
: nullable AExpr = null is writable
1770 var n_kwfor
: TKwfor is writable, noinit
1772 # The list of name of the automatic variables
1773 var n_ids
= new ANodes[TId](self)
1775 # The expression used as the collection to iterate on
1776 var n_expr
: AExpr is writable, noinit
1779 var n_kwdo
: TKwdo is writable, noinit
1781 # The body of the loop
1782 var n_block
: nullable AExpr = null is writable
1785 # An `assert` statement
1789 # The `assert` keyword
1790 var n_kwassert
: TKwassert is writable, noinit
1792 # The name of the assert, if any
1793 var n_id
: nullable TId = null is writable
1795 # The expression used as the condition of the `assert`
1796 var n_expr
: AExpr is writable, noinit
1798 # The body to execute when the assert fails
1799 var n_else
: nullable AExpr = null is writable
1802 # Whatever is a simple assignment. eg `= something`
1803 abstract class AAssignFormExpr
1807 var n_assign
: TAssign is writable, noinit
1809 # The right-value to assign.
1810 var n_value
: AExpr is writable, noinit
1813 # Whatever is a combined assignment. eg `+= something`
1814 abstract class AReassignFormExpr
1817 # The combined operator (eg. `+=`)
1818 var n_assign_op
: AAssignOp is writable, noinit
1820 # The right-value to apply on the combined operator.
1821 var n_value
: AExpr is writable, noinit
1824 # A `once` expression. eg `once x`
1828 # The `once` keyword
1829 var n_kwonce
: TKwonce is writable, noinit
1831 # The expression to evaluate only one time
1832 var n_expr
: AExpr is writable, noinit
1835 # A polymorphic invocation of a method
1836 # The form of the invocation (name, arguments, etc.) are specific
1837 abstract class ASendExpr
1839 # The receiver of the method invocation
1840 var n_expr
: AExpr is writable, noinit
1843 # A binary operation on a method
1844 abstract class ABinopExpr
1846 # The second operand of the operation
1847 # Note: the receiver (`n_expr`) is the first operand
1848 var n_expr2
: AExpr is writable, noinit
1851 # Something that is boolean expression
1852 abstract class ABoolExpr
1856 # Something that is binary boolean expression
1857 abstract class ABinBoolExpr
1860 # The first boolean operand
1861 var n_expr
: AExpr is writable, noinit
1863 # The second boolean operand
1864 var n_expr2
: AExpr is writable, noinit
1872 # A `and` expression
1877 # A `or else` expression
1882 # A `implies` expression
1887 # A `not` expression
1892 var n_kwnot
: TKwnot is writable, noinit
1894 # The boolean operand of the `not`
1895 var n_expr
: AExpr is writable, noinit
1938 # A type-ckeck expression. eg `x isa T`
1942 # The expression to check
1943 var n_expr
: AExpr is writable, noinit
1945 # The destination type to check to
1946 var n_type
: AType is writable, noinit
1959 # A `<=>` expression
1984 # A unary minus expression. eg `-x`
1989 var n_minus
: TMinus is writable, noinit
1992 # An explicit instantiation. eg `new T`
1997 var n_kwnew
: TKwnew is writable, noinit
1999 # The `type` keyword
2000 var n_type
: AType is writable, noinit
2002 # The name of the named-constructor, if any
2003 var n_id
: nullable TId = null is writable
2005 # The arguments of the `new`
2006 var n_args
: AExprs is writable, noinit
2009 # Whatever is a old-style attribute access
2010 abstract class AAttrFormExpr
2013 # The receiver of the attribute
2014 var n_expr
: AExpr is writable, noinit
2016 # The name of the attribute
2017 var n_id
: TAttrid is writable, noinit
2021 # The read of an attribute. eg `x._a`
2026 # The assignment of an attribute. eg `x._a=y`
2027 class AAttrAssignExpr
2029 super AAssignFormExpr
2032 # Whatever looks-like a call with a standard method and any number of arguments.
2033 abstract class ACallFormExpr
2036 # The name of the method
2037 var n_id
: TId is writable, noinit
2039 # The arguments of the call
2040 var n_args
: AExprs is writable, noinit
2043 # A complex setter call (standard or brackets)
2044 abstract class ASendReassignFormExpr
2046 super AReassignFormExpr
2049 # A complex attribute assignment. eg `x._a+=y`
2050 class AAttrReassignExpr
2052 super AReassignFormExpr
2055 # A call with a standard method-name and any number of arguments. eg `x.m(y)`. OR just a simple id
2056 # 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`.
2057 # Semantic analysis have to transform them to instance of `AVarExpr`.
2062 # A setter call with a standard method-name and any number of arguments. eg `x.m(y)=z`. OR just a simple assignment.
2063 # 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`.
2064 # Semantic analysis have to transform them to instance of `AVarAssignExpr`.
2065 class ACallAssignExpr
2067 super AAssignFormExpr
2070 # 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.
2071 # 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`.
2072 # Semantic analysis have to transform them to instance of `AVarReassignExpr`.
2073 class ACallReassignExpr
2075 super ASendReassignFormExpr
2078 # A call to `super`. OR a call of a super-constructor
2082 # The qualifier part before the super (currenlty unused)
2083 var n_qualified
: nullable AQualified = null is writable
2085 # The `super` keyword
2086 var n_kwsuper
: TKwsuper is writable, noinit
2088 # The arguments of the super
2089 var n_args
: AExprs is writable, noinit
2092 # A call to the `init` constructor.
2093 # Note: because `init` is a keyword and not a `TId`, the explicit call to init cannot be a `ACallFormExpr`.
2097 # The `init` keyword
2098 var n_kwinit
: TKwinit is writable, noinit
2100 # The arguments of the init
2101 var n_args
: AExprs is writable, noinit
2104 # Whatever looks-like a call of the brackets `[]` operator.
2105 abstract class ABraFormExpr
2108 # The arguments inside the brackets
2109 var n_args
: AExprs is writable, noinit
2112 # A call of the brackets operator. eg `x[y,z]`
2117 # A setter call of the bracket operator. eg `x[y,z]=t`
2118 class ABraAssignExpr
2120 super AAssignFormExpr
2123 # Whatever is an access to a local variable
2124 abstract class AVarFormExpr
2127 # The name of the attribute
2128 var n_id
: TId is writable, noinit
2131 # A complex setter call of the bracket operator. eg `x[y,z]+=t`
2132 class ABraReassignExpr
2134 super ASendReassignFormExpr
2137 # A local variable read access.
2138 # The parser cannot instantiate them, see `ACallExpr`.
2143 # A local variable simple assignment access
2144 # The parser cannot instantiate them, see `ACallAssignExpr`.
2145 class AVarAssignExpr
2147 super AAssignFormExpr
2150 # A local variable complex assignment access
2151 # The parser cannot instantiate them, see `ACallReassignExpr`.
2152 class AVarReassignExpr
2154 super AReassignFormExpr
2157 # A literal range, open or closed
2158 abstract class ARangeExpr
2161 # The left (lower) element of the range
2162 var n_expr
: AExpr is writable, noinit
2164 # The right (uppr) element of the range
2165 var n_expr2
: AExpr is writable, noinit
2168 # A closed literal range. eg `[x..y]`
2172 # The opening bracket `[`
2173 var n_obra
: TObra is writable, noinit
2175 # The closing bracket `]`
2176 var n_cbra
: TCbra is writable, noinit
2179 # An open literal range. eg `[x..y[`
2183 # The opening bracket `[`
2184 var n_obra
: TObra is writable, noinit
2186 # The closing bracket `[` (because open range)
2187 var n_cbra
: TObra is writable, noinit
2190 # A literal array. eg. `[x,y,z]`
2194 # The opening bracket `[`
2195 var n_obra
: TObra is writable, noinit
2197 # The elements of the array
2198 var n_exprs
= new ANodes[AExpr](self)
2200 # The type of the element of the array (if any)
2201 var n_type
: nullable AType = null is writable
2203 # The closing bracket `]`
2204 var n_cbra
: TCbra is writable, noinit
2211 # The `self` keyword
2212 var n_kwself
: nullable TKwself is writable
2215 # When there is no explicit receiver, `self` is implicit
2216 class AImplicitSelfExpr
2220 # A `true` boolean literal constant
2224 # The `true` keyword
2225 var n_kwtrue
: TKwtrue is writable, noinit
2228 # A `false` boolean literal constant
2232 # The `false` keyword
2233 var n_kwfalse
: TKwfalse is writable, noinit
2236 # A `null` literal constant
2240 # The `null` keyword
2241 var n_kwnull
: TKwnull is writable, noinit
2244 # An integer literal
2249 # An integer literal in decimal format
2254 var n_number
: TNumber is writable, noinit
2257 # An integer literal in hexadecimal format
2261 # The hexadecimal token
2262 var n_hex_number
: THexNumber is writable, noinit
2270 var n_float
: TFloat is writable, noinit
2273 # A character literal
2277 # The character token
2278 var n_char
: TChar is writable, noinit
2282 abstract class AStringFormExpr
2286 var n_string
: Token is writable, noinit
2289 # A simple string. eg. `"abc"`
2291 super AStringFormExpr
2294 # The start of a superstring. eg `"abc{`
2295 class AStartStringExpr
2296 super AStringFormExpr
2299 # The middle of a superstring. eg `}abc{`
2300 class AMidStringExpr
2301 super AStringFormExpr
2304 # The end of a superstrng. eg `}abc"`
2305 class AEndStringExpr
2306 super AStringFormExpr
2309 # A superstring literal. eg `"a{x}b{y}c"`
2310 # Each part is modeled a sequence of expression. eg. `["a{, x, }b{, y, }c"]`
2311 class ASuperstringExpr
2314 # The list of the expressions of the superstring
2315 var n_exprs
= new ANodes[AExpr](self)
2318 # A simple parenthesis. eg `(x)`
2322 # The opening parenthesis
2323 var n_opar
: TOpar is writable, noinit
2325 # The inner expression
2326 var n_expr
: AExpr is writable, noinit
2328 # The closing parenthesis
2329 var n_cpar
: TCpar is writable, noinit
2332 # A cast, against a type or `not null`
2336 # The expression to cast
2337 var n_expr
: AExpr is writable, noinit
2340 var n_kwas
: TKwas is writable, noinit
2342 # The opening parenthesis
2343 var n_opar
: nullable TOpar = null is writable
2345 # The closing parenthesis
2346 var n_cpar
: nullable TCpar = null is writable
2349 # A type cast. eg `x.as(T)`
2353 # The target type to cast to
2354 var n_type
: AType is writable, noinit
2357 # A as-not-null cast. eg `x.as(not null)`
2358 class AAsNotnullExpr
2362 var n_kwnot
: TKwnot is writable, noinit
2364 # The `null` keyword
2365 var n_kwnull
: TKwnull is writable, noinit
2368 # A is-set check of old-style attributes. eg `isset x._a`
2369 class AIssetAttrExpr
2372 # The `isset` keyword
2373 var n_kwisset
: TKwisset is writable, noinit
2376 # An ellipsis notation used to pass an expression as it, in a vararg parameter
2380 # The passed expression
2381 var n_expr
: AExpr is writable, noinit
2384 var n_dotdotdot
: TDotdotdot is writable, noinit
2387 # A list of expression separated with commas (arguments for instance)
2391 # The list of expressions
2392 var n_exprs
= new ANodes[AExpr](self)
2395 # A special expression that encapsulates a static type
2396 # Can only be found in special construction like arguments of annotations.
2400 # The encapsulated type
2401 var n_type
: AType is writable, noinit
2404 # A special expression that encapsulates a method identifier
2405 # Can only be found in special construction like arguments of annotations.
2410 var n_expr
: AExpr is writable, noinit
2412 # The encapsulated method identifier
2413 var n_id
: AMethid is writable, noinit
2416 # A special expression that encapsulate an annotation
2417 # Can only be found in special construction like arguments of annotations.
2419 # The encapsulated annotations are in `n_annotations`
2424 # A special expression to debug types
2425 class ADebugTypeExpr
2428 # The `debug` keyword
2429 var n_kwdebug
: TKwdebug is writable, noinit
2431 # The `type` keyword
2432 var n_kwtype
: TKwtype is writable, noinit
2434 # The expression to check
2435 var n_expr
: AExpr is writable, noinit
2438 var n_type
: AType is writable, noinit
2441 # A list of expression separated with commas (arguments for instance)
2442 abstract class AExprs
2445 # The list of expressions
2446 var n_exprs
= new ANodes[AExpr](self)
2449 # A simple list of expressions
2454 # A list of expressions enclosed in parentheses
2458 # The opening parenthesis
2459 var n_opar
: TOpar is writable, noinit
2461 # The closing parenthesis
2462 var n_cpar
: TCpar is writable, noinit
2465 # A list of expressions enclosed in brackets
2469 # The opening bracket
2470 var n_obra
: TObra is writable, noinit
2472 # The closing bracket
2473 var n_cbra
: TCbra is writable, noinit
2476 # A complex assignment operator. (`+=` and `-=`)
2477 abstract class AAssignOp
2481 # The `+=` assignment operation
2486 var n_pluseq
: TPluseq is writable, noinit
2489 # The `-=` assignment operator
2490 class AMinusAssignOp
2494 var n_minuseq
: TMinuseq is writable, noinit
2497 # A possibly fully-qualified module identifier
2501 # The starting quad (`::`)
2502 var n_quad
: nullable TQuad = null is writable
2504 # The list of quad-separated project/group identifiers
2505 var n_path
= new ANodes[TId](self)
2507 # The final module identifier
2508 var n_id
: TId is writable, noinit
2511 # A language declaration for an extern block
2516 var n_kwin
: TKwin is writable, noinit
2519 var n_string
: TString is writable, noinit
2522 # An full extern block
2523 class AExternCodeBlock
2526 # The language declration
2527 var n_in_language
: nullable AInLanguage = null is writable
2529 # The block of extern code
2530 var n_extern_code_segment
: TExternCodeSegment is writable, noinit
2533 # A possible full method qualifier.
2537 # The starting quad (`::`)
2538 var n_quad
: nullable TQuad = null is writable
2540 # The list of quad-separated project/group/module identifiers
2541 var n_id
= new ANodes[TId](self)
2543 # A class identifier
2544 var n_classid
: nullable TClassid = null is writable
2547 # A documentation of a definition
2548 # It contains the block of comments just above the declaration
2552 # A list of lines of comment
2553 var n_comment
= new ANodes[TComment](self)
2556 # A group of annotation on a node
2558 # This same class is used for the 3 kind of annotations:
2560 # * *is* annotations. eg `module foo is bar`.
2561 # * *at* annotations. eg `foo@bar` or `foo@(bar,baz)`.
2562 # * *class* annotations, defined in classes.
2566 # The `@` symbol, for *at* annotations
2567 var n_at
: nullable TAt = null is writable
2569 # The opening parenthesis in *at* annotations
2570 var n_opar
: nullable TOpar = null is writable
2572 # The list of annotations
2573 var n_items
= new ANodes[AAnnotation](self)
2575 # The closing parenthesis in *at* annotations
2576 var n_cpar
: nullable TCpar = null is writable
2579 # A single annotation
2583 # The name of the annotation
2584 var n_atid
: AAtid is writable, noinit
2586 # The opening parenthesis of the arguments
2587 var n_opar
: nullable TOpar = null is writable
2589 # The list of arguments
2590 var n_args
= new ANodes[AExpr](self)
2592 # The closing parenthesis
2593 var n_cpar
: nullable TCpar = null is writable
2595 # The name of the annotation
2598 return n_atid
.n_id
.text
2602 # An annotation name
2603 abstract class AAtid
2606 # The identifier of the annotation.
2607 # Can be a TId of a keyword
2608 var n_id
: Token is writable, noinit
2611 # An annotation name based on an identifier
2616 # An annotation name based on the keyword `extern`
2621 # An annotation name based on the keyword `import`
2626 # An annotation name based on the keyword `abstract`
2627 class AKwabstractAtid
2631 # The root of the AST
2636 var n_base
: nullable AModule is writable
2638 # The end of file (or error) token
2639 var n_eof
: EOF is writable