1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # AST nodes of the Nit language
16 # Was previously based on parser_abs.nit.
21 # Root of the AST class-hierarchy
23 # Location is set during AST building. Once built, location cannon be null.
24 # However, manual instantiated nodes may need more care.
25 var location
: Location is writable, noinit
27 # The location of the important part of the node (identifier or whatever)
28 fun hot_location
: Location do return location
30 # Display a message for the colored location of the node
31 fun debug
(message
: String)
33 sys
.stderr
.write
"{hot_location} {self.class_name}: {message}\n{hot_location.colored_line("0;32")}\n"
36 # Parent of the node in the AST
37 var parent
: nullable ANode = null
39 # The topmost ancestor of the element
40 # This just apply `parent` until the first one
46 if p
== null then return res
51 # The most specific common parent between `self` and `other`
52 # Return null if the two node are unrelated (distinct root)
53 fun common_parent
(other
: ANode): nullable ANode
55 # First, get the same depth
56 var s
: nullable ANode = self
57 var o
: nullable ANode = other
58 var d
= s
.depth
- o
.depth
67 assert o
.depth
== s
.depth
68 # Second, go up until same in found
76 # Number of nodes between `self` and the `root` of the AST
77 # ENSURE `self == self.root implies result == 0 `
78 # ENSURE `self != self.root implies result == self.parent.depth + 1`
85 if p
== null then return res
91 # Replace a child with an other node in the AST
92 private fun replace_child
(old_child
: ANode, new_child
: nullable ANode) is abstract
94 # Detach a node from its parent
95 # Aborts if the node is not detachable. use `replace_with` instead
96 # REQUIRE: parent != null
97 # REQUIRE: is_detachable
98 # ENDURE: parent == null
101 assert parent
!= null
102 parent
.replace_child
(self, null)
106 # Replace itself with an other node in the AST
107 # REQUIRE: parent != null
108 # ENSURE: node.parent == old(parent)
109 # ENSURE: parent == null
110 fun replace_with
(node
: ANode)
112 assert parent
!= null
113 parent
.replace_child
(self, node
)
117 # Visit all nodes in order.
118 # Thus, call `v.enter_visit(e)` for each child `e`
119 fun visit_all
(v
: Visitor) is abstract
121 # Do a deep search and return an array of tokens that match a given text
122 fun collect_tokens_by_text
(text
: String): Array[Token]
124 var v
= new CollectTokensByTextVisitor(text
)
129 # Do a deep search and return an array of node that are annotated
130 # The attached node can be retrieved by two invocations of parent
131 fun collect_annotations_by_name
(name
: String): Array[AAnnotation]
133 var v
= new CollectAnnotationsByNameVisitor(name
)
139 private class CollectTokensByTextVisitor
142 var result
= new Array[Token]
143 redef fun visit
(node
)
146 if node
isa Token and node
.text
== text
then result
.add
(node
)
150 private class CollectAnnotationsByNameVisitor
153 var result
= new Array[AAnnotation]
154 redef fun visit
(node
)
157 if node
isa AAnnotation and node
.n_atid
.n_id
.text
== name
then result
.add
(node
)
162 # A sequence of nodes
163 # It is a specific class (instead of using a Array) to track the parent/child relation when nodes are added or removed
164 class ANodes[E
: ANode]
166 private var parent
: ANode
167 private var items
= new Array[E
]
168 redef fun iterator
do return items
.iterator
169 redef fun length
do return items
.length
170 redef fun is_empty
do return items
.is_empty
189 var res
= items
.shift
201 redef fun []=(index
, e
)
203 hook_remove
(self[index
])
207 redef fun remove_at
(index
)
209 hook_remove
(items
[index
])
210 items
.remove_at
(index
)
212 private fun hook_add
(e
: E
)
214 #assert e.parent == null
217 private fun hook_remove
(e
: E
)
219 assert e
.parent
== parent
223 # Used in parent constructor to fill elements
224 private fun unsafe_add_all
(nodes
: Collection[Object])
226 var parent
= self.parent
234 private fun replace_child
(old_child
: ANode, new_child
: nullable ANode): Bool
236 var parent
= self.parent
237 for i
in [0..length
[ do
238 if self[i
] == old_child
then
239 if new_child
!= null then
240 assert new_child
isa E
242 new_child
.parent
= parent
252 private fun visit_all
(v
: Visitor)
254 for n
in self do v
.enter_visit
(n
)
258 # Ancestor of all tokens
259 # A token is a node that has a `text` but no children.
263 # The raw content on the token
264 fun text
: String is abstract
266 # The raw content on the token
267 fun text
=(text
: String) is abstract
269 # The previous token in the Lexer.
270 # May have disappeared in the AST
271 var prev_token
: nullable Token = null
273 # The next token in the Lexer.
274 # May have disappeared in the AST
275 var next_token
: nullable Token = null
277 # The verbatim blank text between `prev_token` and `self`
278 fun blank_before
: String
280 if prev_token
== null then return ""
281 var from
= prev_token
.location
.pend
+1
282 var to
= location
.pstart
283 return location
.file
.string
.substring
(from
,to-from
)
286 redef fun to_s
: String do
290 redef fun visit_all
(v
: Visitor) do end
291 redef fun replace_child
(old_child
: ANode, new_child
: nullable ANode) do end
294 redef class SourceFile
295 # The first token parser by the lexer
296 # May have disappeared in the final AST
297 var first_token
: nullable Token = null
299 # The first token parser by the lexer
300 # May have disappeared in the final AST
301 var last_token
: nullable Token = null
304 # Ancestor of all productions
305 # A production is a node without text but that usually has children.
309 # All the annotations attached directly to the node
310 var n_annotations
: nullable AAnnotations = null is writable
312 # Return all its annotations of a given name in the order of their declaration
313 # Retun an empty array if no such an annotation.
314 fun get_annotations
(name
: String): Array[AAnnotation]
316 var res
= new Array[AAnnotation]
317 var nas
= n_annotations
318 if nas
!= null then for na
in nas
.n_items
do
319 if na
.name
!= name
then continue
322 if self isa AClassdef then for na
in n_propdefs
do
323 if na
isa AAnnotPropdef then
324 if na
.name
!= name
then continue
332 redef fun replace_with
(n
: ANode)
336 if not isset n
._location
and isset _location
then n
._location
= _location
340 # Abstract standard visitor on the AST
341 abstract class Visitor
342 # What the visitor do when a node is visited
343 # Concrete visitors should implement this method.
345 protected fun visit
(e
: ANode) is abstract
347 # Ask the visitor to visit a given node.
348 # Usually automatically called by visit_all* methods.
349 # This method should not be redefined
350 fun enter_visit
(e
: nullable ANode)
352 if e
== null then return
353 var old
= _current_node
359 # The current visited node
360 var current_node
: nullable ANode = null is writable
363 # Token of end of line (basically `\n`)
372 # Token of a line of comments
373 # Starts with the `#` and contains the final end-of-line (if any)
378 # A token associated with a keyword
379 abstract class TokenKeyword
383 return "keyword '{text}'"
387 # The deprecated keyword `package`.
392 # The keyword `module`
397 # The keyword `import`
402 # The keyword `class`
407 # The keyword `abstract`
412 # The keyword `interface`
417 # The keywords `enum` ane `universal`
442 # The keyword `redef`
462 # The keyword `extern`
467 # The keyword `public`
472 # The keyword `protected`
477 # The keyword `private`
482 # The keyword `intrude`
502 # The keyword `while`
532 # The keyword `implies`
542 # The keyword `return`
547 # The keyword `continue`
552 # The keyword `break`
557 # The keyword `abort`
562 # The keyword `assert`
582 # The keyword `super`
597 # The keyword `false`
612 # The keyword `nullable`
617 # The keyword `isset`
622 # The keyword `label`
627 # The special keyword `__DEBUG__`
672 # A token associated with an operator (and other lookalike symbols)
673 abstract class TokenOperator
677 return "operator '{text}'"
791 # A class (or formal type) identifier. They start with an uppercase.
796 do return "type identifier '{text}'"
800 # A standard identifier (variable, method...). They start with a lowercase.
805 do return "identifier '{text}'"
809 # An attribute identifier. They start with an underscore.
814 do return "attribute '{text}'"
818 # A token of a literal value (string, integer, etc).
819 abstract class TokenLiteral
823 do return "literal value '{text}'"
827 # A literal decimal integer
832 # A literal hexadecimal integer
837 # A literal floating point number
842 # A literal character
852 # The starting part of a super string (between `"` and `{`)
857 # The middle part of a super string (between `}` and `{`)
862 # The final part of a super string (between `}` and `"`)
872 do return "malformed string {text}"
881 do return "malformed character {text}"
885 # A extern code block
886 class TExternCodeSegment
903 # A lexical error (unexpected character)
907 # A syntactic error (unexpected token)
912 # The main node of a Nit source-file
916 # The declaration part of the module
917 var n_moduledecl
: nullable AModuledecl = null is writable
919 # List of importation clauses
920 var n_imports
= new ANodes[AImport](self)
922 # List of extern blocks
923 var n_extern_code_blocks
= new ANodes[AExternCodeBlock](self)
925 # List of class definition (including top-level methods and the main)
926 var n_classdefs
= new ANodes[AClassdef](self)
929 # Abstract class for definition of entities
930 abstract class ADefinition
933 var n_doc
: nullable ADoc = null is writable
935 # The `redef` keyword
936 var n_kwredef
: nullable TKwredef = null is writable
938 # The declared visibility
939 var n_visibility
: nullable AVisibility = null is writable
942 # The declaration of the module with the documentation, name, and annotations
946 # The `module` keyword
947 var n_kwmodule
: TKwmodule is writable, noinit
949 # The declared module name
950 var n_name
: AModuleName is writable, noinit
953 # A import clause of a module
954 abstract class AImport
957 # The declared visibility
958 var n_visibility
: AVisibility is writable, noinit
960 # The `import` keyword
961 var n_kwimport
: TKwimport is writable, noinit
964 # A standard import clause. eg `import x`
967 # The imported module name
968 var n_name
: AModuleName is writable, noinit
971 # The special import clause of the kernel module. eg `import end`
974 # The `end` keyword, that indicate the root module
975 var n_kwend
: TKwend is writable, noinit
978 # A visibility modifier
980 # The public visibility is an empty production (no keyword).
982 # Note: even if some visibilities are only valid on some placse (for instance, no `protected` class or no `intrude` method)
983 # the parser has no such a restriction, therefore the semantic phases has to check that the visibilities make sense.
984 abstract class AVisibility
988 # An implicit or explicit public visibility modifier
989 class APublicVisibility
991 # The `public` keyword, if any
992 var n_kwpublic
: nullable TKwpublic is writable
994 # An explicit private visibility modifier
995 class APrivateVisibility
997 # The `private` keyword
998 var n_kwprivate
: TKwprivate is writable, noinit
1000 # An explicit protected visibility modifier
1001 class AProtectedVisibility
1003 # The `protected` keyword
1004 var n_kwprotected
: TKwprotected is writable, noinit
1006 # An explicit intrude visibility modifier
1007 class AIntrudeVisibility
1009 # The `intrude` keyword
1010 var n_kwintrude
: TKwintrude is writable, noinit
1013 # A class definition
1014 # While most definition are `AStdClassdef`
1015 # There is tow special case of class definition
1016 abstract class AClassdef
1018 # All the declared properties (including the main method)
1019 var n_propdefs
= new ANodes[APropdef](self)
1022 # A standard class definition with a name, superclasses and properties
1027 # The class kind (interface, abstract class, etc.)
1028 var n_classkind
: AClasskind is writable, noinit
1030 # The name of the class
1031 var n_id
: nullable TClassid = null is writable
1033 # The list of formal parameter types
1034 var n_formaldefs
= new ANodes[AFormaldef](self)
1036 # The extern block code
1037 var n_extern_code_block
: nullable AExternCodeBlock = null is writable
1040 var n_kwend
: TKwend is writable, noinit
1042 fun n_superclasses
: Array[ASuperPropdef] do
1043 return [for d
in n_propdefs
do if d
isa ASuperPropdef then d
]
1046 redef fun hot_location
do return n_id
.location
1049 # The implicit class definition of the implicit main method
1054 # The implicit class definition of the top-level methods
1059 # The modifier for the kind of class (abstract, interface, etc.)
1060 abstract class AClasskind
1064 # A default, or concrete class modifier (just `class`)
1065 class AConcreteClasskind
1068 # The `class` keyword.
1069 var n_kwclass
: TKwclass is writable, noinit
1072 # An abstract class modifier (`abstract class`)
1073 class AAbstractClasskind
1076 # The `abstract` keyword.
1077 var n_kwabstract
: TKwabstract is writable, noinit
1079 # The `class` keyword.
1080 var n_kwclass
: TKwclass is writable, noinit
1083 # An interface class modifier (`interface`)
1084 class AInterfaceClasskind
1087 # The `interface` keyword.
1088 var n_kwinterface
: TKwinterface is writable, noinit
1091 # An enum/universal class modifier (`enum class`)
1092 class AEnumClasskind
1095 # The `enum` keyword.
1096 var n_kwenum
: TKwenum is writable, noinit
1099 # An extern class modifier (`extern class`)
1100 class AExternClasskind
1103 # The `extern` keyword.
1104 var n_kwextern
: TKwextern is writable, noinit
1106 # The `class` keyword.
1107 var n_kwclass
: nullable TKwclass = null is writable
1110 # The definition of a formal generic parameter type. eg `X: Y`
1114 # The name of the parameter type
1115 var n_id
: TClassid is writable, noinit
1117 # The bound of the parameter type
1118 var n_type
: nullable AType = null is writable
1121 # The definition of a property
1122 abstract class APropdef
1126 # A definition of an attribute
1127 # For historical reason, old-syle and new-style attributes use the same `ANode` sub-class
1131 # The identifier for a old-style attribute (null if new-style)
1132 var n_kwvar
: TKwvar is writable, noinit
1134 # The identifier for a new-style attribute (null if old-style)
1135 var n_id2
: TId is writable, noinit
1137 # The declared type of the attribute
1138 var n_type
: nullable AType = null is writable
1140 # The initial value, if any (set with `=`)
1141 var n_expr
: nullable AExpr = null is writable
1143 # The initial value, if any (set with `do return`)
1144 var n_block
: nullable AExpr = null is writable
1146 redef fun hot_location
1148 return n_id2
.location
1152 # A definition of all kind of method (including constructors)
1156 # The `fun` keyword, if any
1157 var n_kwmeth
: nullable TKwmeth = null is writable
1159 # The `init` keyword, if any
1160 var n_kwinit
: nullable TKwinit = null is writable
1162 # The `new` keyword, if any
1163 var n_kwnew
: nullable TKwnew = null is writable
1165 # The name of the method, if any
1166 var n_methid
: nullable AMethid = null is writable
1168 # The signature of the method, if any
1169 var n_signature
: nullable ASignature = null is writable
1171 # The body (in Nit) of the method, if any
1172 var n_block
: nullable AExpr = null is writable
1174 # The list of declared callbacks (for extern methods)
1175 var n_extern_calls
: nullable AExternCalls = null is writable
1177 # The body (in extern code) of the method, if any
1178 var n_extern_code_block
: nullable AExternCodeBlock = null is writable
1180 redef fun hot_location
1182 if n_methid
!= null then
1183 return n_methid
.location
1184 else if n_kwinit
!= null then
1185 return n_kwinit
.location
1186 else if n_kwnew
!= null then
1187 return n_kwnew
.location
1194 # The implicit main method
1195 class AMainMethPropdef
1204 # A super-class. eg `super X`
1209 var n_kwsuper
: TKwsuper is writable, noinit
1211 # The super-class (indicated as a type)
1212 var n_type
: AType is writable, noinit
1216 # Declaration of callbacks for extern methods
1220 # The `import` keyword
1221 var n_kwimport
: TKwimport is writable, noinit
1223 # The list of declared callbacks
1224 var n_extern_calls
: ANodes[AExternCall] = new ANodes[AExternCall](self)
1227 # A single callback declaration
1228 abstract class AExternCall
1232 # A single callback declaration on a method
1233 abstract class APropExternCall
1237 # A single callback declaration on a method on the current receiver
1238 class ALocalPropExternCall
1239 super APropExternCall
1241 # The name of the called-back method
1242 var n_methid
: AMethid is writable, noinit
1245 # A single callback declaration on a method on an explicit receiver type.
1246 class AFullPropExternCall
1247 super APropExternCall
1249 # The type of the receiver of the called-back method
1250 var n_type
: AType is writable, noinit
1253 var n_dot
: nullable TDot = null is writable
1255 # The name of the called-back method
1256 var n_methid
: AMethid is writable, noinit
1259 # A single callback declaration on a method on a constructor
1260 class AInitPropExternCall
1261 super APropExternCall
1263 # The allocated type
1264 var n_type
: AType is writable, noinit
1267 # A single callback declaration on a `super` call
1268 class ASuperExternCall
1271 # The `super` keyword
1272 var n_kwsuper
: TKwsuper is writable, noinit
1275 # A single callback declaration on a cast
1276 abstract class ACastExternCall
1280 # A single callback declaration on a cast to a given type
1281 class ACastAsExternCall
1282 super ACastExternCall
1284 # The origin type of the cast
1285 var n_from_type
: AType is writable, noinit
1288 var n_dot
: nullable TDot = null is writable
1291 var n_kwas
: TKwas is writable, noinit
1293 # The destination of the cast
1294 var n_to_type
: AType is writable, noinit
1297 # A single callback declaration on a cast to a nullable type
1298 class AAsNullableExternCall
1299 super ACastExternCall
1301 # The origin type to cast as nullable
1302 var n_type
: AType is writable, noinit
1305 var n_kwas
: TKwas is writable, noinit
1307 # The `nullable` keyword
1308 var n_kwnullable
: TKwnullable is writable, noinit
1311 # A single callback declaration on a cast to a non-nullable type
1312 class AAsNotNullableExternCall
1313 super ACastExternCall
1315 # The destination type on a cast to not nullable
1316 var n_type
: AType is writable, noinit
1319 var n_kwas
: TKwas is writable, noinit
1322 var n_kwnot
: TKwnot is writable, noinit
1324 # The `nullable` keyword
1325 var n_kwnullable
: TKwnullable is writable, noinit
1328 # A definition of a virtual type
1332 # The `type` keyword
1333 var n_kwtype
: TKwtype is writable, noinit
1335 # The name of the virtual type
1336 var n_id
: TClassid is writable, noinit
1338 # The bound of the virtual type
1339 var n_type
: AType is writable, noinit
1342 # The identifier of a method in a method declaration.
1343 # There is a specific class because of operator and setters.
1344 abstract class AMethid
1348 # A method name with a simple identifier
1352 # The simple identifier
1353 var n_id
: TId is writable, noinit
1361 var n_plus
: TPlus is writable, noinit
1369 var n_minus
: TMinus is writable, noinit
1377 var n_star
: TStar is writable, noinit
1380 # A method name `**`
1381 class AStarstarMethid
1385 var n_starstar
: TStarstar is writable, noinit
1393 var n_slash
: TSlash is writable, noinit
1397 class APercentMethid
1401 var n_percent
: TPercent is writable, noinit
1404 # A method name `==`
1409 var n_eq
: TEq is writable, noinit
1412 # A method name `!=`
1417 var n_ne
: TNe is writable, noinit
1420 # A method name `<=`
1425 var n_le
: TLe is writable, noinit
1428 # A method name `>=`
1433 var n_ge
: TGe is writable, noinit
1441 var n_lt
: TLt is writable, noinit
1449 var n_gt
: TGt is writable, noinit
1452 # A method name `<<`
1457 var n_ll
: TLl is writable, noinit
1460 # A method name `>>`
1465 var n_gg
: TGg is writable, noinit
1468 # A method name `[]`
1473 var n_obra
: TObra is writable, noinit
1476 var n_cbra
: TCbra is writable, noinit
1479 # A method name `<=>`
1480 class AStarshipMethid
1484 var n_starship
: TStarship is writable, noinit
1487 # A setter method name with a simple identifier (with a `=`)
1491 # The base identifier
1492 var n_id
: TId is writable, noinit
1495 var n_assign
: TAssign is writable, noinit
1498 # A method name `[]=`
1499 class ABraassignMethid
1503 var n_obra
: TObra is writable, noinit
1506 var n_cbra
: TCbra is writable, noinit
1509 var n_assign
: TAssign is writable, noinit
1512 # A signature in a method definition. eg `(x,y:X,z:Z):T`
1517 var n_opar
: nullable TOpar = null is writable
1519 # The list of parameters
1520 var n_params
= new ANodes[AParam](self)
1523 var n_cpar
: nullable TCpar = null is writable
1526 var n_type
: nullable AType = null is writable
1529 # A parameter definition in a signature. eg `x:X`
1533 # The name of the parameter
1534 var n_id
: TId is writable, noinit
1536 # The type of the parameter, if any
1537 var n_type
: nullable AType = null is writable
1539 # The `...` symbol to indicate varargs
1540 var n_dotdotdot
: nullable TDotdotdot = null is writable
1543 # A static type. eg `nullable X[Y]`
1546 # The `nullable` keyword
1547 var n_kwnullable
: nullable TKwnullable = null is writable
1549 # The name of the class or of the formal type
1550 var n_id
: TClassid is writable, noinit
1552 # Type arguments for a generic type
1553 var n_types
= new ANodes[AType](self)
1556 # A label at the end of a block or in a break/continue statement. eg `label x`
1560 # The `label` keyword
1561 var n_kwlabel
: TKwlabel is writable, noinit
1563 # The name of the label, if any
1564 var n_id
: nullable TId is writable
1567 # Expression and statements
1568 # From a AST point of view there is no distinction between statement and expressions (even if the parser has to distinguish them)
1569 abstract class AExpr
1573 # A sequence of `AExpr` (usually statements)
1574 # The last `AExpr` gives the value of the whole block
1578 # The list of statements in the bloc.
1579 # The last element is often considered as an expression that give the value of the whole block.
1580 var n_expr
= new ANodes[AExpr](self)
1583 var n_kwend
: nullable TKwend = null is writable
1586 # A declaration of a local variable. eg `var x: X = y`
1591 var n_kwvar
: TKwvar is writable, noinit
1593 # The name of the local variable
1594 var n_id
: TId is writable, noinit
1596 # The declaration type of the local variable
1597 var n_type
: nullable AType = null is writable
1599 # The `=` symbol (for the initial value)
1600 var n_assign
: nullable TAssign = null is writable
1602 # The initial value, if any
1603 var n_expr
: nullable AExpr = null is writable
1606 # A `return` statement. eg `return x`
1610 # The `return` keyword
1611 var n_kwreturn
: nullable TKwreturn = null is writable
1613 # The return value, if any
1614 var n_expr
: nullable AExpr = null is writable
1617 # Something that has a label.
1618 abstract class ALabelable
1621 # The associated label declatation
1622 var n_label
: nullable ALabel = null is writable
1625 # A `break` or a `continue`
1626 abstract class AEscapeExpr
1630 # The return value, if nay (unused currently)
1631 var n_expr
: nullable AExpr = null is writable
1634 # A `break` statement.
1638 # The `break` keyword
1639 var n_kwbreak
: TKwbreak is writable, noinit
1642 # An `abort` statement
1646 # The `abort` keyword
1647 var n_kwabort
: TKwabort is writable, noinit
1650 # A `continue` statement
1654 # The `continue` keyword.
1655 var n_kwcontinue
: nullable TKwcontinue = null is writable
1664 var n_kwdo
: TKwdo is writable, noinit
1666 # The list of statements of the `do`.
1667 var n_block
: nullable AExpr = null is writable
1675 var n_kwif
: TKwif is writable, noinit
1677 # The expression used as the condition of the `if`
1678 var n_expr
: AExpr is writable, noinit
1680 # The body of the `then` part
1681 var n_then
: nullable AExpr = null is writable
1683 # The body of the `else` part
1684 var n_else
: nullable AExpr = null is writable
1687 # A `if` expression (ternary conditional). eg. `if true then 1 else 0`
1692 var n_kwif
: TKwif is writable, noinit
1694 # The expression used as the condition of the `if`
1695 var n_expr
: AExpr is writable, noinit
1697 # The `then` keyword
1698 var n_kwthen
: TKwthen is writable, noinit
1700 # The expression in the `then` part
1701 var n_then
: AExpr is writable, noinit
1703 # The `else` keyword
1704 var n_kwelse
: TKwelse is writable, noinit
1706 # The expression in the `else` part
1707 var n_else
: AExpr is writable, noinit
1710 # A `while` statement
1715 # The `while` keyword
1716 var n_kwwhile
: TKwwhile is writable, noinit
1718 # The expression used as the condition of the `while`
1719 var n_expr
: AExpr is writable, noinit
1722 var n_kwdo
: TKwdo is writable, noinit
1724 # The body of the loop
1725 var n_block
: nullable AExpr = null is writable
1728 # A `loop` statement
1733 # The `loop` keyword
1734 var n_kwloop
: TKwloop is writable, noinit
1736 # The body of the loop
1737 var n_block
: nullable AExpr = null is writable
1746 var n_kwfor
: TKwfor is writable, noinit
1748 # The list of name of the automatic variables
1749 var n_ids
= new ANodes[TId](self)
1751 # The expression used as the collection to iterate on
1752 var n_expr
: AExpr is writable, noinit
1755 var n_kwdo
: TKwdo is writable, noinit
1757 # The body of the loop
1758 var n_block
: nullable AExpr = null is writable
1761 # An `assert` statement
1765 # The `assert` keyword
1766 var n_kwassert
: TKwassert is writable, noinit
1768 # The name of the assert, if any
1769 var n_id
: nullable TId = null is writable
1771 # The expression used as the condition of the `assert`
1772 var n_expr
: AExpr is writable, noinit
1774 # The body to execute when the assert fails
1775 var n_else
: nullable AExpr = null is writable
1778 # Whatever is a simple assignment. eg `= something`
1779 abstract class AAssignFormExpr
1783 var n_assign
: TAssign is writable, noinit
1785 # The right-value to assign.
1786 var n_value
: AExpr is writable, noinit
1789 # Whatever is a combined assignment. eg `+= something`
1790 abstract class AReassignFormExpr
1793 # The combined operator (eg. `+=`)
1794 var n_assign_op
: AAssignOp is writable, noinit
1796 # The right-value to apply on the combined operator.
1797 var n_value
: AExpr is writable, noinit
1800 # A `once` expression. eg `once x`
1804 # The `once` keyword
1805 var n_kwonce
: TKwonce is writable, noinit
1807 # The expression to evaluate only one time
1808 var n_expr
: AExpr is writable, noinit
1811 # A polymorphic invocation of a method
1812 # The form of the invocation (name, arguments, etc.) are specific
1813 abstract class ASendExpr
1815 # The receiver of the method invocation
1816 var n_expr
: AExpr is writable, noinit
1819 # A binary operation on a method
1820 abstract class ABinopExpr
1822 # The second operand of the operation
1823 # Note: the receiver (`n_expr`) is the first operand
1824 var n_expr2
: AExpr is writable, noinit
1827 # Something that is boolean expression
1828 abstract class ABoolExpr
1832 # Something that is binary boolean expression
1833 abstract class ABinBoolExpr
1836 # The first boolean operand
1837 var n_expr
: AExpr is writable, noinit
1839 # The second boolean operand
1840 var n_expr2
: AExpr is writable, noinit
1848 # A `and` expression
1853 # A `or else` expression
1858 # A `implies` expression
1863 # A `not` expression
1868 var n_kwnot
: TKwnot is writable, noinit
1870 # The boolean operand of the `not`
1871 var n_expr
: AExpr is writable, noinit
1914 # A type-ckeck expression. eg `x isa T`
1918 # The expression to check
1919 var n_expr
: AExpr is writable, noinit
1921 # The destination type to check to
1922 var n_type
: AType is writable, noinit
1935 # A `<=>` expression
1960 # A unary minus expression. eg `-x`
1965 var n_minus
: TMinus is writable, noinit
1968 # An explicit instantiation. eg `new T`
1973 var n_kwnew
: TKwnew is writable, noinit
1975 # The `type` keyword
1976 var n_type
: AType is writable, noinit
1978 # The name of the named-constructor, if any
1979 var n_id
: nullable TId = null is writable
1981 # The arguments of the `new`
1982 var n_args
: AExprs is writable, noinit
1985 # Whatever is a old-style attribute access
1986 abstract class AAttrFormExpr
1989 # The receiver of the attribute
1990 var n_expr
: AExpr is writable, noinit
1992 # The name of the attribute
1993 var n_id
: TAttrid is writable, noinit
1997 # The read of an attribute. eg `x._a`
2002 # The assignment of an attribute. eg `x._a=y`
2003 class AAttrAssignExpr
2005 super AAssignFormExpr
2008 # Whatever looks-like a call with a standard method and any number of arguments.
2009 abstract class ACallFormExpr
2012 # The name of the method
2013 var n_id
: TId is writable, noinit
2015 # The arguments of the call
2016 var n_args
: AExprs is writable, noinit
2019 # A complex setter call (standard or brackets)
2020 abstract class ASendReassignFormExpr
2022 super AReassignFormExpr
2025 # A complex attribute assignment. eg `x._a+=y`
2026 class AAttrReassignExpr
2028 super AReassignFormExpr
2031 # A call with a standard method-name and any number of arguments. eg `x.m(y)`. OR just a simple id
2032 # 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`.
2033 # Semantic analysis have to transform them to instance of `AVarExpr`.
2038 # A setter call with a standard method-name and any number of arguments. eg `x.m(y)=z`. OR just a simple assignment.
2039 # 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`.
2040 # Semantic analysis have to transform them to instance of `AVarAssignExpr`.
2041 class ACallAssignExpr
2043 super AAssignFormExpr
2046 # 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.
2047 # 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`.
2048 # Semantic analysis have to transform them to instance of `AVarReassignExpr`.
2049 class ACallReassignExpr
2051 super ASendReassignFormExpr
2054 # A call to `super`. OR a call of a super-constructor
2058 # The qualifier part before the super (currenlty unused)
2059 var n_qualified
: nullable AQualified = null is writable
2061 # The `super` keyword
2062 var n_kwsuper
: TKwsuper is writable, noinit
2064 # The arguments of the super
2065 var n_args
: AExprs is writable, noinit
2068 # A call to the `init` constructor.
2069 # Note: because `init` is a keyword and not a `TId`, the explicit call to init cannot be a `ACallFormExpr`.
2073 # The `init` keyword
2074 var n_kwinit
: TKwinit is writable, noinit
2076 # The arguments of the init
2077 var n_args
: AExprs is writable, noinit
2080 # Whatever looks-like a call of the brackets `[]` operator.
2081 abstract class ABraFormExpr
2084 # The arguments inside the brackets
2085 var n_args
: AExprs is writable, noinit
2088 # A call of the brackets operator. eg `x[y,z]`
2093 # A setter call of the bracket operator. eg `x[y,z]=t`
2094 class ABraAssignExpr
2096 super AAssignFormExpr
2099 # Whatever is an access to a local variable
2100 abstract class AVarFormExpr
2103 # The name of the attribute
2104 var n_id
: TId is writable, noinit
2107 # A complex setter call of the bracket operator. eg `x[y,z]+=t`
2108 class ABraReassignExpr
2110 super ASendReassignFormExpr
2113 # A local variable read access.
2114 # The parser cannot instantiate them, see `ACallExpr`.
2119 # A local variable simple assignment access
2120 # The parser cannot instantiate them, see `ACallAssignExpr`.
2121 class AVarAssignExpr
2123 super AAssignFormExpr
2126 # A local variable complex assignment access
2127 # The parser cannot instantiate them, see `ACallReassignExpr`.
2128 class AVarReassignExpr
2130 super AReassignFormExpr
2133 # A literal range, open or closed
2134 abstract class ARangeExpr
2137 # The left (lower) element of the range
2138 var n_expr
: AExpr is writable, noinit
2140 # The right (uppr) element of the range
2141 var n_expr2
: AExpr is writable, noinit
2144 # A closed literal range. eg `[x..y]`
2148 # The opening bracket `[`
2149 var n_obra
: TObra is writable, noinit
2151 # The closing bracket `]`
2152 var n_cbra
: TCbra is writable, noinit
2155 # An open literal range. eg `[x..y[`
2159 # The opening bracket `[`
2160 var n_obra
: TObra is writable, noinit
2162 # The closing bracket `[` (because open range)
2163 var n_cbra
: TObra is writable, noinit
2166 # A literal array. eg. `[x,y,z]`
2170 # The opening bracket `[`
2171 var n_obra
: TObra is writable, noinit
2173 # The elements of the array
2174 var n_exprs
= new ANodes[AExpr](self)
2176 # The type of the element of the array (if any)
2177 var n_type
: nullable AType = null is writable
2179 # The closing bracket `]`
2180 var n_cbra
: TCbra is writable, noinit
2187 # The `self` keyword
2188 var n_kwself
: nullable TKwself is writable
2191 # When there is no explicit receiver, `self` is implicit
2192 class AImplicitSelfExpr
2196 # A `true` boolean literal constant
2200 # The `true` keyword
2201 var n_kwtrue
: TKwtrue is writable, noinit
2204 # A `false` boolean literal constant
2208 # The `false` keyword
2209 var n_kwfalse
: TKwfalse is writable, noinit
2212 # A `null` literal constant
2216 # The `null` keyword
2217 var n_kwnull
: TKwnull is writable, noinit
2220 # An integer literal
2225 # An integer literal in decimal format
2230 var n_number
: TNumber is writable, noinit
2233 # An integer literal in hexadecimal format
2237 # The hexadecimal token
2238 var n_hex_number
: THexNumber is writable, noinit
2246 var n_float
: TFloat is writable, noinit
2249 # A character literal
2253 # The character token
2254 var n_char
: TChar is writable, noinit
2258 abstract class AStringFormExpr
2262 var n_string
: Token is writable, noinit
2265 # A simple string. eg. `"abc"`
2267 super AStringFormExpr
2270 # The start of a superstring. eg `"abc{`
2271 class AStartStringExpr
2272 super AStringFormExpr
2275 # The middle of a superstring. eg `}abc{`
2276 class AMidStringExpr
2277 super AStringFormExpr
2280 # The end of a superstrng. eg `}abc"`
2281 class AEndStringExpr
2282 super AStringFormExpr
2285 # A superstring literal. eg `"a{x}b{y}c"`
2286 # Each part is modeled a sequence of expression. eg. `["a{, x, }b{, y, }c"]`
2287 class ASuperstringExpr
2290 # The list of the expressions of the superstring
2291 var n_exprs
= new ANodes[AExpr](self)
2294 # A simple parenthesis. eg `(x)`
2298 # The opening parenthesis
2299 var n_opar
: TOpar is writable, noinit
2301 # The inner expression
2302 var n_expr
: AExpr is writable, noinit
2304 # The closing parenthesis
2305 var n_cpar
: TCpar is writable, noinit
2308 # A cast, against a type or `not null`
2312 # The expression to cast
2313 var n_expr
: AExpr is writable, noinit
2316 var n_kwas
: TKwas is writable, noinit
2318 # The opening parenthesis
2319 var n_opar
: nullable TOpar = null is writable
2321 # The closing parenthesis
2322 var n_cpar
: nullable TCpar = null is writable
2325 # A type cast. eg `x.as(T)`
2329 # The target type to cast to
2330 var n_type
: AType is writable, noinit
2333 # A as-not-null cast. eg `x.as(not null)`
2334 class AAsNotnullExpr
2338 var n_kwnot
: TKwnot is writable, noinit
2340 # The `null` keyword
2341 var n_kwnull
: TKwnull is writable, noinit
2344 # A is-set check of old-style attributes. eg `isset x._a`
2345 class AIssetAttrExpr
2348 # The `isset` keyword
2349 var n_kwisset
: TKwisset is writable, noinit
2352 # An ellipsis notation used to pass an expression as it, in a vararg parameter
2356 # The passed expression
2357 var n_expr
: AExpr is writable, noinit
2360 var n_dotdotdot
: TDotdotdot is writable, noinit
2363 # A list of expression separated with commas (arguments for instance)
2367 # The list of expressions
2368 var n_exprs
= new ANodes[AExpr](self)
2371 # A special expression that encapsulates a static type
2372 # Can only be found in special construction like arguments of annotations.
2376 # The encapsulated type
2377 var n_type
: AType is writable, noinit
2380 # A special expression that encapsulates a method identifier
2381 # Can only be found in special construction like arguments of annotations.
2386 var n_expr
: AExpr is writable, noinit
2388 # The encapsulated method identifier
2389 var n_id
: AMethid is writable, noinit
2392 # A special expression that encapsulate an annotation
2393 # Can only be found in special construction like arguments of annotations.
2395 # The encapsulated annotations are in `n_annotations`
2400 # A special expression to debug types
2401 class ADebugTypeExpr
2404 # The `debug` keyword
2405 var n_kwdebug
: TKwdebug is writable, noinit
2407 # The `type` keyword
2408 var n_kwtype
: TKwtype is writable, noinit
2410 # The expression to check
2411 var n_expr
: AExpr is writable, noinit
2414 var n_type
: AType is writable, noinit
2417 # A list of expression separated with commas (arguments for instance)
2418 abstract class AExprs
2421 # The list of expressions
2422 var n_exprs
= new ANodes[AExpr](self)
2425 # A simple list of expressions
2430 # A list of expressions enclosed in parentheses
2434 # The opening parenthesis
2435 var n_opar
: TOpar is writable, noinit
2437 # The closing parenthesis
2438 var n_cpar
: TCpar is writable, noinit
2441 # A list of expressions enclosed in brackets
2445 # The opening bracket
2446 var n_obra
: TObra is writable, noinit
2448 # The closing bracket
2449 var n_cbra
: TCbra is writable, noinit
2452 # A complex assignment operator. (`+=` and `-=`)
2453 abstract class AAssignOp
2457 # The `+=` assignment operation
2462 var n_pluseq
: TPluseq is writable, noinit
2465 # The `-=` assignment operator
2466 class AMinusAssignOp
2470 var n_minuseq
: TMinuseq is writable, noinit
2473 # A possibly fully-qualified module identifier
2477 # The starting quad (`::`)
2478 var n_quad
: nullable TQuad = null is writable
2480 # The list of quad-separated project/group identifiers
2481 var n_path
= new ANodes[TId](self)
2483 # The final module identifier
2484 var n_id
: TId is writable, noinit
2487 # A language declaration for an extern block
2492 var n_kwin
: TKwin is writable, noinit
2495 var n_string
: TString is writable, noinit
2498 # An full extern block
2499 class AExternCodeBlock
2502 # The language declration
2503 var n_in_language
: nullable AInLanguage = null is writable
2505 # The block of extern code
2506 var n_extern_code_segment
: TExternCodeSegment is writable, noinit
2509 # A possible full method qualifier.
2513 # The starting quad (`::`)
2514 var n_quad
: nullable TQuad = null is writable
2516 # The list of quad-separated project/group/module identifiers
2517 var n_id
= new ANodes[TId](self)
2519 # A class identifier
2520 var n_classid
: nullable TClassid = null is writable
2523 # A documentation of a definition
2524 # It contains the block of comments just above the declaration
2528 # A list of lines of comment
2529 var n_comment
= new ANodes[TComment](self)
2532 # A group of annotation on a node
2534 # This same class is used for the 3 kind of annotations:
2536 # * *is* annotations. eg `module foo is bar`.
2537 # * *at* annotations. eg `foo@bar` or `foo@(bar,baz)`.
2538 # * *class* annotations, defined in classes.
2542 # The `@` symbol, for *at* annotations
2543 var n_at
: nullable TAt = null is writable
2545 # The opening parenthesis in *at* annotations
2546 var n_opar
: nullable TOpar = null is writable
2548 # The list of annotations
2549 var n_items
= new ANodes[AAnnotation](self)
2551 # The closing parenthesis in *at* annotations
2552 var n_cpar
: nullable TCpar = null is writable
2555 # A single annotation
2559 # The name of the annotation
2560 var n_atid
: AAtid is writable, noinit
2562 # The opening parenthesis of the arguments
2563 var n_opar
: nullable TOpar = null is writable
2565 # The list of arguments
2566 var n_args
= new ANodes[AExpr](self)
2568 # The closing parenthesis
2569 var n_cpar
: nullable TCpar = null is writable
2571 # The name of the annotation
2574 return n_atid
.n_id
.text
2578 # An annotation name
2579 abstract class AAtid
2582 # The identifier of the annotation.
2583 # Can be a TId of a keyword
2584 var n_id
: Token is writable, noinit
2587 # An annotation name based on an identifier
2592 # An annotation name based on the keyword `extern`
2597 # An annotation name based on the keyword `import`
2602 # An annotation name based on the keyword `abstract`
2603 class AKwabstractAtid
2607 # The root of the AST
2612 var n_base
: nullable AModule is writable
2614 # The end of file (or error) token
2615 var n_eof
: EOF is writable