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 var n_moduledecl
: nullable AModuledecl = null is writable
911 var n_imports
= new ANodes[AImport](self)
912 var n_extern_code_blocks
= new ANodes[AExternCodeBlock](self)
913 var n_classdefs
= new ANodes[AClassdef](self)
916 # The declaration of the module with the documentation, name, and annotations
919 var n_doc
: nullable ADoc = null is writable
920 var n_kwredef
: nullable TKwredef = null is writable
921 var n_visibility
: AVisibility is writable, noinit
922 var n_kwmodule
: TKwmodule is writable, noinit
923 var n_name
: AModuleName is writable, noinit
926 # A import clause of a module
927 abstract class AImport
931 # A standard import clause. eg `import x`
934 var n_visibility
: AVisibility is writable, noinit
935 var n_kwimport
: TKwimport is writable, noinit
936 var n_name
: AModuleName is writable, noinit
939 # The special import clause of the kernel module. eg `import end`
942 var n_visibility
: AVisibility is writable, noinit
943 var n_kwimport
: TKwimport is writable, noinit
944 var n_kwend
: TKwend is writable, noinit
947 # A visibility modifier
949 # The public visibility is an empty production (no keyword).
951 # Note: even if some visibilities are only valid on some placse (for instance, no `protected` class or no `intrude` method)
952 # the parser has no such a restriction, therefore the semantic phases has to check that the visibilities make sense.
953 abstract class AVisibility
957 # An implicit or explicit public visibility modifier
958 class APublicVisibility
960 var n_kwpublic
: nullable TKwpublic is writable
962 # An explicit private visibility modifier
963 class APrivateVisibility
965 var n_kwprivate
: TKwprivate is writable, noinit
967 # An explicit protected visibility modifier
968 class AProtectedVisibility
970 var n_kwprotected
: TKwprotected is writable, noinit
972 # An explicit intrude visibility modifier
973 class AIntrudeVisibility
975 var n_kwintrude
: TKwintrude is writable, noinit
979 # While most definition are `AStdClassdef`
980 # There is tow special case of class definition
981 abstract class AClassdef
983 var n_propdefs
= new ANodes[APropdef](self)
986 # A standard class definition with a name, superclasses and properties
989 var n_doc
: nullable ADoc = null is writable
990 var n_kwredef
: nullable TKwredef = null is writable
991 var n_visibility
: AVisibility is writable, noinit
992 var n_classkind
: AClasskind is writable, noinit
993 var n_id
: nullable TClassid = null is writable
994 var n_formaldefs
= new ANodes[AFormaldef](self)
995 var n_extern_code_block
: nullable AExternCodeBlock = null is writable
996 var n_superclasses
= new ANodes[ASuperclass](self)
997 var n_kwend
: TKwend is writable, noinit
998 redef fun hot_location
do return n_id
.location
1001 # The implicit class definition of the implicit main method
1006 # The implicit class definition of the top-level methods
1011 # The modifier for the kind of class (abstract, interface, etc.)
1012 abstract class AClasskind
1016 # A default, or concrete class modifier (just `class`)
1017 class AConcreteClasskind
1019 var n_kwclass
: TKwclass is writable, noinit
1022 # An abstract class modifier (`abstract class`)
1023 class AAbstractClasskind
1025 var n_kwabstract
: TKwabstract is writable, noinit
1026 var n_kwclass
: TKwclass is writable, noinit
1029 # An interface class modifier (`interface`)
1030 class AInterfaceClasskind
1032 var n_kwinterface
: TKwinterface is writable, noinit
1035 # An enum/universal class modifier (`enum class`)
1036 class AEnumClasskind
1038 var n_kwenum
: TKwenum is writable, noinit
1041 # An extern class modifier (`extern class`)
1042 class AExternClasskind
1044 var n_kwextern
: TKwextern is writable, noinit
1045 var n_kwclass
: nullable TKwclass = null is writable
1048 # The definition of a formal generic parameter type. eg `X: Y`
1051 var n_id
: TClassid is writable, noinit
1052 # The bound of the parameter type
1053 var n_type
: nullable AType = null is writable
1056 # A super-class. eg `super X`
1059 var n_kwsuper
: TKwsuper is writable, noinit
1060 var n_type
: AType is writable, noinit
1063 # The definition of a property
1064 abstract class APropdef
1066 var n_doc
: nullable ADoc = null is writable
1067 var n_kwredef
: nullable TKwredef = null is writable
1068 var n_visibility
: nullable AVisibility = null is writable
1071 # A definition of an attribute
1072 # For historical reason, old-syle and new-style attributes use the same `ANode` sub-class
1075 var n_kwvar
: TKwvar is writable, noinit
1077 # The identifier for a new-style attribute (null if old-style)
1078 var n_id2
: TId is writable, noinit
1080 var n_type
: nullable AType = null is writable
1082 # The initial value, if any
1083 var n_expr
: nullable AExpr = null is writable
1085 var n_block
: nullable AExpr = null is writable
1087 redef fun hot_location
1089 return n_id2
.location
1093 # A definition of all kind of method (including constructors)
1096 var n_kwmeth
: nullable TKwmeth = null is writable
1097 var n_kwinit
: nullable TKwinit = null is writable
1098 var n_kwnew
: nullable TKwnew = null is writable
1099 var n_methid
: nullable AMethid = null is writable
1100 var n_signature
: nullable ASignature = null is writable
1101 var n_block
: nullable AExpr = null is writable
1102 var n_extern_calls
: nullable AExternCalls = null is writable
1103 var n_extern_code_block
: nullable AExternCodeBlock = null is writable
1104 redef fun hot_location
1106 if n_methid
!= null then
1107 return n_methid
.location
1108 else if n_kwinit
!= null then
1109 return n_kwinit
.location
1110 else if n_kwnew
!= null then
1111 return n_kwnew
.location
1118 # The implicit main method
1119 class AMainMethPropdef
1123 # Declaration of callbacks for extern methods
1126 var n_kwimport
: TKwimport is writable, noinit
1127 var n_extern_calls
: ANodes[AExternCall] = new ANodes[AExternCall](self)
1130 # A single callback declaration
1131 abstract class AExternCall
1135 # A single callback declaration on a method
1136 abstract class APropExternCall
1140 # A single callback declaration on a method on the current receiver
1141 class ALocalPropExternCall
1142 super APropExternCall
1143 var n_methid
: AMethid is writable, noinit
1146 # A single callback declaration on a method on an explicit receiver type.
1147 class AFullPropExternCall
1148 super APropExternCall
1149 var n_type
: AType is writable, noinit
1150 var n_dot
: nullable TDot = null is writable
1151 var n_methid
: AMethid is writable, noinit
1154 # A single callback declaration on a method on a constructor
1155 class AInitPropExternCall
1156 super APropExternCall
1157 var n_type
: AType is writable, noinit
1160 # A single callback declaration on a `super` call
1161 class ASuperExternCall
1163 var n_kwsuper
: TKwsuper is writable, noinit
1166 # A single callback declaration on a cast
1167 abstract class ACastExternCall
1171 # A single callback declaration on a cast to a given type
1172 class ACastAsExternCall
1173 super ACastExternCall
1174 var n_from_type
: AType is writable, noinit
1175 var n_dot
: nullable TDot = null is writable
1176 var n_kwas
: TKwas is writable, noinit
1177 var n_to_type
: AType is writable, noinit
1180 # A single callback declaration on a cast to a nullable type
1181 class AAsNullableExternCall
1182 super ACastExternCall
1183 var n_type
: AType is writable, noinit
1184 var n_kwas
: TKwas is writable, noinit
1185 var n_kwnullable
: TKwnullable is writable, noinit
1188 # A single callback declaration on a cast to a non-nullable type
1189 class AAsNotNullableExternCall
1190 super ACastExternCall
1191 var n_type
: AType is writable, noinit
1192 var n_kwas
: TKwas is writable, noinit
1193 var n_kwnot
: TKwnot is writable, noinit
1194 var n_kwnullable
: TKwnullable is writable, noinit
1197 # A definition of a virtual type
1200 var n_kwtype
: TKwtype is writable, noinit
1201 var n_id
: TClassid is writable, noinit
1202 var n_type
: AType is writable, noinit
1205 # The identifier of a method in a method declaration.
1206 # There is a specific class because of operator and setters.
1207 abstract class AMethid
1211 # A method name with a simple identifier
1214 var n_id
: TId is writable, noinit
1220 var n_plus
: TPlus is writable, noinit
1226 var n_minus
: TMinus is writable, noinit
1232 var n_star
: TStar is writable, noinit
1235 # A method name `**`
1236 class AStarstarMethid
1238 var n_starstar
: TStarstar is writable, noinit
1244 var n_slash
: TSlash is writable, noinit
1248 class APercentMethid
1250 var n_percent
: TPercent is writable, noinit
1253 # A method name `==`
1256 var n_eq
: TEq is writable, noinit
1259 # A method name `!=`
1262 var n_ne
: TNe is writable, noinit
1265 # A method name `<=`
1268 var n_le
: TLe is writable, noinit
1271 # A method name `>=`
1274 var n_ge
: TGe is writable, noinit
1280 var n_lt
: TLt is writable, noinit
1286 var n_gt
: TGt is writable, noinit
1289 # A method name `<<`
1292 var n_ll
: TLl is writable, noinit
1295 # A method name `>>`
1298 var n_gg
: TGg is writable, noinit
1301 # A method name `[]`
1304 var n_obra
: TObra is writable, noinit
1305 var n_cbra
: TCbra is writable, noinit
1308 # A method name `<=>`
1309 class AStarshipMethid
1311 var n_starship
: TStarship is writable, noinit
1314 # A setter method name with a simple identifier (with a `=`)
1317 var n_id
: TId is writable, noinit
1318 var n_assign
: TAssign is writable, noinit
1321 # A method name `[]=`
1322 class ABraassignMethid
1324 var n_obra
: TObra is writable, noinit
1325 var n_cbra
: TCbra is writable, noinit
1326 var n_assign
: TAssign is writable, noinit
1329 # A signature in a method definition. eg `(x,y:X,z:Z):T`
1332 var n_opar
: nullable TOpar = null is writable
1333 var n_params
= new ANodes[AParam](self)
1334 var n_cpar
: nullable TCpar = null is writable
1335 var n_type
: nullable AType = null is writable
1338 # A parameter definition in a signature. eg `x:X`
1341 var n_id
: TId is writable, noinit
1342 var n_type
: nullable AType = null is writable
1343 var n_dotdotdot
: nullable TDotdotdot = null is writable
1346 # A static type. eg `nullable X[Y]`
1349 var n_kwnullable
: nullable TKwnullable = null is writable
1351 # The name of the class or of the formal type
1352 var n_id
: TClassid is writable, noinit
1354 # Type arguments for a generic type
1355 var n_types
= new ANodes[AType](self)
1358 # A label at the end of a block or in a break/continue statement. eg `label x`
1361 var n_kwlabel
: TKwlabel is writable, noinit
1362 var n_id
: nullable TId is writable
1365 # Expression and statements
1366 # From a AST point of view there is no distinction between statement and expressions (even if the parser has to distinguish them)
1367 abstract class AExpr
1371 # A sequence of `AExpr` (usually statements)
1372 # The last `AExpr` gives the value of the whole block
1375 var n_expr
= new ANodes[AExpr](self)
1376 var n_kwend
: nullable TKwend = null is writable
1379 # A declaration of a local variable. eg `var x: X = y`
1382 var n_kwvar
: TKwvar is writable, noinit
1383 var n_id
: TId is writable, noinit
1384 var n_type
: nullable AType = null is writable
1385 var n_assign
: nullable TAssign = null is writable
1387 # The initial value, if any
1388 var n_expr
: nullable AExpr = null is writable
1391 # A `return` statement. eg `return x`
1394 var n_kwreturn
: nullable TKwreturn = null is writable
1395 var n_expr
: nullable AExpr = null is writable
1398 # Something that has a label.
1399 abstract class ALabelable
1401 var n_label
: nullable ALabel = null is writable
1404 # A `break` or a `continue`
1405 abstract class AEscapeExpr
1408 var n_expr
: nullable AExpr = null is writable
1411 # A `break` statement.
1414 var n_kwbreak
: TKwbreak is writable, noinit
1417 # An `abort` statement
1420 var n_kwabort
: TKwabort is writable, noinit
1423 # A `continue` statement
1426 var n_kwcontinue
: nullable TKwcontinue = null is writable
1433 var n_kwdo
: TKwdo is writable, noinit
1434 var n_block
: nullable AExpr = null is writable
1440 var n_kwif
: TKwif is writable, noinit
1441 var n_expr
: AExpr is writable, noinit
1442 var n_then
: nullable AExpr = null is writable
1443 var n_else
: nullable AExpr = null is writable
1449 var n_kwif
: TKwif is writable, noinit
1450 var n_expr
: AExpr is writable, noinit
1451 var n_kwthen
: TKwthen is writable, noinit
1452 var n_then
: AExpr is writable, noinit
1453 var n_kwelse
: TKwelse is writable, noinit
1454 var n_else
: AExpr is writable, noinit
1457 # A `while` statement
1461 var n_kwwhile
: TKwwhile is writable, noinit
1462 var n_expr
: AExpr is writable, noinit
1463 var n_kwdo
: TKwdo is writable, noinit
1464 var n_block
: nullable AExpr = null is writable
1467 # A `loop` statement
1471 var n_kwloop
: TKwloop is writable, noinit
1472 var n_block
: nullable AExpr = null is writable
1479 var n_kwfor
: TKwfor is writable, noinit
1480 var n_ids
= new ANodes[TId](self)
1481 var n_expr
: AExpr is writable, noinit
1482 var n_kwdo
: TKwdo is writable, noinit
1483 var n_block
: nullable AExpr = null is writable
1486 # An `assert` statement
1489 var n_kwassert
: TKwassert is writable, noinit
1490 var n_id
: nullable TId = null is writable
1491 var n_expr
: AExpr is writable, noinit
1492 var n_else
: nullable AExpr = null is writable
1495 # Whatever is a simple assignment. eg `= something`
1496 abstract class AAssignFormExpr
1498 var n_assign
: TAssign is writable, noinit
1499 var n_value
: AExpr is writable, noinit
1502 # Whatever is a combined assignment. eg `+= something`
1503 abstract class AReassignFormExpr
1505 var n_assign_op
: AAssignOp is writable, noinit
1506 var n_value
: AExpr is writable, noinit
1509 # A `once` expression. eg `once x`
1512 var n_kwonce
: TKwonce is writable, noinit
1513 var n_expr
: AExpr is writable, noinit
1516 # A polymorphic invocation of a method
1517 # The form of the invocation (name, arguments, etc.) are specific
1518 abstract class ASendExpr
1520 # The receiver of the method invocation
1521 var n_expr
: AExpr is writable, noinit
1524 # A binary operation on a method
1525 abstract class ABinopExpr
1527 # The second operand of the operation
1528 # Note: the receiver (`n_expr`) is the first operand
1529 var n_expr2
: AExpr is writable, noinit
1532 # Something that is boolean expression
1533 abstract class ABoolExpr
1540 var n_expr
: AExpr is writable, noinit
1541 var n_expr2
: AExpr is writable, noinit
1544 # A `and` expression
1547 var n_expr
: AExpr is writable, noinit
1548 var n_expr2
: AExpr is writable, noinit
1551 # A `or else` expression
1554 var n_expr
: AExpr is writable, noinit
1555 var n_expr2
: AExpr is writable, noinit
1558 # A `implies` expression
1561 var n_expr
: AExpr is writable, noinit
1562 var n_expr2
: AExpr is writable, noinit
1565 # A `not` expression
1568 var n_kwnot
: TKwnot is writable, noinit
1569 var n_expr
: AExpr is writable, noinit
1612 # A type-ckeck expression. eg `x isa T`
1615 var n_expr
: AExpr is writable, noinit
1616 var n_type
: AType is writable, noinit
1629 # A `<=>` expression
1654 # A unary minus expression. eg `-x`
1657 var n_minus
: TMinus is writable, noinit
1660 # An explicit instantiation. eg `new T`
1663 var n_kwnew
: TKwnew is writable, noinit
1664 var n_type
: AType is writable, noinit
1666 # The name of the named-constructor, if any
1667 var n_id
: nullable TId = null is writable
1668 var n_args
: AExprs is writable, noinit
1671 # Whatever is a old-style attribute access
1672 abstract class AAttrFormExpr
1675 # The receiver of the attribute
1676 var n_expr
: AExpr is writable, noinit
1678 # The name of the attribute
1679 var n_id
: TAttrid is writable, noinit
1683 # The read of an attribute. eg `x._a`
1688 # The assignment of an attribute. eg `x._a=y`
1689 class AAttrAssignExpr
1691 super AAssignFormExpr
1694 # Whatever looks-like a call with a standard method and any number of arguments.
1695 abstract class ACallFormExpr
1698 # The name of the method
1699 var n_id
: TId is writable, noinit
1701 # The arguments of the call
1702 var n_args
: AExprs is writable, noinit
1705 # A complex setter call (standard or brackets)
1706 abstract class ASendReassignFormExpr
1708 super AReassignFormExpr
1711 # A complex attribute assignment. eg `x._a+=y`
1712 class AAttrReassignExpr
1714 super AReassignFormExpr
1717 # A call with a standard method-name and any number of arguments. eg `x.m(y)`. OR just a simple id
1718 # 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`.
1719 # Semantic analysis have to transform them to instance of `AVarExpr`.
1724 # A setter call with a standard method-name and any number of arguments. eg `x.m(y)=z`. OR just a simple assignment.
1725 # 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`.
1726 # Semantic analysis have to transform them to instance of `AVarAssignExpr`.
1727 class ACallAssignExpr
1729 super AAssignFormExpr
1732 # 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.
1733 # 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`.
1734 # Semantic analysis have to transform them to instance of `AVarReassignExpr`.
1735 class ACallReassignExpr
1737 super ASendReassignFormExpr
1740 # A call to `super`. OR a call of a super-constructor
1743 var n_qualified
: nullable AQualified = null is writable
1744 var n_kwsuper
: TKwsuper is writable, noinit
1745 var n_args
: AExprs is writable, noinit
1748 # A call to the `init` constructor.
1749 # Note: because `init` is a keyword and not a `TId`, the explicit call to init cannot be a `ACallFormExpr`.
1752 var n_kwinit
: TKwinit is writable, noinit
1753 var n_args
: AExprs is writable, noinit
1756 # Whatever looks-like a call of the brackets `[]` operator.
1757 abstract class ABraFormExpr
1759 var n_args
: AExprs is writable, noinit
1762 # A call of the brackets operator. eg `x[y,z]`
1767 # A setter call of the bracket operator. eg `x[y,z]=t`
1768 class ABraAssignExpr
1770 super AAssignFormExpr
1773 # Whatever is an access to a local variable
1774 abstract class AVarFormExpr
1776 var n_id
: TId is writable, noinit
1779 # A complex setter call of the bracket operator. eg `x[y,z]+=t`
1780 class ABraReassignExpr
1782 super ASendReassignFormExpr
1785 # A local variable read access.
1786 # The parser cannot instantiate them, see `ACallExpr`.
1791 # A local variable simple assignment access
1792 # The parser cannot instantiate them, see `ACallAssignExpr`.
1793 class AVarAssignExpr
1795 super AAssignFormExpr
1798 # A local variable complex assignment access
1799 # The parser cannot instantiate them, see `ACallReassignExpr`.
1800 class AVarReassignExpr
1802 super AReassignFormExpr
1805 # A literal range, open or closed
1806 abstract class ARangeExpr
1808 var n_expr
: AExpr is writable, noinit
1809 var n_expr2
: AExpr is writable, noinit
1812 # A closed literal range. eg `[x..y]`
1815 var n_obra
: TObra is writable, noinit
1816 var n_cbra
: TCbra is writable, noinit
1819 # An open literal range. eg `[x..y[`
1822 var n_obra
: TObra is writable, noinit
1823 var n_cbra
: TObra is writable, noinit
1826 # A literal array. eg. `[x,y,z]`
1829 var n_obra
: TObra is writable, noinit
1830 var n_exprs
: AExprs is writable, noinit
1831 var n_type
: nullable AType = null is writable
1832 var n_cbra
: TCbra is writable, noinit
1838 var n_kwself
: nullable TKwself is writable
1841 # When there is no explicit receiver, `self` is implicit
1842 class AImplicitSelfExpr
1846 # A `true` boolean literal constant
1849 var n_kwtrue
: TKwtrue is writable, noinit
1851 # A `false` boolean literal constant
1854 var n_kwfalse
: TKwfalse is writable, noinit
1856 # A `null` literal constant
1859 var n_kwnull
: TKwnull is writable, noinit
1861 # An integer literal
1865 # An integer literal in decimal format
1868 var n_number
: TNumber is writable, noinit
1870 # An integer literal in hexadecimal format
1873 var n_hex_number
: THexNumber is writable, noinit
1878 var n_float
: TFloat is writable, noinit
1880 # A character literal
1883 var n_char
: TChar is writable, noinit
1886 abstract class AStringFormExpr
1888 var n_string
: Token is writable, noinit
1891 # A simple string. eg. `"abc"`
1893 super AStringFormExpr
1896 # The start of a superstring. eg `"abc{`
1897 class AStartStringExpr
1898 super AStringFormExpr
1901 # The middle of a superstring. eg `}abc{`
1902 class AMidStringExpr
1903 super AStringFormExpr
1906 # The end of a superstrng. eg `}abc"`
1907 class AEndStringExpr
1908 super AStringFormExpr
1911 # A superstring literal. eg `"a{x}b{y}c"`
1912 # Each part is modeled a sequence of expression. eg. `["a{, x, }b{, y, }c"]`
1913 class ASuperstringExpr
1915 var n_exprs
= new ANodes[AExpr](self)
1918 # A simple parenthesis. eg `(x)`
1921 var n_opar
: TOpar is writable, noinit
1922 var n_expr
: AExpr is writable, noinit
1923 var n_cpar
: TCpar is writable, noinit
1926 # A type cast. eg `x.as(T)`
1929 var n_expr
: AExpr is writable, noinit
1930 var n_kwas
: TKwas is writable, noinit
1931 var n_opar
: nullable TOpar = null is writable
1932 var n_type
: AType is writable, noinit
1933 var n_cpar
: nullable TCpar = null is writable
1936 # A as-not-null cast. eg `x.as(not null)`
1937 class AAsNotnullExpr
1939 var n_expr
: AExpr is writable, noinit
1940 var n_kwas
: TKwas is writable, noinit
1941 var n_opar
: nullable TOpar = null is writable
1942 var n_kwnot
: TKwnot is writable, noinit
1943 var n_kwnull
: TKwnull is writable, noinit
1944 var n_cpar
: nullable TCpar = null is writable
1947 # A is-set check of old-style attributes. eg `isset x._a`
1948 class AIssetAttrExpr
1950 var n_kwisset
: TKwisset is writable, noinit
1953 # An ellipsis notation used to pass an expression as it, in a vararg parameter
1956 var n_expr
: AExpr is writable, noinit
1957 var n_dotdotdot
: TDotdotdot is writable, noinit
1960 # A list of expression separated with commas (arguments for instance)
1963 var n_exprs
= new ANodes[AExpr](self)
1966 # A special expression that encapsulates a static type
1967 # Can only be found in special construction like arguments of annotations.
1970 var n_type
: AType is writable, noinit
1973 # A special expression that encapsulates a method identifier
1974 # Can only be found in special construction like arguments of annotations.
1977 # The receiver, is any
1978 var n_expr
: AExpr is writable, noinit
1979 var n_id
: AMethid is writable, noinit
1982 # A special expression that encapsulate an annotation
1983 # Can only be found in special construction like arguments of annotations.
1988 # A special expression to debug types
1989 class ADebugTypeExpr
1991 var n_kwdebug
: TKwdebug is writable, noinit
1992 var n_kwtype
: TKwtype is writable, noinit
1993 var n_expr
: AExpr is writable, noinit
1994 var n_type
: AType is writable, noinit
1997 # A list of expression separated with commas (arguments for instance)
1998 abstract class AExprs
2000 var n_exprs
= new ANodes[AExpr](self)
2003 # A simple list of expressions
2008 # A list of expressions enclosed in parentheses
2011 var n_opar
: TOpar is writable, noinit
2012 var n_cpar
: TCpar is writable, noinit
2015 # A list of expressions enclosed in brackets
2018 var n_obra
: TObra is writable, noinit
2019 var n_cbra
: TCbra is writable, noinit
2022 # A complex assignment operator. (`+=` and `-=`)
2023 abstract class AAssignOp
2027 # The `+=` assignment operation
2030 var n_pluseq
: TPluseq is writable, noinit
2033 # The `-=` assignment operator
2034 class AMinusAssignOp
2036 var n_minuseq
: TMinuseq is writable, noinit
2039 # A possibly fully-qualified module identifier
2042 var n_quad
: nullable TQuad = null is writable
2043 var n_path
= new ANodes[TId](self)
2044 var n_id
: TId is writable, noinit
2047 # A language declaration for an extern block
2050 var n_kwin
: TKwin is writable, noinit
2051 var n_string
: TString is writable, noinit
2054 # An full extern block
2055 class AExternCodeBlock
2057 var n_in_language
: nullable AInLanguage = null is writable
2058 var n_extern_code_segment
: TExternCodeSegment is writable, noinit
2061 # A possible full method qualifier.
2064 var n_quad
: nullable TQuad = null is writable
2065 var n_id
= new ANodes[TId](self)
2066 var n_classid
: nullable TClassid = null is writable
2069 # A documentation of a definition
2070 # It contains the block of comments just above the declaration
2073 var n_comment
= new ANodes[TComment](self)
2076 # A group of annotation on a node
2079 var n_at
: nullable TAt = null is writable
2080 var n_opar
: nullable TOpar = null is writable
2081 var n_items
= new ANodes[AAnnotation](self)
2082 var n_cpar
: nullable TCpar = null is writable
2085 # A single annotation
2088 var n_doc
: nullable ADoc = null is writable
2089 var n_kwredef
: nullable TKwredef = null is writable
2090 var n_visibility
: nullable AVisibility is writable
2091 var n_atid
: AAtid is writable, noinit
2092 var n_opar
: nullable TOpar = null is writable
2093 var n_args
= new ANodes[AExpr](self)
2094 var n_cpar
: nullable TCpar = null is writable
2096 # The name of the annotation
2099 return n_atid
.n_id
.text
2103 # An annotation name
2104 abstract class AAtid
2106 var n_id
: Token is writable, noinit
2109 # An annotation name based on an identifier
2114 # An annotation name based on the keyword `extern`
2119 # An annotation name based on the keyword `import`
2124 # An annotation name based on the keyword `abstract`
2125 class AKwabstractAtid
2129 # The root of the AST
2132 var n_base
: nullable AModule is writable
2133 var n_eof
: EOF is writable