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 decimal byte
964 # A literal hexadecimal byte
969 # A literal binary byte
974 # A literal octal byte
979 # A literal floating point number
984 # A literal character
994 # The starting part of a super string (between `"` and `{`)
999 # The middle part of a super string (between `}` and `{`)
1004 # The final part of a super string (between `}` and `"`)
1009 # A malformed string
1014 do return "malformed string {text}"
1023 do return "malformed character {text}"
1027 # A extern code block
1028 class TExternCodeSegment
1037 return "end of file"
1041 # A mark of an error
1045 # A lexical error (unexpected character)
1049 # A syntactic error (unexpected token)
1054 # The main node of a Nit source-file
1058 # The declaration part of the module
1059 var n_moduledecl
: nullable AModuledecl = null is writable
1061 # List of importation clauses
1062 var n_imports
= new ANodes[AImport](self)
1064 # List of extern blocks
1065 var n_extern_code_blocks
= new ANodes[AExternCodeBlock](self)
1067 # List of class definition (including top-level methods and the main)
1068 var n_classdefs
= new ANodes[AClassdef](self)
1071 # Abstract class for definition of entities
1072 abstract class ADefinition
1075 var n_doc
: nullable ADoc = null is writable
1077 # The `redef` keyword
1078 var n_kwredef
: nullable TKwredef = null is writable
1080 # The declared visibility
1081 var n_visibility
: nullable AVisibility = null is writable
1084 # The declaration of the module with the documentation, name, and annotations
1088 # The `module` keyword
1089 var n_kwmodule
: TKwmodule is writable, noinit
1091 # The declared module name
1092 var n_name
: AModuleName is writable, noinit
1095 # A import clause of a module
1096 abstract class AImport
1099 # The declared visibility
1100 var n_visibility
: AVisibility is writable, noinit
1102 # The `import` keyword
1103 var n_kwimport
: TKwimport is writable, noinit
1106 # A standard import clause. eg `import x`
1109 # The imported module name
1110 var n_name
: AModuleName is writable, noinit
1113 # The special import clause of the kernel module. eg `import end`
1116 # The `end` keyword, that indicate the root module
1117 var n_kwend
: TKwend is writable, noinit
1120 # A visibility modifier
1122 # The public visibility is an empty production (no keyword).
1124 # Note: even if some visibilities are only valid on some placse (for instance, no `protected` class or no `intrude` method)
1125 # the parser has no such a restriction, therefore the semantic phases has to check that the visibilities make sense.
1126 abstract class AVisibility
1130 # An implicit or explicit public visibility modifier
1131 class APublicVisibility
1133 # The `public` keyword, if any
1134 var n_kwpublic
: nullable TKwpublic is writable
1136 # An explicit private visibility modifier
1137 class APrivateVisibility
1139 # The `private` keyword
1140 var n_kwprivate
: TKwprivate is writable, noinit
1142 # An explicit protected visibility modifier
1143 class AProtectedVisibility
1145 # The `protected` keyword
1146 var n_kwprotected
: TKwprotected is writable, noinit
1148 # An explicit intrude visibility modifier
1149 class AIntrudeVisibility
1151 # The `intrude` keyword
1152 var n_kwintrude
: TKwintrude is writable, noinit
1155 # A class definition
1156 # While most definition are `AStdClassdef`
1157 # There is tow special case of class definition
1158 abstract class AClassdef
1160 # All the declared properties (including the main method)
1161 var n_propdefs
= new ANodes[APropdef](self)
1164 # A standard class definition with a name, superclasses and properties
1169 # The class kind (interface, abstract class, etc.)
1170 var n_classkind
: AClasskind is writable, noinit
1172 # The name of the class
1173 var n_id
: nullable TClassid = null is writable
1176 var n_obra
: nullable TObra = null is writable
1178 # The list of formal parameter types
1179 var n_formaldefs
= new ANodes[AFormaldef](self)
1182 var n_cbra
: nullable TCbra = null is writable
1184 # The extern block code
1185 var n_extern_code_block
: nullable AExternCodeBlock = null is writable
1188 var n_kwend
: TKwend is writable, noinit
1190 fun n_superclasses
: Array[ASuperPropdef] do
1191 return [for d
in n_propdefs
do if d
isa ASuperPropdef then d
]
1194 redef fun hot_location
do return n_id
.location
1197 # The implicit class definition of the implicit main method
1202 # The implicit class definition of the top-level methods
1207 # The modifier for the kind of class (abstract, interface, etc.)
1208 abstract class AClasskind
1212 # A default, or concrete class modifier (just `class`)
1213 class AConcreteClasskind
1216 # The `class` keyword.
1217 var n_kwclass
: TKwclass is writable, noinit
1220 # An abstract class modifier (`abstract class`)
1221 class AAbstractClasskind
1224 # The `abstract` keyword.
1225 var n_kwabstract
: TKwabstract is writable, noinit
1227 # The `class` keyword.
1228 var n_kwclass
: TKwclass is writable, noinit
1231 # An interface class modifier (`interface`)
1232 class AInterfaceClasskind
1235 # The `interface` keyword.
1236 var n_kwinterface
: TKwinterface is writable, noinit
1239 # An enum/universal class modifier (`enum class`)
1240 class AEnumClasskind
1243 # The `enum` keyword.
1244 var n_kwenum
: TKwenum is writable, noinit
1247 # An extern class modifier (`extern class`)
1248 class AExternClasskind
1251 # The `extern` keyword.
1252 var n_kwextern
: TKwextern is writable, noinit
1254 # The `class` keyword.
1255 var n_kwclass
: nullable TKwclass = null is writable
1258 # The definition of a formal generic parameter type. eg `X: Y`
1262 # The name of the parameter type
1263 var n_id
: TClassid is writable, noinit
1265 # The bound of the parameter type
1266 var n_type
: nullable AType = null is writable
1269 # The definition of a property
1270 abstract class APropdef
1274 # A definition of an attribute
1275 # For historical reason, old-syle and new-style attributes use the same `ANode` sub-class
1280 var n_kwvar
: TKwvar is writable, noinit
1282 # The identifier for a new-style attribute
1283 var n_id2
: TId is writable, noinit
1285 # The declared type of the attribute
1286 var n_type
: nullable AType = null is writable
1289 var n_assign
: nullable TAssign = null is writable
1291 # The initial value, if any (set with `=`)
1292 var n_expr
: nullable AExpr = null is writable
1295 var n_kwdo
: nullable TKwdo = null is writable
1297 # The initial value, if any (set with `do return`)
1298 var n_block
: nullable AExpr = null is writable
1301 var n_kwend
: nullable TKwend = null is writable
1303 redef fun hot_location
1305 return n_id2
.location
1309 # A definition of all kind of method (including constructors)
1313 # The `fun` keyword, if any
1314 var n_kwmeth
: nullable TKwmeth = null is writable
1316 # The `init` keyword, if any
1317 var n_kwinit
: nullable TKwinit = null is writable
1319 # The `new` keyword, if any
1320 var n_kwnew
: nullable TKwnew = null is writable
1322 # The name of the method, if any
1323 var n_methid
: nullable AMethid = null is writable
1325 # The signature of the method, if any
1326 var n_signature
: nullable ASignature = null is writable
1329 var n_kwdo
: nullable TKwdo = null is writable
1331 # The body (in Nit) of the method, if any
1332 var n_block
: nullable AExpr = null is writable
1335 var n_kwend
: nullable TKwend = null is writable
1337 # The list of declared callbacks (for extern methods)
1338 var n_extern_calls
: nullable AExternCalls = null is writable
1340 # The body (in extern code) of the method, if any
1341 var n_extern_code_block
: nullable AExternCodeBlock = null is writable
1343 redef fun hot_location
1345 if n_methid
!= null then
1346 return n_methid
.location
1347 else if n_kwinit
!= null then
1348 return n_kwinit
.location
1349 else if n_kwnew
!= null then
1350 return n_kwnew
.location
1357 # The implicit main method
1358 class AMainMethPropdef
1367 # A super-class. eg `super X`
1372 var n_kwsuper
: TKwsuper is writable, noinit
1374 # The super-class (indicated as a type)
1375 var n_type
: AType is writable, noinit
1379 # Declaration of callbacks for extern methods
1383 # The `import` keyword
1384 var n_kwimport
: TKwimport is writable, noinit
1386 # The list of declared callbacks
1387 var n_extern_calls
: ANodes[AExternCall] = new ANodes[AExternCall](self)
1390 # A single callback declaration
1391 abstract class AExternCall
1395 # A single callback declaration on a method
1396 abstract class APropExternCall
1400 # A single callback declaration on a method on the current receiver
1401 class ALocalPropExternCall
1402 super APropExternCall
1404 # The name of the called-back method
1405 var n_methid
: AMethid is writable, noinit
1408 # A single callback declaration on a method on an explicit receiver type.
1409 class AFullPropExternCall
1410 super APropExternCall
1412 # The type of the receiver of the called-back method
1413 var n_type
: AType is writable, noinit
1416 var n_dot
: nullable TDot = null is writable
1418 # The name of the called-back method
1419 var n_methid
: AMethid is writable, noinit
1422 # A single callback declaration on a method on a constructor
1423 class AInitPropExternCall
1424 super APropExternCall
1426 # The allocated type
1427 var n_type
: AType is writable, noinit
1430 # A single callback declaration on a `super` call
1431 class ASuperExternCall
1434 # The `super` keyword
1435 var n_kwsuper
: TKwsuper is writable, noinit
1438 # A single callback declaration on a cast
1439 abstract class ACastExternCall
1443 # A single callback declaration on a cast to a given type
1444 class ACastAsExternCall
1445 super ACastExternCall
1447 # The origin type of the cast
1448 var n_from_type
: AType is writable, noinit
1451 var n_dot
: nullable TDot = null is writable
1454 var n_kwas
: TKwas is writable, noinit
1456 # The destination of the cast
1457 var n_to_type
: AType is writable, noinit
1460 # A single callback declaration on a cast to a nullable type
1461 class AAsNullableExternCall
1462 super ACastExternCall
1464 # The origin type to cast as nullable
1465 var n_type
: AType is writable, noinit
1468 var n_kwas
: TKwas is writable, noinit
1470 # The `nullable` keyword
1471 var n_kwnullable
: TKwnullable is writable, noinit
1474 # A single callback declaration on a cast to a non-nullable type
1475 class AAsNotNullableExternCall
1476 super ACastExternCall
1478 # The destination type on a cast to not nullable
1479 var n_type
: AType is writable, noinit
1482 var n_kwas
: TKwas is writable, noinit
1485 var n_kwnot
: TKwnot is writable, noinit
1487 # The `nullable` keyword
1488 var n_kwnullable
: TKwnullable is writable, noinit
1491 # A definition of a virtual type
1495 # The `type` keyword
1496 var n_kwtype
: TKwtype is writable, noinit
1498 # The name of the virtual type
1499 var n_id
: TClassid is writable, noinit
1501 # The bound of the virtual type
1502 var n_type
: AType is writable, noinit
1505 # The identifier of a method in a method declaration.
1506 # There is a specific class because of operator and setters.
1507 abstract class AMethid
1511 # A method name with a simple identifier
1515 # The simple identifier
1516 var n_id
: TId is writable, noinit
1519 # A method name for an operator
1520 class AOperatorMethid
1523 # The associated operator symbol
1524 var n_op
: Token is writable, noinit
1528 super AOperatorMethid
1533 super AOperatorMethid
1538 super AOperatorMethid
1541 # A method name `**`
1542 class AStarstarMethid
1543 super AOperatorMethid
1548 super AOperatorMethid
1552 class APercentMethid
1553 super AOperatorMethid
1558 super AOperatorMethid
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 `<=`
1588 super AOperatorMethid
1591 # A method name `>=`
1593 super AOperatorMethid
1598 super AOperatorMethid
1603 super AOperatorMethid
1606 # A method name `<<`
1608 super AOperatorMethid
1611 # A method name `>>`
1613 super AOperatorMethid
1616 # A method name `<=>`
1617 class AStarshipMethid
1618 super AOperatorMethid
1621 # A method name `[]`
1626 var n_obra
: TObra is writable, noinit
1629 var n_cbra
: TCbra is writable, noinit
1632 # A setter method name with a simple identifier (with a `=`)
1636 # The base identifier
1637 var n_id
: TId is writable, noinit
1640 var n_assign
: TAssign is writable, noinit
1643 # A method name `[]=`
1644 class ABraassignMethid
1648 var n_obra
: TObra is writable, noinit
1651 var n_cbra
: TCbra is writable, noinit
1654 var n_assign
: TAssign is writable, noinit
1657 # A signature in a method definition. eg `(x,y:X,z:Z):T`
1662 var n_opar
: nullable TOpar = null is writable
1664 # The list of parameters
1665 var n_params
= new ANodes[AParam](self)
1668 var n_cpar
: nullable TCpar = null is writable
1671 var n_type
: nullable AType = null is writable
1674 # A parameter definition in a signature. eg `x:X`
1678 # The name of the parameter
1679 var n_id
: TId is writable, noinit
1681 # The type of the parameter, if any
1682 var n_type
: nullable AType = null is writable
1684 # The `...` symbol to indicate varargs
1685 var n_dotdotdot
: nullable TDotdotdot = null is writable
1688 # A static type. eg `nullable X[Y]`
1691 # The `nullable` keyword
1692 var n_kwnullable
: nullable TKwnullable = null is writable
1694 # The name of the class or of the formal type
1695 var n_id
: TClassid is writable, noinit
1697 # The opening bracket
1698 var n_obra
: nullable TObra = null is writable
1700 # Type arguments for a generic type
1701 var n_types
= new ANodes[AType](self)
1703 # The closing bracket
1704 var n_cbra
: nullable TCbra = null is writable
1707 # A label at the end of a block or in a break/continue statement. eg `label x`
1711 # The `label` keyword
1712 var n_kwlabel
: TKwlabel is writable, noinit
1714 # The name of the label, if any
1715 var n_id
: nullable TId is writable, noinit
1718 # Expression and statements
1719 # From a AST point of view there is no distinction between statement and expressions (even if the parser has to distinguish them)
1720 abstract class AExpr
1724 # A sequence of `AExpr` (usually statements)
1725 # The last `AExpr` gives the value of the whole block
1729 # The list of statements in the bloc.
1730 # The last element is often considered as an expression that give the value of the whole block.
1731 var n_expr
= new ANodes[AExpr](self)
1734 var n_kwend
: nullable TKwend = null is writable
1737 # A declaration of a local variable. eg `var x: X = y`
1742 var n_kwvar
: nullable TKwvar = null is writable
1744 # The name of the local variable
1745 var n_id
: TId is writable, noinit
1747 # The declaration type of the local variable
1748 var n_type
: nullable AType = null is writable
1750 # The `=` symbol (for the initial value)
1751 var n_assign
: nullable TAssign = null is writable
1753 # The initial value, if any
1754 var n_expr
: nullable AExpr = null is writable
1757 # A `return` statement. eg `return x`
1761 # The `return` keyword
1762 var n_kwreturn
: nullable TKwreturn = null is writable
1764 # The return value, if any
1765 var n_expr
: nullable AExpr = null is writable
1768 # Something that has a label.
1769 abstract class ALabelable
1772 # The associated label declatation
1773 var n_label
: nullable ALabel = null is writable
1776 # A `break` or a `continue`
1777 abstract class AEscapeExpr
1781 # The return value, if nay (unused currently)
1782 var n_expr
: nullable AExpr = null is writable
1785 # A `break` statement.
1789 # The `break` keyword
1790 var n_kwbreak
: TKwbreak is writable, noinit
1793 # An `abort` statement
1797 # The `abort` keyword
1798 var n_kwabort
: TKwabort is writable, noinit
1801 # A `continue` statement
1805 # The `continue` keyword.
1806 var n_kwcontinue
: nullable TKwcontinue = null is writable
1815 var n_kwdo
: TKwdo is writable, noinit
1817 # The list of statements of the `do`.
1818 var n_block
: nullable AExpr = null is writable
1826 var n_kwif
: TKwif is writable, noinit
1828 # The expression used as the condition of the `if`
1829 var n_expr
: AExpr is writable, noinit
1831 # The `then` keyword
1832 var n_kwthen
: TKwthen is writable, noinit
1834 # The body of the `then` part
1835 var n_then
: nullable AExpr = null is writable
1837 # The `else` keyword
1838 var n_kwelse
: nullable TKwelse = null is writable
1840 # The body of the `else` part
1841 var n_else
: nullable AExpr = null is writable
1844 # A `if` expression (ternary conditional). eg. `if true then 1 else 0`
1849 var n_kwif
: TKwif is writable, noinit
1851 # The expression used as the condition of the `if`
1852 var n_expr
: AExpr is writable, noinit
1854 # The `then` keyword
1855 var n_kwthen
: TKwthen is writable, noinit
1857 # The expression in the `then` part
1858 var n_then
: AExpr is writable, noinit
1860 # The `else` keyword
1861 var n_kwelse
: TKwelse is writable, noinit
1863 # The expression in the `else` part
1864 var n_else
: AExpr is writable, noinit
1867 # A `while` statement
1872 # The `while` keyword
1873 var n_kwwhile
: TKwwhile is writable, noinit
1875 # The expression used as the condition of the `while`
1876 var n_expr
: AExpr is writable, noinit
1879 var n_kwdo
: TKwdo is writable, noinit
1881 # The body of the loop
1882 var n_block
: nullable AExpr = null is writable
1885 # A `loop` statement
1890 # The `loop` keyword
1891 var n_kwloop
: TKwloop is writable, noinit
1893 # The body of the loop
1894 var n_block
: nullable AExpr = null is writable
1903 var n_kwfor
: TKwfor is writable, noinit
1905 # The list of name of the automatic variables
1906 var n_ids
= new ANodes[TId](self)
1909 var n_kwin
: TKwin is writable, noinit
1911 # The expression used as the collection to iterate on
1912 var n_expr
: AExpr is writable, noinit
1915 var n_kwdo
: TKwdo is writable, noinit
1917 # The body of the loop
1918 var n_block
: nullable AExpr = null is writable
1921 # A `with` statement
1926 # The `with` keyword
1927 var n_kwwith
: TKwwith is writable, noinit
1929 # The expression used to get the value to control
1930 var n_expr
: AExpr is writable, noinit
1933 var n_kwdo
: TKwdo is writable, noinit
1935 # The body of the loop
1936 var n_block
: nullable AExpr = null is writable
1939 # An `assert` statement
1943 # The `assert` keyword
1944 var n_kwassert
: TKwassert is writable, noinit
1946 # The name of the assert, if any
1947 var n_id
: nullable TId = null is writable
1949 # The expression used as the condition of the `assert`
1950 var n_expr
: AExpr is writable, noinit
1952 # The `else` keyword
1953 var n_kwelse
: nullable TKwelse = null is writable
1955 # The body to execute when the assert fails
1956 var n_else
: nullable AExpr = null is writable
1959 # Whatever is a simple assignment. eg `= something`
1960 abstract class AAssignFormExpr
1964 var n_assign
: TAssign is writable, noinit
1966 # The right-value to assign.
1967 var n_value
: AExpr is writable, noinit
1970 # Whatever is a combined assignment. eg `+= something`
1971 abstract class AReassignFormExpr
1974 # The combined operator (eg. `+=`)
1975 var n_assign_op
: AAssignOp is writable, noinit
1977 # The right-value to apply on the combined operator.
1978 var n_value
: AExpr is writable, noinit
1981 # A `once` expression. eg `once x`
1985 # The `once` keyword
1986 var n_kwonce
: TKwonce is writable, noinit
1988 # The expression to evaluate only one time
1989 var n_expr
: AExpr is writable, noinit
1992 # A polymorphic invocation of a method
1993 # The form of the invocation (name, arguments, etc.) are specific
1994 abstract class ASendExpr
1996 # The receiver of the method invocation
1997 var n_expr
: AExpr is writable, noinit
2000 # A binary operation on a method
2001 abstract class ABinopExpr
2005 var n_op
: Token is writable, noinit
2007 # The second operand of the operation
2008 # Note: the receiver (`n_expr`) is the first operand
2009 var n_expr2
: AExpr is writable, noinit
2011 # The name of the operator (eg '+')
2012 fun operator
: String is abstract
2015 # Something that is boolean expression
2016 abstract class ABoolExpr
2020 # Something that is binary boolean expression
2021 abstract class ABinBoolExpr
2024 # The first boolean operand
2025 var n_expr
: AExpr is writable, noinit
2028 var n_op
: Token is writable, noinit
2030 # The second boolean operand
2031 var n_expr2
: AExpr is writable, noinit
2039 # A `and` expression
2044 # A `or else` expression
2048 # The `else` keyword
2049 var n_kwelse
: TKwelse is writable, noinit
2052 # A `implies` expression
2057 # A `not` expression
2062 var n_kwnot
: TKwnot is writable, noinit
2064 # The boolean operand of the `not`
2065 var n_expr
: AExpr is writable, noinit
2071 redef fun operator
do return "=="
2077 redef fun operator
do return "!="
2083 redef fun operator
do return "<"
2089 redef fun operator
do return "<="
2095 redef fun operator
do return "<<"
2101 redef fun operator
do return ">"
2107 redef fun operator
do return ">="
2113 redef fun operator
do return ">>"
2116 # A type-ckeck expression. eg `x isa T`
2120 # The expression to check
2121 var n_expr
: AExpr is writable, noinit
2124 var n_kwisa
: TKwisa is writable, noinit
2126 # The destination type to check to
2127 var n_type
: AType is writable, noinit
2133 redef fun operator
do return "+"
2139 redef fun operator
do return "-"
2142 # A `<=>` expression
2145 redef fun operator
do return "<=>"
2151 redef fun operator
do return "*"
2157 redef fun operator
do return "**"
2163 redef fun operator
do return "/"
2169 redef fun operator
do return "%"
2175 redef fun operator
do return "|"
2181 redef fun operator
do return "^"
2187 redef fun operator
do return "&"
2190 # A unary operation on a method
2195 var n_op
: Token is writable, noinit
2197 # The name of the operator (eg '+')
2198 fun operator
: String is abstract
2201 # A unary minus expression. eg `-x`
2204 redef fun operator
do return "-"
2207 # A unary plus expression. eg `+x`
2210 redef fun operator
do return "+"
2213 # A unary `~` expression
2216 redef fun operator
do return "~"
2219 # An explicit instantiation. eg `new T`
2224 var n_kwnew
: TKwnew is writable, noinit
2226 # The `type` keyword
2227 var n_type
: AType is writable, noinit
2229 # The name of the named-constructor, if any
2230 var n_id
: nullable TId = null is writable
2232 # The arguments of the `new`
2233 var n_args
: AExprs is writable, noinit
2236 # Whatever is a old-style attribute access
2237 abstract class AAttrFormExpr
2240 # The receiver of the attribute
2241 var n_expr
: AExpr is writable, noinit
2243 # The name of the attribute
2244 var n_id
: TAttrid is writable, noinit
2248 # The read of an attribute. eg `x._a`
2253 # The assignment of an attribute. eg `x._a=y`
2254 class AAttrAssignExpr
2256 super AAssignFormExpr
2259 # Whatever looks-like a call with a standard method and any number of arguments.
2260 abstract class ACallFormExpr
2263 # The name of the method
2264 var n_id
: TId is writable, noinit
2266 # The arguments of the call
2267 var n_args
: AExprs is writable, noinit
2270 # A complex setter call (standard or brackets)
2271 abstract class ASendReassignFormExpr
2273 super AReassignFormExpr
2276 # A complex attribute assignment. eg `x._a+=y`
2277 class AAttrReassignExpr
2279 super AReassignFormExpr
2282 # A call with a standard method-name and any number of arguments. eg `x.m(y)`. OR just a simple id
2283 # 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`.
2284 # Semantic analysis have to transform them to instance of `AVarExpr`.
2289 # A setter call with a standard method-name and any number of arguments. eg `x.m(y)=z`. OR just a simple assignment.
2290 # 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`.
2291 # Semantic analysis have to transform them to instance of `AVarAssignExpr`.
2292 class ACallAssignExpr
2294 super AAssignFormExpr
2297 # 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.
2298 # 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`.
2299 # Semantic analysis have to transform them to instance of `AVarReassignExpr`.
2300 class ACallReassignExpr
2302 super ASendReassignFormExpr
2305 # A call to `super`. OR a call of a super-constructor
2309 # The qualifier part before the super (currenlty unused)
2310 var n_qualified
: nullable AQualified = null is writable
2312 # The `super` keyword
2313 var n_kwsuper
: TKwsuper is writable, noinit
2315 # The arguments of the super
2316 var n_args
: AExprs is writable, noinit
2319 # A call to the `init` constructor.
2320 # Note: because `init` is a keyword and not a `TId`, the explicit call to init cannot be a `ACallFormExpr`.
2324 # The `init` keyword
2325 var n_kwinit
: TKwinit is writable, noinit
2327 # The arguments of the init
2328 var n_args
: AExprs is writable, noinit
2331 # Whatever looks-like a call of the brackets `[]` operator.
2332 abstract class ABraFormExpr
2335 # The arguments inside the brackets
2336 var n_args
: AExprs is writable, noinit
2339 # A call of the brackets operator. eg `x[y,z]`
2344 # A setter call of the bracket operator. eg `x[y,z]=t`
2345 class ABraAssignExpr
2347 super AAssignFormExpr
2350 # Whatever is an access to a local variable
2351 abstract class AVarFormExpr
2354 # The name of the attribute
2355 var n_id
: TId is writable, noinit
2358 # A complex setter call of the bracket operator. eg `x[y,z]+=t`
2359 class ABraReassignExpr
2361 super ASendReassignFormExpr
2364 # A local variable read access.
2365 # The parser cannot instantiate them, see `ACallExpr`.
2370 # A local variable simple assignment access
2371 # The parser cannot instantiate them, see `ACallAssignExpr`.
2372 class AVarAssignExpr
2374 super AAssignFormExpr
2377 # A local variable complex assignment access
2378 # The parser cannot instantiate them, see `ACallReassignExpr`.
2379 class AVarReassignExpr
2381 super AReassignFormExpr
2384 # A literal range, open or closed
2385 abstract class ARangeExpr
2388 # The left (lower) element of the range
2389 var n_expr
: AExpr is writable, noinit
2392 var n_dotdot
: TDotdot is writable, noinit
2394 # The right (upper) element of the range
2395 var n_expr2
: AExpr is writable, noinit
2398 # A closed literal range. eg `[x..y]`
2402 # The opening bracket `[`
2403 var n_obra
: TObra is writable, noinit
2405 # The closing bracket `]`
2406 var n_cbra
: TCbra is writable, noinit
2409 # An open literal range. eg `[x..y[`
2413 # The opening bracket `[`
2414 var n_obra
: TObra is writable, noinit
2416 # The closing bracket `[` (because open range)
2417 var n_cbra
: TObra is writable, noinit
2420 # A literal array. eg. `[x,y,z]`
2424 # The opening bracket `[`
2425 var n_obra
: TObra is writable, noinit
2427 # The elements of the array
2428 var n_exprs
= new ANodes[AExpr](self)
2430 # The type of the element of the array (if any)
2431 var n_type
: nullable AType = null is writable
2433 # The closing bracket `]`
2434 var n_cbra
: TCbra is writable, noinit
2441 # The `self` keyword
2442 var n_kwself
: nullable TKwself = null is writable
2445 # When there is no explicit receiver, `self` is implicit
2446 class AImplicitSelfExpr
2450 # A `true` boolean literal constant
2454 # The `true` keyword
2455 var n_kwtrue
: TKwtrue is writable, noinit
2458 # A `false` boolean literal constant
2462 # The `false` keyword
2463 var n_kwfalse
: TKwfalse is writable, noinit
2466 # A `null` literal constant
2470 # The `null` keyword
2471 var n_kwnull
: TKwnull is writable, noinit
2474 # An integer literal
2479 # An integer literal in decimal format
2484 var n_number
: TNumber is writable, noinit
2487 # An integer literal in hexadecimal format
2491 # The hexadecimal token
2492 var n_hex_number
: THexNumber is writable, noinit
2495 # An integer literal in binary format
2500 var n_bin_number
: TBinNumber is writable, noinit
2503 # An integer literal in octal format
2508 var n_oct_number
: TOctNumber is writable, noinit
2516 # An byte literal in decimal format
2521 var n_bytenum
: TBytenum is writable, noinit
2524 # An byte literal in hexadecimal format
2528 # The hexadecimal token
2529 var n_hex_bytenum
: THexBytenum is writable, noinit
2532 # An byte literal in binary format
2537 var n_bin_bytenum
: TBinBytenum is writable, noinit
2540 # An byte literal in octal format
2545 var n_oct_bytenum
: TOctBytenum is writable, noinit
2553 var n_float
: TFloat is writable, noinit
2556 # A character literal
2560 # The character token
2561 var n_char
: TChar is writable, noinit
2565 abstract class AStringFormExpr
2569 var n_string
: Token is writable, noinit
2572 # A simple string. eg. `"abc"`
2574 super AStringFormExpr
2577 # The start of a superstring. eg `"abc{`
2578 class AStartStringExpr
2579 super AStringFormExpr
2582 # The middle of a superstring. eg `}abc{`
2583 class AMidStringExpr
2584 super AStringFormExpr
2587 # The end of a superstrng. eg `}abc"`
2588 class AEndStringExpr
2589 super AStringFormExpr
2592 # A superstring literal. eg `"a{x}b{y}c"`
2593 # Each part is modeled a sequence of expression. eg. `["a{, x, }b{, y, }c"]`
2594 class ASuperstringExpr
2597 # The list of the expressions of the superstring
2598 var n_exprs
= new ANodes[AExpr](self)
2601 # A simple parenthesis. eg `(x)`
2605 # The opening parenthesis
2606 var n_opar
: TOpar is writable, noinit
2608 # The inner expression
2609 var n_expr
: AExpr is writable, noinit
2611 # The closing parenthesis
2612 var n_cpar
: TCpar is writable, noinit
2615 # A cast, against a type or `not null`
2619 # The expression to cast
2620 var n_expr
: AExpr is writable, noinit
2623 var n_kwas
: TKwas is writable, noinit
2625 # The opening parenthesis
2626 var n_opar
: nullable TOpar = null is writable
2628 # The closing parenthesis
2629 var n_cpar
: nullable TCpar = null is writable
2632 # A type cast. eg `x.as(T)`
2636 # The target type to cast to
2637 var n_type
: AType is writable, noinit
2640 # A as-not-null cast. eg `x.as(not null)`
2641 class AAsNotnullExpr
2645 var n_kwnot
: TKwnot is writable, noinit
2647 # The `null` keyword
2648 var n_kwnull
: TKwnull is writable, noinit
2651 # A is-set check of old-style attributes. eg `isset x._a`
2652 class AIssetAttrExpr
2655 # The `isset` keyword
2656 var n_kwisset
: TKwisset is writable, noinit
2659 # An ellipsis notation used to pass an expression as it, in a vararg parameter
2663 # The passed expression
2664 var n_expr
: AExpr is writable, noinit
2667 var n_dotdotdot
: TDotdotdot is writable, noinit
2670 # An named notation used to pass an expression by name in a parameter
2674 # The name of the argument
2675 var n_id
: TId is writable, noinit
2678 var n_assign
: TAssign is writable, noinit
2680 # The passed expression
2681 var n_expr
: AExpr is writable, noinit
2684 # A list of expression separated with commas (arguments for instance)
2688 # The list of expressions
2689 var n_exprs
= new ANodes[AExpr](self)
2692 # A special expression that encapsulates a static type
2693 # Can only be found in special construction like arguments of annotations.
2697 # The encapsulated type
2698 var n_type
: AType is writable, noinit
2701 # A special expression that encapsulates a method identifier
2702 # Can only be found in special construction like arguments of annotations.
2707 var n_expr
: AExpr is writable, noinit
2709 # The encapsulated method identifier
2710 var n_id
: AMethid is writable, noinit
2713 # A special expression that encapsulate an annotation
2714 # Can only be found in special construction like arguments of annotations.
2716 # The encapsulated annotations are in `n_annotations`
2721 # A special expression to debug types
2722 class ADebugTypeExpr
2725 # The `debug` keyword
2726 var n_kwdebug
: TKwdebug is writable, noinit
2728 # The `type` keyword
2729 var n_kwtype
: TKwtype is writable, noinit
2731 # The expression to check
2732 var n_expr
: AExpr is writable, noinit
2735 var n_type
: AType is writable, noinit
2738 # A list of expression separated with commas (arguments for instance)
2739 abstract class AExprs
2742 # The list of expressions
2743 var n_exprs
= new ANodes[AExpr](self)
2746 # A simple list of expressions
2751 # A list of expressions enclosed in parentheses
2755 # The opening parenthesis
2756 var n_opar
: TOpar is writable, noinit
2758 # The closing parenthesis
2759 var n_cpar
: TCpar is writable, noinit
2762 # A list of expressions enclosed in brackets
2766 # The opening bracket
2767 var n_obra
: TObra is writable, noinit
2769 # The closing bracket
2770 var n_cbra
: TCbra is writable, noinit
2773 # A complex assignment operator. (`+=` and `-=`)
2774 abstract class AAssignOp
2777 # The combined assignment operator
2778 var n_op
: Token is writable, noinit
2780 # The name of the operator without the `=` (eg '+')
2781 fun operator
: String is abstract
2784 # A `+=` assignment operation
2788 redef fun operator
do return "+"
2791 # A `-=` assignment operation
2792 class AMinusAssignOp
2795 redef fun operator
do return "-"
2798 # A `*=` assignment operation
2802 redef fun operator
do return "*"
2805 # A `/=` assignment operation
2806 class ASlashAssignOp
2809 redef fun operator
do return "/"
2812 # A `%=` assignment operation
2813 class APercentAssignOp
2816 redef fun operator
do return "%"
2819 # A `**=` assignment operation
2820 class AStarstarAssignOp
2823 redef fun operator
do return "**"
2826 # A `|=` assignment operation
2830 redef fun operator
do return "|"
2833 # A `^=` assignment operation
2834 class ACaretAssignOp
2837 redef fun operator
do return "^"
2840 # A `&=` assignment operation
2844 redef fun operator
do return "&"
2847 # A `<<=` assignment operation
2851 redef fun operator
do return "<<"
2854 # A `>>=` assignment operation
2858 redef fun operator
do return ">>"
2861 # A possibly fully-qualified module identifier
2865 # The starting quad (`::`)
2866 var n_quad
: nullable TQuad = null is writable
2868 # The list of quad-separated project/group identifiers
2869 var n_path
= new ANodes[TId](self)
2871 # The final module identifier
2872 var n_id
: TId is writable, noinit
2875 # A language declaration for an extern block
2880 var n_kwin
: TKwin is writable, noinit
2883 var n_string
: TString is writable, noinit
2886 # An full extern block
2887 class AExternCodeBlock
2890 # The language declration
2891 var n_in_language
: nullable AInLanguage = null is writable
2893 # The block of extern code
2894 var n_extern_code_segment
: TExternCodeSegment is writable, noinit
2897 # A possible full method qualifier.
2901 # The starting quad (`::`)
2902 var n_quad
: nullable TQuad = null is writable
2904 # The list of quad-separated project/group/module identifiers
2905 var n_id
= new ANodes[TId](self)
2907 # A class identifier
2908 var n_classid
: nullable TClassid = null is writable
2911 # A documentation of a definition
2912 # It contains the block of comments just above the declaration
2916 # A list of lines of comment
2917 var n_comment
= new ANodes[TComment](self)
2920 # A group of annotation on a node
2922 # This same class is used for the 3 kind of annotations:
2924 # * *is* annotations. eg `module foo is bar`.
2925 # * *at* annotations. eg `foo@bar` or `foo@(bar,baz)`.
2926 # * *class* annotations, defined in classes.
2930 # The `is` keyword, for *is* annotations
2931 var n_kwis
: nullable TKwis = null is writable
2933 # The `@` symbol, for *at* annotations
2934 var n_at
: nullable TAt = null is writable
2936 # The opening parenthesis in *at* annotations
2937 var n_opar
: nullable TOpar = null is writable
2939 # The list of annotations
2940 var n_items
= new ANodes[AAnnotation](self)
2942 # The closing parenthesis in *at* annotations
2943 var n_cpar
: nullable TCpar = null is writable
2945 # The `end` keyword, for *is* annotations
2946 var n_kwend
: nullable TKwend = null is writable
2949 # A single annotation
2953 # The name of the annotation
2954 var n_atid
: AAtid is writable, noinit
2956 # The opening parenthesis of the arguments
2957 var n_opar
: nullable TOpar = null is writable
2959 # The list of arguments
2960 var n_args
= new ANodes[AExpr](self)
2962 # The closing parenthesis
2963 var n_cpar
: nullable TCpar = null is writable
2965 # The name of the annotation
2968 return n_atid
.n_id
.text
2972 # An annotation name
2973 abstract class AAtid
2976 # The identifier of the annotation.
2977 # Can be a TId of a keyword
2978 var n_id
: Token is writable, noinit
2981 # An annotation name based on an identifier
2986 # An annotation name based on the keyword `extern`
2991 # An annotation name based on the keyword `import`
2996 # An annotation name based on the keyword `abstract`
2997 class AKwabstractAtid
3001 # The root of the AST
3006 var n_base
: nullable AModule is writable
3008 # The end of file (or error) token
3009 var n_eof
: EOF is writable