1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # AST nodes of the Nit language
16 # Was previously based on parser_abs.nit.
22 # Root of the AST class-hierarchy
24 # Location is set during AST building. Once built, location cannon be null.
25 # However, manual instantiated nodes may need more care.
26 var location
: Location is writable, noinit
28 # The location of the important part of the node (identifier or whatever)
29 fun hot_location
: Location do return location
31 # Display a message for the colored location of the node
32 fun debug
(message
: String)
34 sys
.stderr
.write
"{hot_location} {self.class_name}: {message}\n{hot_location.colored_line("0;32")}\n"
37 # Write the subtree on stdout.
43 d
.write_to
(sys
.stdout
)
46 # Parent of the node in the AST
47 var parent
: nullable ANode = null
49 # The topmost ancestor of the element
50 # This just apply `parent` until the first one
56 if p
== null then return res
61 # The most specific common parent between `self` and `other`
62 # Return null if the two node are unrelated (distinct root)
63 fun common_parent
(other
: ANode): nullable ANode
65 # First, get the same depth
66 var s
: nullable ANode = self
67 var o
: nullable ANode = other
68 var d
= s
.depth
- o
.depth
77 assert o
.depth
== s
.depth
78 # Second, go up until same in found
86 # Number of nodes between `self` and the `root` of the AST
87 # ENSURE `self == self.root implies result == 0 `
88 # ENSURE `self != self.root implies result == self.parent.depth + 1`
95 if p
== null then return res
101 # Replace a child with an other node in the AST
102 private fun replace_child
(old_child
: ANode, new_child
: nullable ANode) is abstract
104 # Detach a node from its parent
105 # Aborts if the node is not detachable. use `replace_with` instead
106 # REQUIRE: parent != null
107 # REQUIRE: is_detachable
108 # ENDURE: parent == null
111 assert parent
!= null
112 parent
.replace_child
(self, null)
116 # Replace itself with an other node in the AST
117 # REQUIRE: parent != null
118 # ENSURE: node.parent == old(parent)
119 # ENSURE: parent == null
120 fun replace_with
(node
: ANode)
122 assert parent
!= null
123 parent
.replace_child
(self, node
)
127 # Visit all nodes in order.
128 # Thus, call `v.enter_visit(e)` for each child `e`
129 fun visit_all
(v
: Visitor) is abstract
131 # Do a deep search and return an array of tokens that match a given text
132 fun collect_tokens_by_text
(text
: String): Array[Token]
134 var v
= new CollectTokensByTextVisitor(text
)
139 # Do a deep search and return an array of node that are annotated
140 # The attached node can be retrieved by two invocations of parent
141 fun collect_annotations_by_name
(name
: String): Array[AAnnotation]
143 var v
= new CollectAnnotationsByNameVisitor(name
)
149 private class CollectTokensByTextVisitor
152 var result
= new Array[Token]
153 redef fun visit
(node
)
156 if node
isa Token and node
.text
== text
then result
.add
(node
)
160 private class CollectAnnotationsByNameVisitor
163 var result
= new Array[AAnnotation]
164 redef fun visit
(node
)
167 if node
isa AAnnotation and node
.n_atid
.n_id
.text
== name
then result
.add
(node
)
171 # A helper class to handle (print) Nit AST as an OrderedTree
174 super OrderedTree[ANode]
176 # Reference to the last parent in the Ordered Tree
177 # Is used to handle the initial node parent and workaround possible inconsistent `ANode::parent`
178 private var last_parent
: nullable ANode = null
192 return "{n.class_name} \"{n.text.escape_to_c}\
" @{n.location}"
194 return "{n.class_name} @{n.location}"
199 # A sequence of nodes
200 # It is a specific class (instead of using a Array) to track the parent/child relation when nodes are added or removed
201 class ANodes[E
: ANode]
203 private var parent
: ANode
204 private var items
= new Array[E
]
205 redef fun iterator
do return items
.iterator
206 redef fun length
do return items
.length
207 redef fun is_empty
do return items
.is_empty
226 var res
= items
.shift
238 redef fun []=(index
, e
)
240 hook_remove
(self[index
])
244 redef fun remove_at
(index
)
246 hook_remove
(items
[index
])
247 items
.remove_at
(index
)
249 private fun hook_add
(e
: E
)
251 #assert e.parent == null
254 private fun hook_remove
(e
: E
)
256 assert e
.parent
== parent
260 # Used in parent constructor to fill elements
261 private fun unsafe_add_all
(nodes
: Collection[Object])
263 var parent
= self.parent
271 private fun replace_child
(old_child
: ANode, new_child
: nullable ANode): Bool
273 var parent
= self.parent
274 for i
in [0..length
[ do
275 if self[i
] == old_child
then
276 if new_child
!= null then
277 assert new_child
isa E
279 new_child
.parent
= parent
289 private fun visit_all
(v
: Visitor)
291 for n
in self do v
.enter_visit
(n
)
295 # Ancestor of all tokens
296 # A token is a node that has a `text` but no children.
300 # The raw content on the token
301 fun text
: String is abstract
303 # The raw content on the token
304 fun text
=(text
: String) is abstract
306 # The previous token in the Lexer.
307 # May have disappeared in the AST
308 var prev_token
: nullable Token = null
310 # The next token in the Lexer.
311 # May have disappeared in the AST
312 var next_token
: nullable Token = null
314 # The verbatim blank text between `prev_token` and `self`
315 fun blank_before
: String
317 if prev_token
== null then return ""
318 var from
= prev_token
.location
.pend
+1
319 var to
= location
.pstart
320 return location
.file
.string
.substring
(from
,to-from
)
323 redef fun to_s
: String do
327 redef fun visit_all
(v
: Visitor) do end
328 redef fun replace_child
(old_child
: ANode, new_child
: nullable ANode) do end
331 redef class SourceFile
332 # The first token parser by the lexer
333 # May have disappeared in the final AST
334 var first_token
: nullable Token = null
336 # The first token parser by the lexer
337 # May have disappeared in the final AST
338 var last_token
: nullable Token = null
341 # Ancestor of all productions
342 # A production is a node without text but that usually has children.
346 # All the annotations attached directly to the node
347 var n_annotations
: nullable AAnnotations = null is writable
349 # Return all its annotations of a given name in the order of their declaration
350 # Retun an empty array if no such an annotation.
351 fun get_annotations
(name
: String): Array[AAnnotation]
353 var res
= new Array[AAnnotation]
354 var nas
= n_annotations
355 if nas
!= null then for na
in nas
.n_items
do
356 if na
.name
!= name
then continue
359 if self isa AClassdef then for na
in n_propdefs
do
360 if na
isa AAnnotPropdef then
361 if na
.name
!= name
then continue
369 redef fun replace_with
(n
: ANode)
373 if not isset n
._location
and isset _location
then n
._location
= _location
377 # Abstract standard visitor on the AST
378 abstract class Visitor
379 # What the visitor do when a node is visited
380 # Concrete visitors should implement this method.
382 protected fun visit
(e
: ANode) is abstract
384 # Ask the visitor to visit a given node.
385 # Usually automatically called by visit_all* methods.
386 # This method should not be redefined
387 fun enter_visit
(e
: nullable ANode)
389 if e
== null then return
390 var old
= _current_node
396 # The current visited node
397 var current_node
: nullable ANode = null is writable
400 # Token of end of line (basically `\n`)
409 # Token of a line of comments
410 # Starts with the `#` and contains the final end-of-line (if any)
415 # A token associated with a keyword
416 abstract class TokenKeyword
420 return "keyword '{text}'"
424 # The deprecated keyword `package`.
429 # The keyword `module`
434 # The keyword `import`
439 # The keyword `class`
444 # The keyword `abstract`
449 # The keyword `interface`
454 # The keywords `enum` ane `universal`
479 # The keyword `redef`
499 # The keyword `extern`
504 # The keyword `public`
509 # The keyword `protected`
514 # The keyword `private`
519 # The keyword `intrude`
539 # The keyword `while`
569 # The keyword `implies`
579 # The keyword `return`
584 # The keyword `continue`
589 # The keyword `break`
594 # The keyword `abort`
599 # The keyword `assert`
619 # The keyword `super`
634 # The keyword `false`
649 # The keyword `nullable`
654 # The keyword `isset`
659 # The keyword `label`
669 # The special keyword `__DEBUG__`
714 # A token associated with an operator (and other lookalike symbols)
715 abstract class TokenOperator
719 return "operator '{text}'"
903 # A class (or formal type) identifier. They start with an uppercase.
908 do return "type identifier '{text}'"
912 # A standard identifier (variable, method...). They start with a lowercase.
917 do return "identifier '{text}'"
921 # An attribute identifier. They start with an underscore.
926 do return "attribute '{text}'"
930 # A token of a literal value (string, integer, etc).
931 abstract class TokenLiteral
935 do return "literal value '{text}'"
939 # A literal decimal integer
944 # A literal hexadecimal integer
949 # A literal floating point number
954 # A literal character
964 # The starting part of a super string (between `"` and `{`)
969 # The middle part of a super string (between `}` and `{`)
974 # The final part of a super string (between `}` and `"`)
984 do return "malformed string {text}"
993 do return "malformed character {text}"
997 # A extern code block
998 class TExternCodeSegment
1007 return "end of file"
1011 # A mark of an error
1015 # A lexical error (unexpected character)
1019 # A syntactic error (unexpected token)
1024 # The main node of a Nit source-file
1028 # The declaration part of the module
1029 var n_moduledecl
: nullable AModuledecl = null is writable
1031 # List of importation clauses
1032 var n_imports
= new ANodes[AImport](self)
1034 # List of extern blocks
1035 var n_extern_code_blocks
= new ANodes[AExternCodeBlock](self)
1037 # List of class definition (including top-level methods and the main)
1038 var n_classdefs
= new ANodes[AClassdef](self)
1041 # Abstract class for definition of entities
1042 abstract class ADefinition
1045 var n_doc
: nullable ADoc = null is writable
1047 # The `redef` keyword
1048 var n_kwredef
: nullable TKwredef = null is writable
1050 # The declared visibility
1051 var n_visibility
: nullable AVisibility = null is writable
1054 # The declaration of the module with the documentation, name, and annotations
1058 # The `module` keyword
1059 var n_kwmodule
: TKwmodule is writable, noinit
1061 # The declared module name
1062 var n_name
: AModuleName is writable, noinit
1065 # A import clause of a module
1066 abstract class AImport
1069 # The declared visibility
1070 var n_visibility
: AVisibility is writable, noinit
1072 # The `import` keyword
1073 var n_kwimport
: TKwimport is writable, noinit
1076 # A standard import clause. eg `import x`
1079 # The imported module name
1080 var n_name
: AModuleName is writable, noinit
1083 # The special import clause of the kernel module. eg `import end`
1086 # The `end` keyword, that indicate the root module
1087 var n_kwend
: TKwend is writable, noinit
1090 # A visibility modifier
1092 # The public visibility is an empty production (no keyword).
1094 # Note: even if some visibilities are only valid on some placse (for instance, no `protected` class or no `intrude` method)
1095 # the parser has no such a restriction, therefore the semantic phases has to check that the visibilities make sense.
1096 abstract class AVisibility
1100 # An implicit or explicit public visibility modifier
1101 class APublicVisibility
1103 # The `public` keyword, if any
1104 var n_kwpublic
: nullable TKwpublic is writable
1106 # An explicit private visibility modifier
1107 class APrivateVisibility
1109 # The `private` keyword
1110 var n_kwprivate
: TKwprivate is writable, noinit
1112 # An explicit protected visibility modifier
1113 class AProtectedVisibility
1115 # The `protected` keyword
1116 var n_kwprotected
: TKwprotected is writable, noinit
1118 # An explicit intrude visibility modifier
1119 class AIntrudeVisibility
1121 # The `intrude` keyword
1122 var n_kwintrude
: TKwintrude is writable, noinit
1125 # A class definition
1126 # While most definition are `AStdClassdef`
1127 # There is tow special case of class definition
1128 abstract class AClassdef
1130 # All the declared properties (including the main method)
1131 var n_propdefs
= new ANodes[APropdef](self)
1134 # A standard class definition with a name, superclasses and properties
1139 # The class kind (interface, abstract class, etc.)
1140 var n_classkind
: AClasskind is writable, noinit
1142 # The name of the class
1143 var n_id
: nullable TClassid = null is writable
1146 var n_obra
: nullable TObra = null is writable
1148 # The list of formal parameter types
1149 var n_formaldefs
= new ANodes[AFormaldef](self)
1152 var n_cbra
: nullable TCbra = null is writable
1154 # The extern block code
1155 var n_extern_code_block
: nullable AExternCodeBlock = null is writable
1158 var n_kwend
: TKwend is writable, noinit
1160 fun n_superclasses
: Array[ASuperPropdef] do
1161 return [for d
in n_propdefs
do if d
isa ASuperPropdef then d
]
1164 redef fun hot_location
do return n_id
.location
1167 # The implicit class definition of the implicit main method
1172 # The implicit class definition of the top-level methods
1177 # The modifier for the kind of class (abstract, interface, etc.)
1178 abstract class AClasskind
1182 # A default, or concrete class modifier (just `class`)
1183 class AConcreteClasskind
1186 # The `class` keyword.
1187 var n_kwclass
: TKwclass is writable, noinit
1190 # An abstract class modifier (`abstract class`)
1191 class AAbstractClasskind
1194 # The `abstract` keyword.
1195 var n_kwabstract
: TKwabstract is writable, noinit
1197 # The `class` keyword.
1198 var n_kwclass
: TKwclass is writable, noinit
1201 # An interface class modifier (`interface`)
1202 class AInterfaceClasskind
1205 # The `interface` keyword.
1206 var n_kwinterface
: TKwinterface is writable, noinit
1209 # An enum/universal class modifier (`enum class`)
1210 class AEnumClasskind
1213 # The `enum` keyword.
1214 var n_kwenum
: TKwenum is writable, noinit
1217 # An extern class modifier (`extern class`)
1218 class AExternClasskind
1221 # The `extern` keyword.
1222 var n_kwextern
: TKwextern is writable, noinit
1224 # The `class` keyword.
1225 var n_kwclass
: nullable TKwclass = null is writable
1228 # The definition of a formal generic parameter type. eg `X: Y`
1232 # The name of the parameter type
1233 var n_id
: TClassid is writable, noinit
1235 # The bound of the parameter type
1236 var n_type
: nullable AType = null is writable
1239 # The definition of a property
1240 abstract class APropdef
1244 # A definition of an attribute
1245 # For historical reason, old-syle and new-style attributes use the same `ANode` sub-class
1250 var n_kwvar
: TKwvar is writable, noinit
1252 # The identifier for a new-style attribute
1253 var n_id2
: TId is writable, noinit
1255 # The declared type of the attribute
1256 var n_type
: nullable AType = null is writable
1259 var n_assign
: nullable TAssign = null is writable
1261 # The initial value, if any (set with `=`)
1262 var n_expr
: nullable AExpr = null is writable
1265 var n_kwdo
: nullable TKwdo = null is writable
1267 # The initial value, if any (set with `do return`)
1268 var n_block
: nullable AExpr = null is writable
1271 var n_kwend
: nullable TKwend = null is writable
1273 redef fun hot_location
1275 return n_id2
.location
1279 # A definition of all kind of method (including constructors)
1283 # The `fun` keyword, if any
1284 var n_kwmeth
: nullable TKwmeth = null is writable
1286 # The `init` keyword, if any
1287 var n_kwinit
: nullable TKwinit = null is writable
1289 # The `new` keyword, if any
1290 var n_kwnew
: nullable TKwnew = null is writable
1292 # The name of the method, if any
1293 var n_methid
: nullable AMethid = null is writable
1295 # The signature of the method, if any
1296 var n_signature
: nullable ASignature = null is writable
1299 var n_kwdo
: nullable TKwdo = null is writable
1301 # The body (in Nit) of the method, if any
1302 var n_block
: nullable AExpr = null is writable
1305 var n_kwend
: nullable TKwend = null is writable
1307 # The list of declared callbacks (for extern methods)
1308 var n_extern_calls
: nullable AExternCalls = null is writable
1310 # The body (in extern code) of the method, if any
1311 var n_extern_code_block
: nullable AExternCodeBlock = null is writable
1313 redef fun hot_location
1315 if n_methid
!= null then
1316 return n_methid
.location
1317 else if n_kwinit
!= null then
1318 return n_kwinit
.location
1319 else if n_kwnew
!= null then
1320 return n_kwnew
.location
1327 # The implicit main method
1328 class AMainMethPropdef
1337 # A super-class. eg `super X`
1342 var n_kwsuper
: TKwsuper is writable, noinit
1344 # The super-class (indicated as a type)
1345 var n_type
: AType is writable, noinit
1349 # Declaration of callbacks for extern methods
1353 # The `import` keyword
1354 var n_kwimport
: TKwimport is writable, noinit
1356 # The list of declared callbacks
1357 var n_extern_calls
: ANodes[AExternCall] = new ANodes[AExternCall](self)
1360 # A single callback declaration
1361 abstract class AExternCall
1365 # A single callback declaration on a method
1366 abstract class APropExternCall
1370 # A single callback declaration on a method on the current receiver
1371 class ALocalPropExternCall
1372 super APropExternCall
1374 # The name of the called-back method
1375 var n_methid
: AMethid is writable, noinit
1378 # A single callback declaration on a method on an explicit receiver type.
1379 class AFullPropExternCall
1380 super APropExternCall
1382 # The type of the receiver of the called-back method
1383 var n_type
: AType is writable, noinit
1386 var n_dot
: nullable TDot = null is writable
1388 # The name of the called-back method
1389 var n_methid
: AMethid is writable, noinit
1392 # A single callback declaration on a method on a constructor
1393 class AInitPropExternCall
1394 super APropExternCall
1396 # The allocated type
1397 var n_type
: AType is writable, noinit
1400 # A single callback declaration on a `super` call
1401 class ASuperExternCall
1404 # The `super` keyword
1405 var n_kwsuper
: TKwsuper is writable, noinit
1408 # A single callback declaration on a cast
1409 abstract class ACastExternCall
1413 # A single callback declaration on a cast to a given type
1414 class ACastAsExternCall
1415 super ACastExternCall
1417 # The origin type of the cast
1418 var n_from_type
: AType is writable, noinit
1421 var n_dot
: nullable TDot = null is writable
1424 var n_kwas
: TKwas is writable, noinit
1426 # The destination of the cast
1427 var n_to_type
: AType is writable, noinit
1430 # A single callback declaration on a cast to a nullable type
1431 class AAsNullableExternCall
1432 super ACastExternCall
1434 # The origin type to cast as nullable
1435 var n_type
: AType is writable, noinit
1438 var n_kwas
: TKwas is writable, noinit
1440 # The `nullable` keyword
1441 var n_kwnullable
: TKwnullable is writable, noinit
1444 # A single callback declaration on a cast to a non-nullable type
1445 class AAsNotNullableExternCall
1446 super ACastExternCall
1448 # The destination type on a cast to not nullable
1449 var n_type
: AType is writable, noinit
1452 var n_kwas
: TKwas is writable, noinit
1455 var n_kwnot
: TKwnot is writable, noinit
1457 # The `nullable` keyword
1458 var n_kwnullable
: TKwnullable is writable, noinit
1461 # A definition of a virtual type
1465 # The `type` keyword
1466 var n_kwtype
: TKwtype is writable, noinit
1468 # The name of the virtual type
1469 var n_id
: TClassid is writable, noinit
1471 # The bound of the virtual type
1472 var n_type
: AType is writable, noinit
1475 # The identifier of a method in a method declaration.
1476 # There is a specific class because of operator and setters.
1477 abstract class AMethid
1481 # A method name with a simple identifier
1485 # The simple identifier
1486 var n_id
: TId is writable, noinit
1489 # A method name for an operator
1490 class AOperatorMethid
1493 # The associated operator symbol
1494 var n_op
: Token is writable, noinit
1498 super AOperatorMethid
1503 super AOperatorMethid
1508 super AOperatorMethid
1511 # A method name `**`
1512 class AStarstarMethid
1513 super AOperatorMethid
1518 super AOperatorMethid
1522 class APercentMethid
1523 super AOperatorMethid
1528 super AOperatorMethid
1533 super AOperatorMethid
1538 super AOperatorMethid
1543 super AOperatorMethid
1546 # A method name `==`
1548 super AOperatorMethid
1551 # A method name `!=`
1553 super AOperatorMethid
1556 # A method name `<=`
1558 super AOperatorMethid
1561 # A method name `>=`
1563 super AOperatorMethid
1568 super AOperatorMethid
1573 super AOperatorMethid
1576 # A method name `<<`
1578 super AOperatorMethid
1581 # A method name `>>`
1583 super AOperatorMethid
1586 # A method name `<=>`
1587 class AStarshipMethid
1588 super AOperatorMethid
1591 # A method name `[]`
1596 var n_obra
: TObra is writable, noinit
1599 var n_cbra
: TCbra is writable, noinit
1602 # A setter method name with a simple identifier (with a `=`)
1606 # The base identifier
1607 var n_id
: TId is writable, noinit
1610 var n_assign
: TAssign is writable, noinit
1613 # A method name `[]=`
1614 class ABraassignMethid
1618 var n_obra
: TObra is writable, noinit
1621 var n_cbra
: TCbra is writable, noinit
1624 var n_assign
: TAssign is writable, noinit
1627 # A signature in a method definition. eg `(x,y:X,z:Z):T`
1632 var n_opar
: nullable TOpar = null is writable
1634 # The list of parameters
1635 var n_params
= new ANodes[AParam](self)
1638 var n_cpar
: nullable TCpar = null is writable
1641 var n_type
: nullable AType = null is writable
1644 # A parameter definition in a signature. eg `x:X`
1648 # The name of the parameter
1649 var n_id
: TId is writable, noinit
1651 # The type of the parameter, if any
1652 var n_type
: nullable AType = null is writable
1654 # The `...` symbol to indicate varargs
1655 var n_dotdotdot
: nullable TDotdotdot = null is writable
1658 # A static type. eg `nullable X[Y]`
1661 # The `nullable` keyword
1662 var n_kwnullable
: nullable TKwnullable = null is writable
1664 # The name of the class or of the formal type
1665 var n_id
: TClassid is writable, noinit
1667 # The opening bracket
1668 var n_obra
: nullable TObra = null is writable
1670 # Type arguments for a generic type
1671 var n_types
= new ANodes[AType](self)
1673 # The closing bracket
1674 var n_cbra
: nullable TCbra = null is writable
1677 # A label at the end of a block or in a break/continue statement. eg `label x`
1681 # The `label` keyword
1682 var n_kwlabel
: TKwlabel is writable, noinit
1684 # The name of the label, if any
1685 var n_id
: nullable TId is writable, noinit
1688 # Expression and statements
1689 # From a AST point of view there is no distinction between statement and expressions (even if the parser has to distinguish them)
1690 abstract class AExpr
1694 # A sequence of `AExpr` (usually statements)
1695 # The last `AExpr` gives the value of the whole block
1699 # The list of statements in the bloc.
1700 # The last element is often considered as an expression that give the value of the whole block.
1701 var n_expr
= new ANodes[AExpr](self)
1704 var n_kwend
: nullable TKwend = null is writable
1707 # A declaration of a local variable. eg `var x: X = y`
1712 var n_kwvar
: nullable TKwvar = null is writable
1714 # The name of the local variable
1715 var n_id
: TId is writable, noinit
1717 # The declaration type of the local variable
1718 var n_type
: nullable AType = null is writable
1720 # The `=` symbol (for the initial value)
1721 var n_assign
: nullable TAssign = null is writable
1723 # The initial value, if any
1724 var n_expr
: nullable AExpr = null is writable
1727 # A `return` statement. eg `return x`
1731 # The `return` keyword
1732 var n_kwreturn
: nullable TKwreturn = null is writable
1734 # The return value, if any
1735 var n_expr
: nullable AExpr = null is writable
1738 # Something that has a label.
1739 abstract class ALabelable
1742 # The associated label declatation
1743 var n_label
: nullable ALabel = null is writable
1746 # A `break` or a `continue`
1747 abstract class AEscapeExpr
1751 # The return value, if nay (unused currently)
1752 var n_expr
: nullable AExpr = null is writable
1755 # A `break` statement.
1759 # The `break` keyword
1760 var n_kwbreak
: TKwbreak is writable, noinit
1763 # An `abort` statement
1767 # The `abort` keyword
1768 var n_kwabort
: TKwabort is writable, noinit
1771 # A `continue` statement
1775 # The `continue` keyword.
1776 var n_kwcontinue
: nullable TKwcontinue = null is writable
1785 var n_kwdo
: TKwdo is writable, noinit
1787 # The list of statements of the `do`.
1788 var n_block
: nullable AExpr = null is writable
1796 var n_kwif
: TKwif is writable, noinit
1798 # The expression used as the condition of the `if`
1799 var n_expr
: AExpr is writable, noinit
1801 # The `then` keyword
1802 var n_kwthen
: TKwthen is writable, noinit
1804 # The body of the `then` part
1805 var n_then
: nullable AExpr = null is writable
1807 # The `else` keyword
1808 var n_kwelse
: nullable TKwelse = null is writable
1810 # The body of the `else` part
1811 var n_else
: nullable AExpr = null is writable
1814 # A `if` expression (ternary conditional). eg. `if true then 1 else 0`
1819 var n_kwif
: TKwif is writable, noinit
1821 # The expression used as the condition of the `if`
1822 var n_expr
: AExpr is writable, noinit
1824 # The `then` keyword
1825 var n_kwthen
: TKwthen is writable, noinit
1827 # The expression in the `then` part
1828 var n_then
: AExpr is writable, noinit
1830 # The `else` keyword
1831 var n_kwelse
: TKwelse is writable, noinit
1833 # The expression in the `else` part
1834 var n_else
: AExpr is writable, noinit
1837 # A `while` statement
1842 # The `while` keyword
1843 var n_kwwhile
: TKwwhile is writable, noinit
1845 # The expression used as the condition of the `while`
1846 var n_expr
: AExpr is writable, noinit
1849 var n_kwdo
: TKwdo is writable, noinit
1851 # The body of the loop
1852 var n_block
: nullable AExpr = null is writable
1855 # A `loop` statement
1860 # The `loop` keyword
1861 var n_kwloop
: TKwloop is writable, noinit
1863 # The body of the loop
1864 var n_block
: nullable AExpr = null is writable
1873 var n_kwfor
: TKwfor is writable, noinit
1875 # The list of name of the automatic variables
1876 var n_ids
= new ANodes[TId](self)
1879 var n_kwin
: TKwin is writable, noinit
1881 # The expression used as the collection to iterate on
1882 var n_expr
: AExpr is writable, noinit
1885 var n_kwdo
: TKwdo is writable, noinit
1887 # The body of the loop
1888 var n_block
: nullable AExpr = null is writable
1891 # A `with` statement
1896 # The `with` keyword
1897 var n_kwwith
: TKwwith is writable, noinit
1899 # The expression used to get the value to control
1900 var n_expr
: AExpr is writable, noinit
1903 var n_kwdo
: TKwdo is writable, noinit
1905 # The body of the loop
1906 var n_block
: nullable AExpr = null is writable
1909 # An `assert` statement
1913 # The `assert` keyword
1914 var n_kwassert
: TKwassert is writable, noinit
1916 # The name of the assert, if any
1917 var n_id
: nullable TId = null is writable
1919 # The expression used as the condition of the `assert`
1920 var n_expr
: AExpr is writable, noinit
1922 # The `else` keyword
1923 var n_kwelse
: nullable TKwelse = null is writable
1925 # The body to execute when the assert fails
1926 var n_else
: nullable AExpr = null is writable
1929 # Whatever is a simple assignment. eg `= something`
1930 abstract class AAssignFormExpr
1934 var n_assign
: TAssign is writable, noinit
1936 # The right-value to assign.
1937 var n_value
: AExpr is writable, noinit
1940 # Whatever is a combined assignment. eg `+= something`
1941 abstract class AReassignFormExpr
1944 # The combined operator (eg. `+=`)
1945 var n_assign_op
: AAssignOp is writable, noinit
1947 # The right-value to apply on the combined operator.
1948 var n_value
: AExpr is writable, noinit
1951 # A `once` expression. eg `once x`
1955 # The `once` keyword
1956 var n_kwonce
: TKwonce is writable, noinit
1958 # The expression to evaluate only one time
1959 var n_expr
: AExpr is writable, noinit
1962 # A polymorphic invocation of a method
1963 # The form of the invocation (name, arguments, etc.) are specific
1964 abstract class ASendExpr
1966 # The receiver of the method invocation
1967 var n_expr
: AExpr is writable, noinit
1970 # A binary operation on a method
1971 abstract class ABinopExpr
1975 var n_op
: Token is writable, noinit
1977 # The second operand of the operation
1978 # Note: the receiver (`n_expr`) is the first operand
1979 var n_expr2
: AExpr is writable, noinit
1981 # The name of the operator (eg '+')
1982 fun operator
: String is abstract
1985 # Something that is boolean expression
1986 abstract class ABoolExpr
1990 # Something that is binary boolean expression
1991 abstract class ABinBoolExpr
1994 # The first boolean operand
1995 var n_expr
: AExpr is writable, noinit
1998 var n_op
: Token is writable, noinit
2000 # The second boolean operand
2001 var n_expr2
: AExpr is writable, noinit
2009 # A `and` expression
2014 # A `or else` expression
2018 # The `else` keyword
2019 var n_kwelse
: TKwelse is writable, noinit
2022 # A `implies` expression
2027 # A `not` expression
2032 var n_kwnot
: TKwnot is writable, noinit
2034 # The boolean operand of the `not`
2035 var n_expr
: AExpr is writable, noinit
2041 redef fun operator
do return "=="
2047 redef fun operator
do return "!="
2053 redef fun operator
do return "<"
2059 redef fun operator
do return "<="
2065 redef fun operator
do return "<<"
2071 redef fun operator
do return ">"
2077 redef fun operator
do return ">="
2083 redef fun operator
do return ">>"
2086 # A type-ckeck expression. eg `x isa T`
2090 # The expression to check
2091 var n_expr
: AExpr is writable, noinit
2094 var n_kwisa
: TKwisa is writable, noinit
2096 # The destination type to check to
2097 var n_type
: AType is writable, noinit
2103 redef fun operator
do return "+"
2109 redef fun operator
do return "-"
2112 # A `<=>` expression
2115 redef fun operator
do return "<=>"
2121 redef fun operator
do return "*"
2127 redef fun operator
do return "**"
2133 redef fun operator
do return "/"
2139 redef fun operator
do return "%"
2145 redef fun operator
do return "|"
2151 redef fun operator
do return "^"
2157 redef fun operator
do return "&"
2160 # A unary operation on a method
2165 var n_op
: Token is writable, noinit
2167 # The name of the operator (eg '+')
2168 fun operator
: String is abstract
2171 # A unary minus expression. eg `-x`
2174 redef fun operator
do return "-"
2177 # A unary plus expression. eg `+x`
2180 redef fun operator
do return "+"
2183 # A unary `~` expression
2186 redef fun operator
do return "~"
2189 # An explicit instantiation. eg `new T`
2194 var n_kwnew
: TKwnew is writable, noinit
2196 # The `type` keyword
2197 var n_type
: AType is writable, noinit
2199 # The name of the named-constructor, if any
2200 var n_id
: nullable TId = null is writable
2202 # The arguments of the `new`
2203 var n_args
: AExprs is writable, noinit
2206 # Whatever is a old-style attribute access
2207 abstract class AAttrFormExpr
2210 # The receiver of the attribute
2211 var n_expr
: AExpr is writable, noinit
2213 # The name of the attribute
2214 var n_id
: TAttrid is writable, noinit
2218 # The read of an attribute. eg `x._a`
2223 # The assignment of an attribute. eg `x._a=y`
2224 class AAttrAssignExpr
2226 super AAssignFormExpr
2229 # Whatever looks-like a call with a standard method and any number of arguments.
2230 abstract class ACallFormExpr
2233 # The name of the method
2234 var n_id
: TId is writable, noinit
2236 # The arguments of the call
2237 var n_args
: AExprs is writable, noinit
2240 # A complex setter call (standard or brackets)
2241 abstract class ASendReassignFormExpr
2243 super AReassignFormExpr
2246 # A complex attribute assignment. eg `x._a+=y`
2247 class AAttrReassignExpr
2249 super AReassignFormExpr
2252 # A call with a standard method-name and any number of arguments. eg `x.m(y)`. OR just a simple id
2253 # 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`.
2254 # Semantic analysis have to transform them to instance of `AVarExpr`.
2259 # A setter call with a standard method-name and any number of arguments. eg `x.m(y)=z`. OR just a simple assignment.
2260 # 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`.
2261 # Semantic analysis have to transform them to instance of `AVarAssignExpr`.
2262 class ACallAssignExpr
2264 super AAssignFormExpr
2267 # 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.
2268 # 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`.
2269 # Semantic analysis have to transform them to instance of `AVarReassignExpr`.
2270 class ACallReassignExpr
2272 super ASendReassignFormExpr
2275 # A call to `super`. OR a call of a super-constructor
2279 # The qualifier part before the super (currenlty unused)
2280 var n_qualified
: nullable AQualified = null is writable
2282 # The `super` keyword
2283 var n_kwsuper
: TKwsuper is writable, noinit
2285 # The arguments of the super
2286 var n_args
: AExprs is writable, noinit
2289 # A call to the `init` constructor.
2290 # Note: because `init` is a keyword and not a `TId`, the explicit call to init cannot be a `ACallFormExpr`.
2294 # The `init` keyword
2295 var n_kwinit
: TKwinit is writable, noinit
2297 # The arguments of the init
2298 var n_args
: AExprs is writable, noinit
2301 # Whatever looks-like a call of the brackets `[]` operator.
2302 abstract class ABraFormExpr
2305 # The arguments inside the brackets
2306 var n_args
: AExprs is writable, noinit
2309 # A call of the brackets operator. eg `x[y,z]`
2314 # A setter call of the bracket operator. eg `x[y,z]=t`
2315 class ABraAssignExpr
2317 super AAssignFormExpr
2320 # Whatever is an access to a local variable
2321 abstract class AVarFormExpr
2324 # The name of the attribute
2325 var n_id
: TId is writable, noinit
2328 # A complex setter call of the bracket operator. eg `x[y,z]+=t`
2329 class ABraReassignExpr
2331 super ASendReassignFormExpr
2334 # A local variable read access.
2335 # The parser cannot instantiate them, see `ACallExpr`.
2340 # A local variable simple assignment access
2341 # The parser cannot instantiate them, see `ACallAssignExpr`.
2342 class AVarAssignExpr
2344 super AAssignFormExpr
2347 # A local variable complex assignment access
2348 # The parser cannot instantiate them, see `ACallReassignExpr`.
2349 class AVarReassignExpr
2351 super AReassignFormExpr
2354 # A literal range, open or closed
2355 abstract class ARangeExpr
2358 # The left (lower) element of the range
2359 var n_expr
: AExpr is writable, noinit
2362 var n_dotdot
: TDotdot is writable, noinit
2364 # The right (upper) element of the range
2365 var n_expr2
: AExpr is writable, noinit
2368 # A closed literal range. eg `[x..y]`
2372 # The opening bracket `[`
2373 var n_obra
: TObra is writable, noinit
2375 # The closing bracket `]`
2376 var n_cbra
: TCbra is writable, noinit
2379 # An open literal range. eg `[x..y[`
2383 # The opening bracket `[`
2384 var n_obra
: TObra is writable, noinit
2386 # The closing bracket `[` (because open range)
2387 var n_cbra
: TObra is writable, noinit
2390 # A literal array. eg. `[x,y,z]`
2394 # The opening bracket `[`
2395 var n_obra
: TObra is writable, noinit
2397 # The elements of the array
2398 var n_exprs
= new ANodes[AExpr](self)
2400 # The type of the element of the array (if any)
2401 var n_type
: nullable AType = null is writable
2403 # The closing bracket `]`
2404 var n_cbra
: TCbra is writable, noinit
2411 # The `self` keyword
2412 var n_kwself
: nullable TKwself = null is writable
2415 # When there is no explicit receiver, `self` is implicit
2416 class AImplicitSelfExpr
2420 # A `true` boolean literal constant
2424 # The `true` keyword
2425 var n_kwtrue
: TKwtrue is writable, noinit
2428 # A `false` boolean literal constant
2432 # The `false` keyword
2433 var n_kwfalse
: TKwfalse is writable, noinit
2436 # A `null` literal constant
2440 # The `null` keyword
2441 var n_kwnull
: TKwnull is writable, noinit
2444 # An integer literal
2449 # An integer literal in decimal format
2454 var n_number
: TNumber is writable, noinit
2457 # An integer literal in hexadecimal format
2461 # The hexadecimal token
2462 var n_hex_number
: THexNumber is writable, noinit
2470 var n_float
: TFloat is writable, noinit
2473 # A character literal
2477 # The character token
2478 var n_char
: TChar is writable, noinit
2482 abstract class AStringFormExpr
2486 var n_string
: Token is writable, noinit
2489 # A simple string. eg. `"abc"`
2491 super AStringFormExpr
2494 # The start of a superstring. eg `"abc{`
2495 class AStartStringExpr
2496 super AStringFormExpr
2499 # The middle of a superstring. eg `}abc{`
2500 class AMidStringExpr
2501 super AStringFormExpr
2504 # The end of a superstrng. eg `}abc"`
2505 class AEndStringExpr
2506 super AStringFormExpr
2509 # A superstring literal. eg `"a{x}b{y}c"`
2510 # Each part is modeled a sequence of expression. eg. `["a{, x, }b{, y, }c"]`
2511 class ASuperstringExpr
2514 # The list of the expressions of the superstring
2515 var n_exprs
= new ANodes[AExpr](self)
2518 # A simple parenthesis. eg `(x)`
2522 # The opening parenthesis
2523 var n_opar
: TOpar is writable, noinit
2525 # The inner expression
2526 var n_expr
: AExpr is writable, noinit
2528 # The closing parenthesis
2529 var n_cpar
: TCpar is writable, noinit
2532 # A cast, against a type or `not null`
2536 # The expression to cast
2537 var n_expr
: AExpr is writable, noinit
2540 var n_kwas
: TKwas is writable, noinit
2542 # The opening parenthesis
2543 var n_opar
: nullable TOpar = null is writable
2545 # The closing parenthesis
2546 var n_cpar
: nullable TCpar = null is writable
2549 # A type cast. eg `x.as(T)`
2553 # The target type to cast to
2554 var n_type
: AType is writable, noinit
2557 # A as-not-null cast. eg `x.as(not null)`
2558 class AAsNotnullExpr
2562 var n_kwnot
: TKwnot is writable, noinit
2564 # The `null` keyword
2565 var n_kwnull
: TKwnull is writable, noinit
2568 # A is-set check of old-style attributes. eg `isset x._a`
2569 class AIssetAttrExpr
2572 # The `isset` keyword
2573 var n_kwisset
: TKwisset is writable, noinit
2576 # An ellipsis notation used to pass an expression as it, in a vararg parameter
2580 # The passed expression
2581 var n_expr
: AExpr is writable, noinit
2584 var n_dotdotdot
: TDotdotdot is writable, noinit
2587 # An named notation used to pass an expression by name in a parameter
2591 # The name of the argument
2592 var n_id
: TId is writable, noinit
2595 var n_assign
: TAssign is writable, noinit
2597 # The passed expression
2598 var n_expr
: AExpr is writable, noinit
2601 # A list of expression separated with commas (arguments for instance)
2605 # The list of expressions
2606 var n_exprs
= new ANodes[AExpr](self)
2609 # A special expression that encapsulates a static type
2610 # Can only be found in special construction like arguments of annotations.
2614 # The encapsulated type
2615 var n_type
: AType is writable, noinit
2618 # A special expression that encapsulates a method identifier
2619 # Can only be found in special construction like arguments of annotations.
2624 var n_expr
: AExpr is writable, noinit
2626 # The encapsulated method identifier
2627 var n_id
: AMethid is writable, noinit
2630 # A special expression that encapsulate an annotation
2631 # Can only be found in special construction like arguments of annotations.
2633 # The encapsulated annotations are in `n_annotations`
2638 # A special expression to debug types
2639 class ADebugTypeExpr
2642 # The `debug` keyword
2643 var n_kwdebug
: TKwdebug is writable, noinit
2645 # The `type` keyword
2646 var n_kwtype
: TKwtype is writable, noinit
2648 # The expression to check
2649 var n_expr
: AExpr is writable, noinit
2652 var n_type
: AType is writable, noinit
2655 # A list of expression separated with commas (arguments for instance)
2656 abstract class AExprs
2659 # The list of expressions
2660 var n_exprs
= new ANodes[AExpr](self)
2663 # A simple list of expressions
2668 # A list of expressions enclosed in parentheses
2672 # The opening parenthesis
2673 var n_opar
: TOpar is writable, noinit
2675 # The closing parenthesis
2676 var n_cpar
: TCpar is writable, noinit
2679 # A list of expressions enclosed in brackets
2683 # The opening bracket
2684 var n_obra
: TObra is writable, noinit
2686 # The closing bracket
2687 var n_cbra
: TCbra is writable, noinit
2690 # A complex assignment operator. (`+=` and `-=`)
2691 abstract class AAssignOp
2694 # The combined assignment operator
2695 var n_op
: Token is writable, noinit
2697 # The name of the operator without the `=` (eg '+')
2698 fun operator
: String is abstract
2701 # A `+=` assignment operation
2705 redef fun operator
do return "+"
2708 # A `-=` assignment operation
2709 class AMinusAssignOp
2712 redef fun operator
do return "-"
2715 # A `*=` assignment operation
2719 redef fun operator
do return "*"
2722 # A `/=` assignment operation
2723 class ASlashAssignOp
2726 redef fun operator
do return "/"
2729 # A `%=` assignment operation
2730 class APercentAssignOp
2733 redef fun operator
do return "%"
2736 # A `**=` assignment operation
2737 class AStarstarAssignOp
2740 redef fun operator
do return "**"
2743 # A `|=` assignment operation
2747 redef fun operator
do return "|"
2750 # A `^=` assignment operation
2751 class ACaretAssignOp
2754 redef fun operator
do return "^"
2757 # A `&=` assignment operation
2761 redef fun operator
do return "&"
2764 # A `<<=` assignment operation
2768 redef fun operator
do return "<<"
2771 # A `>>=` assignment operation
2775 redef fun operator
do return ">>"
2778 # A possibly fully-qualified module identifier
2782 # The starting quad (`::`)
2783 var n_quad
: nullable TQuad = null is writable
2785 # The list of quad-separated project/group identifiers
2786 var n_path
= new ANodes[TId](self)
2788 # The final module identifier
2789 var n_id
: TId is writable, noinit
2792 # A language declaration for an extern block
2797 var n_kwin
: TKwin is writable, noinit
2800 var n_string
: TString is writable, noinit
2803 # An full extern block
2804 class AExternCodeBlock
2807 # The language declration
2808 var n_in_language
: nullable AInLanguage = null is writable
2810 # The block of extern code
2811 var n_extern_code_segment
: TExternCodeSegment is writable, noinit
2814 # A possible full method qualifier.
2818 # The starting quad (`::`)
2819 var n_quad
: nullable TQuad = null is writable
2821 # The list of quad-separated project/group/module identifiers
2822 var n_id
= new ANodes[TId](self)
2824 # A class identifier
2825 var n_classid
: nullable TClassid = null is writable
2828 # A documentation of a definition
2829 # It contains the block of comments just above the declaration
2833 # A list of lines of comment
2834 var n_comment
= new ANodes[TComment](self)
2837 # A group of annotation on a node
2839 # This same class is used for the 3 kind of annotations:
2841 # * *is* annotations. eg `module foo is bar`.
2842 # * *at* annotations. eg `foo@bar` or `foo@(bar,baz)`.
2843 # * *class* annotations, defined in classes.
2847 # The `is` keyword, for *is* annotations
2848 var n_kwis
: nullable TKwis = null is writable
2850 # The `@` symbol, for *at* annotations
2851 var n_at
: nullable TAt = null is writable
2853 # The opening parenthesis in *at* annotations
2854 var n_opar
: nullable TOpar = null is writable
2856 # The list of annotations
2857 var n_items
= new ANodes[AAnnotation](self)
2859 # The closing parenthesis in *at* annotations
2860 var n_cpar
: nullable TCpar = null is writable
2862 # The `end` keyword, for *is* annotations
2863 var n_kwend
: nullable TKwend = null is writable
2866 # A single annotation
2870 # The name of the annotation
2871 var n_atid
: AAtid is writable, noinit
2873 # The opening parenthesis of the arguments
2874 var n_opar
: nullable TOpar = null is writable
2876 # The list of arguments
2877 var n_args
= new ANodes[AExpr](self)
2879 # The closing parenthesis
2880 var n_cpar
: nullable TCpar = null is writable
2882 # The name of the annotation
2885 return n_atid
.n_id
.text
2889 # An annotation name
2890 abstract class AAtid
2893 # The identifier of the annotation.
2894 # Can be a TId of a keyword
2895 var n_id
: Token is writable, noinit
2898 # An annotation name based on an identifier
2903 # An annotation name based on the keyword `extern`
2908 # An annotation name based on the keyword `import`
2913 # An annotation name based on the keyword `abstract`
2914 class AKwabstractAtid
2918 # The root of the AST
2923 var n_base
: nullable AModule is writable
2925 # The end of file (or error) token
2926 var n_eof
: EOF is writable