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}'"
863 # A class (or formal type) identifier. They start with an uppercase.
868 do return "type identifier '{text}'"
872 # A standard identifier (variable, method...). They start with a lowercase.
877 do return "identifier '{text}'"
881 # An attribute identifier. They start with an underscore.
886 do return "attribute '{text}'"
890 # A token of a literal value (string, integer, etc).
891 abstract class TokenLiteral
895 do return "literal value '{text}'"
899 # A literal decimal integer
904 # A literal hexadecimal integer
909 # A literal floating point number
914 # A literal character
924 # The starting part of a super string (between `"` and `{`)
929 # The middle part of a super string (between `}` and `{`)
934 # The final part of a super string (between `}` and `"`)
944 do return "malformed string {text}"
953 do return "malformed character {text}"
957 # A extern code block
958 class TExternCodeSegment
975 # A lexical error (unexpected character)
979 # A syntactic error (unexpected token)
984 # The main node of a Nit source-file
988 # The declaration part of the module
989 var n_moduledecl
: nullable AModuledecl = null is writable
991 # List of importation clauses
992 var n_imports
= new ANodes[AImport](self)
994 # List of extern blocks
995 var n_extern_code_blocks
= new ANodes[AExternCodeBlock](self)
997 # List of class definition (including top-level methods and the main)
998 var n_classdefs
= new ANodes[AClassdef](self)
1001 # Abstract class for definition of entities
1002 abstract class ADefinition
1005 var n_doc
: nullable ADoc = null is writable
1007 # The `redef` keyword
1008 var n_kwredef
: nullable TKwredef = null is writable
1010 # The declared visibility
1011 var n_visibility
: nullable AVisibility = null is writable
1014 # The declaration of the module with the documentation, name, and annotations
1018 # The `module` keyword
1019 var n_kwmodule
: TKwmodule is writable, noinit
1021 # The declared module name
1022 var n_name
: AModuleName is writable, noinit
1025 # A import clause of a module
1026 abstract class AImport
1029 # The declared visibility
1030 var n_visibility
: AVisibility is writable, noinit
1032 # The `import` keyword
1033 var n_kwimport
: TKwimport is writable, noinit
1036 # A standard import clause. eg `import x`
1039 # The imported module name
1040 var n_name
: AModuleName is writable, noinit
1043 # The special import clause of the kernel module. eg `import end`
1046 # The `end` keyword, that indicate the root module
1047 var n_kwend
: TKwend is writable, noinit
1050 # A visibility modifier
1052 # The public visibility is an empty production (no keyword).
1054 # Note: even if some visibilities are only valid on some placse (for instance, no `protected` class or no `intrude` method)
1055 # the parser has no such a restriction, therefore the semantic phases has to check that the visibilities make sense.
1056 abstract class AVisibility
1060 # An implicit or explicit public visibility modifier
1061 class APublicVisibility
1063 # The `public` keyword, if any
1064 var n_kwpublic
: nullable TKwpublic is writable
1066 # An explicit private visibility modifier
1067 class APrivateVisibility
1069 # The `private` keyword
1070 var n_kwprivate
: TKwprivate is writable, noinit
1072 # An explicit protected visibility modifier
1073 class AProtectedVisibility
1075 # The `protected` keyword
1076 var n_kwprotected
: TKwprotected is writable, noinit
1078 # An explicit intrude visibility modifier
1079 class AIntrudeVisibility
1081 # The `intrude` keyword
1082 var n_kwintrude
: TKwintrude is writable, noinit
1085 # A class definition
1086 # While most definition are `AStdClassdef`
1087 # There is tow special case of class definition
1088 abstract class AClassdef
1090 # All the declared properties (including the main method)
1091 var n_propdefs
= new ANodes[APropdef](self)
1094 # A standard class definition with a name, superclasses and properties
1099 # The class kind (interface, abstract class, etc.)
1100 var n_classkind
: AClasskind is writable, noinit
1102 # The name of the class
1103 var n_id
: nullable TClassid = null is writable
1105 # The list of formal parameter types
1106 var n_formaldefs
= new ANodes[AFormaldef](self)
1108 # The extern block code
1109 var n_extern_code_block
: nullable AExternCodeBlock = null is writable
1112 var n_kwend
: TKwend is writable, noinit
1114 fun n_superclasses
: Array[ASuperPropdef] do
1115 return [for d
in n_propdefs
do if d
isa ASuperPropdef then d
]
1118 redef fun hot_location
do return n_id
.location
1121 # The implicit class definition of the implicit main method
1126 # The implicit class definition of the top-level methods
1131 # The modifier for the kind of class (abstract, interface, etc.)
1132 abstract class AClasskind
1136 # A default, or concrete class modifier (just `class`)
1137 class AConcreteClasskind
1140 # The `class` keyword.
1141 var n_kwclass
: TKwclass is writable, noinit
1144 # An abstract class modifier (`abstract class`)
1145 class AAbstractClasskind
1148 # The `abstract` keyword.
1149 var n_kwabstract
: TKwabstract is writable, noinit
1151 # The `class` keyword.
1152 var n_kwclass
: TKwclass is writable, noinit
1155 # An interface class modifier (`interface`)
1156 class AInterfaceClasskind
1159 # The `interface` keyword.
1160 var n_kwinterface
: TKwinterface is writable, noinit
1163 # An enum/universal class modifier (`enum class`)
1164 class AEnumClasskind
1167 # The `enum` keyword.
1168 var n_kwenum
: TKwenum is writable, noinit
1171 # An extern class modifier (`extern class`)
1172 class AExternClasskind
1175 # The `extern` keyword.
1176 var n_kwextern
: TKwextern is writable, noinit
1178 # The `class` keyword.
1179 var n_kwclass
: nullable TKwclass = null is writable
1182 # The definition of a formal generic parameter type. eg `X: Y`
1186 # The name of the parameter type
1187 var n_id
: TClassid is writable, noinit
1189 # The bound of the parameter type
1190 var n_type
: nullable AType = null is writable
1193 # The definition of a property
1194 abstract class APropdef
1198 # A definition of an attribute
1199 # For historical reason, old-syle and new-style attributes use the same `ANode` sub-class
1203 # The identifier for a old-style attribute (null if new-style)
1204 var n_kwvar
: TKwvar is writable, noinit
1206 # The identifier for a new-style attribute (null if old-style)
1207 var n_id2
: TId is writable, noinit
1209 # The declared type of the attribute
1210 var n_type
: nullable AType = null is writable
1212 # The initial value, if any (set with `=`)
1213 var n_expr
: nullable AExpr = null is writable
1215 # The initial value, if any (set with `do return`)
1216 var n_block
: nullable AExpr = null is writable
1218 redef fun hot_location
1220 return n_id2
.location
1224 # A definition of all kind of method (including constructors)
1228 # The `fun` keyword, if any
1229 var n_kwmeth
: nullable TKwmeth = null is writable
1231 # The `init` keyword, if any
1232 var n_kwinit
: nullable TKwinit = null is writable
1234 # The `new` keyword, if any
1235 var n_kwnew
: nullable TKwnew = null is writable
1237 # The name of the method, if any
1238 var n_methid
: nullable AMethid = null is writable
1240 # The signature of the method, if any
1241 var n_signature
: nullable ASignature = null is writable
1243 # The body (in Nit) of the method, if any
1244 var n_block
: nullable AExpr = null is writable
1246 # The list of declared callbacks (for extern methods)
1247 var n_extern_calls
: nullable AExternCalls = null is writable
1249 # The body (in extern code) of the method, if any
1250 var n_extern_code_block
: nullable AExternCodeBlock = null is writable
1252 redef fun hot_location
1254 if n_methid
!= null then
1255 return n_methid
.location
1256 else if n_kwinit
!= null then
1257 return n_kwinit
.location
1258 else if n_kwnew
!= null then
1259 return n_kwnew
.location
1266 # The implicit main method
1267 class AMainMethPropdef
1276 # A super-class. eg `super X`
1281 var n_kwsuper
: TKwsuper is writable, noinit
1283 # The super-class (indicated as a type)
1284 var n_type
: AType is writable, noinit
1288 # Declaration of callbacks for extern methods
1292 # The `import` keyword
1293 var n_kwimport
: TKwimport is writable, noinit
1295 # The list of declared callbacks
1296 var n_extern_calls
: ANodes[AExternCall] = new ANodes[AExternCall](self)
1299 # A single callback declaration
1300 abstract class AExternCall
1304 # A single callback declaration on a method
1305 abstract class APropExternCall
1309 # A single callback declaration on a method on the current receiver
1310 class ALocalPropExternCall
1311 super APropExternCall
1313 # The name of the called-back method
1314 var n_methid
: AMethid is writable, noinit
1317 # A single callback declaration on a method on an explicit receiver type.
1318 class AFullPropExternCall
1319 super APropExternCall
1321 # The type of the receiver of the called-back method
1322 var n_type
: AType is writable, noinit
1325 var n_dot
: nullable TDot = null is writable
1327 # The name of the called-back method
1328 var n_methid
: AMethid is writable, noinit
1331 # A single callback declaration on a method on a constructor
1332 class AInitPropExternCall
1333 super APropExternCall
1335 # The allocated type
1336 var n_type
: AType is writable, noinit
1339 # A single callback declaration on a `super` call
1340 class ASuperExternCall
1343 # The `super` keyword
1344 var n_kwsuper
: TKwsuper is writable, noinit
1347 # A single callback declaration on a cast
1348 abstract class ACastExternCall
1352 # A single callback declaration on a cast to a given type
1353 class ACastAsExternCall
1354 super ACastExternCall
1356 # The origin type of the cast
1357 var n_from_type
: AType is writable, noinit
1360 var n_dot
: nullable TDot = null is writable
1363 var n_kwas
: TKwas is writable, noinit
1365 # The destination of the cast
1366 var n_to_type
: AType is writable, noinit
1369 # A single callback declaration on a cast to a nullable type
1370 class AAsNullableExternCall
1371 super ACastExternCall
1373 # The origin type to cast as nullable
1374 var n_type
: AType is writable, noinit
1377 var n_kwas
: TKwas is writable, noinit
1379 # The `nullable` keyword
1380 var n_kwnullable
: TKwnullable is writable, noinit
1383 # A single callback declaration on a cast to a non-nullable type
1384 class AAsNotNullableExternCall
1385 super ACastExternCall
1387 # The destination type on a cast to not nullable
1388 var n_type
: AType is writable, noinit
1391 var n_kwas
: TKwas is writable, noinit
1394 var n_kwnot
: TKwnot is writable, noinit
1396 # The `nullable` keyword
1397 var n_kwnullable
: TKwnullable is writable, noinit
1400 # A definition of a virtual type
1404 # The `type` keyword
1405 var n_kwtype
: TKwtype is writable, noinit
1407 # The name of the virtual type
1408 var n_id
: TClassid is writable, noinit
1410 # The bound of the virtual type
1411 var n_type
: AType is writable, noinit
1414 # The identifier of a method in a method declaration.
1415 # There is a specific class because of operator and setters.
1416 abstract class AMethid
1420 # A method name with a simple identifier
1424 # The simple identifier
1425 var n_id
: TId is writable, noinit
1428 # A method name for an operator
1429 class AOperatorMethid
1432 # The associated operator symbol
1433 var n_op
: Token is writable, noinit
1437 super AOperatorMethid
1442 super AOperatorMethid
1447 super AOperatorMethid
1450 # A method name `**`
1451 class AStarstarMethid
1452 super AOperatorMethid
1457 super AOperatorMethid
1461 class APercentMethid
1462 super AOperatorMethid
1466 # A method name `==`
1468 super AOperatorMethid
1471 # A method name `!=`
1473 super AOperatorMethid
1476 # A method name `<=`
1478 super AOperatorMethid
1481 # A method name `>=`
1483 super AOperatorMethid
1488 super AOperatorMethid
1493 super AOperatorMethid
1496 # A method name `<<`
1498 super AOperatorMethid
1501 # A method name `>>`
1503 super AOperatorMethid
1506 # A method name `<=>`
1507 class AStarshipMethid
1508 super AOperatorMethid
1511 # A method name `[]`
1516 var n_obra
: TObra is writable, noinit
1519 var n_cbra
: TCbra is writable, noinit
1522 # A setter method name with a simple identifier (with a `=`)
1526 # The base identifier
1527 var n_id
: TId is writable, noinit
1530 var n_assign
: TAssign is writable, noinit
1533 # A method name `[]=`
1534 class ABraassignMethid
1538 var n_obra
: TObra is writable, noinit
1541 var n_cbra
: TCbra is writable, noinit
1544 var n_assign
: TAssign is writable, noinit
1547 # A signature in a method definition. eg `(x,y:X,z:Z):T`
1552 var n_opar
: nullable TOpar = null is writable
1554 # The list of parameters
1555 var n_params
= new ANodes[AParam](self)
1558 var n_cpar
: nullable TCpar = null is writable
1561 var n_type
: nullable AType = null is writable
1564 # A parameter definition in a signature. eg `x:X`
1568 # The name of the parameter
1569 var n_id
: TId is writable, noinit
1571 # The type of the parameter, if any
1572 var n_type
: nullable AType = null is writable
1574 # The `...` symbol to indicate varargs
1575 var n_dotdotdot
: nullable TDotdotdot = null is writable
1578 # A static type. eg `nullable X[Y]`
1581 # The `nullable` keyword
1582 var n_kwnullable
: nullable TKwnullable = null is writable
1584 # The name of the class or of the formal type
1585 var n_id
: TClassid is writable, noinit
1587 # Type arguments for a generic type
1588 var n_types
= new ANodes[AType](self)
1591 # A label at the end of a block or in a break/continue statement. eg `label x`
1595 # The `label` keyword
1596 var n_kwlabel
: TKwlabel is writable, noinit
1598 # The name of the label, if any
1599 var n_id
: nullable TId is writable, noinit
1602 # Expression and statements
1603 # From a AST point of view there is no distinction between statement and expressions (even if the parser has to distinguish them)
1604 abstract class AExpr
1608 # A sequence of `AExpr` (usually statements)
1609 # The last `AExpr` gives the value of the whole block
1613 # The list of statements in the bloc.
1614 # The last element is often considered as an expression that give the value of the whole block.
1615 var n_expr
= new ANodes[AExpr](self)
1618 var n_kwend
: nullable TKwend = null is writable
1621 # A declaration of a local variable. eg `var x: X = y`
1626 var n_kwvar
: nullable TKwvar = null is writable
1628 # The name of the local variable
1629 var n_id
: TId is writable, noinit
1631 # The declaration type of the local variable
1632 var n_type
: nullable AType = null is writable
1634 # The `=` symbol (for the initial value)
1635 var n_assign
: nullable TAssign = null is writable
1637 # The initial value, if any
1638 var n_expr
: nullable AExpr = null is writable
1641 # A `return` statement. eg `return x`
1645 # The `return` keyword
1646 var n_kwreturn
: nullable TKwreturn = null is writable
1648 # The return value, if any
1649 var n_expr
: nullable AExpr = null is writable
1652 # Something that has a label.
1653 abstract class ALabelable
1656 # The associated label declatation
1657 var n_label
: nullable ALabel = null is writable
1660 # A `break` or a `continue`
1661 abstract class AEscapeExpr
1665 # The return value, if nay (unused currently)
1666 var n_expr
: nullable AExpr = null is writable
1669 # A `break` statement.
1673 # The `break` keyword
1674 var n_kwbreak
: TKwbreak is writable, noinit
1677 # An `abort` statement
1681 # The `abort` keyword
1682 var n_kwabort
: TKwabort is writable, noinit
1685 # A `continue` statement
1689 # The `continue` keyword.
1690 var n_kwcontinue
: nullable TKwcontinue = null is writable
1699 var n_kwdo
: TKwdo is writable, noinit
1701 # The list of statements of the `do`.
1702 var n_block
: nullable AExpr = null is writable
1710 var n_kwif
: TKwif is writable, noinit
1712 # The expression used as the condition of the `if`
1713 var n_expr
: AExpr is writable, noinit
1715 # The body of the `then` part
1716 var n_then
: nullable AExpr = null is writable
1718 # The body of the `else` part
1719 var n_else
: nullable AExpr = null is writable
1722 # A `if` expression (ternary conditional). eg. `if true then 1 else 0`
1727 var n_kwif
: TKwif is writable, noinit
1729 # The expression used as the condition of the `if`
1730 var n_expr
: AExpr is writable, noinit
1732 # The `then` keyword
1733 var n_kwthen
: TKwthen is writable, noinit
1735 # The expression in the `then` part
1736 var n_then
: AExpr is writable, noinit
1738 # The `else` keyword
1739 var n_kwelse
: TKwelse is writable, noinit
1741 # The expression in the `else` part
1742 var n_else
: AExpr is writable, noinit
1745 # A `while` statement
1750 # The `while` keyword
1751 var n_kwwhile
: TKwwhile is writable, noinit
1753 # The expression used as the condition of the `while`
1754 var n_expr
: AExpr is writable, noinit
1757 var n_kwdo
: TKwdo is writable, noinit
1759 # The body of the loop
1760 var n_block
: nullable AExpr = null is writable
1763 # A `loop` statement
1768 # The `loop` keyword
1769 var n_kwloop
: TKwloop is writable, noinit
1771 # The body of the loop
1772 var n_block
: nullable AExpr = null is writable
1781 var n_kwfor
: TKwfor is writable, noinit
1783 # The list of name of the automatic variables
1784 var n_ids
= new ANodes[TId](self)
1786 # The expression used as the collection to iterate on
1787 var n_expr
: AExpr is writable, noinit
1790 var n_kwdo
: TKwdo is writable, noinit
1792 # The body of the loop
1793 var n_block
: nullable AExpr = null is writable
1796 # A `with` statement
1801 # The `with` keyword
1802 var n_kwwith
: TKwwith is writable, noinit
1804 # The expression used to get the value to control
1805 var n_expr
: AExpr is writable, noinit
1808 var n_kwdo
: TKwdo is writable, noinit
1810 # The body of the loop
1811 var n_block
: nullable AExpr = null is writable
1814 # An `assert` statement
1818 # The `assert` keyword
1819 var n_kwassert
: TKwassert is writable, noinit
1821 # The name of the assert, if any
1822 var n_id
: nullable TId = null is writable
1824 # The expression used as the condition of the `assert`
1825 var n_expr
: AExpr is writable, noinit
1827 # The body to execute when the assert fails
1828 var n_else
: nullable AExpr = null is writable
1831 # Whatever is a simple assignment. eg `= something`
1832 abstract class AAssignFormExpr
1836 var n_assign
: TAssign is writable, noinit
1838 # The right-value to assign.
1839 var n_value
: AExpr is writable, noinit
1842 # Whatever is a combined assignment. eg `+= something`
1843 abstract class AReassignFormExpr
1846 # The combined operator (eg. `+=`)
1847 var n_assign_op
: AAssignOp is writable, noinit
1849 # The right-value to apply on the combined operator.
1850 var n_value
: AExpr is writable, noinit
1853 # A `once` expression. eg `once x`
1857 # The `once` keyword
1858 var n_kwonce
: TKwonce is writable, noinit
1860 # The expression to evaluate only one time
1861 var n_expr
: AExpr is writable, noinit
1864 # A polymorphic invocation of a method
1865 # The form of the invocation (name, arguments, etc.) are specific
1866 abstract class ASendExpr
1868 # The receiver of the method invocation
1869 var n_expr
: AExpr is writable, noinit
1872 # A binary operation on a method
1873 abstract class ABinopExpr
1877 var n_op
: Token is writable, noinit
1879 # The second operand of the operation
1880 # Note: the receiver (`n_expr`) is the first operand
1881 var n_expr2
: AExpr is writable, noinit
1883 # The name of the operator (eg '+')
1884 fun operator
: String is abstract
1887 # Something that is boolean expression
1888 abstract class ABoolExpr
1892 # Something that is binary boolean expression
1893 abstract class ABinBoolExpr
1896 # The first boolean operand
1897 var n_expr
: AExpr is writable, noinit
1900 var n_op
: Token is writable, noinit
1902 # The second boolean operand
1903 var n_expr2
: AExpr is writable, noinit
1911 # A `and` expression
1916 # A `or else` expression
1920 # The `else` keyword
1921 var n_kwelse
: TKwelse is writable, noinit
1924 # A `implies` expression
1929 # A `not` expression
1934 var n_kwnot
: TKwnot is writable, noinit
1936 # The boolean operand of the `not`
1937 var n_expr
: AExpr is writable, noinit
1943 redef fun operator
do return "=="
1949 redef fun operator
do return "!="
1955 redef fun operator
do return "<"
1961 redef fun operator
do return "<="
1967 redef fun operator
do return "<<"
1973 redef fun operator
do return ">"
1979 redef fun operator
do return ">="
1985 redef fun operator
do return ">>"
1988 # A type-ckeck expression. eg `x isa T`
1992 # The expression to check
1993 var n_expr
: AExpr is writable, noinit
1996 var n_kwisa
: TKwisa is writable, noinit
1998 # The destination type to check to
1999 var n_type
: AType is writable, noinit
2005 redef fun operator
do return "+"
2011 redef fun operator
do return "-"
2014 # A `<=>` expression
2017 redef fun operator
do return "<=>"
2023 redef fun operator
do return "*"
2029 redef fun operator
do return "**"
2035 redef fun operator
do return "/"
2041 redef fun operator
do return "%"
2044 # A unary operation on a method
2049 var n_op
: Token is writable, noinit
2051 # The name of the operator (eg '+')
2052 fun operator
: String is abstract
2055 # A unary minus expression. eg `-x`
2058 redef fun operator
do return "-"
2061 # A unary plus expression. eg `+x`
2064 redef fun operator
do return "+"
2068 # An explicit instantiation. eg `new T`
2073 var n_kwnew
: TKwnew is writable, noinit
2075 # The `type` keyword
2076 var n_type
: AType is writable, noinit
2078 # The name of the named-constructor, if any
2079 var n_id
: nullable TId = null is writable
2081 # The arguments of the `new`
2082 var n_args
: AExprs is writable, noinit
2085 # Whatever is a old-style attribute access
2086 abstract class AAttrFormExpr
2089 # The receiver of the attribute
2090 var n_expr
: AExpr is writable, noinit
2092 # The name of the attribute
2093 var n_id
: TAttrid is writable, noinit
2097 # The read of an attribute. eg `x._a`
2102 # The assignment of an attribute. eg `x._a=y`
2103 class AAttrAssignExpr
2105 super AAssignFormExpr
2108 # Whatever looks-like a call with a standard method and any number of arguments.
2109 abstract class ACallFormExpr
2112 # The name of the method
2113 var n_id
: TId is writable, noinit
2115 # The arguments of the call
2116 var n_args
: AExprs is writable, noinit
2119 # A complex setter call (standard or brackets)
2120 abstract class ASendReassignFormExpr
2122 super AReassignFormExpr
2125 # A complex attribute assignment. eg `x._a+=y`
2126 class AAttrReassignExpr
2128 super AReassignFormExpr
2131 # A call with a standard method-name and any number of arguments. eg `x.m(y)`. OR just a simple id
2132 # 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`.
2133 # Semantic analysis have to transform them to instance of `AVarExpr`.
2138 # A setter call with a standard method-name and any number of arguments. eg `x.m(y)=z`. OR just a simple assignment.
2139 # 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`.
2140 # Semantic analysis have to transform them to instance of `AVarAssignExpr`.
2141 class ACallAssignExpr
2143 super AAssignFormExpr
2146 # 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.
2147 # 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`.
2148 # Semantic analysis have to transform them to instance of `AVarReassignExpr`.
2149 class ACallReassignExpr
2151 super ASendReassignFormExpr
2154 # A call to `super`. OR a call of a super-constructor
2158 # The qualifier part before the super (currenlty unused)
2159 var n_qualified
: nullable AQualified = null is writable
2161 # The `super` keyword
2162 var n_kwsuper
: TKwsuper is writable, noinit
2164 # The arguments of the super
2165 var n_args
: AExprs is writable, noinit
2168 # A call to the `init` constructor.
2169 # Note: because `init` is a keyword and not a `TId`, the explicit call to init cannot be a `ACallFormExpr`.
2173 # The `init` keyword
2174 var n_kwinit
: TKwinit is writable, noinit
2176 # The arguments of the init
2177 var n_args
: AExprs is writable, noinit
2180 # Whatever looks-like a call of the brackets `[]` operator.
2181 abstract class ABraFormExpr
2184 # The arguments inside the brackets
2185 var n_args
: AExprs is writable, noinit
2188 # A call of the brackets operator. eg `x[y,z]`
2193 # A setter call of the bracket operator. eg `x[y,z]=t`
2194 class ABraAssignExpr
2196 super AAssignFormExpr
2199 # Whatever is an access to a local variable
2200 abstract class AVarFormExpr
2203 # The name of the attribute
2204 var n_id
: TId is writable, noinit
2207 # A complex setter call of the bracket operator. eg `x[y,z]+=t`
2208 class ABraReassignExpr
2210 super ASendReassignFormExpr
2213 # A local variable read access.
2214 # The parser cannot instantiate them, see `ACallExpr`.
2219 # A local variable simple assignment access
2220 # The parser cannot instantiate them, see `ACallAssignExpr`.
2221 class AVarAssignExpr
2223 super AAssignFormExpr
2226 # A local variable complex assignment access
2227 # The parser cannot instantiate them, see `ACallReassignExpr`.
2228 class AVarReassignExpr
2230 super AReassignFormExpr
2233 # A literal range, open or closed
2234 abstract class ARangeExpr
2237 # The left (lower) element of the range
2238 var n_expr
: AExpr is writable, noinit
2240 # The right (uppr) element of the range
2241 var n_expr2
: AExpr is writable, noinit
2244 # A closed literal range. eg `[x..y]`
2248 # The opening bracket `[`
2249 var n_obra
: TObra is writable, noinit
2251 # The closing bracket `]`
2252 var n_cbra
: TCbra is writable, noinit
2255 # An open literal range. eg `[x..y[`
2259 # The opening bracket `[`
2260 var n_obra
: TObra is writable, noinit
2262 # The closing bracket `[` (because open range)
2263 var n_cbra
: TObra is writable, noinit
2266 # A literal array. eg. `[x,y,z]`
2270 # The opening bracket `[`
2271 var n_obra
: TObra is writable, noinit
2273 # The elements of the array
2274 var n_exprs
= new ANodes[AExpr](self)
2276 # The type of the element of the array (if any)
2277 var n_type
: nullable AType = null is writable
2279 # The closing bracket `]`
2280 var n_cbra
: TCbra is writable, noinit
2287 # The `self` keyword
2288 var n_kwself
: nullable TKwself = null is writable
2291 # When there is no explicit receiver, `self` is implicit
2292 class AImplicitSelfExpr
2296 # A `true` boolean literal constant
2300 # The `true` keyword
2301 var n_kwtrue
: TKwtrue is writable, noinit
2304 # A `false` boolean literal constant
2308 # The `false` keyword
2309 var n_kwfalse
: TKwfalse is writable, noinit
2312 # A `null` literal constant
2316 # The `null` keyword
2317 var n_kwnull
: TKwnull is writable, noinit
2320 # An integer literal
2325 # An integer literal in decimal format
2330 var n_number
: TNumber is writable, noinit
2333 # An integer literal in hexadecimal format
2337 # The hexadecimal token
2338 var n_hex_number
: THexNumber is writable, noinit
2346 var n_float
: TFloat is writable, noinit
2349 # A character literal
2353 # The character token
2354 var n_char
: TChar is writable, noinit
2358 abstract class AStringFormExpr
2362 var n_string
: Token is writable, noinit
2365 # A simple string. eg. `"abc"`
2367 super AStringFormExpr
2370 # The start of a superstring. eg `"abc{`
2371 class AStartStringExpr
2372 super AStringFormExpr
2375 # The middle of a superstring. eg `}abc{`
2376 class AMidStringExpr
2377 super AStringFormExpr
2380 # The end of a superstrng. eg `}abc"`
2381 class AEndStringExpr
2382 super AStringFormExpr
2385 # A superstring literal. eg `"a{x}b{y}c"`
2386 # Each part is modeled a sequence of expression. eg. `["a{, x, }b{, y, }c"]`
2387 class ASuperstringExpr
2390 # The list of the expressions of the superstring
2391 var n_exprs
= new ANodes[AExpr](self)
2394 # A simple parenthesis. eg `(x)`
2398 # The opening parenthesis
2399 var n_opar
: TOpar is writable, noinit
2401 # The inner expression
2402 var n_expr
: AExpr is writable, noinit
2404 # The closing parenthesis
2405 var n_cpar
: TCpar is writable, noinit
2408 # A cast, against a type or `not null`
2412 # The expression to cast
2413 var n_expr
: AExpr is writable, noinit
2416 var n_kwas
: TKwas is writable, noinit
2418 # The opening parenthesis
2419 var n_opar
: nullable TOpar = null is writable
2421 # The closing parenthesis
2422 var n_cpar
: nullable TCpar = null is writable
2425 # A type cast. eg `x.as(T)`
2429 # The target type to cast to
2430 var n_type
: AType is writable, noinit
2433 # A as-not-null cast. eg `x.as(not null)`
2434 class AAsNotnullExpr
2438 var n_kwnot
: TKwnot is writable, noinit
2440 # The `null` keyword
2441 var n_kwnull
: TKwnull is writable, noinit
2444 # A is-set check of old-style attributes. eg `isset x._a`
2445 class AIssetAttrExpr
2448 # The `isset` keyword
2449 var n_kwisset
: TKwisset is writable, noinit
2452 # An ellipsis notation used to pass an expression as it, in a vararg parameter
2456 # The passed expression
2457 var n_expr
: AExpr is writable, noinit
2460 var n_dotdotdot
: TDotdotdot is writable, noinit
2463 # A list of expression separated with commas (arguments for instance)
2467 # The list of expressions
2468 var n_exprs
= new ANodes[AExpr](self)
2471 # A special expression that encapsulates a static type
2472 # Can only be found in special construction like arguments of annotations.
2476 # The encapsulated type
2477 var n_type
: AType is writable, noinit
2480 # A special expression that encapsulates a method identifier
2481 # Can only be found in special construction like arguments of annotations.
2486 var n_expr
: AExpr is writable, noinit
2488 # The encapsulated method identifier
2489 var n_id
: AMethid is writable, noinit
2492 # A special expression that encapsulate an annotation
2493 # Can only be found in special construction like arguments of annotations.
2495 # The encapsulated annotations are in `n_annotations`
2500 # A special expression to debug types
2501 class ADebugTypeExpr
2504 # The `debug` keyword
2505 var n_kwdebug
: TKwdebug is writable, noinit
2507 # The `type` keyword
2508 var n_kwtype
: TKwtype is writable, noinit
2510 # The expression to check
2511 var n_expr
: AExpr is writable, noinit
2514 var n_type
: AType is writable, noinit
2517 # A list of expression separated with commas (arguments for instance)
2518 abstract class AExprs
2521 # The list of expressions
2522 var n_exprs
= new ANodes[AExpr](self)
2525 # A simple list of expressions
2530 # A list of expressions enclosed in parentheses
2534 # The opening parenthesis
2535 var n_opar
: TOpar is writable, noinit
2537 # The closing parenthesis
2538 var n_cpar
: TCpar is writable, noinit
2541 # A list of expressions enclosed in brackets
2545 # The opening bracket
2546 var n_obra
: TObra is writable, noinit
2548 # The closing bracket
2549 var n_cbra
: TCbra is writable, noinit
2552 # A complex assignment operator. (`+=` and `-=`)
2553 abstract class AAssignOp
2556 # The combined assignment operator
2557 var n_op
: Token is writable, noinit
2559 # The name of the operator without the `=` (eg '+')
2560 fun operator
: String is abstract
2563 # A `+=` assignment operation
2567 redef fun operator
do return "+"
2570 # A `-=` assignment operation
2571 class AMinusAssignOp
2574 redef fun operator
do return "-"
2577 # A `*=` assignment operation
2581 redef fun operator
do return "*"
2584 # A `/=` assignment operation
2585 class ASlashAssignOp
2588 redef fun operator
do return "/"
2591 # A `%=` assignment operation
2592 class APercentAssignOp
2595 redef fun operator
do return "%"
2598 # A `**=` assignment operation
2599 class AStarstarAssignOp
2602 redef fun operator
do return "**"
2605 # A `<<=` assignment operation
2609 redef fun operator
do return "<<"
2612 # A `>>=` assignment operation
2616 redef fun operator
do return ">>"
2619 # A possibly fully-qualified module identifier
2623 # The starting quad (`::`)
2624 var n_quad
: nullable TQuad = null is writable
2626 # The list of quad-separated project/group identifiers
2627 var n_path
= new ANodes[TId](self)
2629 # The final module identifier
2630 var n_id
: TId is writable, noinit
2633 # A language declaration for an extern block
2638 var n_kwin
: TKwin is writable, noinit
2641 var n_string
: TString is writable, noinit
2644 # An full extern block
2645 class AExternCodeBlock
2648 # The language declration
2649 var n_in_language
: nullable AInLanguage = null is writable
2651 # The block of extern code
2652 var n_extern_code_segment
: TExternCodeSegment is writable, noinit
2655 # A possible full method qualifier.
2659 # The starting quad (`::`)
2660 var n_quad
: nullable TQuad = null is writable
2662 # The list of quad-separated project/group/module identifiers
2663 var n_id
= new ANodes[TId](self)
2665 # A class identifier
2666 var n_classid
: nullable TClassid = null is writable
2669 # A documentation of a definition
2670 # It contains the block of comments just above the declaration
2674 # A list of lines of comment
2675 var n_comment
= new ANodes[TComment](self)
2678 # A group of annotation on a node
2680 # This same class is used for the 3 kind of annotations:
2682 # * *is* annotations. eg `module foo is bar`.
2683 # * *at* annotations. eg `foo@bar` or `foo@(bar,baz)`.
2684 # * *class* annotations, defined in classes.
2688 # The `@` symbol, for *at* annotations
2689 var n_at
: nullable TAt = null is writable
2691 # The opening parenthesis in *at* annotations
2692 var n_opar
: nullable TOpar = null is writable
2694 # The list of annotations
2695 var n_items
= new ANodes[AAnnotation](self)
2697 # The closing parenthesis in *at* annotations
2698 var n_cpar
: nullable TCpar = null is writable
2701 # A single annotation
2705 # The name of the annotation
2706 var n_atid
: AAtid is writable, noinit
2708 # The opening parenthesis of the arguments
2709 var n_opar
: nullable TOpar = null is writable
2711 # The list of arguments
2712 var n_args
= new ANodes[AExpr](self)
2714 # The closing parenthesis
2715 var n_cpar
: nullable TCpar = null is writable
2717 # The name of the annotation
2720 return n_atid
.n_id
.text
2724 # An annotation name
2725 abstract class AAtid
2728 # The identifier of the annotation.
2729 # Can be a TId of a keyword
2730 var n_id
: Token is writable, noinit
2733 # An annotation name based on an identifier
2738 # An annotation name based on the keyword `extern`
2743 # An annotation name based on the keyword `import`
2748 # An annotation name based on the keyword `abstract`
2749 class AKwabstractAtid
2753 # The root of the AST
2758 var n_base
: nullable AModule is writable
2760 # The end of file (or error) token
2761 var n_eof
: EOF is writable