a4d6d446bbc17e0c697219fc6fc708e333f0413c
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
122 # A sequence of nodes
123 # It is a specific class (instead of using a Array) to track the parent/child relation when nodes are added or removed
124 class ANodes[E
: ANode]
126 private var parent
: ANode
127 private var items
= new Array[E
]
128 redef fun iterator
do return items
.iterator
129 redef fun length
do return items
.length
130 redef fun is_empty
do return items
.is_empty
149 var res
= items
.shift
161 redef fun []=(index
, e
)
163 hook_remove
(self[index
])
167 redef fun remove_at
(index
)
169 hook_remove
(items
[index
])
170 items
.remove_at
(index
)
172 private fun hook_add
(e
: E
)
174 #assert e.parent == null
177 private fun hook_remove
(e
: E
)
179 assert e
.parent
== parent
183 # Used in parent constructor to fill elements
184 private fun unsafe_add_all
(nodes
: Collection[Object])
186 var parent
= self.parent
194 private fun replace_child
(old_child
: ANode, new_child
: nullable ANode): Bool
196 var parent
= self.parent
197 for i
in [0..length
[ do
198 if self[i
] == old_child
then
199 if new_child
!= null then
200 assert new_child
isa E
202 new_child
.parent
= parent
212 private fun visit_all
(v
: Visitor)
214 for n
in self do v
.enter_visit
(n
)
218 # Ancestor of all tokens
219 # A token is a node that has a `text` but no children.
223 # The raw content on the token
224 fun text
: String is abstract
226 # The raw content on the token
227 fun text
=(text
: String) is abstract
229 # The previous token in the Lexer.
230 # May have disappeared in the AST
231 var prev_token
: nullable Token = null
233 # The next token in the Lexer.
234 # May have disappeared in the AST
235 var next_token
: nullable Token = null
237 # The verbatim blank text between `prev_token` and `self`
238 fun blank_before
: String
240 if prev_token
== null then return ""
241 var from
= prev_token
.location
.pend
+1
242 var to
= location
.pstart
243 return location
.file
.string
.substring
(from
,to-from
)
246 redef fun to_s
: String do
250 redef fun visit_all
(v
: Visitor) do end
251 redef fun replace_child
(old_child
: ANode, new_child
: nullable ANode) do end
254 redef class SourceFile
255 # The first token parser by the lexer
256 # May have disappeared in the final AST
257 var first_token
: nullable Token = null
259 # The first token parser by the lexer
260 # May have disappeared in the final AST
261 var last_token
: nullable Token = null
264 # Ancestor of all productions
265 # A production is a node without text but that usually has children.
269 # All the annotations attached directly to the node
270 var n_annotations
: nullable AAnnotations = null is writable
272 redef fun replace_with
(n
: ANode)
276 if not isset n
._location
and isset _location
then n
._location
= _location
280 # Abstract standard visitor on the AST
281 abstract class Visitor
282 # What the visitor do when a node is visited
283 # Concrete visitors should implement this method.
285 protected fun visit
(e
: ANode) is abstract
287 # Ask the visitor to visit a given node.
288 # Usually automatically called by visit_all* methods.
289 # This method should not be redefined
290 fun enter_visit
(e
: nullable ANode)
292 if e
== null then return
293 var old
= _current_node
299 # The current visited node
300 var current_node
: nullable ANode = null is writable
303 # Token of end of line (basically `\n`)
312 # Token of a line of comments
313 # Starts with the `#` and contains the final end-of-line (if any)
318 # A token associated with a keyword
319 abstract class TokenKeyword
323 return "keyword '{text}'"
327 # The deprecated keyword `package`.
332 # The keyword `module`
337 # The keyword `import`
342 # The keyword `class`
347 # The keyword `abstract`
352 # The keyword `interface`
357 # The keywords `enum` ane `universal`
382 # The keyword `redef`
402 # The keyword `extern`
407 # The keyword `public`
412 # The keyword `protected`
417 # The keyword `private`
422 # The keyword `intrude`
442 # The keyword `while`
472 # The keyword `implies`
482 # The keyword `return`
487 # The keyword `continue`
492 # The keyword `break`
497 # The keyword `abort`
502 # The keyword `assert`
522 # The keyword `super`
537 # The keyword `false`
552 # The keyword `nullable`
557 # The keyword `isset`
562 # The keyword `label`
567 # The special keyword `__DEBUG__`
612 # A token associated with an operator (and other lookalike symbols)
613 abstract class TokenOperator
617 return "operator '{text}'"
731 # A class (or formal type) identifier. They start with an uppercase.
736 do return "type identifier '{text}'"
740 # A standard identifier (variable, method...). They start with a lowercase.
745 do return "identifier '{text}'"
749 # An attribute identifier. They start with an underscore.
754 do return "attribute '{text}'"
758 # A token of a literal value (string, integer, etc).
759 abstract class TokenLiteral
763 do return "literal value '{text}'"
767 # A literal decimal integer
772 # A literal hexadecimal integer
777 # A literal floating point number
782 # A literal character
792 # The starting part of a super string (between `"` and `{`)
797 # The middle part of a super string (between `}` and `{`)
802 # The final part of a super string (between `}` and `"`)
812 do return "malformed string {text}"
821 do return "malformed character {text}"
825 # A extern code block
826 class TExternCodeSegment
843 # A lexical error (unexpected character)
847 # A syntactic error (unexpected token)
852 # The main node of a Nit source-file
856 var n_moduledecl
: nullable AModuledecl = null is writable
857 var n_imports
= new ANodes[AImport](self)
858 var n_extern_code_blocks
= new ANodes[AExternCodeBlock](self)
859 var n_classdefs
= new ANodes[AClassdef](self)
862 # The declaration of the module with the documentation, name, and annotations
865 var n_doc
: nullable ADoc = null is writable
866 var n_kwredef
: nullable TKwredef = null is writable
867 var n_visibility
: AVisibility is writable, noinit
868 var n_kwmodule
: TKwmodule is writable, noinit
869 var n_name
: AModuleName is writable, noinit
872 # A import clause of a module
873 abstract class AImport
877 # A standard import clause. eg `import x`
880 var n_visibility
: AVisibility is writable, noinit
881 var n_kwimport
: TKwimport is writable, noinit
882 var n_name
: AModuleName is writable, noinit
885 # The special import clause of the kernel module. eg `import end`
888 var n_visibility
: AVisibility is writable, noinit
889 var n_kwimport
: TKwimport is writable, noinit
890 var n_kwend
: TKwend is writable, noinit
893 # A visibility modifier
895 # The public visibility is an empty production (no keyword).
897 # Note: even if some visibilities are only valid on some placse (for instance, no `protected` class or no `intrude` method)
898 # the parser has no such a restriction, therefore the semantic phases has to check that the visibilities make sense.
899 abstract class AVisibility
903 # An implicit or explicit public visibility modifier
904 class APublicVisibility
906 var n_kwpublic
: nullable TKwpublic is writable
908 # An explicit private visibility modifier
909 class APrivateVisibility
911 var n_kwprivate
: TKwprivate is writable, noinit
913 # An explicit protected visibility modifier
914 class AProtectedVisibility
916 var n_kwprotected
: TKwprotected is writable, noinit
918 # An explicit intrude visibility modifier
919 class AIntrudeVisibility
921 var n_kwintrude
: TKwintrude is writable, noinit
925 # While most definition are `AStdClassdef`
926 # There is tow special case of class definition
927 abstract class AClassdef
929 var n_propdefs
= new ANodes[APropdef](self)
932 # A standard class definition with a name, superclasses and properties
935 var n_doc
: nullable ADoc = null is writable
936 var n_kwredef
: nullable TKwredef = null is writable
937 var n_visibility
: AVisibility is writable, noinit
938 var n_classkind
: AClasskind is writable, noinit
939 var n_id
: nullable TClassid = null is writable
940 var n_formaldefs
= new ANodes[AFormaldef](self)
941 var n_extern_code_block
: nullable AExternCodeBlock = null is writable
942 var n_superclasses
= new ANodes[ASuperclass](self)
943 var n_kwend
: TKwend is writable, noinit
944 redef fun hot_location
do return n_id
.location
947 # The implicit class definition of the implicit main method
952 # The implicit class definition of the top-level methods
957 # The modifier for the kind of class (abstract, interface, etc.)
958 abstract class AClasskind
962 # A default, or concrete class modifier (just `class`)
963 class AConcreteClasskind
965 var n_kwclass
: TKwclass is writable, noinit
968 # An abstract class modifier (`abstract class`)
969 class AAbstractClasskind
971 var n_kwabstract
: TKwabstract is writable, noinit
972 var n_kwclass
: TKwclass is writable, noinit
975 # An interface class modifier (`interface`)
976 class AInterfaceClasskind
978 var n_kwinterface
: TKwinterface is writable, noinit
981 # An enum/universal class modifier (`enum class`)
984 var n_kwenum
: TKwenum is writable, noinit
987 # An extern class modifier (`extern class`)
988 class AExternClasskind
990 var n_kwextern
: TKwextern is writable, noinit
991 var n_kwclass
: nullable TKwclass = null is writable
994 # The definition of a formal generic parameter type. eg `X: Y`
997 var n_id
: TClassid is writable, noinit
998 # The bound of the parameter type
999 var n_type
: nullable AType = null is writable
1002 # A super-class. eg `super X`
1005 var n_kwsuper
: TKwsuper is writable, noinit
1006 var n_type
: AType is writable, noinit
1009 # The definition of a property
1010 abstract class APropdef
1012 var n_doc
: nullable ADoc = null is writable
1013 var n_kwredef
: nullable TKwredef = null is writable
1014 var n_visibility
: nullable AVisibility = null is writable
1017 # A definition of an attribute
1018 # For historical reason, old-syle and new-style attributes use the same `ANode` sub-class
1021 var n_kwvar
: TKwvar is writable, noinit
1023 # The identifier for a new-style attribute (null if old-style)
1024 var n_id2
: TId is writable, noinit
1026 var n_type
: nullable AType = null is writable
1028 # The initial value, if any
1029 var n_expr
: nullable AExpr = null is writable
1031 var n_block
: nullable AExpr = null is writable
1033 redef fun hot_location
1035 return n_id2
.location
1039 # A definition of all kind of method (including constructors)
1042 var n_kwmeth
: nullable TKwmeth = null is writable
1043 var n_kwinit
: nullable TKwinit = null is writable
1044 var n_kwnew
: nullable TKwnew = null is writable
1045 var n_methid
: nullable AMethid = null is writable
1046 var n_signature
: nullable ASignature = null is writable
1047 var n_block
: nullable AExpr = null is writable
1048 var n_extern_calls
: nullable AExternCalls = null is writable
1049 var n_extern_code_block
: nullable AExternCodeBlock = null is writable
1050 redef fun hot_location
1052 if n_methid
!= null then
1053 return n_methid
.location
1054 else if n_kwinit
!= null then
1055 return n_kwinit
.location
1056 else if n_kwnew
!= null then
1057 return n_kwnew
.location
1064 # The implicit main method
1065 class AMainMethPropdef
1069 # Declaration of callbacks for extern methods
1072 var n_kwimport
: TKwimport is writable, noinit
1073 var n_extern_calls
: ANodes[AExternCall] = new ANodes[AExternCall](self)
1076 # A single callback declaration
1077 abstract class AExternCall
1081 # A single callback declaration on a method
1082 abstract class APropExternCall
1086 # A single callback declaration on a method on the current receiver
1087 class ALocalPropExternCall
1088 super APropExternCall
1089 var n_methid
: AMethid is writable, noinit
1092 # A single callback declaration on a method on an explicit receiver type.
1093 class AFullPropExternCall
1094 super APropExternCall
1095 var n_type
: AType is writable, noinit
1096 var n_dot
: nullable TDot = null is writable
1097 var n_methid
: AMethid is writable, noinit
1100 # A single callback declaration on a method on a constructor
1101 class AInitPropExternCall
1102 super APropExternCall
1103 var n_type
: AType is writable, noinit
1106 # A single callback declaration on a `super` call
1107 class ASuperExternCall
1109 var n_kwsuper
: TKwsuper is writable, noinit
1112 # A single callback declaration on a cast
1113 abstract class ACastExternCall
1117 # A single callback declaration on a cast to a given type
1118 class ACastAsExternCall
1119 super ACastExternCall
1120 var n_from_type
: AType is writable, noinit
1121 var n_dot
: nullable TDot = null is writable
1122 var n_kwas
: TKwas is writable, noinit
1123 var n_to_type
: AType is writable, noinit
1126 # A single callback declaration on a cast to a nullable type
1127 class AAsNullableExternCall
1128 super ACastExternCall
1129 var n_type
: AType is writable, noinit
1130 var n_kwas
: TKwas is writable, noinit
1131 var n_kwnullable
: TKwnullable is writable, noinit
1134 # A single callback declaration on a cast to a non-nullable type
1135 class AAsNotNullableExternCall
1136 super ACastExternCall
1137 var n_type
: AType is writable, noinit
1138 var n_kwas
: TKwas is writable, noinit
1139 var n_kwnot
: TKwnot is writable, noinit
1140 var n_kwnullable
: TKwnullable is writable, noinit
1143 # A definition of a virtual type
1146 var n_kwtype
: TKwtype is writable, noinit
1147 var n_id
: TClassid is writable, noinit
1148 var n_type
: AType is writable, noinit
1151 # The identifier of a method in a method declaration.
1152 # There is a specific class because of operator and setters.
1153 abstract class AMethid
1157 # A method name with a simple identifier
1160 var n_id
: TId is writable, noinit
1166 var n_plus
: TPlus is writable, noinit
1172 var n_minus
: TMinus is writable, noinit
1178 var n_star
: TStar is writable, noinit
1181 # A method name `**`
1182 class AStarstarMethid
1184 var n_starstar
: TStarstar is writable, noinit
1190 var n_slash
: TSlash is writable, noinit
1194 class APercentMethid
1196 var n_percent
: TPercent is writable, noinit
1199 # A method name `==`
1202 var n_eq
: TEq is writable, noinit
1205 # A method name `!=`
1208 var n_ne
: TNe is writable, noinit
1211 # A method name `<=`
1214 var n_le
: TLe is writable, noinit
1217 # A method name `>=`
1220 var n_ge
: TGe is writable, noinit
1226 var n_lt
: TLt is writable, noinit
1232 var n_gt
: TGt is writable, noinit
1235 # A method name `<<`
1238 var n_ll
: TLl is writable, noinit
1241 # A method name `>>`
1244 var n_gg
: TGg is writable, noinit
1247 # A method name `[]`
1250 var n_obra
: TObra is writable, noinit
1251 var n_cbra
: TCbra is writable, noinit
1254 # A method name `<=>`
1255 class AStarshipMethid
1257 var n_starship
: TStarship is writable, noinit
1260 # A setter method name with a simple identifier (with a `=`)
1263 var n_id
: TId is writable, noinit
1264 var n_assign
: TAssign is writable, noinit
1267 # A method name `[]=`
1268 class ABraassignMethid
1270 var n_obra
: TObra is writable, noinit
1271 var n_cbra
: TCbra is writable, noinit
1272 var n_assign
: TAssign is writable, noinit
1275 # A signature in a method definition. eg `(x,y:X,z:Z):T`
1278 var n_opar
: nullable TOpar = null is writable
1279 var n_params
= new ANodes[AParam](self)
1280 var n_cpar
: nullable TCpar = null is writable
1281 var n_type
: nullable AType = null is writable
1284 # A parameter definition in a signature. eg `x:X`
1287 var n_id
: TId is writable, noinit
1288 var n_type
: nullable AType = null is writable
1289 var n_dotdotdot
: nullable TDotdotdot = null is writable
1292 # A static type. eg `nullable X[Y]`
1295 var n_kwnullable
: nullable TKwnullable = null is writable
1297 # The name of the class or of the formal type
1298 var n_id
: TClassid is writable, noinit
1300 # Type arguments for a generic type
1301 var n_types
= new ANodes[AType](self)
1304 # A label at the end of a block or in a break/continue statement. eg `label x`
1307 var n_kwlabel
: TKwlabel is writable, noinit
1308 var n_id
: nullable TId is writable
1311 # Expression and statements
1312 # From a AST point of view there is no distinction between statement and expressions (even if the parser has to distinguish them)
1313 abstract class AExpr
1317 # A sequence of `AExpr` (usually statements)
1318 # The last `AExpr` gives the value of the whole block
1321 var n_expr
= new ANodes[AExpr](self)
1322 var n_kwend
: nullable TKwend = null is writable
1325 # A declaration of a local variable. eg `var x: X = y`
1328 var n_kwvar
: TKwvar is writable, noinit
1329 var n_id
: TId is writable, noinit
1330 var n_type
: nullable AType = null is writable
1331 var n_assign
: nullable TAssign = null is writable
1333 # The initial value, if any
1334 var n_expr
: nullable AExpr = null is writable
1337 # A `return` statement. eg `return x`
1340 var n_kwreturn
: nullable TKwreturn = null is writable
1341 var n_expr
: nullable AExpr = null is writable
1344 # Something that has a label.
1345 abstract class ALabelable
1347 var n_label
: nullable ALabel = null is writable
1350 # A `break` or a `continue`
1351 abstract class AEscapeExpr
1354 var n_expr
: nullable AExpr = null is writable
1357 # A `break` statement.
1360 var n_kwbreak
: TKwbreak is writable, noinit
1363 # An `abort` statement
1366 var n_kwabort
: TKwabort is writable, noinit
1369 # A `continue` statement
1372 var n_kwcontinue
: nullable TKwcontinue = null is writable
1379 var n_kwdo
: TKwdo is writable, noinit
1380 var n_block
: nullable AExpr = null is writable
1386 var n_kwif
: TKwif is writable, noinit
1387 var n_expr
: AExpr is writable, noinit
1388 var n_then
: nullable AExpr = null is writable
1389 var n_else
: nullable AExpr = null is writable
1395 var n_kwif
: TKwif is writable, noinit
1396 var n_expr
: AExpr is writable, noinit
1397 var n_kwthen
: TKwthen is writable, noinit
1398 var n_then
: AExpr is writable, noinit
1399 var n_kwelse
: TKwelse is writable, noinit
1400 var n_else
: AExpr is writable, noinit
1403 # A `while` statement
1407 var n_kwwhile
: TKwwhile is writable, noinit
1408 var n_expr
: AExpr is writable, noinit
1409 var n_kwdo
: TKwdo is writable, noinit
1410 var n_block
: nullable AExpr = null is writable
1413 # A `loop` statement
1417 var n_kwloop
: TKwloop is writable, noinit
1418 var n_block
: nullable AExpr = null is writable
1425 var n_kwfor
: TKwfor is writable, noinit
1426 var n_ids
= new ANodes[TId](self)
1427 var n_expr
: AExpr is writable, noinit
1428 var n_kwdo
: TKwdo is writable, noinit
1429 var n_block
: nullable AExpr = null is writable
1432 # An `assert` statement
1435 var n_kwassert
: TKwassert is writable, noinit
1436 var n_id
: nullable TId = null is writable
1437 var n_expr
: AExpr is writable, noinit
1438 var n_else
: nullable AExpr = null is writable
1441 # Whatever is a simple assignment. eg `= something`
1442 abstract class AAssignFormExpr
1444 var n_assign
: TAssign is writable, noinit
1445 var n_value
: AExpr is writable, noinit
1448 # Whatever is a combined assignment. eg `+= something`
1449 abstract class AReassignFormExpr
1451 var n_assign_op
: AAssignOp is writable, noinit
1452 var n_value
: AExpr is writable, noinit
1455 # A `once` expression. eg `once x`
1458 var n_kwonce
: TKwonce is writable, noinit
1459 var n_expr
: AExpr is writable, noinit
1462 # A polymorphic invocation of a method
1463 # The form of the invocation (name, arguments, etc.) are specific
1464 abstract class ASendExpr
1466 # The receiver of the method invocation
1467 var n_expr
: AExpr is writable, noinit
1470 # A binary operation on a method
1471 abstract class ABinopExpr
1473 # The second operand of the operation
1474 # Note: the receiver (`n_expr`) is the first operand
1475 var n_expr2
: AExpr is writable, noinit
1478 # Something that is boolean expression
1479 abstract class ABoolExpr
1486 var n_expr
: AExpr is writable, noinit
1487 var n_expr2
: AExpr is writable, noinit
1490 # A `and` expression
1493 var n_expr
: AExpr is writable, noinit
1494 var n_expr2
: AExpr is writable, noinit
1497 # A `or else` expression
1500 var n_expr
: AExpr is writable, noinit
1501 var n_expr2
: AExpr is writable, noinit
1504 # A `implies` expression
1507 var n_expr
: AExpr is writable, noinit
1508 var n_expr2
: AExpr is writable, noinit
1511 # A `not` expression
1514 var n_kwnot
: TKwnot is writable, noinit
1515 var n_expr
: AExpr is writable, noinit
1558 # A type-ckeck expression. eg `x isa T`
1561 var n_expr
: AExpr is writable, noinit
1562 var n_type
: AType is writable, noinit
1575 # A `<=>` expression
1600 # A unary minus expression. eg `-x`
1603 var n_minus
: TMinus is writable, noinit
1606 # An explicit instantiation. eg `new T`
1609 var n_kwnew
: TKwnew is writable, noinit
1610 var n_type
: AType is writable, noinit
1612 # The name of the named-constructor, if any
1613 var n_id
: nullable TId = null is writable
1614 var n_args
: AExprs is writable, noinit
1617 # Whatever is a old-style attribute access
1618 abstract class AAttrFormExpr
1621 # The receiver of the attribute
1622 var n_expr
: AExpr is writable, noinit
1624 # The name of the attribute
1625 var n_id
: TAttrid is writable, noinit
1629 # The read of an attribute. eg `x._a`
1634 # The assignment of an attribute. eg `x._a=y`
1635 class AAttrAssignExpr
1637 super AAssignFormExpr
1640 # Whatever looks-like a call with a standard method and any number of arguments.
1641 abstract class ACallFormExpr
1644 # The name of the method
1645 var n_id
: TId is writable, noinit
1647 # The arguments of the call
1648 var n_args
: AExprs is writable, noinit
1651 # A complex setter call (standard or brackets)
1652 abstract class ASendReassignFormExpr
1654 super AReassignFormExpr
1657 # A complex attribute assignment. eg `x._a+=y`
1658 class AAttrReassignExpr
1660 super AReassignFormExpr
1663 # A call with a standard method-name and any number of arguments. eg `x.m(y)`. OR just a simple id
1664 # 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`.
1665 # Semantic analysis have to transform them to instance of `AVarExpr`.
1670 # A setter call with a standard method-name and any number of arguments. eg `x.m(y)=z`. OR just a simple assignment.
1671 # 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`.
1672 # Semantic analysis have to transform them to instance of `AVarAssignExpr`.
1673 class ACallAssignExpr
1675 super AAssignFormExpr
1678 # 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.
1679 # 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`.
1680 # Semantic analysis have to transform them to instance of `AVarReassignExpr`.
1681 class ACallReassignExpr
1683 super ASendReassignFormExpr
1686 # A call to `super`. OR a call of a super-constructor
1689 var n_qualified
: nullable AQualified = null is writable
1690 var n_kwsuper
: TKwsuper is writable, noinit
1691 var n_args
: AExprs is writable, noinit
1694 # A call to the `init` constructor.
1695 # Note: because `init` is a keyword and not a `TId`, the explicit call to init cannot be a `ACallFormExpr`.
1698 var n_kwinit
: TKwinit is writable, noinit
1699 var n_args
: AExprs is writable, noinit
1702 # Whatever looks-like a call of the brackets `[]` operator.
1703 abstract class ABraFormExpr
1705 var n_args
: AExprs is writable, noinit
1708 # A call of the brackets operator. eg `x[y,z]`
1713 # A setter call of the bracket operator. eg `x[y,z]=t`
1714 class ABraAssignExpr
1716 super AAssignFormExpr
1719 # Whatever is an access to a local variable
1720 abstract class AVarFormExpr
1722 var n_id
: TId is writable, noinit
1725 # A complex setter call of the bracket operator. eg `x[y,z]+=t`
1726 class ABraReassignExpr
1728 super ASendReassignFormExpr
1731 # A local variable read access.
1732 # The parser cannot instantiate them, see `ACallExpr`.
1737 # A local variable simple assignment access
1738 # The parser cannot instantiate them, see `ACallAssignExpr`.
1739 class AVarAssignExpr
1741 super AAssignFormExpr
1744 # A local variable complex assignment access
1745 # The parser cannot instantiate them, see `ACallReassignExpr`.
1746 class AVarReassignExpr
1748 super AReassignFormExpr
1751 # A literal range, open or closed
1752 abstract class ARangeExpr
1754 var n_expr
: AExpr is writable, noinit
1755 var n_expr2
: AExpr is writable, noinit
1758 # A closed literal range. eg `[x..y]`
1761 var n_obra
: TObra is writable, noinit
1762 var n_cbra
: TCbra is writable, noinit
1765 # An open literal range. eg `[x..y[`
1768 var n_obra
: TObra is writable, noinit
1769 var n_cbra
: TObra is writable, noinit
1772 # A literal array. eg. `[x,y,z]`
1775 var n_obra
: TObra is writable, noinit
1776 var n_exprs
: AExprs is writable, noinit
1777 var n_type
: nullable AType = null is writable
1778 var n_cbra
: TCbra is writable, noinit
1784 var n_kwself
: nullable TKwself is writable
1787 # When there is no explicit receiver, `self` is implicit
1788 class AImplicitSelfExpr
1792 # A `true` boolean literal constant
1795 var n_kwtrue
: TKwtrue is writable, noinit
1797 # A `false` boolean literal constant
1800 var n_kwfalse
: TKwfalse is writable, noinit
1802 # A `null` literal constant
1805 var n_kwnull
: TKwnull is writable, noinit
1807 # An integer literal
1811 # An integer literal in decimal format
1814 var n_number
: TNumber is writable, noinit
1816 # An integer literal in hexadecimal format
1819 var n_hex_number
: THexNumber is writable, noinit
1824 var n_float
: TFloat is writable, noinit
1826 # A character literal
1829 var n_char
: TChar is writable, noinit
1832 abstract class AStringFormExpr
1834 var n_string
: Token is writable, noinit
1837 # A simple string. eg. `"abc"`
1839 super AStringFormExpr
1842 # The start of a superstring. eg `"abc{`
1843 class AStartStringExpr
1844 super AStringFormExpr
1847 # The middle of a superstring. eg `}abc{`
1848 class AMidStringExpr
1849 super AStringFormExpr
1852 # The end of a superstrng. eg `}abc"`
1853 class AEndStringExpr
1854 super AStringFormExpr
1857 # A superstring literal. eg `"a{x}b{y}c"`
1858 # Each part is modeled a sequence of expression. eg. `["a{, x, }b{, y, }c"]`
1859 class ASuperstringExpr
1861 var n_exprs
= new ANodes[AExpr](self)
1864 # A simple parenthesis. eg `(x)`
1867 var n_opar
: TOpar is writable, noinit
1868 var n_expr
: AExpr is writable, noinit
1869 var n_cpar
: TCpar is writable, noinit
1872 # A type cast. eg `x.as(T)`
1875 var n_expr
: AExpr is writable, noinit
1876 var n_kwas
: TKwas is writable, noinit
1877 var n_opar
: nullable TOpar = null is writable
1878 var n_type
: AType is writable, noinit
1879 var n_cpar
: nullable TCpar = null is writable
1882 # A as-not-null cast. eg `x.as(not null)`
1883 class AAsNotnullExpr
1885 var n_expr
: AExpr is writable, noinit
1886 var n_kwas
: TKwas is writable, noinit
1887 var n_opar
: nullable TOpar = null is writable
1888 var n_kwnot
: TKwnot is writable, noinit
1889 var n_kwnull
: TKwnull is writable, noinit
1890 var n_cpar
: nullable TCpar = null is writable
1893 # A is-set check of old-style attributes. eg `isset x._a`
1894 class AIssetAttrExpr
1896 var n_kwisset
: TKwisset is writable, noinit
1899 # An ellipsis notation used to pass an expression as it, in a vararg parameter
1902 var n_expr
: AExpr is writable, noinit
1903 var n_dotdotdot
: TDotdotdot is writable, noinit
1906 # A list of expression separated with commas (arguments for instance)
1909 var n_exprs
= new ANodes[AExpr](self)
1912 # A special expression that encapsulates a static type
1913 # Can only be found in special construction like arguments of annotations.
1916 var n_type
: AType is writable, noinit
1919 # A special expression that encapsulates a method identifier
1920 # Can only be found in special construction like arguments of annotations.
1923 # The receiver, is any
1924 var n_expr
: AExpr is writable, noinit
1925 var n_id
: AMethid is writable, noinit
1928 # A special expression that encapsulate an annotation
1929 # Can only be found in special construction like arguments of annotations.
1934 # A special expression to debug types
1935 class ADebugTypeExpr
1937 var n_kwdebug
: TKwdebug is writable, noinit
1938 var n_kwtype
: TKwtype is writable, noinit
1939 var n_expr
: AExpr is writable, noinit
1940 var n_type
: AType is writable, noinit
1943 # A list of expression separated with commas (arguments for instance)
1944 abstract class AExprs
1946 var n_exprs
= new ANodes[AExpr](self)
1949 # A simple list of expressions
1954 # A list of expressions enclosed in parentheses
1957 var n_opar
: TOpar is writable, noinit
1958 var n_cpar
: TCpar is writable, noinit
1961 # A list of expressions enclosed in brackets
1964 var n_obra
: TObra is writable, noinit
1965 var n_cbra
: TCbra is writable, noinit
1968 # A complex assignment operator. (`+=` and `-=`)
1969 abstract class AAssignOp
1973 # The `+=` assignment operation
1976 var n_pluseq
: TPluseq is writable, noinit
1979 # The `-=` assignment operator
1980 class AMinusAssignOp
1982 var n_minuseq
: TMinuseq is writable, noinit
1985 # A possibly fully-qualified module identifier
1988 var n_quad
: nullable TQuad = null is writable
1989 var n_path
= new ANodes[TId](self)
1990 var n_id
: TId is writable, noinit
1993 # A language declaration for an extern block
1996 var n_kwin
: TKwin is writable, noinit
1997 var n_string
: TString is writable, noinit
2000 # An full extern block
2001 class AExternCodeBlock
2003 var n_in_language
: nullable AInLanguage = null is writable
2004 var n_extern_code_segment
: TExternCodeSegment is writable, noinit
2007 # A possible full method qualifier.
2010 var n_quad
: nullable TQuad = null is writable
2011 var n_id
= new ANodes[TId](self)
2012 var n_classid
: nullable TClassid = null is writable
2015 # A documentation of a definition
2016 # It contains the block of comments just above the declaration
2019 var n_comment
= new ANodes[TComment](self)
2022 # A group of annotation on a node
2025 var n_at
: nullable TAt = null is writable
2026 var n_opar
: nullable TOpar = null is writable
2027 var n_items
= new ANodes[AAnnotation](self)
2028 var n_cpar
: nullable TCpar = null is writable
2031 # A single annotation
2034 var n_doc
: nullable ADoc = null is writable
2035 var n_kwredef
: nullable TKwredef = null is writable
2036 var n_visibility
: nullable AVisibility is writable
2037 var n_atid
: AAtid is writable, noinit
2038 var n_opar
: nullable TOpar = null is writable
2039 var n_args
= new ANodes[AExpr](self)
2040 var n_cpar
: nullable TCpar = null is writable
2043 # An annotation name
2044 abstract class AAtid
2046 var n_id
: Token is writable, noinit
2049 # An annotation name based on an identifier
2054 # An annotation name based on the keyword `extern`
2059 # An annotation name based on the keyword `import`
2064 # An annotation name based on the keyword `abstract`
2065 class AKwabstractAtid
2069 # The root of the AST
2072 var n_base
: nullable AModule is writable
2073 var n_eof
: EOF is writable, noinit
2074 init(n_base
: nullable AModule, n_eof
: EOF)
2076 self._n_base
= n_base