1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # AST nodes of the Nit language
16 # Was previously based on parser_abs.nit.
21 # Root of the AST class-hierarchy
23 # Location is set during AST building. Once built, location cannon be null.
24 # However, manual instantiated nodes may need more care.
25 var location
: Location is writable, noinit
27 # The location of the important part of the node (identifier or whatever)
28 fun hot_location
: Location do return location
30 # Display a message for the colored location of the node
31 fun debug
(message
: String)
33 sys
.stderr
.write
"{hot_location} {self.class_name}: {message}\n{hot_location.colored_line("0;32")}\n"
36 # Parent of the node in the AST
37 var parent
: nullable ANode = null
39 # The topmost ancestor of the element
40 # This just apply `parent` until the first one
46 if p
== null then return res
51 # The most specific common parent between `self` and `other`
52 # Return null if the two node are unrelated (distinct root)
53 fun common_parent
(other
: ANode): nullable ANode
55 # First, get the same depth
56 var s
: nullable ANode = self
57 var o
: nullable ANode = other
58 var d
= s
.depth
- o
.depth
67 assert o
.depth
== s
.depth
68 # Second, go up until same in found
76 # Number of nodes between `self` and the `root` of the AST
77 # ENSURE `self == self.root implies result == 0 `
78 # ENSURE `self != self.root implies result == self.parent.depth + 1`
85 if p
== null then return res
91 # Replace a child with an other node in the AST
92 private fun replace_child
(old_child
: ANode, new_child
: nullable ANode) is abstract
94 # Detach a node from its parent
95 # Aborts if the node is not detachable. use `replace_with` instead
96 # REQUIRE: parent != null
97 # REQUIRE: is_detachable
98 # ENDURE: parent == null
101 assert parent
!= null
102 parent
.replace_child
(self, null)
106 # Replace itself with an other node in the AST
107 # REQUIRE: parent != null
108 # ENSURE: node.parent == old(parent)
109 # ENSURE: parent == null
110 fun replace_with
(node
: ANode)
112 assert parent
!= null
113 parent
.replace_child
(self, node
)
117 # Visit all nodes in order.
118 # Thus, call `v.enter_visit(e)` for each child `e`
119 fun visit_all
(v
: Visitor) is abstract
121 # Do a deep search and return an array of tokens that match a given text
122 fun collect_tokens_by_text
(text
: String): Array[Token]
124 var v
= new CollectTokensByTextVisitor(text
)
129 # Do a deep search and return an array of node that are annotated
130 # The attached node can be retrieved by two invocations of parent
131 fun collect_annotations_by_name
(name
: String): Array[AAnnotation]
133 var v
= new CollectAnnotationsByNameVisitor(name
)
139 private class CollectTokensByTextVisitor
142 var result
= new Array[Token]
143 redef fun visit
(node
)
146 if node
isa Token and node
.text
== text
then result
.add
(node
)
150 private class CollectAnnotationsByNameVisitor
153 var result
= new Array[AAnnotation]
154 redef fun visit
(node
)
157 if node
isa AAnnotation and node
.n_atid
.n_id
.text
== name
then result
.add
(node
)
162 # A sequence of nodes
163 # It is a specific class (instead of using a Array) to track the parent/child relation when nodes are added or removed
164 class ANodes[E
: ANode]
166 private var parent
: ANode
167 private var items
= new Array[E
]
168 redef fun iterator
do return items
.iterator
169 redef fun length
do return items
.length
170 redef fun is_empty
do return items
.is_empty
189 var res
= items
.shift
201 redef fun []=(index
, e
)
203 hook_remove
(self[index
])
207 redef fun remove_at
(index
)
209 hook_remove
(items
[index
])
210 items
.remove_at
(index
)
212 private fun hook_add
(e
: E
)
214 #assert e.parent == null
217 private fun hook_remove
(e
: E
)
219 assert e
.parent
== parent
223 # Used in parent constructor to fill elements
224 private fun unsafe_add_all
(nodes
: Collection[Object])
226 var parent
= self.parent
234 private fun replace_child
(old_child
: ANode, new_child
: nullable ANode): Bool
236 var parent
= self.parent
237 for i
in [0..length
[ do
238 if self[i
] == old_child
then
239 if new_child
!= null then
240 assert new_child
isa E
242 new_child
.parent
= parent
252 private fun visit_all
(v
: Visitor)
254 for n
in self do v
.enter_visit
(n
)
258 # Ancestor of all tokens
259 # A token is a node that has a `text` but no children.
263 # The raw content on the token
264 fun text
: String is abstract
266 # The raw content on the token
267 fun text
=(text
: String) is abstract
269 # The previous token in the Lexer.
270 # May have disappeared in the AST
271 var prev_token
: nullable Token = null
273 # The next token in the Lexer.
274 # May have disappeared in the AST
275 var next_token
: nullable Token = null
277 # The verbatim blank text between `prev_token` and `self`
278 fun blank_before
: String
280 if prev_token
== null then return ""
281 var from
= prev_token
.location
.pend
+1
282 var to
= location
.pstart
283 return location
.file
.string
.substring
(from
,to-from
)
286 redef fun to_s
: String do
290 redef fun visit_all
(v
: Visitor) do end
291 redef fun replace_child
(old_child
: ANode, new_child
: nullable ANode) do end
294 redef class SourceFile
295 # The first token parser by the lexer
296 # May have disappeared in the final AST
297 var first_token
: nullable Token = null
299 # The first token parser by the lexer
300 # May have disappeared in the final AST
301 var last_token
: nullable Token = null
304 # Ancestor of all productions
305 # A production is a node without text but that usually has children.
309 # All the annotations attached directly to the node
310 var n_annotations
: nullable AAnnotations = null is writable
312 # Return all its annotations of a given name in the order of their declaration
313 # Retun an empty array if no such an annotation.
314 fun get_annotations
(name
: String): Array[AAnnotation]
316 var res
= new Array[AAnnotation]
317 var nas
= n_annotations
318 if nas
== null then return res
319 for na
in nas
.n_items
do
320 if na
.name
!= name
then continue
326 redef fun replace_with
(n
: ANode)
330 if not isset n
._location
and isset _location
then n
._location
= _location
334 # Abstract standard visitor on the AST
335 abstract class Visitor
336 # What the visitor do when a node is visited
337 # Concrete visitors should implement this method.
339 protected fun visit
(e
: ANode) is abstract
341 # Ask the visitor to visit a given node.
342 # Usually automatically called by visit_all* methods.
343 # This method should not be redefined
344 fun enter_visit
(e
: nullable ANode)
346 if e
== null then return
347 var old
= _current_node
353 # The current visited node
354 var current_node
: nullable ANode = null is writable
357 # Token of end of line (basically `\n`)
366 # Token of a line of comments
367 # Starts with the `#` and contains the final end-of-line (if any)
372 # A token associated with a keyword
373 abstract class TokenKeyword
377 return "keyword '{text}'"
381 # The deprecated keyword `package`.
386 # The keyword `module`
391 # The keyword `import`
396 # The keyword `class`
401 # The keyword `abstract`
406 # The keyword `interface`
411 # The keywords `enum` ane `universal`
436 # The keyword `redef`
456 # The keyword `extern`
461 # The keyword `public`
466 # The keyword `protected`
471 # The keyword `private`
476 # The keyword `intrude`
496 # The keyword `while`
526 # The keyword `implies`
536 # The keyword `return`
541 # The keyword `continue`
546 # The keyword `break`
551 # The keyword `abort`
556 # The keyword `assert`
576 # The keyword `super`
591 # The keyword `false`
606 # The keyword `nullable`
611 # The keyword `isset`
616 # The keyword `label`
621 # The special keyword `__DEBUG__`
666 # A token associated with an operator (and other lookalike symbols)
667 abstract class TokenOperator
671 return "operator '{text}'"
785 # A class (or formal type) identifier. They start with an uppercase.
790 do return "type identifier '{text}'"
794 # A standard identifier (variable, method...). They start with a lowercase.
799 do return "identifier '{text}'"
803 # An attribute identifier. They start with an underscore.
808 do return "attribute '{text}'"
812 # A token of a literal value (string, integer, etc).
813 abstract class TokenLiteral
817 do return "literal value '{text}'"
821 # A literal decimal integer
826 # A literal hexadecimal integer
831 # A literal floating point number
836 # A literal character
846 # The starting part of a super string (between `"` and `{`)
851 # The middle part of a super string (between `}` and `{`)
856 # The final part of a super string (between `}` and `"`)
866 do return "malformed string {text}"
875 do return "malformed character {text}"
879 # A extern code block
880 class TExternCodeSegment
897 # A lexical error (unexpected character)
901 # A syntactic error (unexpected token)
906 # The main node of a Nit source-file
910 # The declaration part of the module
911 var n_moduledecl
: nullable AModuledecl = null is writable
913 # List of importation clauses
914 var n_imports
= new ANodes[AImport](self)
916 # List of extern blocks
917 var n_extern_code_blocks
= new ANodes[AExternCodeBlock](self)
919 # List of class definition (including top-level methods and the main)
920 var n_classdefs
= new ANodes[AClassdef](self)
923 # Abstract class for definition of entities
924 abstract class ADefinition
927 var n_doc
: nullable ADoc = null is writable
929 # The `redef` keyword
930 var n_kwredef
: nullable TKwredef = null is writable
932 # The declared visibility
933 var n_visibility
: nullable AVisibility = null is writable
936 # The declaration of the module with the documentation, name, and annotations
940 # The `module` keyword
941 var n_kwmodule
: TKwmodule is writable, noinit
943 # The declared module name
944 var n_name
: AModuleName is writable, noinit
947 # A import clause of a module
948 abstract class AImport
951 # The declared visibility
952 var n_visibility
: AVisibility is writable, noinit
954 # The `import` keyword
955 var n_kwimport
: TKwimport is writable, noinit
958 # A standard import clause. eg `import x`
961 # The imported module name
962 var n_name
: AModuleName is writable, noinit
965 # The special import clause of the kernel module. eg `import end`
968 # The `end` keyword, that indicate the root module
969 var n_kwend
: TKwend is writable, noinit
972 # A visibility modifier
974 # The public visibility is an empty production (no keyword).
976 # Note: even if some visibilities are only valid on some placse (for instance, no `protected` class or no `intrude` method)
977 # the parser has no such a restriction, therefore the semantic phases has to check that the visibilities make sense.
978 abstract class AVisibility
982 # An implicit or explicit public visibility modifier
983 class APublicVisibility
985 # The `public` keyword, if any
986 var n_kwpublic
: nullable TKwpublic is writable
988 # An explicit private visibility modifier
989 class APrivateVisibility
991 # The `private` keyword
992 var n_kwprivate
: TKwprivate is writable, noinit
994 # An explicit protected visibility modifier
995 class AProtectedVisibility
997 # The `protected` keyword
998 var n_kwprotected
: TKwprotected is writable, noinit
1000 # An explicit intrude visibility modifier
1001 class AIntrudeVisibility
1003 # The `intrude` keyword
1004 var n_kwintrude
: TKwintrude is writable, noinit
1007 # A class definition
1008 # While most definition are `AStdClassdef`
1009 # There is tow special case of class definition
1010 abstract class AClassdef
1012 # All the declared properties (including the main method)
1013 var n_propdefs
= new ANodes[APropdef](self)
1016 # A standard class definition with a name, superclasses and properties
1021 # The class kind (interface, abstract class, etc.)
1022 var n_classkind
: AClasskind is writable, noinit
1024 # The name of the class
1025 var n_id
: nullable TClassid = null is writable
1027 # The list of formal parameter types
1028 var n_formaldefs
= new ANodes[AFormaldef](self)
1030 # The extern block code
1031 var n_extern_code_block
: nullable AExternCodeBlock = null is writable
1034 var n_kwend
: TKwend is writable, noinit
1036 fun n_superclasses
: Array[ASuperPropdef] do
1037 return [for d
in n_propdefs
do if d
isa ASuperPropdef then d
]
1040 redef fun hot_location
do return n_id
.location
1043 # The implicit class definition of the implicit main method
1048 # The implicit class definition of the top-level methods
1053 # The modifier for the kind of class (abstract, interface, etc.)
1054 abstract class AClasskind
1058 # A default, or concrete class modifier (just `class`)
1059 class AConcreteClasskind
1062 # The `class` keyword.
1063 var n_kwclass
: TKwclass is writable, noinit
1066 # An abstract class modifier (`abstract class`)
1067 class AAbstractClasskind
1070 # The `abstract` keyword.
1071 var n_kwabstract
: TKwabstract is writable, noinit
1073 # The `class` keyword.
1074 var n_kwclass
: TKwclass is writable, noinit
1077 # An interface class modifier (`interface`)
1078 class AInterfaceClasskind
1081 # The `interface` keyword.
1082 var n_kwinterface
: TKwinterface is writable, noinit
1085 # An enum/universal class modifier (`enum class`)
1086 class AEnumClasskind
1089 # The `enum` keyword.
1090 var n_kwenum
: TKwenum is writable, noinit
1093 # An extern class modifier (`extern class`)
1094 class AExternClasskind
1097 # The `extern` keyword.
1098 var n_kwextern
: TKwextern is writable, noinit
1100 # The `class` keyword.
1101 var n_kwclass
: nullable TKwclass = null is writable
1104 # The definition of a formal generic parameter type. eg `X: Y`
1108 # The name of the parameter type
1109 var n_id
: TClassid is writable, noinit
1111 # The bound of the parameter type
1112 var n_type
: nullable AType = null is writable
1115 # The definition of a property
1116 abstract class APropdef
1120 # A definition of an attribute
1121 # For historical reason, old-syle and new-style attributes use the same `ANode` sub-class
1125 # The identifier for a old-style attribute (null if new-style)
1126 var n_kwvar
: TKwvar is writable, noinit
1128 # The identifier for a new-style attribute (null if old-style)
1129 var n_id2
: TId is writable, noinit
1131 # The declared type of the attribute
1132 var n_type
: nullable AType = null is writable
1134 # The initial value, if any (set with `=`)
1135 var n_expr
: nullable AExpr = null is writable
1137 # The initial value, if any (set with `do return`)
1138 var n_block
: nullable AExpr = null is writable
1140 redef fun hot_location
1142 return n_id2
.location
1146 # A definition of all kind of method (including constructors)
1150 # The `fun` keyword, if any
1151 var n_kwmeth
: nullable TKwmeth = null is writable
1153 # The `init` keyword, if any
1154 var n_kwinit
: nullable TKwinit = null is writable
1156 # The `new` keyword, if any
1157 var n_kwnew
: nullable TKwnew = null is writable
1159 # The name of the method, if any
1160 var n_methid
: nullable AMethid = null is writable
1162 # The signature of the method, if any
1163 var n_signature
: nullable ASignature = null is writable
1165 # The body (in Nit) of the method, if any
1166 var n_block
: nullable AExpr = null is writable
1168 # The list of declared callbacks (for extern methods)
1169 var n_extern_calls
: nullable AExternCalls = null is writable
1171 # The body (in extern code) of the method, if any
1172 var n_extern_code_block
: nullable AExternCodeBlock = null is writable
1174 redef fun hot_location
1176 if n_methid
!= null then
1177 return n_methid
.location
1178 else if n_kwinit
!= null then
1179 return n_kwinit
.location
1180 else if n_kwnew
!= null then
1181 return n_kwnew
.location
1188 # The implicit main method
1189 class AMainMethPropdef
1193 # A super-class. eg `super X`
1198 var n_kwsuper
: TKwsuper is writable, noinit
1200 # The super-class (indicated as a type)
1201 var n_type
: AType is writable, noinit
1205 # Declaration of callbacks for extern methods
1209 # The `import` keyword
1210 var n_kwimport
: TKwimport is writable, noinit
1212 # The list of declared callbacks
1213 var n_extern_calls
: ANodes[AExternCall] = new ANodes[AExternCall](self)
1216 # A single callback declaration
1217 abstract class AExternCall
1221 # A single callback declaration on a method
1222 abstract class APropExternCall
1226 # A single callback declaration on a method on the current receiver
1227 class ALocalPropExternCall
1228 super APropExternCall
1230 # The name of the called-back method
1231 var n_methid
: AMethid is writable, noinit
1234 # A single callback declaration on a method on an explicit receiver type.
1235 class AFullPropExternCall
1236 super APropExternCall
1238 # The type of the receiver of the called-back method
1239 var n_type
: AType is writable, noinit
1242 var n_dot
: nullable TDot = null is writable
1244 # The name of the called-back method
1245 var n_methid
: AMethid is writable, noinit
1248 # A single callback declaration on a method on a constructor
1249 class AInitPropExternCall
1250 super APropExternCall
1252 # The allocated type
1253 var n_type
: AType is writable, noinit
1256 # A single callback declaration on a `super` call
1257 class ASuperExternCall
1260 # The `super` keyword
1261 var n_kwsuper
: TKwsuper is writable, noinit
1264 # A single callback declaration on a cast
1265 abstract class ACastExternCall
1269 # A single callback declaration on a cast to a given type
1270 class ACastAsExternCall
1271 super ACastExternCall
1273 # The origin type of the cast
1274 var n_from_type
: AType is writable, noinit
1277 var n_dot
: nullable TDot = null is writable
1280 var n_kwas
: TKwas is writable, noinit
1282 # The destination of the cast
1283 var n_to_type
: AType is writable, noinit
1286 # A single callback declaration on a cast to a nullable type
1287 class AAsNullableExternCall
1288 super ACastExternCall
1290 # The origin type to cast as nullable
1291 var n_type
: AType is writable, noinit
1294 var n_kwas
: TKwas is writable, noinit
1296 # The `nullable` keyword
1297 var n_kwnullable
: TKwnullable is writable, noinit
1300 # A single callback declaration on a cast to a non-nullable type
1301 class AAsNotNullableExternCall
1302 super ACastExternCall
1304 # The destination type on a cast to not nullable
1305 var n_type
: AType is writable, noinit
1308 var n_kwas
: TKwas is writable, noinit
1311 var n_kwnot
: TKwnot is writable, noinit
1313 # The `nullable` keyword
1314 var n_kwnullable
: TKwnullable is writable, noinit
1317 # A definition of a virtual type
1321 # The `type` keyword
1322 var n_kwtype
: TKwtype is writable, noinit
1324 # The name of the virtual type
1325 var n_id
: TClassid is writable, noinit
1327 # The bound of the virtual type
1328 var n_type
: AType is writable, noinit
1331 # The identifier of a method in a method declaration.
1332 # There is a specific class because of operator and setters.
1333 abstract class AMethid
1337 # A method name with a simple identifier
1341 # The simple identifier
1342 var n_id
: TId is writable, noinit
1350 var n_plus
: TPlus is writable, noinit
1358 var n_minus
: TMinus is writable, noinit
1366 var n_star
: TStar is writable, noinit
1369 # A method name `**`
1370 class AStarstarMethid
1374 var n_starstar
: TStarstar is writable, noinit
1382 var n_slash
: TSlash is writable, noinit
1386 class APercentMethid
1390 var n_percent
: TPercent is writable, noinit
1393 # A method name `==`
1398 var n_eq
: TEq is writable, noinit
1401 # A method name `!=`
1406 var n_ne
: TNe is writable, noinit
1409 # A method name `<=`
1414 var n_le
: TLe is writable, noinit
1417 # A method name `>=`
1422 var n_ge
: TGe is writable, noinit
1430 var n_lt
: TLt is writable, noinit
1438 var n_gt
: TGt is writable, noinit
1441 # A method name `<<`
1446 var n_ll
: TLl is writable, noinit
1449 # A method name `>>`
1454 var n_gg
: TGg is writable, noinit
1457 # A method name `[]`
1462 var n_obra
: TObra is writable, noinit
1465 var n_cbra
: TCbra is writable, noinit
1468 # A method name `<=>`
1469 class AStarshipMethid
1473 var n_starship
: TStarship is writable, noinit
1476 # A setter method name with a simple identifier (with a `=`)
1480 # The base identifier
1481 var n_id
: TId is writable, noinit
1484 var n_assign
: TAssign is writable, noinit
1487 # A method name `[]=`
1488 class ABraassignMethid
1492 var n_obra
: TObra is writable, noinit
1495 var n_cbra
: TCbra is writable, noinit
1498 var n_assign
: TAssign is writable, noinit
1501 # A signature in a method definition. eg `(x,y:X,z:Z):T`
1506 var n_opar
: nullable TOpar = null is writable
1508 # The list of parameters
1509 var n_params
= new ANodes[AParam](self)
1512 var n_cpar
: nullable TCpar = null is writable
1515 var n_type
: nullable AType = null is writable
1518 # A parameter definition in a signature. eg `x:X`
1522 # The name of the parameter
1523 var n_id
: TId is writable, noinit
1525 # The type of the parameter, if any
1526 var n_type
: nullable AType = null is writable
1528 # The `...` symbol to indicate varargs
1529 var n_dotdotdot
: nullable TDotdotdot = null is writable
1532 # A static type. eg `nullable X[Y]`
1535 # The `nullable` keyword
1536 var n_kwnullable
: nullable TKwnullable = null is writable
1538 # The name of the class or of the formal type
1539 var n_id
: TClassid is writable, noinit
1541 # Type arguments for a generic type
1542 var n_types
= new ANodes[AType](self)
1545 # A label at the end of a block or in a break/continue statement. eg `label x`
1549 # The `label` keyword
1550 var n_kwlabel
: TKwlabel is writable, noinit
1552 # The name of the label, if any
1553 var n_id
: nullable TId is writable
1556 # Expression and statements
1557 # From a AST point of view there is no distinction between statement and expressions (even if the parser has to distinguish them)
1558 abstract class AExpr
1562 # A sequence of `AExpr` (usually statements)
1563 # The last `AExpr` gives the value of the whole block
1567 # The list of statements in the bloc.
1568 # The last element is often considered as an expression that give the value of the whole block.
1569 var n_expr
= new ANodes[AExpr](self)
1572 var n_kwend
: nullable TKwend = null is writable
1575 # A declaration of a local variable. eg `var x: X = y`
1580 var n_kwvar
: TKwvar is writable, noinit
1582 # The name of the local variable
1583 var n_id
: TId is writable, noinit
1585 # The declaration type of the local variable
1586 var n_type
: nullable AType = null is writable
1588 # The `=` symbol (for the initial value)
1589 var n_assign
: nullable TAssign = null is writable
1591 # The initial value, if any
1592 var n_expr
: nullable AExpr = null is writable
1595 # A `return` statement. eg `return x`
1599 # The `return` keyword
1600 var n_kwreturn
: nullable TKwreturn = null is writable
1602 # The return value, if any
1603 var n_expr
: nullable AExpr = null is writable
1606 # Something that has a label.
1607 abstract class ALabelable
1610 # The associated label declatation
1611 var n_label
: nullable ALabel = null is writable
1614 # A `break` or a `continue`
1615 abstract class AEscapeExpr
1619 # The return value, if nay (unused currently)
1620 var n_expr
: nullable AExpr = null is writable
1623 # A `break` statement.
1627 # The `break` keyword
1628 var n_kwbreak
: TKwbreak is writable, noinit
1631 # An `abort` statement
1635 # The `abort` keyword
1636 var n_kwabort
: TKwabort is writable, noinit
1639 # A `continue` statement
1643 # The `continue` keyword.
1644 var n_kwcontinue
: nullable TKwcontinue = null is writable
1653 var n_kwdo
: TKwdo is writable, noinit
1655 # The list of statements of the `do`.
1656 var n_block
: nullable AExpr = null is writable
1664 var n_kwif
: TKwif is writable, noinit
1666 # The expression used as the condition of the `if`
1667 var n_expr
: AExpr is writable, noinit
1669 # The body of the `then` part
1670 var n_then
: nullable AExpr = null is writable
1672 # The body of the `else` part
1673 var n_else
: nullable AExpr = null is writable
1676 # A `if` expression (ternary conditional). eg. `if true then 1 else 0`
1681 var n_kwif
: TKwif is writable, noinit
1683 # The expression used as the condition of the `if`
1684 var n_expr
: AExpr is writable, noinit
1686 # The `then` keyword
1687 var n_kwthen
: TKwthen is writable, noinit
1689 # The expression in the `then` part
1690 var n_then
: AExpr is writable, noinit
1692 # The `else` keyword
1693 var n_kwelse
: TKwelse is writable, noinit
1695 # The expression in the `else` part
1696 var n_else
: AExpr is writable, noinit
1699 # A `while` statement
1704 # The `while` keyword
1705 var n_kwwhile
: TKwwhile is writable, noinit
1707 # The expression used as the condition of the `while`
1708 var n_expr
: AExpr is writable, noinit
1711 var n_kwdo
: TKwdo is writable, noinit
1713 # The body of the loop
1714 var n_block
: nullable AExpr = null is writable
1717 # A `loop` statement
1722 # The `loop` keyword
1723 var n_kwloop
: TKwloop is writable, noinit
1725 # The body of the loop
1726 var n_block
: nullable AExpr = null is writable
1735 var n_kwfor
: TKwfor is writable, noinit
1737 # The list of name of the automatic variables
1738 var n_ids
= new ANodes[TId](self)
1740 # The expression used as the collection to iterate on
1741 var n_expr
: AExpr is writable, noinit
1744 var n_kwdo
: TKwdo is writable, noinit
1746 # The body of the loop
1747 var n_block
: nullable AExpr = null is writable
1750 # An `assert` statement
1754 # The `assert` keyword
1755 var n_kwassert
: TKwassert is writable, noinit
1757 # The name of the assert, if any
1758 var n_id
: nullable TId = null is writable
1760 # The expression used as the condition of the `assert`
1761 var n_expr
: AExpr is writable, noinit
1763 # The body to execute when the assert fails
1764 var n_else
: nullable AExpr = null is writable
1767 # Whatever is a simple assignment. eg `= something`
1768 abstract class AAssignFormExpr
1772 var n_assign
: TAssign is writable, noinit
1774 # The right-value to assign.
1775 var n_value
: AExpr is writable, noinit
1778 # Whatever is a combined assignment. eg `+= something`
1779 abstract class AReassignFormExpr
1782 # The combined operator (eg. `+=`)
1783 var n_assign_op
: AAssignOp is writable, noinit
1785 # The right-value to apply on the combined operator.
1786 var n_value
: AExpr is writable, noinit
1789 # A `once` expression. eg `once x`
1793 # The `once` keyword
1794 var n_kwonce
: TKwonce is writable, noinit
1796 # The expression to evaluate only one time
1797 var n_expr
: AExpr is writable, noinit
1800 # A polymorphic invocation of a method
1801 # The form of the invocation (name, arguments, etc.) are specific
1802 abstract class ASendExpr
1804 # The receiver of the method invocation
1805 var n_expr
: AExpr is writable, noinit
1808 # A binary operation on a method
1809 abstract class ABinopExpr
1811 # The second operand of the operation
1812 # Note: the receiver (`n_expr`) is the first operand
1813 var n_expr2
: AExpr is writable, noinit
1816 # Something that is boolean expression
1817 abstract class ABoolExpr
1821 # Something that is binary boolean expression
1822 abstract class ABinBoolExpr
1825 # The first boolean operand
1826 var n_expr
: AExpr is writable, noinit
1828 # The second boolean operand
1829 var n_expr2
: AExpr is writable, noinit
1837 # A `and` expression
1842 # A `or else` expression
1847 # A `implies` expression
1852 # A `not` expression
1857 var n_kwnot
: TKwnot is writable, noinit
1859 # The boolean operand of the `not`
1860 var n_expr
: AExpr is writable, noinit
1903 # A type-ckeck expression. eg `x isa T`
1907 # The expression to check
1908 var n_expr
: AExpr is writable, noinit
1910 # The destination type to check to
1911 var n_type
: AType is writable, noinit
1924 # A `<=>` expression
1949 # A unary minus expression. eg `-x`
1954 var n_minus
: TMinus is writable, noinit
1957 # An explicit instantiation. eg `new T`
1962 var n_kwnew
: TKwnew is writable, noinit
1964 # The `type` keyword
1965 var n_type
: AType is writable, noinit
1967 # The name of the named-constructor, if any
1968 var n_id
: nullable TId = null is writable
1970 # The arguments of the `new`
1971 var n_args
: AExprs is writable, noinit
1974 # Whatever is a old-style attribute access
1975 abstract class AAttrFormExpr
1978 # The receiver of the attribute
1979 var n_expr
: AExpr is writable, noinit
1981 # The name of the attribute
1982 var n_id
: TAttrid is writable, noinit
1986 # The read of an attribute. eg `x._a`
1991 # The assignment of an attribute. eg `x._a=y`
1992 class AAttrAssignExpr
1994 super AAssignFormExpr
1997 # Whatever looks-like a call with a standard method and any number of arguments.
1998 abstract class ACallFormExpr
2001 # The name of the method
2002 var n_id
: TId is writable, noinit
2004 # The arguments of the call
2005 var n_args
: AExprs is writable, noinit
2008 # A complex setter call (standard or brackets)
2009 abstract class ASendReassignFormExpr
2011 super AReassignFormExpr
2014 # A complex attribute assignment. eg `x._a+=y`
2015 class AAttrReassignExpr
2017 super AReassignFormExpr
2020 # A call with a standard method-name and any number of arguments. eg `x.m(y)`. OR just a simple id
2021 # 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`.
2022 # Semantic analysis have to transform them to instance of `AVarExpr`.
2027 # A setter call with a standard method-name and any number of arguments. eg `x.m(y)=z`. OR just a simple assignment.
2028 # 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`.
2029 # Semantic analysis have to transform them to instance of `AVarAssignExpr`.
2030 class ACallAssignExpr
2032 super AAssignFormExpr
2035 # 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.
2036 # 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`.
2037 # Semantic analysis have to transform them to instance of `AVarReassignExpr`.
2038 class ACallReassignExpr
2040 super ASendReassignFormExpr
2043 # A call to `super`. OR a call of a super-constructor
2047 # The qualifier part before the super (currenlty unused)
2048 var n_qualified
: nullable AQualified = null is writable
2050 # The `super` keyword
2051 var n_kwsuper
: TKwsuper is writable, noinit
2053 # The arguments of the super
2054 var n_args
: AExprs is writable, noinit
2057 # A call to the `init` constructor.
2058 # Note: because `init` is a keyword and not a `TId`, the explicit call to init cannot be a `ACallFormExpr`.
2062 # The `init` keyword
2063 var n_kwinit
: TKwinit is writable, noinit
2065 # The arguments of the init
2066 var n_args
: AExprs is writable, noinit
2069 # Whatever looks-like a call of the brackets `[]` operator.
2070 abstract class ABraFormExpr
2073 # The arguments inside the brackets
2074 var n_args
: AExprs is writable, noinit
2077 # A call of the brackets operator. eg `x[y,z]`
2082 # A setter call of the bracket operator. eg `x[y,z]=t`
2083 class ABraAssignExpr
2085 super AAssignFormExpr
2088 # Whatever is an access to a local variable
2089 abstract class AVarFormExpr
2092 # The name of the attribute
2093 var n_id
: TId is writable, noinit
2096 # A complex setter call of the bracket operator. eg `x[y,z]+=t`
2097 class ABraReassignExpr
2099 super ASendReassignFormExpr
2102 # A local variable read access.
2103 # The parser cannot instantiate them, see `ACallExpr`.
2108 # A local variable simple assignment access
2109 # The parser cannot instantiate them, see `ACallAssignExpr`.
2110 class AVarAssignExpr
2112 super AAssignFormExpr
2115 # A local variable complex assignment access
2116 # The parser cannot instantiate them, see `ACallReassignExpr`.
2117 class AVarReassignExpr
2119 super AReassignFormExpr
2122 # A literal range, open or closed
2123 abstract class ARangeExpr
2126 # The left (lower) element of the range
2127 var n_expr
: AExpr is writable, noinit
2129 # The right (uppr) element of the range
2130 var n_expr2
: AExpr is writable, noinit
2133 # A closed literal range. eg `[x..y]`
2137 # The opening bracket `[`
2138 var n_obra
: TObra is writable, noinit
2140 # The closing bracket `]`
2141 var n_cbra
: TCbra is writable, noinit
2144 # An open literal range. eg `[x..y[`
2148 # The opening bracket `[`
2149 var n_obra
: TObra is writable, noinit
2151 # The closing bracket `[` (because open range)
2152 var n_cbra
: TObra is writable, noinit
2155 # A literal array. eg. `[x,y,z]`
2159 # The opening bracket `[`
2160 var n_obra
: TObra is writable, noinit
2162 # The elements of the array
2163 var n_exprs
= new ANodes[AExpr](self)
2165 # The type of the element of the array (if any)
2166 var n_type
: nullable AType = null is writable
2168 # The closing bracket `]`
2169 var n_cbra
: TCbra is writable, noinit
2176 # The `self` keyword
2177 var n_kwself
: nullable TKwself is writable
2180 # When there is no explicit receiver, `self` is implicit
2181 class AImplicitSelfExpr
2185 # A `true` boolean literal constant
2189 # The `true` keyword
2190 var n_kwtrue
: TKwtrue is writable, noinit
2193 # A `false` boolean literal constant
2197 # The `false` keyword
2198 var n_kwfalse
: TKwfalse is writable, noinit
2201 # A `null` literal constant
2205 # The `null` keyword
2206 var n_kwnull
: TKwnull is writable, noinit
2209 # An integer literal
2214 # An integer literal in decimal format
2219 var n_number
: TNumber is writable, noinit
2222 # An integer literal in hexadecimal format
2226 # The hexadecimal token
2227 var n_hex_number
: THexNumber is writable, noinit
2235 var n_float
: TFloat is writable, noinit
2238 # A character literal
2242 # The character token
2243 var n_char
: TChar is writable, noinit
2247 abstract class AStringFormExpr
2251 var n_string
: Token is writable, noinit
2254 # A simple string. eg. `"abc"`
2256 super AStringFormExpr
2259 # The start of a superstring. eg `"abc{`
2260 class AStartStringExpr
2261 super AStringFormExpr
2264 # The middle of a superstring. eg `}abc{`
2265 class AMidStringExpr
2266 super AStringFormExpr
2269 # The end of a superstrng. eg `}abc"`
2270 class AEndStringExpr
2271 super AStringFormExpr
2274 # A superstring literal. eg `"a{x}b{y}c"`
2275 # Each part is modeled a sequence of expression. eg. `["a{, x, }b{, y, }c"]`
2276 class ASuperstringExpr
2279 # The list of the expressions of the superstring
2280 var n_exprs
= new ANodes[AExpr](self)
2283 # A simple parenthesis. eg `(x)`
2287 # The opening parenthesis
2288 var n_opar
: TOpar is writable, noinit
2290 # The inner expression
2291 var n_expr
: AExpr is writable, noinit
2293 # The closing parenthesis
2294 var n_cpar
: TCpar is writable, noinit
2297 # A cast, against a type or `not null`
2301 # The expression to cast
2302 var n_expr
: AExpr is writable, noinit
2305 var n_kwas
: TKwas is writable, noinit
2307 # The opening parenthesis
2308 var n_opar
: nullable TOpar = null is writable
2310 # The closing parenthesis
2311 var n_cpar
: nullable TCpar = null is writable
2314 # A type cast. eg `x.as(T)`
2318 # The target type to cast to
2319 var n_type
: AType is writable, noinit
2322 # A as-not-null cast. eg `x.as(not null)`
2323 class AAsNotnullExpr
2327 var n_kwnot
: TKwnot is writable, noinit
2329 # The `null` keyword
2330 var n_kwnull
: TKwnull is writable, noinit
2333 # A is-set check of old-style attributes. eg `isset x._a`
2334 class AIssetAttrExpr
2337 # The `isset` keyword
2338 var n_kwisset
: TKwisset is writable, noinit
2341 # An ellipsis notation used to pass an expression as it, in a vararg parameter
2345 # The passed expression
2346 var n_expr
: AExpr is writable, noinit
2349 var n_dotdotdot
: TDotdotdot is writable, noinit
2352 # A list of expression separated with commas (arguments for instance)
2356 # The list of expressions
2357 var n_exprs
= new ANodes[AExpr](self)
2360 # A special expression that encapsulates a static type
2361 # Can only be found in special construction like arguments of annotations.
2365 # The encapsulated type
2366 var n_type
: AType is writable, noinit
2369 # A special expression that encapsulates a method identifier
2370 # Can only be found in special construction like arguments of annotations.
2375 var n_expr
: AExpr is writable, noinit
2377 # The encapsulated method identifier
2378 var n_id
: AMethid is writable, noinit
2381 # A special expression that encapsulate an annotation
2382 # Can only be found in special construction like arguments of annotations.
2384 # The encapsulated annotations are in `n_annotations`
2389 # A special expression to debug types
2390 class ADebugTypeExpr
2393 # The `debug` keyword
2394 var n_kwdebug
: TKwdebug is writable, noinit
2396 # The `type` keyword
2397 var n_kwtype
: TKwtype is writable, noinit
2399 # The expression to check
2400 var n_expr
: AExpr is writable, noinit
2403 var n_type
: AType is writable, noinit
2406 # A list of expression separated with commas (arguments for instance)
2407 abstract class AExprs
2410 # The list of expressions
2411 var n_exprs
= new ANodes[AExpr](self)
2414 # A simple list of expressions
2419 # A list of expressions enclosed in parentheses
2423 # The opening parenthesis
2424 var n_opar
: TOpar is writable, noinit
2426 # The closing parenthesis
2427 var n_cpar
: TCpar is writable, noinit
2430 # A list of expressions enclosed in brackets
2434 # The opening bracket
2435 var n_obra
: TObra is writable, noinit
2437 # The closing bracket
2438 var n_cbra
: TCbra is writable, noinit
2441 # A complex assignment operator. (`+=` and `-=`)
2442 abstract class AAssignOp
2446 # The `+=` assignment operation
2451 var n_pluseq
: TPluseq is writable, noinit
2454 # The `-=` assignment operator
2455 class AMinusAssignOp
2459 var n_minuseq
: TMinuseq is writable, noinit
2462 # A possibly fully-qualified module identifier
2466 # The starting quad (`::`)
2467 var n_quad
: nullable TQuad = null is writable
2469 # The list of quad-separated project/group identifiers
2470 var n_path
= new ANodes[TId](self)
2472 # The final module identifier
2473 var n_id
: TId is writable, noinit
2476 # A language declaration for an extern block
2481 var n_kwin
: TKwin is writable, noinit
2484 var n_string
: TString is writable, noinit
2487 # An full extern block
2488 class AExternCodeBlock
2491 # The language declration
2492 var n_in_language
: nullable AInLanguage = null is writable
2494 # The block of extern code
2495 var n_extern_code_segment
: TExternCodeSegment is writable, noinit
2498 # A possible full method qualifier.
2502 # The starting quad (`::`)
2503 var n_quad
: nullable TQuad = null is writable
2505 # The list of quad-separated project/group/module identifiers
2506 var n_id
= new ANodes[TId](self)
2508 # A class identifier
2509 var n_classid
: nullable TClassid = null is writable
2512 # A documentation of a definition
2513 # It contains the block of comments just above the declaration
2517 # A list of lines of comment
2518 var n_comment
= new ANodes[TComment](self)
2521 # A group of annotation on a node
2523 # This same class is used for the 3 kind of annotations:
2525 # * *is* annotations. eg `module foo is bar`.
2526 # * *at* annotations. eg `foo@bar` or `foo@(bar,baz)`.
2527 # * *class* annotations, defined in classes.
2531 # The `@` symbol, for *at* annotations
2532 var n_at
: nullable TAt = null is writable
2534 # The opening parenthesis in *at* annotations
2535 var n_opar
: nullable TOpar = null is writable
2537 # The list of annotations
2538 var n_items
= new ANodes[AAnnotation](self)
2540 # The closing parenthesis in *at* annotations
2541 var n_cpar
: nullable TCpar = null is writable
2544 # A single annotation
2548 # The name of the annotation
2549 var n_atid
: AAtid is writable, noinit
2551 # The opening parenthesis of the arguments
2552 var n_opar
: nullable TOpar = null is writable
2554 # The list of arguments
2555 var n_args
= new ANodes[AExpr](self)
2557 # The closing parenthesis
2558 var n_cpar
: nullable TCpar = null is writable
2560 # The name of the annotation
2563 return n_atid
.n_id
.text
2567 # An annotation name
2568 abstract class AAtid
2571 # The identifier of the annotation.
2572 # Can be a TId of a keyword
2573 var n_id
: Token is writable, noinit
2576 # An annotation name based on an identifier
2581 # An annotation name based on the keyword `extern`
2586 # An annotation name based on the keyword `import`
2591 # An annotation name based on the keyword `abstract`
2592 class AKwabstractAtid
2596 # The root of the AST
2601 var n_base
: nullable AModule is writable
2603 # The end of file (or error) token
2604 var n_eof
: EOF is writable