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 binary integer
954 # A literal octal integer
959 # A literal floating point number
964 # A literal character
974 # The starting part of a super string (between `"` and `{`)
979 # The middle part of a super string (between `}` and `{`)
984 # The final part of a super string (between `}` and `"`)
994 do return "malformed string {text}"
1003 do return "malformed character {text}"
1007 # A extern code block
1008 class TExternCodeSegment
1017 return "end of file"
1021 # A mark of an error
1025 # A lexical error (unexpected character)
1029 # A syntactic error (unexpected token)
1034 # The main node of a Nit source-file
1038 # The declaration part of the module
1039 var n_moduledecl
: nullable AModuledecl = null is writable
1041 # List of importation clauses
1042 var n_imports
= new ANodes[AImport](self)
1044 # List of extern blocks
1045 var n_extern_code_blocks
= new ANodes[AExternCodeBlock](self)
1047 # List of class definition (including top-level methods and the main)
1048 var n_classdefs
= new ANodes[AClassdef](self)
1051 # Abstract class for definition of entities
1052 abstract class ADefinition
1055 var n_doc
: nullable ADoc = null is writable
1057 # The `redef` keyword
1058 var n_kwredef
: nullable TKwredef = null is writable
1060 # The declared visibility
1061 var n_visibility
: nullable AVisibility = null is writable
1064 # The declaration of the module with the documentation, name, and annotations
1068 # The `module` keyword
1069 var n_kwmodule
: TKwmodule is writable, noinit
1071 # The declared module name
1072 var n_name
: AModuleName is writable, noinit
1075 # A import clause of a module
1076 abstract class AImport
1079 # The declared visibility
1080 var n_visibility
: AVisibility is writable, noinit
1082 # The `import` keyword
1083 var n_kwimport
: TKwimport is writable, noinit
1086 # A standard import clause. eg `import x`
1089 # The imported module name
1090 var n_name
: AModuleName is writable, noinit
1093 # The special import clause of the kernel module. eg `import end`
1096 # The `end` keyword, that indicate the root module
1097 var n_kwend
: TKwend is writable, noinit
1100 # A visibility modifier
1102 # The public visibility is an empty production (no keyword).
1104 # Note: even if some visibilities are only valid on some placse (for instance, no `protected` class or no `intrude` method)
1105 # the parser has no such a restriction, therefore the semantic phases has to check that the visibilities make sense.
1106 abstract class AVisibility
1110 # An implicit or explicit public visibility modifier
1111 class APublicVisibility
1113 # The `public` keyword, if any
1114 var n_kwpublic
: nullable TKwpublic is writable
1116 # An explicit private visibility modifier
1117 class APrivateVisibility
1119 # The `private` keyword
1120 var n_kwprivate
: TKwprivate is writable, noinit
1122 # An explicit protected visibility modifier
1123 class AProtectedVisibility
1125 # The `protected` keyword
1126 var n_kwprotected
: TKwprotected is writable, noinit
1128 # An explicit intrude visibility modifier
1129 class AIntrudeVisibility
1131 # The `intrude` keyword
1132 var n_kwintrude
: TKwintrude is writable, noinit
1135 # A class definition
1136 # While most definition are `AStdClassdef`
1137 # There is tow special case of class definition
1138 abstract class AClassdef
1140 # All the declared properties (including the main method)
1141 var n_propdefs
= new ANodes[APropdef](self)
1144 # A standard class definition with a name, superclasses and properties
1149 # The class kind (interface, abstract class, etc.)
1150 var n_classkind
: AClasskind is writable, noinit
1152 # The name of the class
1153 var n_id
: nullable TClassid = null is writable
1156 var n_obra
: nullable TObra = null is writable
1158 # The list of formal parameter types
1159 var n_formaldefs
= new ANodes[AFormaldef](self)
1162 var n_cbra
: nullable TCbra = null is writable
1164 # The extern block code
1165 var n_extern_code_block
: nullable AExternCodeBlock = null is writable
1168 var n_kwend
: TKwend is writable, noinit
1170 fun n_superclasses
: Array[ASuperPropdef] do
1171 return [for d
in n_propdefs
do if d
isa ASuperPropdef then d
]
1174 redef fun hot_location
do return n_id
.location
1177 # The implicit class definition of the implicit main method
1182 # The implicit class definition of the top-level methods
1187 # The modifier for the kind of class (abstract, interface, etc.)
1188 abstract class AClasskind
1192 # A default, or concrete class modifier (just `class`)
1193 class AConcreteClasskind
1196 # The `class` keyword.
1197 var n_kwclass
: TKwclass is writable, noinit
1200 # An abstract class modifier (`abstract class`)
1201 class AAbstractClasskind
1204 # The `abstract` keyword.
1205 var n_kwabstract
: TKwabstract is writable, noinit
1207 # The `class` keyword.
1208 var n_kwclass
: TKwclass is writable, noinit
1211 # An interface class modifier (`interface`)
1212 class AInterfaceClasskind
1215 # The `interface` keyword.
1216 var n_kwinterface
: TKwinterface is writable, noinit
1219 # An enum/universal class modifier (`enum class`)
1220 class AEnumClasskind
1223 # The `enum` keyword.
1224 var n_kwenum
: TKwenum is writable, noinit
1227 # An extern class modifier (`extern class`)
1228 class AExternClasskind
1231 # The `extern` keyword.
1232 var n_kwextern
: TKwextern is writable, noinit
1234 # The `class` keyword.
1235 var n_kwclass
: nullable TKwclass = null is writable
1238 # The definition of a formal generic parameter type. eg `X: Y`
1242 # The name of the parameter type
1243 var n_id
: TClassid is writable, noinit
1245 # The bound of the parameter type
1246 var n_type
: nullable AType = null is writable
1249 # The definition of a property
1250 abstract class APropdef
1254 # A definition of an attribute
1255 # For historical reason, old-syle and new-style attributes use the same `ANode` sub-class
1260 var n_kwvar
: TKwvar is writable, noinit
1262 # The identifier for a new-style attribute
1263 var n_id2
: TId is writable, noinit
1265 # The declared type of the attribute
1266 var n_type
: nullable AType = null is writable
1269 var n_assign
: nullable TAssign = null is writable
1271 # The initial value, if any (set with `=`)
1272 var n_expr
: nullable AExpr = null is writable
1275 var n_kwdo
: nullable TKwdo = null is writable
1277 # The initial value, if any (set with `do return`)
1278 var n_block
: nullable AExpr = null is writable
1281 var n_kwend
: nullable TKwend = null is writable
1283 redef fun hot_location
1285 return n_id2
.location
1289 # A definition of all kind of method (including constructors)
1293 # The `fun` keyword, if any
1294 var n_kwmeth
: nullable TKwmeth = null is writable
1296 # The `init` keyword, if any
1297 var n_kwinit
: nullable TKwinit = null is writable
1299 # The `new` keyword, if any
1300 var n_kwnew
: nullable TKwnew = null is writable
1302 # The name of the method, if any
1303 var n_methid
: nullable AMethid = null is writable
1305 # The signature of the method, if any
1306 var n_signature
: nullable ASignature = null is writable
1309 var n_kwdo
: nullable TKwdo = null is writable
1311 # The body (in Nit) of the method, if any
1312 var n_block
: nullable AExpr = null is writable
1315 var n_kwend
: nullable TKwend = null is writable
1317 # The list of declared callbacks (for extern methods)
1318 var n_extern_calls
: nullable AExternCalls = null is writable
1320 # The body (in extern code) of the method, if any
1321 var n_extern_code_block
: nullable AExternCodeBlock = null is writable
1323 redef fun hot_location
1325 if n_methid
!= null then
1326 return n_methid
.location
1327 else if n_kwinit
!= null then
1328 return n_kwinit
.location
1329 else if n_kwnew
!= null then
1330 return n_kwnew
.location
1337 # The implicit main method
1338 class AMainMethPropdef
1347 # A super-class. eg `super X`
1352 var n_kwsuper
: TKwsuper is writable, noinit
1354 # The super-class (indicated as a type)
1355 var n_type
: AType is writable, noinit
1359 # Declaration of callbacks for extern methods
1363 # The `import` keyword
1364 var n_kwimport
: TKwimport is writable, noinit
1366 # The list of declared callbacks
1367 var n_extern_calls
: ANodes[AExternCall] = new ANodes[AExternCall](self)
1370 # A single callback declaration
1371 abstract class AExternCall
1375 # A single callback declaration on a method
1376 abstract class APropExternCall
1380 # A single callback declaration on a method on the current receiver
1381 class ALocalPropExternCall
1382 super APropExternCall
1384 # The name of the called-back method
1385 var n_methid
: AMethid is writable, noinit
1388 # A single callback declaration on a method on an explicit receiver type.
1389 class AFullPropExternCall
1390 super APropExternCall
1392 # The type of the receiver of the called-back method
1393 var n_type
: AType is writable, noinit
1396 var n_dot
: nullable TDot = null is writable
1398 # The name of the called-back method
1399 var n_methid
: AMethid is writable, noinit
1402 # A single callback declaration on a method on a constructor
1403 class AInitPropExternCall
1404 super APropExternCall
1406 # The allocated type
1407 var n_type
: AType is writable, noinit
1410 # A single callback declaration on a `super` call
1411 class ASuperExternCall
1414 # The `super` keyword
1415 var n_kwsuper
: TKwsuper is writable, noinit
1418 # A single callback declaration on a cast
1419 abstract class ACastExternCall
1423 # A single callback declaration on a cast to a given type
1424 class ACastAsExternCall
1425 super ACastExternCall
1427 # The origin type of the cast
1428 var n_from_type
: AType is writable, noinit
1431 var n_dot
: nullable TDot = null is writable
1434 var n_kwas
: TKwas is writable, noinit
1436 # The destination of the cast
1437 var n_to_type
: AType is writable, noinit
1440 # A single callback declaration on a cast to a nullable type
1441 class AAsNullableExternCall
1442 super ACastExternCall
1444 # The origin type to cast as nullable
1445 var n_type
: AType is writable, noinit
1448 var n_kwas
: TKwas is writable, noinit
1450 # The `nullable` keyword
1451 var n_kwnullable
: TKwnullable is writable, noinit
1454 # A single callback declaration on a cast to a non-nullable type
1455 class AAsNotNullableExternCall
1456 super ACastExternCall
1458 # The destination type on a cast to not nullable
1459 var n_type
: AType is writable, noinit
1462 var n_kwas
: TKwas is writable, noinit
1465 var n_kwnot
: TKwnot is writable, noinit
1467 # The `nullable` keyword
1468 var n_kwnullable
: TKwnullable is writable, noinit
1471 # A definition of a virtual type
1475 # The `type` keyword
1476 var n_kwtype
: TKwtype is writable, noinit
1478 # The name of the virtual type
1479 var n_id
: TClassid is writable, noinit
1481 # The bound of the virtual type
1482 var n_type
: AType is writable, noinit
1485 # The identifier of a method in a method declaration.
1486 # There is a specific class because of operator and setters.
1487 abstract class AMethid
1491 # A method name with a simple identifier
1495 # The simple identifier
1496 var n_id
: TId is writable, noinit
1499 # A method name for an operator
1500 class AOperatorMethid
1503 # The associated operator symbol
1504 var n_op
: Token is writable, noinit
1508 super AOperatorMethid
1513 super AOperatorMethid
1518 super AOperatorMethid
1521 # A method name `**`
1522 class AStarstarMethid
1523 super AOperatorMethid
1528 super AOperatorMethid
1532 class APercentMethid
1533 super AOperatorMethid
1538 super AOperatorMethid
1543 super AOperatorMethid
1548 super AOperatorMethid
1553 super AOperatorMethid
1556 # A method name `==`
1558 super AOperatorMethid
1561 # A method name `!=`
1563 super AOperatorMethid
1566 # A method name `<=`
1568 super AOperatorMethid
1571 # A method name `>=`
1573 super AOperatorMethid
1578 super AOperatorMethid
1583 super AOperatorMethid
1586 # A method name `<<`
1588 super AOperatorMethid
1591 # A method name `>>`
1593 super AOperatorMethid
1596 # A method name `<=>`
1597 class AStarshipMethid
1598 super AOperatorMethid
1601 # A method name `[]`
1606 var n_obra
: TObra is writable, noinit
1609 var n_cbra
: TCbra is writable, noinit
1612 # A setter method name with a simple identifier (with a `=`)
1616 # The base identifier
1617 var n_id
: TId is writable, noinit
1620 var n_assign
: TAssign is writable, noinit
1623 # A method name `[]=`
1624 class ABraassignMethid
1628 var n_obra
: TObra is writable, noinit
1631 var n_cbra
: TCbra is writable, noinit
1634 var n_assign
: TAssign is writable, noinit
1637 # A signature in a method definition. eg `(x,y:X,z:Z):T`
1642 var n_opar
: nullable TOpar = null is writable
1644 # The list of parameters
1645 var n_params
= new ANodes[AParam](self)
1648 var n_cpar
: nullable TCpar = null is writable
1651 var n_type
: nullable AType = null is writable
1654 # A parameter definition in a signature. eg `x:X`
1658 # The name of the parameter
1659 var n_id
: TId is writable, noinit
1661 # The type of the parameter, if any
1662 var n_type
: nullable AType = null is writable
1664 # The `...` symbol to indicate varargs
1665 var n_dotdotdot
: nullable TDotdotdot = null is writable
1668 # A static type. eg `nullable X[Y]`
1671 # The `nullable` keyword
1672 var n_kwnullable
: nullable TKwnullable = null is writable
1674 # The name of the class or of the formal type
1675 var n_id
: TClassid is writable, noinit
1677 # The opening bracket
1678 var n_obra
: nullable TObra = null is writable
1680 # Type arguments for a generic type
1681 var n_types
= new ANodes[AType](self)
1683 # The closing bracket
1684 var n_cbra
: nullable TCbra = null is writable
1687 # A label at the end of a block or in a break/continue statement. eg `label x`
1691 # The `label` keyword
1692 var n_kwlabel
: TKwlabel is writable, noinit
1694 # The name of the label, if any
1695 var n_id
: nullable TId is writable, noinit
1698 # Expression and statements
1699 # From a AST point of view there is no distinction between statement and expressions (even if the parser has to distinguish them)
1700 abstract class AExpr
1704 # A sequence of `AExpr` (usually statements)
1705 # The last `AExpr` gives the value of the whole block
1709 # The list of statements in the bloc.
1710 # The last element is often considered as an expression that give the value of the whole block.
1711 var n_expr
= new ANodes[AExpr](self)
1714 var n_kwend
: nullable TKwend = null is writable
1717 # A declaration of a local variable. eg `var x: X = y`
1722 var n_kwvar
: nullable TKwvar = null is writable
1724 # The name of the local variable
1725 var n_id
: TId is writable, noinit
1727 # The declaration type of the local variable
1728 var n_type
: nullable AType = null is writable
1730 # The `=` symbol (for the initial value)
1731 var n_assign
: nullable TAssign = null is writable
1733 # The initial value, if any
1734 var n_expr
: nullable AExpr = null is writable
1737 # A `return` statement. eg `return x`
1741 # The `return` keyword
1742 var n_kwreturn
: nullable TKwreturn = null is writable
1744 # The return value, if any
1745 var n_expr
: nullable AExpr = null is writable
1748 # Something that has a label.
1749 abstract class ALabelable
1752 # The associated label declatation
1753 var n_label
: nullable ALabel = null is writable
1756 # A `break` or a `continue`
1757 abstract class AEscapeExpr
1761 # The return value, if nay (unused currently)
1762 var n_expr
: nullable AExpr = null is writable
1765 # A `break` statement.
1769 # The `break` keyword
1770 var n_kwbreak
: TKwbreak is writable, noinit
1773 # An `abort` statement
1777 # The `abort` keyword
1778 var n_kwabort
: TKwabort is writable, noinit
1781 # A `continue` statement
1785 # The `continue` keyword.
1786 var n_kwcontinue
: nullable TKwcontinue = null is writable
1795 var n_kwdo
: TKwdo is writable, noinit
1797 # The list of statements of the `do`.
1798 var n_block
: nullable AExpr = null is writable
1806 var n_kwif
: TKwif is writable, noinit
1808 # The expression used as the condition of the `if`
1809 var n_expr
: AExpr is writable, noinit
1811 # The `then` keyword
1812 var n_kwthen
: TKwthen is writable, noinit
1814 # The body of the `then` part
1815 var n_then
: nullable AExpr = null is writable
1817 # The `else` keyword
1818 var n_kwelse
: nullable TKwelse = null is writable
1820 # The body of the `else` part
1821 var n_else
: nullable AExpr = null is writable
1824 # A `if` expression (ternary conditional). eg. `if true then 1 else 0`
1829 var n_kwif
: TKwif is writable, noinit
1831 # The expression used as the condition of the `if`
1832 var n_expr
: AExpr is writable, noinit
1834 # The `then` keyword
1835 var n_kwthen
: TKwthen is writable, noinit
1837 # The expression in the `then` part
1838 var n_then
: AExpr is writable, noinit
1840 # The `else` keyword
1841 var n_kwelse
: TKwelse is writable, noinit
1843 # The expression in the `else` part
1844 var n_else
: AExpr is writable, noinit
1847 # A `while` statement
1852 # The `while` keyword
1853 var n_kwwhile
: TKwwhile is writable, noinit
1855 # The expression used as the condition of the `while`
1856 var n_expr
: AExpr is writable, noinit
1859 var n_kwdo
: TKwdo is writable, noinit
1861 # The body of the loop
1862 var n_block
: nullable AExpr = null is writable
1865 # A `loop` statement
1870 # The `loop` keyword
1871 var n_kwloop
: TKwloop is writable, noinit
1873 # The body of the loop
1874 var n_block
: nullable AExpr = null is writable
1883 var n_kwfor
: TKwfor is writable, noinit
1885 # The list of name of the automatic variables
1886 var n_ids
= new ANodes[TId](self)
1889 var n_kwin
: TKwin is writable, noinit
1891 # The expression used as the collection to iterate on
1892 var n_expr
: AExpr is writable, noinit
1895 var n_kwdo
: TKwdo is writable, noinit
1897 # The body of the loop
1898 var n_block
: nullable AExpr = null is writable
1901 # A `with` statement
1906 # The `with` keyword
1907 var n_kwwith
: TKwwith is writable, noinit
1909 # The expression used to get the value to control
1910 var n_expr
: AExpr is writable, noinit
1913 var n_kwdo
: TKwdo is writable, noinit
1915 # The body of the loop
1916 var n_block
: nullable AExpr = null is writable
1919 # An `assert` statement
1923 # The `assert` keyword
1924 var n_kwassert
: TKwassert is writable, noinit
1926 # The name of the assert, if any
1927 var n_id
: nullable TId = null is writable
1929 # The expression used as the condition of the `assert`
1930 var n_expr
: AExpr is writable, noinit
1932 # The `else` keyword
1933 var n_kwelse
: nullable TKwelse = null is writable
1935 # The body to execute when the assert fails
1936 var n_else
: nullable AExpr = null is writable
1939 # Whatever is a simple assignment. eg `= something`
1940 abstract class AAssignFormExpr
1944 var n_assign
: TAssign is writable, noinit
1946 # The right-value to assign.
1947 var n_value
: AExpr is writable, noinit
1950 # Whatever is a combined assignment. eg `+= something`
1951 abstract class AReassignFormExpr
1954 # The combined operator (eg. `+=`)
1955 var n_assign_op
: AAssignOp is writable, noinit
1957 # The right-value to apply on the combined operator.
1958 var n_value
: AExpr is writable, noinit
1961 # A `once` expression. eg `once x`
1965 # The `once` keyword
1966 var n_kwonce
: TKwonce is writable, noinit
1968 # The expression to evaluate only one time
1969 var n_expr
: AExpr is writable, noinit
1972 # A polymorphic invocation of a method
1973 # The form of the invocation (name, arguments, etc.) are specific
1974 abstract class ASendExpr
1976 # The receiver of the method invocation
1977 var n_expr
: AExpr is writable, noinit
1980 # A binary operation on a method
1981 abstract class ABinopExpr
1985 var n_op
: Token is writable, noinit
1987 # The second operand of the operation
1988 # Note: the receiver (`n_expr`) is the first operand
1989 var n_expr2
: AExpr is writable, noinit
1991 # The name of the operator (eg '+')
1992 fun operator
: String is abstract
1995 # Something that is boolean expression
1996 abstract class ABoolExpr
2000 # Something that is binary boolean expression
2001 abstract class ABinBoolExpr
2004 # The first boolean operand
2005 var n_expr
: AExpr is writable, noinit
2008 var n_op
: Token is writable, noinit
2010 # The second boolean operand
2011 var n_expr2
: AExpr is writable, noinit
2019 # A `and` expression
2024 # A `or else` expression
2028 # The `else` keyword
2029 var n_kwelse
: TKwelse is writable, noinit
2032 # A `implies` expression
2037 # A `not` expression
2042 var n_kwnot
: TKwnot is writable, noinit
2044 # The boolean operand of the `not`
2045 var n_expr
: AExpr is writable, noinit
2051 redef fun operator
do return "=="
2057 redef fun operator
do return "!="
2063 redef fun operator
do return "<"
2069 redef fun operator
do return "<="
2075 redef fun operator
do return "<<"
2081 redef fun operator
do return ">"
2087 redef fun operator
do return ">="
2093 redef fun operator
do return ">>"
2096 # A type-ckeck expression. eg `x isa T`
2100 # The expression to check
2101 var n_expr
: AExpr is writable, noinit
2104 var n_kwisa
: TKwisa is writable, noinit
2106 # The destination type to check to
2107 var n_type
: AType is writable, noinit
2113 redef fun operator
do return "+"
2119 redef fun operator
do return "-"
2122 # A `<=>` expression
2125 redef fun operator
do return "<=>"
2131 redef fun operator
do return "*"
2137 redef fun operator
do return "**"
2143 redef fun operator
do return "/"
2149 redef fun operator
do return "%"
2155 redef fun operator
do return "|"
2161 redef fun operator
do return "^"
2167 redef fun operator
do return "&"
2170 # A unary operation on a method
2175 var n_op
: Token is writable, noinit
2177 # The name of the operator (eg '+')
2178 fun operator
: String is abstract
2181 # A unary minus expression. eg `-x`
2184 redef fun operator
do return "-"
2187 # A unary plus expression. eg `+x`
2190 redef fun operator
do return "+"
2193 # A unary `~` expression
2196 redef fun operator
do return "~"
2199 # An explicit instantiation. eg `new T`
2204 var n_kwnew
: TKwnew is writable, noinit
2206 # The `type` keyword
2207 var n_type
: AType is writable, noinit
2209 # The name of the named-constructor, if any
2210 var n_id
: nullable TId = null is writable
2212 # The arguments of the `new`
2213 var n_args
: AExprs is writable, noinit
2216 # Whatever is a old-style attribute access
2217 abstract class AAttrFormExpr
2220 # The receiver of the attribute
2221 var n_expr
: AExpr is writable, noinit
2223 # The name of the attribute
2224 var n_id
: TAttrid is writable, noinit
2228 # The read of an attribute. eg `x._a`
2233 # The assignment of an attribute. eg `x._a=y`
2234 class AAttrAssignExpr
2236 super AAssignFormExpr
2239 # Whatever looks-like a call with a standard method and any number of arguments.
2240 abstract class ACallFormExpr
2243 # The name of the method
2244 var n_id
: TId is writable, noinit
2246 # The arguments of the call
2247 var n_args
: AExprs is writable, noinit
2250 # A complex setter call (standard or brackets)
2251 abstract class ASendReassignFormExpr
2253 super AReassignFormExpr
2256 # A complex attribute assignment. eg `x._a+=y`
2257 class AAttrReassignExpr
2259 super AReassignFormExpr
2262 # A call with a standard method-name and any number of arguments. eg `x.m(y)`. OR just a simple id
2263 # 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`.
2264 # Semantic analysis have to transform them to instance of `AVarExpr`.
2269 # A setter call with a standard method-name and any number of arguments. eg `x.m(y)=z`. OR just a simple assignment.
2270 # 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`.
2271 # Semantic analysis have to transform them to instance of `AVarAssignExpr`.
2272 class ACallAssignExpr
2274 super AAssignFormExpr
2277 # 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.
2278 # 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`.
2279 # Semantic analysis have to transform them to instance of `AVarReassignExpr`.
2280 class ACallReassignExpr
2282 super ASendReassignFormExpr
2285 # A call to `super`. OR a call of a super-constructor
2289 # The qualifier part before the super (currenlty unused)
2290 var n_qualified
: nullable AQualified = null is writable
2292 # The `super` keyword
2293 var n_kwsuper
: TKwsuper is writable, noinit
2295 # The arguments of the super
2296 var n_args
: AExprs is writable, noinit
2299 # A call to the `init` constructor.
2300 # Note: because `init` is a keyword and not a `TId`, the explicit call to init cannot be a `ACallFormExpr`.
2304 # The `init` keyword
2305 var n_kwinit
: TKwinit is writable, noinit
2307 # The arguments of the init
2308 var n_args
: AExprs is writable, noinit
2311 # Whatever looks-like a call of the brackets `[]` operator.
2312 abstract class ABraFormExpr
2315 # The arguments inside the brackets
2316 var n_args
: AExprs is writable, noinit
2319 # A call of the brackets operator. eg `x[y,z]`
2324 # A setter call of the bracket operator. eg `x[y,z]=t`
2325 class ABraAssignExpr
2327 super AAssignFormExpr
2330 # Whatever is an access to a local variable
2331 abstract class AVarFormExpr
2334 # The name of the attribute
2335 var n_id
: TId is writable, noinit
2338 # A complex setter call of the bracket operator. eg `x[y,z]+=t`
2339 class ABraReassignExpr
2341 super ASendReassignFormExpr
2344 # A local variable read access.
2345 # The parser cannot instantiate them, see `ACallExpr`.
2350 # A local variable simple assignment access
2351 # The parser cannot instantiate them, see `ACallAssignExpr`.
2352 class AVarAssignExpr
2354 super AAssignFormExpr
2357 # A local variable complex assignment access
2358 # The parser cannot instantiate them, see `ACallReassignExpr`.
2359 class AVarReassignExpr
2361 super AReassignFormExpr
2364 # A literal range, open or closed
2365 abstract class ARangeExpr
2368 # The left (lower) element of the range
2369 var n_expr
: AExpr is writable, noinit
2372 var n_dotdot
: TDotdot is writable, noinit
2374 # The right (upper) element of the range
2375 var n_expr2
: AExpr is writable, noinit
2378 # A closed literal range. eg `[x..y]`
2382 # The opening bracket `[`
2383 var n_obra
: TObra is writable, noinit
2385 # The closing bracket `]`
2386 var n_cbra
: TCbra is writable, noinit
2389 # An open literal range. eg `[x..y[`
2393 # The opening bracket `[`
2394 var n_obra
: TObra is writable, noinit
2396 # The closing bracket `[` (because open range)
2397 var n_cbra
: TObra is writable, noinit
2400 # A literal array. eg. `[x,y,z]`
2404 # The opening bracket `[`
2405 var n_obra
: TObra is writable, noinit
2407 # The elements of the array
2408 var n_exprs
= new ANodes[AExpr](self)
2410 # The type of the element of the array (if any)
2411 var n_type
: nullable AType = null is writable
2413 # The closing bracket `]`
2414 var n_cbra
: TCbra is writable, noinit
2421 # The `self` keyword
2422 var n_kwself
: nullable TKwself = null is writable
2425 # When there is no explicit receiver, `self` is implicit
2426 class AImplicitSelfExpr
2430 # A `true` boolean literal constant
2434 # The `true` keyword
2435 var n_kwtrue
: TKwtrue is writable, noinit
2438 # A `false` boolean literal constant
2442 # The `false` keyword
2443 var n_kwfalse
: TKwfalse is writable, noinit
2446 # A `null` literal constant
2450 # The `null` keyword
2451 var n_kwnull
: TKwnull is writable, noinit
2454 # An integer literal
2459 # An integer literal in decimal format
2464 var n_number
: TNumber is writable, noinit
2467 # An integer literal in hexadecimal format
2471 # The hexadecimal token
2472 var n_hex_number
: THexNumber is writable, noinit
2475 # An integer literal in binary format
2480 var n_bin_number
: TBinNumber is writable, noinit
2483 # An integer literal in octal format
2488 var n_oct_number
: TOctNumber is writable, noinit
2496 var n_float
: TFloat is writable, noinit
2499 # A character literal
2503 # The character token
2504 var n_char
: TChar is writable, noinit
2508 abstract class AStringFormExpr
2512 var n_string
: Token is writable, noinit
2515 # A simple string. eg. `"abc"`
2517 super AStringFormExpr
2520 # The start of a superstring. eg `"abc{`
2521 class AStartStringExpr
2522 super AStringFormExpr
2525 # The middle of a superstring. eg `}abc{`
2526 class AMidStringExpr
2527 super AStringFormExpr
2530 # The end of a superstrng. eg `}abc"`
2531 class AEndStringExpr
2532 super AStringFormExpr
2535 # A superstring literal. eg `"a{x}b{y}c"`
2536 # Each part is modeled a sequence of expression. eg. `["a{, x, }b{, y, }c"]`
2537 class ASuperstringExpr
2540 # The list of the expressions of the superstring
2541 var n_exprs
= new ANodes[AExpr](self)
2544 # A simple parenthesis. eg `(x)`
2548 # The opening parenthesis
2549 var n_opar
: TOpar is writable, noinit
2551 # The inner expression
2552 var n_expr
: AExpr is writable, noinit
2554 # The closing parenthesis
2555 var n_cpar
: TCpar is writable, noinit
2558 # A cast, against a type or `not null`
2562 # The expression to cast
2563 var n_expr
: AExpr is writable, noinit
2566 var n_kwas
: TKwas is writable, noinit
2568 # The opening parenthesis
2569 var n_opar
: nullable TOpar = null is writable
2571 # The closing parenthesis
2572 var n_cpar
: nullable TCpar = null is writable
2575 # A type cast. eg `x.as(T)`
2579 # The target type to cast to
2580 var n_type
: AType is writable, noinit
2583 # A as-not-null cast. eg `x.as(not null)`
2584 class AAsNotnullExpr
2588 var n_kwnot
: TKwnot is writable, noinit
2590 # The `null` keyword
2591 var n_kwnull
: TKwnull is writable, noinit
2594 # A is-set check of old-style attributes. eg `isset x._a`
2595 class AIssetAttrExpr
2598 # The `isset` keyword
2599 var n_kwisset
: TKwisset is writable, noinit
2602 # An ellipsis notation used to pass an expression as it, in a vararg parameter
2606 # The passed expression
2607 var n_expr
: AExpr is writable, noinit
2610 var n_dotdotdot
: TDotdotdot is writable, noinit
2613 # An named notation used to pass an expression by name in a parameter
2617 # The name of the argument
2618 var n_id
: TId is writable, noinit
2621 var n_assign
: TAssign is writable, noinit
2623 # The passed expression
2624 var n_expr
: AExpr is writable, noinit
2627 # A list of expression separated with commas (arguments for instance)
2631 # The list of expressions
2632 var n_exprs
= new ANodes[AExpr](self)
2635 # A special expression that encapsulates a static type
2636 # Can only be found in special construction like arguments of annotations.
2640 # The encapsulated type
2641 var n_type
: AType is writable, noinit
2644 # A special expression that encapsulates a method identifier
2645 # Can only be found in special construction like arguments of annotations.
2650 var n_expr
: AExpr is writable, noinit
2652 # The encapsulated method identifier
2653 var n_id
: AMethid is writable, noinit
2656 # A special expression that encapsulate an annotation
2657 # Can only be found in special construction like arguments of annotations.
2659 # The encapsulated annotations are in `n_annotations`
2664 # A special expression to debug types
2665 class ADebugTypeExpr
2668 # The `debug` keyword
2669 var n_kwdebug
: TKwdebug is writable, noinit
2671 # The `type` keyword
2672 var n_kwtype
: TKwtype is writable, noinit
2674 # The expression to check
2675 var n_expr
: AExpr is writable, noinit
2678 var n_type
: AType is writable, noinit
2681 # A list of expression separated with commas (arguments for instance)
2682 abstract class AExprs
2685 # The list of expressions
2686 var n_exprs
= new ANodes[AExpr](self)
2689 # A simple list of expressions
2694 # A list of expressions enclosed in parentheses
2698 # The opening parenthesis
2699 var n_opar
: TOpar is writable, noinit
2701 # The closing parenthesis
2702 var n_cpar
: TCpar is writable, noinit
2705 # A list of expressions enclosed in brackets
2709 # The opening bracket
2710 var n_obra
: TObra is writable, noinit
2712 # The closing bracket
2713 var n_cbra
: TCbra is writable, noinit
2716 # A complex assignment operator. (`+=` and `-=`)
2717 abstract class AAssignOp
2720 # The combined assignment operator
2721 var n_op
: Token is writable, noinit
2723 # The name of the operator without the `=` (eg '+')
2724 fun operator
: String is abstract
2727 # A `+=` assignment operation
2731 redef fun operator
do return "+"
2734 # A `-=` assignment operation
2735 class AMinusAssignOp
2738 redef fun operator
do return "-"
2741 # A `*=` assignment operation
2745 redef fun operator
do return "*"
2748 # A `/=` assignment operation
2749 class ASlashAssignOp
2752 redef fun operator
do return "/"
2755 # A `%=` assignment operation
2756 class APercentAssignOp
2759 redef fun operator
do return "%"
2762 # A `**=` assignment operation
2763 class AStarstarAssignOp
2766 redef fun operator
do return "**"
2769 # A `|=` assignment operation
2773 redef fun operator
do return "|"
2776 # A `^=` assignment operation
2777 class ACaretAssignOp
2780 redef fun operator
do return "^"
2783 # A `&=` assignment operation
2787 redef fun operator
do return "&"
2790 # A `<<=` assignment operation
2794 redef fun operator
do return "<<"
2797 # A `>>=` assignment operation
2801 redef fun operator
do return ">>"
2804 # A possibly fully-qualified module identifier
2808 # The starting quad (`::`)
2809 var n_quad
: nullable TQuad = null is writable
2811 # The list of quad-separated project/group identifiers
2812 var n_path
= new ANodes[TId](self)
2814 # The final module identifier
2815 var n_id
: TId is writable, noinit
2818 # A language declaration for an extern block
2823 var n_kwin
: TKwin is writable, noinit
2826 var n_string
: TString is writable, noinit
2829 # An full extern block
2830 class AExternCodeBlock
2833 # The language declration
2834 var n_in_language
: nullable AInLanguage = null is writable
2836 # The block of extern code
2837 var n_extern_code_segment
: TExternCodeSegment is writable, noinit
2840 # A possible full method qualifier.
2844 # The starting quad (`::`)
2845 var n_quad
: nullable TQuad = null is writable
2847 # The list of quad-separated project/group/module identifiers
2848 var n_id
= new ANodes[TId](self)
2850 # A class identifier
2851 var n_classid
: nullable TClassid = null is writable
2854 # A documentation of a definition
2855 # It contains the block of comments just above the declaration
2859 # A list of lines of comment
2860 var n_comment
= new ANodes[TComment](self)
2863 # A group of annotation on a node
2865 # This same class is used for the 3 kind of annotations:
2867 # * *is* annotations. eg `module foo is bar`.
2868 # * *at* annotations. eg `foo@bar` or `foo@(bar,baz)`.
2869 # * *class* annotations, defined in classes.
2873 # The `is` keyword, for *is* annotations
2874 var n_kwis
: nullable TKwis = null is writable
2876 # The `@` symbol, for *at* annotations
2877 var n_at
: nullable TAt = null is writable
2879 # The opening parenthesis in *at* annotations
2880 var n_opar
: nullable TOpar = null is writable
2882 # The list of annotations
2883 var n_items
= new ANodes[AAnnotation](self)
2885 # The closing parenthesis in *at* annotations
2886 var n_cpar
: nullable TCpar = null is writable
2888 # The `end` keyword, for *is* annotations
2889 var n_kwend
: nullable TKwend = null is writable
2892 # A single annotation
2896 # The name of the annotation
2897 var n_atid
: AAtid is writable, noinit
2899 # The opening parenthesis of the arguments
2900 var n_opar
: nullable TOpar = null is writable
2902 # The list of arguments
2903 var n_args
= new ANodes[AExpr](self)
2905 # The closing parenthesis
2906 var n_cpar
: nullable TCpar = null is writable
2908 # The name of the annotation
2911 return n_atid
.n_id
.text
2915 # An annotation name
2916 abstract class AAtid
2919 # The identifier of the annotation.
2920 # Can be a TId of a keyword
2921 var n_id
: Token is writable, noinit
2924 # An annotation name based on an identifier
2929 # An annotation name based on the keyword `extern`
2934 # An annotation name based on the keyword `import`
2939 # An annotation name based on the keyword `abstract`
2940 class AKwabstractAtid
2944 # The root of the AST
2949 var n_base
: nullable AModule is writable
2951 # The end of file (or error) token
2952 var n_eof
: EOF is writable