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`
664 # The special keyword `__DEBUG__`
709 # A token associated with an operator (and other lookalike symbols)
710 abstract class TokenOperator
714 return "operator '{text}'"
828 # A class (or formal type) identifier. They start with an uppercase.
833 do return "type identifier '{text}'"
837 # A standard identifier (variable, method...). They start with a lowercase.
842 do return "identifier '{text}'"
846 # An attribute identifier. They start with an underscore.
851 do return "attribute '{text}'"
855 # A token of a literal value (string, integer, etc).
856 abstract class TokenLiteral
860 do return "literal value '{text}'"
864 # A literal decimal integer
869 # A literal hexadecimal integer
874 # A literal floating point number
879 # A literal character
889 # The starting part of a super string (between `"` and `{`)
894 # The middle part of a super string (between `}` and `{`)
899 # The final part of a super string (between `}` and `"`)
909 do return "malformed string {text}"
918 do return "malformed character {text}"
922 # A extern code block
923 class TExternCodeSegment
940 # A lexical error (unexpected character)
944 # A syntactic error (unexpected token)
949 # The main node of a Nit source-file
953 # The declaration part of the module
954 var n_moduledecl
: nullable AModuledecl = null is writable
956 # List of importation clauses
957 var n_imports
= new ANodes[AImport](self)
959 # List of extern blocks
960 var n_extern_code_blocks
= new ANodes[AExternCodeBlock](self)
962 # List of class definition (including top-level methods and the main)
963 var n_classdefs
= new ANodes[AClassdef](self)
966 # Abstract class for definition of entities
967 abstract class ADefinition
970 var n_doc
: nullable ADoc = null is writable
972 # The `redef` keyword
973 var n_kwredef
: nullable TKwredef = null is writable
975 # The declared visibility
976 var n_visibility
: nullable AVisibility = null is writable
979 # The declaration of the module with the documentation, name, and annotations
983 # The `module` keyword
984 var n_kwmodule
: TKwmodule is writable, noinit
986 # The declared module name
987 var n_name
: AModuleName is writable, noinit
990 # A import clause of a module
991 abstract class AImport
994 # The declared visibility
995 var n_visibility
: AVisibility is writable, noinit
997 # The `import` keyword
998 var n_kwimport
: TKwimport is writable, noinit
1001 # A standard import clause. eg `import x`
1004 # The imported module name
1005 var n_name
: AModuleName is writable, noinit
1008 # The special import clause of the kernel module. eg `import end`
1011 # The `end` keyword, that indicate the root module
1012 var n_kwend
: TKwend is writable, noinit
1015 # A visibility modifier
1017 # The public visibility is an empty production (no keyword).
1019 # Note: even if some visibilities are only valid on some placse (for instance, no `protected` class or no `intrude` method)
1020 # the parser has no such a restriction, therefore the semantic phases has to check that the visibilities make sense.
1021 abstract class AVisibility
1025 # An implicit or explicit public visibility modifier
1026 class APublicVisibility
1028 # The `public` keyword, if any
1029 var n_kwpublic
: nullable TKwpublic is writable
1031 # An explicit private visibility modifier
1032 class APrivateVisibility
1034 # The `private` keyword
1035 var n_kwprivate
: TKwprivate is writable, noinit
1037 # An explicit protected visibility modifier
1038 class AProtectedVisibility
1040 # The `protected` keyword
1041 var n_kwprotected
: TKwprotected is writable, noinit
1043 # An explicit intrude visibility modifier
1044 class AIntrudeVisibility
1046 # The `intrude` keyword
1047 var n_kwintrude
: TKwintrude is writable, noinit
1050 # A class definition
1051 # While most definition are `AStdClassdef`
1052 # There is tow special case of class definition
1053 abstract class AClassdef
1055 # All the declared properties (including the main method)
1056 var n_propdefs
= new ANodes[APropdef](self)
1059 # A standard class definition with a name, superclasses and properties
1064 # The class kind (interface, abstract class, etc.)
1065 var n_classkind
: AClasskind is writable, noinit
1067 # The name of the class
1068 var n_id
: nullable TClassid = null is writable
1070 # The list of formal parameter types
1071 var n_formaldefs
= new ANodes[AFormaldef](self)
1073 # The extern block code
1074 var n_extern_code_block
: nullable AExternCodeBlock = null is writable
1077 var n_kwend
: TKwend is writable, noinit
1079 fun n_superclasses
: Array[ASuperPropdef] do
1080 return [for d
in n_propdefs
do if d
isa ASuperPropdef then d
]
1083 redef fun hot_location
do return n_id
.location
1086 # The implicit class definition of the implicit main method
1091 # The implicit class definition of the top-level methods
1096 # The modifier for the kind of class (abstract, interface, etc.)
1097 abstract class AClasskind
1101 # A default, or concrete class modifier (just `class`)
1102 class AConcreteClasskind
1105 # The `class` keyword.
1106 var n_kwclass
: TKwclass is writable, noinit
1109 # An abstract class modifier (`abstract class`)
1110 class AAbstractClasskind
1113 # The `abstract` keyword.
1114 var n_kwabstract
: TKwabstract is writable, noinit
1116 # The `class` keyword.
1117 var n_kwclass
: TKwclass is writable, noinit
1120 # An interface class modifier (`interface`)
1121 class AInterfaceClasskind
1124 # The `interface` keyword.
1125 var n_kwinterface
: TKwinterface is writable, noinit
1128 # An enum/universal class modifier (`enum class`)
1129 class AEnumClasskind
1132 # The `enum` keyword.
1133 var n_kwenum
: TKwenum is writable, noinit
1136 # An extern class modifier (`extern class`)
1137 class AExternClasskind
1140 # The `extern` keyword.
1141 var n_kwextern
: TKwextern is writable, noinit
1143 # The `class` keyword.
1144 var n_kwclass
: nullable TKwclass = null is writable
1147 # The definition of a formal generic parameter type. eg `X: Y`
1151 # The name of the parameter type
1152 var n_id
: TClassid is writable, noinit
1154 # The bound of the parameter type
1155 var n_type
: nullable AType = null is writable
1158 # The definition of a property
1159 abstract class APropdef
1163 # A definition of an attribute
1164 # For historical reason, old-syle and new-style attributes use the same `ANode` sub-class
1168 # The identifier for a old-style attribute (null if new-style)
1169 var n_kwvar
: TKwvar is writable, noinit
1171 # The identifier for a new-style attribute (null if old-style)
1172 var n_id2
: TId is writable, noinit
1174 # The declared type of the attribute
1175 var n_type
: nullable AType = null is writable
1177 # The initial value, if any (set with `=`)
1178 var n_expr
: nullable AExpr = null is writable
1180 # The initial value, if any (set with `do return`)
1181 var n_block
: nullable AExpr = null is writable
1183 redef fun hot_location
1185 return n_id2
.location
1189 # A definition of all kind of method (including constructors)
1193 # The `fun` keyword, if any
1194 var n_kwmeth
: nullable TKwmeth = null is writable
1196 # The `init` keyword, if any
1197 var n_kwinit
: nullable TKwinit = null is writable
1199 # The `new` keyword, if any
1200 var n_kwnew
: nullable TKwnew = null is writable
1202 # The name of the method, if any
1203 var n_methid
: nullable AMethid = null is writable
1205 # The signature of the method, if any
1206 var n_signature
: nullable ASignature = null is writable
1208 # The body (in Nit) of the method, if any
1209 var n_block
: nullable AExpr = null is writable
1211 # The list of declared callbacks (for extern methods)
1212 var n_extern_calls
: nullable AExternCalls = null is writable
1214 # The body (in extern code) of the method, if any
1215 var n_extern_code_block
: nullable AExternCodeBlock = null is writable
1217 redef fun hot_location
1219 if n_methid
!= null then
1220 return n_methid
.location
1221 else if n_kwinit
!= null then
1222 return n_kwinit
.location
1223 else if n_kwnew
!= null then
1224 return n_kwnew
.location
1231 # The implicit main method
1232 class AMainMethPropdef
1241 # A super-class. eg `super X`
1246 var n_kwsuper
: TKwsuper is writable, noinit
1248 # The super-class (indicated as a type)
1249 var n_type
: AType is writable, noinit
1253 # Declaration of callbacks for extern methods
1257 # The `import` keyword
1258 var n_kwimport
: TKwimport is writable, noinit
1260 # The list of declared callbacks
1261 var n_extern_calls
: ANodes[AExternCall] = new ANodes[AExternCall](self)
1264 # A single callback declaration
1265 abstract class AExternCall
1269 # A single callback declaration on a method
1270 abstract class APropExternCall
1274 # A single callback declaration on a method on the current receiver
1275 class ALocalPropExternCall
1276 super APropExternCall
1278 # The name of the called-back method
1279 var n_methid
: AMethid is writable, noinit
1282 # A single callback declaration on a method on an explicit receiver type.
1283 class AFullPropExternCall
1284 super APropExternCall
1286 # The type of the receiver of the called-back method
1287 var n_type
: AType is writable, noinit
1290 var n_dot
: nullable TDot = null is writable
1292 # The name of the called-back method
1293 var n_methid
: AMethid is writable, noinit
1296 # A single callback declaration on a method on a constructor
1297 class AInitPropExternCall
1298 super APropExternCall
1300 # The allocated type
1301 var n_type
: AType is writable, noinit
1304 # A single callback declaration on a `super` call
1305 class ASuperExternCall
1308 # The `super` keyword
1309 var n_kwsuper
: TKwsuper is writable, noinit
1312 # A single callback declaration on a cast
1313 abstract class ACastExternCall
1317 # A single callback declaration on a cast to a given type
1318 class ACastAsExternCall
1319 super ACastExternCall
1321 # The origin type of the cast
1322 var n_from_type
: AType is writable, noinit
1325 var n_dot
: nullable TDot = null is writable
1328 var n_kwas
: TKwas is writable, noinit
1330 # The destination of the cast
1331 var n_to_type
: AType is writable, noinit
1334 # A single callback declaration on a cast to a nullable type
1335 class AAsNullableExternCall
1336 super ACastExternCall
1338 # The origin type to cast as nullable
1339 var n_type
: AType is writable, noinit
1342 var n_kwas
: TKwas is writable, noinit
1344 # The `nullable` keyword
1345 var n_kwnullable
: TKwnullable is writable, noinit
1348 # A single callback declaration on a cast to a non-nullable type
1349 class AAsNotNullableExternCall
1350 super ACastExternCall
1352 # The destination type on a cast to not nullable
1353 var n_type
: AType is writable, noinit
1356 var n_kwas
: TKwas is writable, noinit
1359 var n_kwnot
: TKwnot is writable, noinit
1361 # The `nullable` keyword
1362 var n_kwnullable
: TKwnullable is writable, noinit
1365 # A definition of a virtual type
1369 # The `type` keyword
1370 var n_kwtype
: TKwtype is writable, noinit
1372 # The name of the virtual type
1373 var n_id
: TClassid is writable, noinit
1375 # The bound of the virtual type
1376 var n_type
: AType is writable, noinit
1379 # The identifier of a method in a method declaration.
1380 # There is a specific class because of operator and setters.
1381 abstract class AMethid
1385 # A method name with a simple identifier
1389 # The simple identifier
1390 var n_id
: TId is writable, noinit
1398 var n_plus
: TPlus is writable, noinit
1406 var n_minus
: TMinus is writable, noinit
1414 var n_star
: TStar is writable, noinit
1417 # A method name `**`
1418 class AStarstarMethid
1422 var n_starstar
: TStarstar is writable, noinit
1430 var n_slash
: TSlash is writable, noinit
1434 class APercentMethid
1438 var n_percent
: TPercent is writable, noinit
1441 # A method name `==`
1446 var n_eq
: TEq is writable, noinit
1449 # A method name `!=`
1454 var n_ne
: TNe is writable, noinit
1457 # A method name `<=`
1462 var n_le
: TLe is writable, noinit
1465 # A method name `>=`
1470 var n_ge
: TGe is writable, noinit
1478 var n_lt
: TLt is writable, noinit
1486 var n_gt
: TGt is writable, noinit
1489 # A method name `<<`
1494 var n_ll
: TLl is writable, noinit
1497 # A method name `>>`
1502 var n_gg
: TGg is writable, noinit
1505 # A method name `[]`
1510 var n_obra
: TObra is writable, noinit
1513 var n_cbra
: TCbra is writable, noinit
1516 # A method name `<=>`
1517 class AStarshipMethid
1521 var n_starship
: TStarship is writable, noinit
1524 # A setter method name with a simple identifier (with a `=`)
1528 # The base identifier
1529 var n_id
: TId is writable, noinit
1532 var n_assign
: TAssign is writable, noinit
1535 # A method name `[]=`
1536 class ABraassignMethid
1540 var n_obra
: TObra is writable, noinit
1543 var n_cbra
: TCbra is writable, noinit
1546 var n_assign
: TAssign is writable, noinit
1549 # A signature in a method definition. eg `(x,y:X,z:Z):T`
1554 var n_opar
: nullable TOpar = null is writable
1556 # The list of parameters
1557 var n_params
= new ANodes[AParam](self)
1560 var n_cpar
: nullable TCpar = null is writable
1563 var n_type
: nullable AType = null is writable
1566 # A parameter definition in a signature. eg `x:X`
1570 # The name of the parameter
1571 var n_id
: TId is writable, noinit
1573 # The type of the parameter, if any
1574 var n_type
: nullable AType = null is writable
1576 # The `...` symbol to indicate varargs
1577 var n_dotdotdot
: nullable TDotdotdot = null is writable
1580 # A static type. eg `nullable X[Y]`
1583 # The `nullable` keyword
1584 var n_kwnullable
: nullable TKwnullable = null is writable
1586 # The name of the class or of the formal type
1587 var n_id
: TClassid is writable, noinit
1589 # Type arguments for a generic type
1590 var n_types
= new ANodes[AType](self)
1593 # A label at the end of a block or in a break/continue statement. eg `label x`
1597 # The `label` keyword
1598 var n_kwlabel
: TKwlabel is writable, noinit
1600 # The name of the label, if any
1601 var n_id
: nullable TId is writable
1604 # Expression and statements
1605 # From a AST point of view there is no distinction between statement and expressions (even if the parser has to distinguish them)
1606 abstract class AExpr
1610 # A sequence of `AExpr` (usually statements)
1611 # The last `AExpr` gives the value of the whole block
1615 # The list of statements in the bloc.
1616 # The last element is often considered as an expression that give the value of the whole block.
1617 var n_expr
= new ANodes[AExpr](self)
1620 var n_kwend
: nullable TKwend = null is writable
1623 # A declaration of a local variable. eg `var x: X = y`
1628 var n_kwvar
: TKwvar is writable, noinit
1630 # The name of the local variable
1631 var n_id
: TId is writable, noinit
1633 # The declaration type of the local variable
1634 var n_type
: nullable AType = null is writable
1636 # The `=` symbol (for the initial value)
1637 var n_assign
: nullable TAssign = null is writable
1639 # The initial value, if any
1640 var n_expr
: nullable AExpr = null is writable
1643 # A `return` statement. eg `return x`
1647 # The `return` keyword
1648 var n_kwreturn
: nullable TKwreturn = null is writable
1650 # The return value, if any
1651 var n_expr
: nullable AExpr = null is writable
1654 # Something that has a label.
1655 abstract class ALabelable
1658 # The associated label declatation
1659 var n_label
: nullable ALabel = null is writable
1662 # A `break` or a `continue`
1663 abstract class AEscapeExpr
1667 # The return value, if nay (unused currently)
1668 var n_expr
: nullable AExpr = null is writable
1671 # A `break` statement.
1675 # The `break` keyword
1676 var n_kwbreak
: TKwbreak is writable, noinit
1679 # An `abort` statement
1683 # The `abort` keyword
1684 var n_kwabort
: TKwabort is writable, noinit
1687 # A `continue` statement
1691 # The `continue` keyword.
1692 var n_kwcontinue
: nullable TKwcontinue = null is writable
1701 var n_kwdo
: TKwdo is writable, noinit
1703 # The list of statements of the `do`.
1704 var n_block
: nullable AExpr = null is writable
1712 var n_kwif
: TKwif is writable, noinit
1714 # The expression used as the condition of the `if`
1715 var n_expr
: AExpr is writable, noinit
1717 # The body of the `then` part
1718 var n_then
: nullable AExpr = null is writable
1720 # The body of the `else` part
1721 var n_else
: nullable AExpr = null is writable
1724 # A `if` expression (ternary conditional). eg. `if true then 1 else 0`
1729 var n_kwif
: TKwif is writable, noinit
1731 # The expression used as the condition of the `if`
1732 var n_expr
: AExpr is writable, noinit
1734 # The `then` keyword
1735 var n_kwthen
: TKwthen is writable, noinit
1737 # The expression in the `then` part
1738 var n_then
: AExpr is writable, noinit
1740 # The `else` keyword
1741 var n_kwelse
: TKwelse is writable, noinit
1743 # The expression in the `else` part
1744 var n_else
: AExpr is writable, noinit
1747 # A `while` statement
1752 # The `while` keyword
1753 var n_kwwhile
: TKwwhile is writable, noinit
1755 # The expression used as the condition of the `while`
1756 var n_expr
: AExpr is writable, noinit
1759 var n_kwdo
: TKwdo is writable, noinit
1761 # The body of the loop
1762 var n_block
: nullable AExpr = null is writable
1765 # A `loop` statement
1770 # The `loop` keyword
1771 var n_kwloop
: TKwloop is writable, noinit
1773 # The body of the loop
1774 var n_block
: nullable AExpr = null is writable
1783 var n_kwfor
: TKwfor is writable, noinit
1785 # The list of name of the automatic variables
1786 var n_ids
= new ANodes[TId](self)
1788 # The expression used as the collection to iterate on
1789 var n_expr
: AExpr is writable, noinit
1792 var n_kwdo
: TKwdo is writable, noinit
1794 # The body of the loop
1795 var n_block
: nullable AExpr = null is writable
1798 # An `assert` statement
1802 # The `assert` keyword
1803 var n_kwassert
: TKwassert is writable, noinit
1805 # The name of the assert, if any
1806 var n_id
: nullable TId = null is writable
1808 # The expression used as the condition of the `assert`
1809 var n_expr
: AExpr is writable, noinit
1811 # The body to execute when the assert fails
1812 var n_else
: nullable AExpr = null is writable
1815 # Whatever is a simple assignment. eg `= something`
1816 abstract class AAssignFormExpr
1820 var n_assign
: TAssign is writable, noinit
1822 # The right-value to assign.
1823 var n_value
: AExpr is writable, noinit
1826 # Whatever is a combined assignment. eg `+= something`
1827 abstract class AReassignFormExpr
1830 # The combined operator (eg. `+=`)
1831 var n_assign_op
: AAssignOp is writable, noinit
1833 # The right-value to apply on the combined operator.
1834 var n_value
: AExpr is writable, noinit
1837 # A `once` expression. eg `once x`
1841 # The `once` keyword
1842 var n_kwonce
: TKwonce is writable, noinit
1844 # The expression to evaluate only one time
1845 var n_expr
: AExpr is writable, noinit
1848 # A polymorphic invocation of a method
1849 # The form of the invocation (name, arguments, etc.) are specific
1850 abstract class ASendExpr
1852 # The receiver of the method invocation
1853 var n_expr
: AExpr is writable, noinit
1856 # A binary operation on a method
1857 abstract class ABinopExpr
1859 # The second operand of the operation
1860 # Note: the receiver (`n_expr`) is the first operand
1861 var n_expr2
: AExpr is writable, noinit
1864 # Something that is boolean expression
1865 abstract class ABoolExpr
1869 # Something that is binary boolean expression
1870 abstract class ABinBoolExpr
1873 # The first boolean operand
1874 var n_expr
: AExpr is writable, noinit
1876 # The second boolean operand
1877 var n_expr2
: AExpr is writable, noinit
1885 # A `and` expression
1890 # A `or else` expression
1895 # A `implies` expression
1900 # A `not` expression
1905 var n_kwnot
: TKwnot is writable, noinit
1907 # The boolean operand of the `not`
1908 var n_expr
: AExpr is writable, noinit
1951 # A type-ckeck expression. eg `x isa T`
1955 # The expression to check
1956 var n_expr
: AExpr is writable, noinit
1958 # The destination type to check to
1959 var n_type
: AType is writable, noinit
1972 # A `<=>` expression
1997 # A unary minus expression. eg `-x`
2002 var n_minus
: TMinus is writable, noinit
2005 # An explicit instantiation. eg `new T`
2010 var n_kwnew
: TKwnew is writable, noinit
2012 # The `type` keyword
2013 var n_type
: AType is writable, noinit
2015 # The name of the named-constructor, if any
2016 var n_id
: nullable TId = null is writable
2018 # The arguments of the `new`
2019 var n_args
: AExprs is writable, noinit
2022 # Whatever is a old-style attribute access
2023 abstract class AAttrFormExpr
2026 # The receiver of the attribute
2027 var n_expr
: AExpr is writable, noinit
2029 # The name of the attribute
2030 var n_id
: TAttrid is writable, noinit
2034 # The read of an attribute. eg `x._a`
2039 # The assignment of an attribute. eg `x._a=y`
2040 class AAttrAssignExpr
2042 super AAssignFormExpr
2045 # Whatever looks-like a call with a standard method and any number of arguments.
2046 abstract class ACallFormExpr
2049 # The name of the method
2050 var n_id
: TId is writable, noinit
2052 # The arguments of the call
2053 var n_args
: AExprs is writable, noinit
2056 # A complex setter call (standard or brackets)
2057 abstract class ASendReassignFormExpr
2059 super AReassignFormExpr
2062 # A complex attribute assignment. eg `x._a+=y`
2063 class AAttrReassignExpr
2065 super AReassignFormExpr
2068 # A call with a standard method-name and any number of arguments. eg `x.m(y)`. OR just a simple id
2069 # 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`.
2070 # Semantic analysis have to transform them to instance of `AVarExpr`.
2075 # A setter call with a standard method-name and any number of arguments. eg `x.m(y)=z`. OR just a simple assignment.
2076 # 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`.
2077 # Semantic analysis have to transform them to instance of `AVarAssignExpr`.
2078 class ACallAssignExpr
2080 super AAssignFormExpr
2083 # 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.
2084 # 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`.
2085 # Semantic analysis have to transform them to instance of `AVarReassignExpr`.
2086 class ACallReassignExpr
2088 super ASendReassignFormExpr
2091 # A call to `super`. OR a call of a super-constructor
2095 # The qualifier part before the super (currenlty unused)
2096 var n_qualified
: nullable AQualified = null is writable
2098 # The `super` keyword
2099 var n_kwsuper
: TKwsuper is writable, noinit
2101 # The arguments of the super
2102 var n_args
: AExprs is writable, noinit
2105 # A call to the `init` constructor.
2106 # Note: because `init` is a keyword and not a `TId`, the explicit call to init cannot be a `ACallFormExpr`.
2110 # The `init` keyword
2111 var n_kwinit
: TKwinit is writable, noinit
2113 # The arguments of the init
2114 var n_args
: AExprs is writable, noinit
2117 # Whatever looks-like a call of the brackets `[]` operator.
2118 abstract class ABraFormExpr
2121 # The arguments inside the brackets
2122 var n_args
: AExprs is writable, noinit
2125 # A call of the brackets operator. eg `x[y,z]`
2130 # A setter call of the bracket operator. eg `x[y,z]=t`
2131 class ABraAssignExpr
2133 super AAssignFormExpr
2136 # Whatever is an access to a local variable
2137 abstract class AVarFormExpr
2140 # The name of the attribute
2141 var n_id
: TId is writable, noinit
2144 # A complex setter call of the bracket operator. eg `x[y,z]+=t`
2145 class ABraReassignExpr
2147 super ASendReassignFormExpr
2150 # A local variable read access.
2151 # The parser cannot instantiate them, see `ACallExpr`.
2156 # A local variable simple assignment access
2157 # The parser cannot instantiate them, see `ACallAssignExpr`.
2158 class AVarAssignExpr
2160 super AAssignFormExpr
2163 # A local variable complex assignment access
2164 # The parser cannot instantiate them, see `ACallReassignExpr`.
2165 class AVarReassignExpr
2167 super AReassignFormExpr
2170 # A literal range, open or closed
2171 abstract class ARangeExpr
2174 # The left (lower) element of the range
2175 var n_expr
: AExpr is writable, noinit
2177 # The right (uppr) element of the range
2178 var n_expr2
: AExpr is writable, noinit
2181 # A closed literal range. eg `[x..y]`
2185 # The opening bracket `[`
2186 var n_obra
: TObra is writable, noinit
2188 # The closing bracket `]`
2189 var n_cbra
: TCbra is writable, noinit
2192 # An open literal range. eg `[x..y[`
2196 # The opening bracket `[`
2197 var n_obra
: TObra is writable, noinit
2199 # The closing bracket `[` (because open range)
2200 var n_cbra
: TObra is writable, noinit
2203 # A literal array. eg. `[x,y,z]`
2207 # The opening bracket `[`
2208 var n_obra
: TObra is writable, noinit
2210 # The elements of the array
2211 var n_exprs
= new ANodes[AExpr](self)
2213 # The type of the element of the array (if any)
2214 var n_type
: nullable AType = null is writable
2216 # The closing bracket `]`
2217 var n_cbra
: TCbra is writable, noinit
2224 # The `self` keyword
2225 var n_kwself
: nullable TKwself is writable
2228 # When there is no explicit receiver, `self` is implicit
2229 class AImplicitSelfExpr
2233 # A `true` boolean literal constant
2237 # The `true` keyword
2238 var n_kwtrue
: TKwtrue is writable, noinit
2241 # A `false` boolean literal constant
2245 # The `false` keyword
2246 var n_kwfalse
: TKwfalse is writable, noinit
2249 # A `null` literal constant
2253 # The `null` keyword
2254 var n_kwnull
: TKwnull is writable, noinit
2257 # An integer literal
2262 # An integer literal in decimal format
2267 var n_number
: TNumber is writable, noinit
2270 # An integer literal in hexadecimal format
2274 # The hexadecimal token
2275 var n_hex_number
: THexNumber is writable, noinit
2283 var n_float
: TFloat is writable, noinit
2286 # A character literal
2290 # The character token
2291 var n_char
: TChar is writable, noinit
2295 abstract class AStringFormExpr
2299 var n_string
: Token is writable, noinit
2302 # A simple string. eg. `"abc"`
2304 super AStringFormExpr
2307 # The start of a superstring. eg `"abc{`
2308 class AStartStringExpr
2309 super AStringFormExpr
2312 # The middle of a superstring. eg `}abc{`
2313 class AMidStringExpr
2314 super AStringFormExpr
2317 # The end of a superstrng. eg `}abc"`
2318 class AEndStringExpr
2319 super AStringFormExpr
2322 # A superstring literal. eg `"a{x}b{y}c"`
2323 # Each part is modeled a sequence of expression. eg. `["a{, x, }b{, y, }c"]`
2324 class ASuperstringExpr
2327 # The list of the expressions of the superstring
2328 var n_exprs
= new ANodes[AExpr](self)
2331 # A simple parenthesis. eg `(x)`
2335 # The opening parenthesis
2336 var n_opar
: TOpar is writable, noinit
2338 # The inner expression
2339 var n_expr
: AExpr is writable, noinit
2341 # The closing parenthesis
2342 var n_cpar
: TCpar is writable, noinit
2345 # A cast, against a type or `not null`
2349 # The expression to cast
2350 var n_expr
: AExpr is writable, noinit
2353 var n_kwas
: TKwas is writable, noinit
2355 # The opening parenthesis
2356 var n_opar
: nullable TOpar = null is writable
2358 # The closing parenthesis
2359 var n_cpar
: nullable TCpar = null is writable
2362 # A type cast. eg `x.as(T)`
2366 # The target type to cast to
2367 var n_type
: AType is writable, noinit
2370 # A as-not-null cast. eg `x.as(not null)`
2371 class AAsNotnullExpr
2375 var n_kwnot
: TKwnot is writable, noinit
2377 # The `null` keyword
2378 var n_kwnull
: TKwnull is writable, noinit
2381 # A is-set check of old-style attributes. eg `isset x._a`
2382 class AIssetAttrExpr
2385 # The `isset` keyword
2386 var n_kwisset
: TKwisset is writable, noinit
2389 # An ellipsis notation used to pass an expression as it, in a vararg parameter
2393 # The passed expression
2394 var n_expr
: AExpr is writable, noinit
2397 var n_dotdotdot
: TDotdotdot is writable, noinit
2400 # A list of expression separated with commas (arguments for instance)
2404 # The list of expressions
2405 var n_exprs
= new ANodes[AExpr](self)
2408 # A special expression that encapsulates a static type
2409 # Can only be found in special construction like arguments of annotations.
2413 # The encapsulated type
2414 var n_type
: AType is writable, noinit
2417 # A special expression that encapsulates a method identifier
2418 # Can only be found in special construction like arguments of annotations.
2423 var n_expr
: AExpr is writable, noinit
2425 # The encapsulated method identifier
2426 var n_id
: AMethid is writable, noinit
2429 # A special expression that encapsulate an annotation
2430 # Can only be found in special construction like arguments of annotations.
2432 # The encapsulated annotations are in `n_annotations`
2437 # A special expression to debug types
2438 class ADebugTypeExpr
2441 # The `debug` keyword
2442 var n_kwdebug
: TKwdebug is writable, noinit
2444 # The `type` keyword
2445 var n_kwtype
: TKwtype is writable, noinit
2447 # The expression to check
2448 var n_expr
: AExpr is writable, noinit
2451 var n_type
: AType is writable, noinit
2454 # A list of expression separated with commas (arguments for instance)
2455 abstract class AExprs
2458 # The list of expressions
2459 var n_exprs
= new ANodes[AExpr](self)
2462 # A simple list of expressions
2467 # A list of expressions enclosed in parentheses
2471 # The opening parenthesis
2472 var n_opar
: TOpar is writable, noinit
2474 # The closing parenthesis
2475 var n_cpar
: TCpar is writable, noinit
2478 # A list of expressions enclosed in brackets
2482 # The opening bracket
2483 var n_obra
: TObra is writable, noinit
2485 # The closing bracket
2486 var n_cbra
: TCbra is writable, noinit
2489 # A complex assignment operator. (`+=` and `-=`)
2490 abstract class AAssignOp
2494 # The `+=` assignment operation
2499 var n_pluseq
: TPluseq is writable, noinit
2502 # The `-=` assignment operator
2503 class AMinusAssignOp
2507 var n_minuseq
: TMinuseq is writable, noinit
2510 # A possibly fully-qualified module identifier
2514 # The starting quad (`::`)
2515 var n_quad
: nullable TQuad = null is writable
2517 # The list of quad-separated project/group identifiers
2518 var n_path
= new ANodes[TId](self)
2520 # The final module identifier
2521 var n_id
: TId is writable, noinit
2524 # A language declaration for an extern block
2529 var n_kwin
: TKwin is writable, noinit
2532 var n_string
: TString is writable, noinit
2535 # An full extern block
2536 class AExternCodeBlock
2539 # The language declration
2540 var n_in_language
: nullable AInLanguage = null is writable
2542 # The block of extern code
2543 var n_extern_code_segment
: TExternCodeSegment is writable, noinit
2546 # A possible full method qualifier.
2550 # The starting quad (`::`)
2551 var n_quad
: nullable TQuad = null is writable
2553 # The list of quad-separated project/group/module identifiers
2554 var n_id
= new ANodes[TId](self)
2556 # A class identifier
2557 var n_classid
: nullable TClassid = null is writable
2560 # A documentation of a definition
2561 # It contains the block of comments just above the declaration
2565 # A list of lines of comment
2566 var n_comment
= new ANodes[TComment](self)
2569 # A group of annotation on a node
2571 # This same class is used for the 3 kind of annotations:
2573 # * *is* annotations. eg `module foo is bar`.
2574 # * *at* annotations. eg `foo@bar` or `foo@(bar,baz)`.
2575 # * *class* annotations, defined in classes.
2579 # The `@` symbol, for *at* annotations
2580 var n_at
: nullable TAt = null is writable
2582 # The opening parenthesis in *at* annotations
2583 var n_opar
: nullable TOpar = null is writable
2585 # The list of annotations
2586 var n_items
= new ANodes[AAnnotation](self)
2588 # The closing parenthesis in *at* annotations
2589 var n_cpar
: nullable TCpar = null is writable
2592 # A single annotation
2596 # The name of the annotation
2597 var n_atid
: AAtid is writable, noinit
2599 # The opening parenthesis of the arguments
2600 var n_opar
: nullable TOpar = null is writable
2602 # The list of arguments
2603 var n_args
= new ANodes[AExpr](self)
2605 # The closing parenthesis
2606 var n_cpar
: nullable TCpar = null is writable
2608 # The name of the annotation
2611 return n_atid
.n_id
.text
2615 # An annotation name
2616 abstract class AAtid
2619 # The identifier of the annotation.
2620 # Can be a TId of a keyword
2621 var n_id
: Token is writable, noinit
2624 # An annotation name based on an identifier
2629 # An annotation name based on the keyword `extern`
2634 # An annotation name based on the keyword `import`
2639 # An annotation name based on the keyword `abstract`
2640 class AKwabstractAtid
2644 # The root of the AST
2649 var n_base
: nullable AModule is writable
2651 # The end of file (or error) token
2652 var n_eof
: EOF is writable