5204376fbfd3205ed1055dcebe3aed8adcb6d207
[nit.git] / src / parser / parser_nodes.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
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
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14
15 # AST nodes of the Nit language
16 # Was previously based on parser_abs.nit.
17 module parser_nodes
18
19 import location
20 import ordered_tree
21
22 # Root of the AST class-hierarchy
23 abstract class ANode
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
27
28 # The location of the important part of the node (identifier or whatever)
29 fun hot_location: Location do return location
30
31 # Display a message for the colored location of the node
32 fun debug(message: String)
33 do
34 sys.stderr.write "{hot_location} {self.class_name}: {message}\n{hot_location.colored_line("0;32")}\n"
35 end
36
37 # Write the subtree on stdout.
38 # See `ASTDump`
39 fun dump_tree
40 do
41 var d = new ASTDump
42 d.enter_visit(self)
43 d.write_to(sys.stdout)
44 end
45
46 # Parent of the node in the AST
47 var parent: nullable ANode = null
48
49 # The topmost ancestor of the element
50 # This just apply `parent` until the first one
51 fun root: ANode
52 do
53 var res = self
54 loop
55 var p = res.parent
56 if p == null then return res
57 res = p
58 end
59 end
60
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
64 do
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
69 while d > 0 do
70 s = s.parent
71 d -= 1
72 end
73 while d < 0 do
74 o = o.parent
75 d += 1
76 end
77 assert o.depth == s.depth
78 # Second, go up until same in found
79 while s != o do
80 s = s.parent
81 o = o.parent
82 end
83 return s
84 end
85
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`
89 fun depth: Int
90 do
91 var n = self
92 var res = 0
93 loop
94 var p = n.parent
95 if p == null then return res
96 n = p
97 res += 1
98 end
99 end
100
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
103
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
109 fun detach
110 do
111 assert parent != null
112 parent.replace_child(self, null)
113 parent = null
114 end
115
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)
121 do
122 assert parent != null
123 parent.replace_child(self, node)
124 parent = null
125 end
126
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
130
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]
133 do
134 var v = new CollectTokensByTextVisitor(text)
135 v.enter_visit(self)
136 return v.result
137 end
138
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]
142 do
143 var v = new CollectAnnotationsByNameVisitor(name)
144 v.enter_visit(self)
145 return v.result
146 end
147 end
148
149 private class CollectTokensByTextVisitor
150 super Visitor
151 var text: String
152 var result = new Array[Token]
153 redef fun visit(node)
154 do
155 node.visit_all(self)
156 if node isa Token and node.text == text then result.add(node)
157 end
158 end
159
160 private class CollectAnnotationsByNameVisitor
161 super Visitor
162 var name: String
163 var result = new Array[AAnnotation]
164 redef fun visit(node)
165 do
166 node.visit_all(self)
167 if node isa AAnnotation and node.n_atid.n_id.text == name then result.add(node)
168 end
169 end
170
171 # A helper class to handle (print) Nit AST as an OrderedTree
172 class ASTDump
173 super Visitor
174 super OrderedTree[ANode]
175
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
179
180 redef fun visit(n)
181 do
182 var p = last_parent
183 add(p, n)
184 last_parent = n
185 n.visit_all(self)
186 last_parent = p
187 end
188
189 redef fun display(n)
190 do
191 if n isa Token then
192 return "{n.class_name} \"{n.text.escape_to_c}\" @{n.location}"
193 else
194 return "{n.class_name} @{n.location}"
195 end
196 end
197 end
198
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]
202 super Sequence[E]
203 private var parent: ANode
204 private var items = new Array[E]
205 redef fun iterator do return items.iterator
206 redef fun reverse_iterator do return items.reverse_iterator
207 redef fun length do return items.length
208 redef fun is_empty do return items.is_empty
209 redef fun push(e)
210 do
211 hook_add(e)
212 items.push(e)
213 end
214 redef fun pop
215 do
216 var res = items.pop
217 hook_remove(res)
218 return res
219 end
220 redef fun unshift(e)
221 do
222 hook_add(e)
223 items.unshift(e)
224 end
225 redef fun shift
226 do
227 var res = items.shift
228 hook_remove(res)
229 return res
230 end
231 redef fun has(e)
232 do
233 return items.has(e)
234 end
235 redef fun [](index)
236 do
237 return items[index]
238 end
239 redef fun []=(index, e)
240 do
241 hook_remove(self[index])
242 hook_add(e)
243 items[index]=e
244 end
245 redef fun remove_at(index)
246 do
247 hook_remove(items[index])
248 items.remove_at(index)
249 end
250 private fun hook_add(e: E)
251 do
252 #assert e.parent == null
253 e.parent = parent
254 end
255 private fun hook_remove(e: E)
256 do
257 assert e.parent == parent
258 e.parent = null
259 end
260
261 # Used in parent constructor to fill elements
262 private fun unsafe_add_all(nodes: Collection[Object])
263 do
264 var parent = self.parent
265 for n in nodes do
266 assert n isa E
267 add n
268 n.parent = parent
269 end
270 end
271
272 private fun replace_child(old_child: ANode, new_child: nullable ANode): Bool
273 do
274 var parent = self.parent
275 for i in [0..length[ do
276 if self[i] == old_child then
277 if new_child != null then
278 assert new_child isa E
279 self[i] = new_child
280 new_child.parent = parent
281 else
282 self.remove_at(i)
283 end
284 return true
285 end
286 end
287 return false
288 end
289
290 private fun visit_all(v: Visitor)
291 do
292 for n in self do v.enter_visit(n)
293 end
294 end
295
296 # Ancestor of all tokens
297 # A token is a node that has a `text` but no children.
298 abstract class Token
299 super ANode
300
301 # The raw content on the token
302 fun text: String is abstract
303
304 # The raw content on the token
305 fun text=(text: String) is abstract
306
307 # The previous token in the Lexer.
308 # May have disappeared in the AST
309 var prev_token: nullable Token = null
310
311 # The next token in the Lexer.
312 # May have disappeared in the AST
313 var next_token: nullable Token = null
314
315 # Is `self` a token discarded from the AST?
316 #
317 # Loose tokens are not present in the AST.
318 # It means they were identified by the lexer but were discarded by the parser.
319 # It also means that they are not visited or manipulated by AST-related functions.
320 #
321 # Each loose token is attached to the non-loose token that precedes or follows it.
322 # The rules are the following:
323 #
324 # * tokens that follow a non-loose token on a same line are attached to it.
325 # See `next_looses`.
326 # * other tokens, thus that precede a non-loose token on the same line or the next one,
327 # are attached to this one. See `prev_looses`.
328 #
329 # Loose tokens are mostly end of lines (`TEol`) and comments (`TComment`).
330 # Whitespace are ignored by the lexer, so they are not even considered as loose tokens.
331 # See `blank_before` to get the whitespace that separate tokens.
332 var is_loose = false
333
334 # Loose tokens that precede `self`.
335 #
336 # These tokens start the line or belong to a line with only loose tokens.
337 var prev_looses = new Array[Token] is lazy
338
339 # Loose tokens that follow `self`
340 #
341 # These tokens are on the same line than `self`.
342 var next_looses = new Array[Token] is lazy
343
344 # The verbatim blank text between `prev_token` and `self`
345 fun blank_before: String
346 do
347 if prev_token == null then return ""
348 var from = prev_token.location.pend+1
349 var to = location.pstart
350 return location.file.string.substring(from,to-from)
351 end
352
353 redef fun to_s: String do
354 return "'{text}'"
355 end
356
357 redef fun visit_all(v: Visitor) do end
358 redef fun replace_child(old_child: ANode, new_child: nullable ANode) do end
359 end
360
361 redef class SourceFile
362 # The first token parser by the lexer
363 # May have disappeared in the final AST
364 var first_token: nullable Token = null
365
366 # The first token parser by the lexer
367 # May have disappeared in the final AST
368 var last_token: nullable Token = null
369 end
370
371 # Ancestor of all productions
372 # A production is a node without text but that usually has children.
373 abstract class Prod
374 super ANode
375
376 # All the annotations attached directly to the node
377 var n_annotations: nullable AAnnotations = null is writable
378
379 # Return all its annotations of a given name in the order of their declaration
380 # Retun an empty array if no such an annotation.
381 fun get_annotations(name: String): Array[AAnnotation]
382 do
383 var res = new Array[AAnnotation]
384 var nas = n_annotations
385 if nas != null then for na in nas.n_items do
386 if na.name != name then continue
387 res.add(na)
388 end
389 if self isa AClassdef then for na in n_propdefs do
390 if na isa AAnnotPropdef then
391 if na.name != name then continue
392 res.add na
393 end
394 end
395
396 return res
397 end
398
399 redef fun replace_with(n: ANode)
400 do
401 super
402 assert n isa Prod
403 if not isset n._location and isset _location then n._location = _location
404 end
405 end
406
407 # Abstract standard visitor on the AST
408 abstract class Visitor
409 # What the visitor do when a node is visited
410 # Concrete visitors should implement this method.
411 # @toimplement
412 protected fun visit(e: ANode) is abstract
413
414 # Ask the visitor to visit a given node.
415 # Usually automatically called by visit_all* methods.
416 # This method should not be redefined
417 fun enter_visit(e: nullable ANode)
418 do
419 if e == null then return
420 var old = _current_node
421 _current_node = e
422 visit(e)
423 _current_node = old
424 end
425
426 # The current visited node
427 var current_node: nullable ANode = null is writable
428 end
429
430 # Token of end of line (basically `\n`)
431 class TEol
432 super Token
433 redef fun to_s
434 do
435 return "end of line"
436 end
437 end
438
439 # Token of a line of comments
440 # Starts with the `#` and contains the final end-of-line (if any)
441 class TComment
442 super Token
443 end
444
445 # A token associated with a keyword
446 abstract class TokenKeyword
447 super Token
448 redef fun to_s
449 do
450 return "keyword '{text}'"
451 end
452 end
453
454 # The deprecated keyword `package`.
455 class TKwpackage
456 super TokenKeyword
457 end
458
459 # The keyword `module`
460 class TKwmodule
461 super TokenKeyword
462 end
463
464 # The keyword `import`
465 class TKwimport
466 super TokenKeyword
467 end
468
469 # The keyword `class`
470 class TKwclass
471 super TokenKeyword
472 end
473
474 # The keyword `abstract`
475 class TKwabstract
476 super TokenKeyword
477 end
478
479 # The keyword `interface`
480 class TKwinterface
481 super TokenKeyword
482 end
483
484 # The keywords `enum` ane `universal`
485 class TKwenum
486 super TokenKeyword
487 end
488
489 # The keyword `end`
490 class TKwend
491 super TokenKeyword
492 end
493
494 # The keyword `fun`
495 class TKwmeth
496 super TokenKeyword
497 end
498
499 # The keyword `type`
500 class TKwtype
501 super TokenKeyword
502 end
503
504 # The keyword `init`
505 class TKwinit
506 super TokenKeyword
507 end
508
509 # The keyword `redef`
510 class TKwredef
511 super TokenKeyword
512 end
513
514 # The keyword `is`
515 class TKwis
516 super TokenKeyword
517 end
518
519 # The keyword `do`
520 class TKwdo
521 super TokenKeyword
522 end
523
524 # The keyword `var`
525 class TKwvar
526 super TokenKeyword
527 end
528
529 # The keyword `extern`
530 class TKwextern
531 super TokenKeyword
532 end
533
534 # The keyword `public`
535 class TKwpublic
536 super TokenKeyword
537 end
538
539 # The keyword `protected`
540 class TKwprotected
541 super TokenKeyword
542 end
543
544 # The keyword `private`
545 class TKwprivate
546 super TokenKeyword
547 end
548
549 # The keyword `intrude`
550 class TKwintrude
551 super TokenKeyword
552 end
553
554 # The keyword `if`
555 class TKwif
556 super TokenKeyword
557 end
558
559 # The keyword `then`
560 class TKwthen
561 super TokenKeyword
562 end
563
564 # The keyword `else`
565 class TKwelse
566 super TokenKeyword
567 end
568
569 # The keyword `while`
570 class TKwwhile
571 super TokenKeyword
572 end
573
574 # The keyword `loop`
575 class TKwloop
576 super TokenKeyword
577 end
578
579 # The keyword `for`
580 class TKwfor
581 super TokenKeyword
582 end
583
584 # The keyword `in`
585 class TKwin
586 super TokenKeyword
587 end
588
589 # The keyword `and`
590 class TKwand
591 super TokenKeyword
592 end
593
594 # The keyword `or`
595 class TKwor
596 super TokenKeyword
597 end
598
599 # The keyword `implies`
600 class TKwimplies
601 super TokenKeyword
602 end
603
604 # The keyword `not`
605 class TKwnot
606 super TokenKeyword
607 end
608
609 # The keyword `return`
610 class TKwreturn
611 super TokenKeyword
612 end
613
614 # The keyword `continue`
615 class TKwcontinue
616 super TokenKeyword
617 end
618
619 # The keyword `break`
620 class TKwbreak
621 super TokenKeyword
622 end
623
624 # The keyword `abort`
625 class TKwabort
626 super TokenKeyword
627 end
628
629 # The keyword `assert`
630 class TKwassert
631 super TokenKeyword
632 end
633
634 # The keyword `new`
635 class TKwnew
636 super TokenKeyword
637 end
638
639 # The keyword `isa`
640 class TKwisa
641 super TokenKeyword
642 end
643
644 # The keyword `once`
645 class TKwonce
646 super TokenKeyword
647 end
648
649 # The keyword `super`
650 class TKwsuper
651 super TokenKeyword
652 end
653
654 # The keyword `self`
655 class TKwself
656 super TokenKeyword
657 end
658
659 # The keyword `true`
660 class TKwtrue
661 super TokenKeyword
662 end
663
664 # The keyword `false`
665 class TKwfalse
666 super TokenKeyword
667 end
668
669 # The keyword `null`
670 class TKwnull
671 super TokenKeyword
672 end
673
674 # The keyword `as`
675 class TKwas
676 super TokenKeyword
677 end
678
679 # The keyword `nullable`
680 class TKwnullable
681 super TokenKeyword
682 end
683
684 # The keyword `isset`
685 class TKwisset
686 super TokenKeyword
687 end
688
689 # The keyword `label`
690 class TKwlabel
691 super TokenKeyword
692 end
693
694 # The keyword `with`
695 class TKwwith
696 super TokenKeyword
697 end
698
699 # The special keyword `__DEBUG__`
700 class TKwdebug
701 super Token
702 end
703
704 # The symbol `(`
705 class TOpar
706 super Token
707 end
708
709 # The symbol `)`
710 class TCpar
711 super Token
712 end
713
714 # The symbol `[`
715 class TObra
716 super Token
717 end
718
719 # The symbol `]`
720 class TCbra
721 super Token
722 end
723
724 # The symbol `,`
725 class TComma
726 super Token
727 end
728
729 # The symbol `:`
730 class TColumn
731 super Token
732 end
733
734 # The symbol `::`
735 class TQuad
736 super Token
737 end
738
739 # The symbol `=`
740 class TAssign
741 super Token
742 end
743
744 # A token associated with an operator (and other lookalike symbols)
745 abstract class TokenOperator
746 super Token
747 redef fun to_s
748 do
749 return "operator '{text}'"
750 end
751 end
752
753 # The operator `+=`
754 class TPluseq
755 super TokenOperator
756 end
757
758 # The operator `-=`
759 class TMinuseq
760 super TokenOperator
761 end
762
763 # The operator `*=`
764 class TStareq
765 super TokenOperator
766 end
767
768 # The operator `/=`
769 class TSlasheq
770 super TokenOperator
771 end
772
773 # The operator `%=`
774 class TPercenteq
775 super TokenOperator
776 end
777
778 # The operator `**=`
779 class TStarstareq
780 super TokenOperator
781 end
782
783 # The operator `|=`
784 class TPipeeq
785 super TokenOperator
786 end
787
788 # The operator `^=`
789 class TCareteq
790 super TokenOperator
791 end
792
793 # The operator `&=`
794 class TAmpeq
795 super TokenOperator
796 end
797
798 # The operator `<<=`
799 class TLleq
800 super TokenOperator
801 end
802
803 # The operator `>>=`
804 class TGgeq
805 super TokenOperator
806 end
807
808 # The symbol `...`
809 class TDotdotdot
810 super Token
811 end
812
813 # The symbol `..`
814 class TDotdot
815 super Token
816 end
817
818 # The symbol `.`
819 class TDot
820 super Token
821 end
822
823 # The operator `+`
824 class TPlus
825 super TokenOperator
826 end
827
828 # The operator `-`
829 class TMinus
830 super TokenOperator
831 end
832
833 # The operator `*`
834 class TStar
835 super TokenOperator
836 end
837
838 # The operator `**`
839 class TStarstar
840 super TokenOperator
841 end
842
843 # The operator `/`
844 class TSlash
845 super TokenOperator
846 end
847
848 # The operator `%`
849 class TPercent
850 super TokenOperator
851 end
852
853 # The operator `|`
854 class TPipe
855 super TokenOperator
856 end
857
858 # The operator `^`
859 class TCaret
860 super TokenOperator
861 end
862
863 # The operator `&`
864 class TAmp
865 super TokenOperator
866 end
867
868 # The operator `~`
869 class TTilde
870 super TokenOperator
871 end
872
873 # The operator `==`
874 class TEq
875 super TokenOperator
876 end
877
878 # The operator `!=`
879 class TNe
880 super TokenOperator
881 end
882
883 # The operator `<`
884 class TLt
885 super TokenOperator
886 end
887
888 # The operator `<=`
889 class TLe
890 super TokenOperator
891 end
892
893 # The operator `<<`
894 class TLl
895 super TokenOperator
896 end
897
898 # The operator `>`
899 class TGt
900 super TokenOperator
901 end
902
903 # The operator `>=`
904 class TGe
905 super TokenOperator
906 end
907
908 # The operator `>>`
909 class TGg
910 super TokenOperator
911 end
912
913 # The operator `<=>`
914 class TStarship
915 super TokenOperator
916 end
917
918 # The operator `!`
919 class TBang
920 super TokenOperator
921 end
922
923 # The symbol `@`
924 class TAt
925 super Token
926 end
927
928 # The symbol `;`
929 class TSemi
930 super Token
931 end
932
933 # A class (or formal type) identifier. They start with an uppercase.
934 class TClassid
935 super Token
936 redef fun to_s
937 do
938 do return "type identifier '{text}'"
939 end
940 end
941
942 # A standard identifier (variable, method...). They start with a lowercase.
943 class TId
944 super Token
945 redef fun to_s
946 do
947 do return "identifier '{text}'"
948 end
949 end
950
951 # An attribute identifier. They start with an underscore.
952 class TAttrid
953 super Token
954 redef fun to_s
955 do
956 do return "attribute '{text}'"
957 end
958 end
959
960 # A token of a literal value (string, integer, etc).
961 abstract class TokenLiteral
962 super Token
963 redef fun to_s
964 do
965 do return "literal value '{text}'"
966 end
967 end
968
969 # A literal integer
970 class TInteger
971 super TokenLiteral
972 end
973
974 # A literal floating point number
975 class TFloat
976 super TokenLiteral
977 end
978
979 # A literal character
980 class TChar
981 super TokenLiteral
982 end
983
984 # A literal string
985 class TString
986 super TokenLiteral
987 end
988
989 # The starting part of a super string (between `"` and `{`)
990 class TStartString
991 super TokenLiteral
992 end
993
994 # The middle part of a super string (between `}` and `{`)
995 class TMidString
996 super TokenLiteral
997 end
998
999 # The final part of a super string (between `}` and `"`)
1000 class TEndString
1001 super TokenLiteral
1002 end
1003
1004 # A malformed string
1005 class TBadString
1006 super Token
1007 redef fun to_s
1008 do
1009 do return "malformed string {text}"
1010 end
1011 end
1012
1013 # A malformed char
1014 class TBadChar
1015 super Token
1016 redef fun to_s
1017 do
1018 do return "malformed character {text}"
1019 end
1020 end
1021
1022 # A extern code block
1023 class TExternCodeSegment
1024 super Token
1025 end
1026
1027 # A end of file
1028 class EOF
1029 super Token
1030 redef fun to_s
1031 do
1032 return "end of file"
1033 end
1034 end
1035
1036 # A mark of an error
1037 class AError
1038 super EOF
1039 end
1040 # A lexical error (unexpected character)
1041 class ALexerError
1042 super AError
1043 end
1044 # A syntactic error (unexpected token)
1045 class AParserError
1046 super AError
1047 end
1048
1049 # The main node of a Nit source-file
1050 class AModule
1051 super Prod
1052
1053 # The declaration part of the module
1054 var n_moduledecl: nullable AModuledecl = null is writable
1055
1056 # List of importation clauses
1057 var n_imports = new ANodes[AImport](self)
1058
1059 # List of extern blocks
1060 var n_extern_code_blocks = new ANodes[AExternCodeBlock](self)
1061
1062 # List of class definition (including top-level methods and the main)
1063 var n_classdefs = new ANodes[AClassdef](self)
1064 end
1065
1066 # Abstract class for definition of entities
1067 abstract class ADefinition
1068 super Prod
1069 # The documentation
1070 var n_doc: nullable ADoc = null is writable
1071
1072 # The `redef` keyword
1073 var n_kwredef: nullable TKwredef = null is writable
1074
1075 # The declared visibility
1076 var n_visibility: nullable AVisibility = null is writable
1077 end
1078
1079 # The declaration of the module with the documentation, name, and annotations
1080 class AModuledecl
1081 super ADefinition
1082
1083 # The `module` keyword
1084 var n_kwmodule: TKwmodule is writable, noinit
1085
1086 # The declared module name
1087 var n_name: AModuleName is writable, noinit
1088 end
1089
1090 # A import clause of a module
1091 abstract class AImport
1092 super Prod
1093
1094 # The declared visibility
1095 var n_visibility: AVisibility is writable, noinit
1096
1097 # The `import` keyword
1098 var n_kwimport: TKwimport is writable, noinit
1099 end
1100
1101 # A standard import clause. eg `import x`
1102 class AStdImport
1103 super AImport
1104 # The imported module name
1105 var n_name: AModuleName is writable, noinit
1106 end
1107
1108 # The special import clause of the kernel module. eg `import end`
1109 class ANoImport
1110 super AImport
1111 # The `end` keyword, that indicate the root module
1112 var n_kwend: TKwend is writable, noinit
1113 end
1114
1115 # A visibility modifier
1116 #
1117 # The public visibility is an empty production (no keyword).
1118 #
1119 # Note: even if some visibilities are only valid on some placse (for instance, no `protected` class or no `intrude` method)
1120 # the parser has no such a restriction, therefore the semantic phases has to check that the visibilities make sense.
1121 abstract class AVisibility
1122 super Prod
1123 end
1124
1125 # An implicit or explicit public visibility modifier
1126 class APublicVisibility
1127 super AVisibility
1128 # The `public` keyword, if any
1129 var n_kwpublic: nullable TKwpublic is writable
1130 end
1131 # An explicit private visibility modifier
1132 class APrivateVisibility
1133 super AVisibility
1134 # The `private` keyword
1135 var n_kwprivate: TKwprivate is writable, noinit
1136 end
1137 # An explicit protected visibility modifier
1138 class AProtectedVisibility
1139 super AVisibility
1140 # The `protected` keyword
1141 var n_kwprotected: TKwprotected is writable, noinit
1142 end
1143 # An explicit intrude visibility modifier
1144 class AIntrudeVisibility
1145 super AVisibility
1146 # The `intrude` keyword
1147 var n_kwintrude: TKwintrude is writable, noinit
1148 end
1149
1150 # A class definition
1151 # While most definition are `AStdClassdef`
1152 # There is tow special case of class definition
1153 abstract class AClassdef
1154 super Prod
1155 # All the declared properties (including the main method)
1156 var n_propdefs = new ANodes[APropdef](self)
1157 end
1158
1159 # A standard class definition with a name, superclasses and properties
1160 class AStdClassdef
1161 super AClassdef
1162 super ADefinition
1163
1164 # The class kind (interface, abstract class, etc.)
1165 var n_classkind: AClasskind is writable, noinit
1166
1167 # The name of the class
1168 var n_id: nullable TClassid = null is writable
1169
1170 # The `[` symbol
1171 var n_obra: nullable TObra = null is writable
1172
1173 # The list of formal parameter types
1174 var n_formaldefs = new ANodes[AFormaldef](self)
1175
1176 # The `]` symbol
1177 var n_cbra: nullable TCbra = null is writable
1178
1179 # The extern block code
1180 var n_extern_code_block: nullable AExternCodeBlock = null is writable
1181
1182 # The `end` keyword
1183 var n_kwend: TKwend is writable, noinit
1184
1185 fun n_superclasses: Array[ASuperPropdef] do
1186 return [for d in n_propdefs do if d isa ASuperPropdef then d]
1187 end
1188
1189 redef fun hot_location do return n_id.location
1190 end
1191
1192 # The implicit class definition of the implicit main method
1193 class ATopClassdef
1194 super AClassdef
1195 end
1196
1197 # The implicit class definition of the top-level methods
1198 class AMainClassdef
1199 super AClassdef
1200 end
1201
1202 # The modifier for the kind of class (abstract, interface, etc.)
1203 abstract class AClasskind
1204 super Prod
1205 end
1206
1207 # A default, or concrete class modifier (just `class`)
1208 class AConcreteClasskind
1209 super AClasskind
1210
1211 # The `class` keyword.
1212 var n_kwclass: TKwclass is writable, noinit
1213 end
1214
1215 # An abstract class modifier (`abstract class`)
1216 class AAbstractClasskind
1217 super AClasskind
1218
1219 # The `abstract` keyword.
1220 var n_kwabstract: TKwabstract is writable, noinit
1221
1222 # The `class` keyword.
1223 var n_kwclass: TKwclass is writable, noinit
1224 end
1225
1226 # An interface class modifier (`interface`)
1227 class AInterfaceClasskind
1228 super AClasskind
1229
1230 # The `interface` keyword.
1231 var n_kwinterface: TKwinterface is writable, noinit
1232 end
1233
1234 # An enum/universal class modifier (`enum class`)
1235 class AEnumClasskind
1236 super AClasskind
1237
1238 # The `enum` keyword.
1239 var n_kwenum: TKwenum is writable, noinit
1240 end
1241
1242 # An extern class modifier (`extern class`)
1243 class AExternClasskind
1244 super AClasskind
1245
1246 # The `extern` keyword.
1247 var n_kwextern: TKwextern is writable, noinit
1248
1249 # The `class` keyword.
1250 var n_kwclass: nullable TKwclass = null is writable
1251 end
1252
1253 # The definition of a formal generic parameter type. eg `X: Y`
1254 class AFormaldef
1255 super Prod
1256
1257 # The name of the parameter type
1258 var n_id: TClassid is writable, noinit
1259
1260 # The bound of the parameter type
1261 var n_type: nullable AType = null is writable
1262 end
1263
1264 # The definition of a property
1265 abstract class APropdef
1266 super ADefinition
1267 end
1268
1269 # A definition of an attribute
1270 # For historical reason, old-syle and new-style attributes use the same `ANode` sub-class
1271 class AAttrPropdef
1272 super APropdef
1273
1274 # The `var` keyword
1275 var n_kwvar: TKwvar is writable, noinit
1276
1277 # The identifier for a new-style attribute
1278 var n_id2: TId is writable, noinit
1279
1280 # The declared type of the attribute
1281 var n_type: nullable AType = null is writable
1282
1283 # The `=` symbol
1284 var n_assign: nullable TAssign = null is writable
1285
1286 # The initial value, if any (set with `=`)
1287 var n_expr: nullable AExpr = null is writable
1288
1289 # The `do` keyword
1290 var n_kwdo: nullable TKwdo = null is writable
1291
1292 # The initial value, if any (set with `do return`)
1293 var n_block: nullable AExpr = null is writable
1294
1295 # The `end` keyword
1296 var n_kwend: nullable TKwend = null is writable
1297
1298 redef fun hot_location
1299 do
1300 return n_id2.location
1301 end
1302 end
1303
1304 # A definition of all kind of method (including constructors)
1305 class AMethPropdef
1306 super APropdef
1307
1308 # The `fun` keyword, if any
1309 var n_kwmeth: nullable TKwmeth = null is writable
1310
1311 # The `init` keyword, if any
1312 var n_kwinit: nullable TKwinit = null is writable
1313
1314 # The `new` keyword, if any
1315 var n_kwnew: nullable TKwnew = null is writable
1316
1317 # The name of the method, if any
1318 var n_methid: nullable AMethid = null is writable
1319
1320 # The signature of the method, if any
1321 var n_signature: nullable ASignature = null is writable
1322
1323 # The `do` keyword
1324 var n_kwdo: nullable TKwdo = null is writable
1325
1326 # The body (in Nit) of the method, if any
1327 var n_block: nullable AExpr = null is writable
1328
1329 # The `end` keyword
1330 var n_kwend: nullable TKwend = null is writable
1331
1332 # The list of declared callbacks (for extern methods)
1333 var n_extern_calls: nullable AExternCalls = null is writable
1334
1335 # The body (in extern code) of the method, if any
1336 var n_extern_code_block: nullable AExternCodeBlock = null is writable
1337
1338 redef fun hot_location
1339 do
1340 if n_methid != null then
1341 return n_methid.location
1342 else if n_kwinit != null then
1343 return n_kwinit.location
1344 else if n_kwnew != null then
1345 return n_kwnew.location
1346 else
1347 return location
1348 end
1349 end
1350 end
1351
1352 # The implicit main method
1353 class AMainMethPropdef
1354 super AMethPropdef
1355 end
1356
1357 class AAnnotPropdef
1358 super APropdef
1359 super AAnnotation
1360 end
1361
1362 # A super-class. eg `super X`
1363 class ASuperPropdef
1364 super APropdef
1365
1366 # The super keyword
1367 var n_kwsuper: TKwsuper is writable, noinit
1368
1369 # The super-class (indicated as a type)
1370 var n_type: AType is writable, noinit
1371 end
1372
1373
1374 # Declaration of callbacks for extern methods
1375 class AExternCalls
1376 super Prod
1377
1378 # The `import` keyword
1379 var n_kwimport: TKwimport is writable, noinit
1380
1381 # The list of declared callbacks
1382 var n_extern_calls: ANodes[AExternCall] = new ANodes[AExternCall](self)
1383 end
1384
1385 # A single callback declaration
1386 abstract class AExternCall
1387 super Prod
1388 end
1389
1390 # A single callback declaration on a method
1391 abstract class APropExternCall
1392 super AExternCall
1393 end
1394
1395 # A single callback declaration on a method on the current receiver
1396 class ALocalPropExternCall
1397 super APropExternCall
1398
1399 # The name of the called-back method
1400 var n_methid: AMethid is writable, noinit
1401 end
1402
1403 # A single callback declaration on a method on an explicit receiver type.
1404 class AFullPropExternCall
1405 super APropExternCall
1406
1407 # The type of the receiver of the called-back method
1408 var n_type: AType is writable, noinit
1409
1410 # The dot `.`
1411 var n_dot: nullable TDot = null is writable
1412
1413 # The name of the called-back method
1414 var n_methid: AMethid is writable, noinit
1415 end
1416
1417 # A single callback declaration on a method on a constructor
1418 class AInitPropExternCall
1419 super APropExternCall
1420
1421 # The allocated type
1422 var n_type: AType is writable, noinit
1423 end
1424
1425 # A single callback declaration on a `super` call
1426 class ASuperExternCall
1427 super AExternCall
1428
1429 # The `super` keyword
1430 var n_kwsuper: TKwsuper is writable, noinit
1431 end
1432
1433 # A single callback declaration on a cast
1434 abstract class ACastExternCall
1435 super AExternCall
1436 end
1437
1438 # A single callback declaration on a cast to a given type
1439 class ACastAsExternCall
1440 super ACastExternCall
1441
1442 # The origin type of the cast
1443 var n_from_type: AType is writable, noinit
1444
1445 # The dot (`.`)
1446 var n_dot: nullable TDot = null is writable
1447
1448 # The `as` keyword
1449 var n_kwas: TKwas is writable, noinit
1450
1451 # The destination of the cast
1452 var n_to_type: AType is writable, noinit
1453 end
1454
1455 # A single callback declaration on a cast to a nullable type
1456 class AAsNullableExternCall
1457 super ACastExternCall
1458
1459 # The origin type to cast as nullable
1460 var n_type: AType is writable, noinit
1461
1462 # The `as` keyword
1463 var n_kwas: TKwas is writable, noinit
1464
1465 # The `nullable` keyword
1466 var n_kwnullable: TKwnullable is writable, noinit
1467 end
1468
1469 # A single callback declaration on a cast to a non-nullable type
1470 class AAsNotNullableExternCall
1471 super ACastExternCall
1472
1473 # The destination type on a cast to not nullable
1474 var n_type: AType is writable, noinit
1475
1476 # The `as` keyword.
1477 var n_kwas: TKwas is writable, noinit
1478
1479 # The `not` keyword
1480 var n_kwnot: TKwnot is writable, noinit
1481
1482 # The `nullable` keyword
1483 var n_kwnullable: TKwnullable is writable, noinit
1484 end
1485
1486 # A definition of a virtual type
1487 class ATypePropdef
1488 super APropdef
1489
1490 # The `type` keyword
1491 var n_kwtype: TKwtype is writable, noinit
1492
1493 # The name of the virtual type
1494 var n_id: TClassid is writable, noinit
1495
1496 # The bound of the virtual type
1497 var n_type: AType is writable, noinit
1498 end
1499
1500 # The identifier of a method in a method declaration.
1501 # There is a specific class because of operator and setters.
1502 abstract class AMethid
1503 super Prod
1504 end
1505
1506 # A method name with a simple identifier
1507 class AIdMethid
1508 super AMethid
1509
1510 # The simple identifier
1511 var n_id: TId is writable, noinit
1512 end
1513
1514 # A method name for an operator
1515 class AOperatorMethid
1516 super AMethid
1517
1518 # The associated operator symbol
1519 var n_op: Token is writable, noinit
1520 end
1521 # A method name `+`
1522 class APlusMethid
1523 super AOperatorMethid
1524 end
1525
1526 # A method name `-`
1527 class AMinusMethid
1528 super AOperatorMethid
1529 end
1530
1531 # A method name `*`
1532 class AStarMethid
1533 super AOperatorMethid
1534 end
1535
1536 # A method name `**`
1537 class AStarstarMethid
1538 super AOperatorMethid
1539 end
1540
1541 # A method name `/`
1542 class ASlashMethid
1543 super AOperatorMethid
1544 end
1545
1546 # A method name `%`
1547 class APercentMethid
1548 super AOperatorMethid
1549 end
1550
1551 # A method name `|`
1552 class APipeMethid
1553 super AOperatorMethid
1554 end
1555
1556 # A method name `^`
1557 class ACaretMethid
1558 super AOperatorMethid
1559 end
1560
1561 # A method name `&`
1562 class AAmpMethid
1563 super AOperatorMethid
1564 end
1565
1566 # A method name `~`
1567 class ATildeMethid
1568 super AOperatorMethid
1569 end
1570
1571 # A method name `==`
1572 class AEqMethid
1573 super AOperatorMethid
1574 end
1575
1576 # A method name `!=`
1577 class ANeMethid
1578 super AOperatorMethid
1579 end
1580
1581 # A method name `<=`
1582 class ALeMethid
1583 super AOperatorMethid
1584 end
1585
1586 # A method name `>=`
1587 class AGeMethid
1588 super AOperatorMethid
1589 end
1590
1591 # A method name `<`
1592 class ALtMethid
1593 super AOperatorMethid
1594 end
1595
1596 # A method name `>`
1597 class AGtMethid
1598 super AOperatorMethid
1599 end
1600
1601 # A method name `<<`
1602 class ALlMethid
1603 super AOperatorMethid
1604 end
1605
1606 # A method name `>>`
1607 class AGgMethid
1608 super AOperatorMethid
1609 end
1610
1611 # A method name `<=>`
1612 class AStarshipMethid
1613 super AOperatorMethid
1614 end
1615
1616 # A method name `[]`
1617 class ABraMethid
1618 super AMethid
1619
1620 # The `[` symbol
1621 var n_obra: TObra is writable, noinit
1622
1623 # The `]` symbol
1624 var n_cbra: TCbra is writable, noinit
1625 end
1626
1627 # A setter method name with a simple identifier (with a `=`)
1628 class AAssignMethid
1629 super AMethid
1630
1631 # The base identifier
1632 var n_id: TId is writable, noinit
1633
1634 # The `=` symbol
1635 var n_assign: TAssign is writable, noinit
1636 end
1637
1638 # A method name `[]=`
1639 class ABraassignMethid
1640 super AMethid
1641
1642 # The `[` symbol
1643 var n_obra: TObra is writable, noinit
1644
1645 # The `]` symbol
1646 var n_cbra: TCbra is writable, noinit
1647
1648 # The `=` symbol
1649 var n_assign: TAssign is writable, noinit
1650 end
1651
1652 # A potentially qualified simple identifier `foo::bar::baz`
1653 class AQid
1654 super Prod
1655 # The qualifier, if any
1656 var n_qualified: nullable AQualified = null is writable
1657
1658 # The final identifier
1659 var n_id: TId is writable, noinit
1660 end
1661
1662 # A signature in a method definition. eg `(x,y:X,z:Z):T`
1663 class ASignature
1664 super Prod
1665
1666 # The `(` symbol
1667 var n_opar: nullable TOpar = null is writable
1668
1669 # The list of parameters
1670 var n_params = new ANodes[AParam](self)
1671
1672 # The `)` symbol
1673 var n_cpar: nullable TCpar = null is writable
1674
1675 # The return type
1676 var n_type: nullable AType = null is writable
1677 end
1678
1679 # A parameter definition in a signature. eg `x:X`
1680 class AParam
1681 super Prod
1682
1683 # The name of the parameter
1684 var n_id: TId is writable, noinit
1685
1686 # The type of the parameter, if any
1687 var n_type: nullable AType = null is writable
1688
1689 # The `...` symbol to indicate varargs
1690 var n_dotdotdot: nullable TDotdotdot = null is writable
1691 end
1692
1693 # A static type. eg `nullable X[Y]`
1694 class AType
1695 super Prod
1696 # The `nullable` keyword
1697 var n_kwnullable: nullable TKwnullable = null is writable
1698
1699 # The name of the class or of the formal type
1700 var n_id: TClassid is writable, noinit
1701
1702 # The opening bracket
1703 var n_obra: nullable TObra = null is writable
1704
1705 # Type arguments for a generic type
1706 var n_types = new ANodes[AType](self)
1707
1708 # The closing bracket
1709 var n_cbra: nullable TCbra = null is writable
1710 end
1711
1712 # A label at the end of a block or in a break/continue statement. eg `label x`
1713 class ALabel
1714 super Prod
1715
1716 # The `label` keyword
1717 var n_kwlabel: TKwlabel is writable, noinit
1718
1719 # The name of the label, if any
1720 var n_id: nullable TId is writable, noinit
1721 end
1722
1723 # Expression and statements
1724 # From a AST point of view there is no distinction between statement and expressions (even if the parser has to distinguish them)
1725 abstract class AExpr
1726 super Prod
1727 end
1728
1729 # A sequence of `AExpr` (usually statements)
1730 # The last `AExpr` gives the value of the whole block
1731 class ABlockExpr
1732 super AExpr
1733
1734 # The list of statements in the bloc.
1735 # The last element is often considered as an expression that give the value of the whole block.
1736 var n_expr = new ANodes[AExpr](self)
1737
1738 # The `end` keyword
1739 var n_kwend: nullable TKwend = null is writable
1740 end
1741
1742 # A declaration of a local variable. eg `var x: X = y`
1743 class AVardeclExpr
1744 super AExpr
1745
1746 # The `var` keyword
1747 var n_kwvar: nullable TKwvar = null is writable
1748
1749 # The name of the local variable
1750 var n_id: TId is writable, noinit
1751
1752 # The declaration type of the local variable
1753 var n_type: nullable AType = null is writable
1754
1755 # The `=` symbol (for the initial value)
1756 var n_assign: nullable TAssign = null is writable
1757
1758 # The initial value, if any
1759 var n_expr: nullable AExpr = null is writable
1760 end
1761
1762 # A `return` statement. eg `return x`
1763 class AReturnExpr
1764 super AExpr
1765
1766 # The `return` keyword
1767 var n_kwreturn: nullable TKwreturn = null is writable
1768
1769 # The return value, if any
1770 var n_expr: nullable AExpr = null is writable
1771 end
1772
1773 # Something that has a label.
1774 abstract class ALabelable
1775 super Prod
1776
1777 # The associated label declatation
1778 var n_label: nullable ALabel = null is writable
1779 end
1780
1781 # A `break` or a `continue`
1782 abstract class AEscapeExpr
1783 super AExpr
1784 super ALabelable
1785
1786 # The return value, if nay (unused currently)
1787 var n_expr: nullable AExpr = null is writable
1788 end
1789
1790 # A `break` statement.
1791 class ABreakExpr
1792 super AEscapeExpr
1793
1794 # The `break` keyword
1795 var n_kwbreak: TKwbreak is writable, noinit
1796 end
1797
1798 # An `abort` statement
1799 class AAbortExpr
1800 super AExpr
1801
1802 # The `abort` keyword
1803 var n_kwabort: TKwabort is writable, noinit
1804 end
1805
1806 # A `continue` statement
1807 class AContinueExpr
1808 super AEscapeExpr
1809
1810 # The `continue` keyword.
1811 var n_kwcontinue: nullable TKwcontinue = null is writable
1812 end
1813
1814 # A `do` statement
1815 class ADoExpr
1816 super AExpr
1817 super ALabelable
1818
1819 # The `do` keyword
1820 var n_kwdo: TKwdo is writable, noinit
1821
1822 # The list of statements of the `do`.
1823 var n_block: nullable AExpr = null is writable
1824 end
1825
1826 # A `if` statement
1827 class AIfExpr
1828 super AExpr
1829
1830 # The `if` keyword
1831 var n_kwif: TKwif is writable, noinit
1832
1833 # The expression used as the condition of the `if`
1834 var n_expr: AExpr is writable, noinit
1835
1836 # The `then` keyword
1837 var n_kwthen: TKwthen is writable, noinit
1838
1839 # The body of the `then` part
1840 var n_then: nullable AExpr = null is writable
1841
1842 # The `else` keyword
1843 var n_kwelse: nullable TKwelse = null is writable
1844
1845 # The body of the `else` part
1846 var n_else: nullable AExpr = null is writable
1847 end
1848
1849 # A `if` expression (ternary conditional). eg. `if true then 1 else 0`
1850 class AIfexprExpr
1851 super AExpr
1852
1853 # The `if` keyword
1854 var n_kwif: TKwif is writable, noinit
1855
1856 # The expression used as the condition of the `if`
1857 var n_expr: AExpr is writable, noinit
1858
1859 # The `then` keyword
1860 var n_kwthen: TKwthen is writable, noinit
1861
1862 # The expression in the `then` part
1863 var n_then: AExpr is writable, noinit
1864
1865 # The `else` keyword
1866 var n_kwelse: TKwelse is writable, noinit
1867
1868 # The expression in the `else` part
1869 var n_else: AExpr is writable, noinit
1870 end
1871
1872 # A `while` statement
1873 class AWhileExpr
1874 super AExpr
1875 super ALabelable
1876
1877 # The `while` keyword
1878 var n_kwwhile: TKwwhile is writable, noinit
1879
1880 # The expression used as the condition of the `while`
1881 var n_expr: AExpr is writable, noinit
1882
1883 # The `do` keyword
1884 var n_kwdo: TKwdo is writable, noinit
1885
1886 # The body of the loop
1887 var n_block: nullable AExpr = null is writable
1888 end
1889
1890 # A `loop` statement
1891 class ALoopExpr
1892 super AExpr
1893 super ALabelable
1894
1895 # The `loop` keyword
1896 var n_kwloop: TKwloop is writable, noinit
1897
1898 # The body of the loop
1899 var n_block: nullable AExpr = null is writable
1900 end
1901
1902 # A `for` statement
1903 class AForExpr
1904 super AExpr
1905 super ALabelable
1906
1907 # The `for` keyword
1908 var n_kwfor: TKwfor is writable, noinit
1909
1910 # The list of name of the automatic variables
1911 var n_ids = new ANodes[TId](self)
1912
1913 # The `in` keyword
1914 var n_kwin: TKwin is writable, noinit
1915
1916 # The expression used as the collection to iterate on
1917 var n_expr: AExpr is writable, noinit
1918
1919 # The `do` keyword
1920 var n_kwdo: TKwdo is writable, noinit
1921
1922 # The body of the loop
1923 var n_block: nullable AExpr = null is writable
1924 end
1925
1926 # A `with` statement
1927 class AWithExpr
1928 super AExpr
1929 super ALabelable
1930
1931 # The `with` keyword
1932 var n_kwwith: TKwwith is writable, noinit
1933
1934 # The expression used to get the value to control
1935 var n_expr: AExpr is writable, noinit
1936
1937 # The `do` keyword
1938 var n_kwdo: TKwdo is writable, noinit
1939
1940 # The body of the loop
1941 var n_block: nullable AExpr = null is writable
1942 end
1943
1944 # An `assert` statement
1945 class AAssertExpr
1946 super AExpr
1947
1948 # The `assert` keyword
1949 var n_kwassert: TKwassert is writable, noinit
1950
1951 # The name of the assert, if any
1952 var n_id: nullable TId = null is writable
1953
1954 # The expression used as the condition of the `assert`
1955 var n_expr: AExpr is writable, noinit
1956
1957 # The `else` keyword
1958 var n_kwelse: nullable TKwelse = null is writable
1959
1960 # The body to execute when the assert fails
1961 var n_else: nullable AExpr = null is writable
1962 end
1963
1964 # Whatever is a simple assignment. eg `= something`
1965 abstract class AAssignFormExpr
1966 super AExpr
1967
1968 # The `=` symbol
1969 var n_assign: TAssign is writable, noinit
1970
1971 # The right-value to assign.
1972 var n_value: AExpr is writable, noinit
1973 end
1974
1975 # Whatever is a combined assignment. eg `+= something`
1976 abstract class AReassignFormExpr
1977 super AExpr
1978
1979 # The combined operator (eg. `+=`)
1980 var n_assign_op: AAssignOp is writable, noinit
1981
1982 # The right-value to apply on the combined operator.
1983 var n_value: AExpr is writable, noinit
1984 end
1985
1986 # A `once` expression. eg `once x`
1987 class AOnceExpr
1988 super AExpr
1989
1990 # The `once` keyword
1991 var n_kwonce: TKwonce is writable, noinit
1992
1993 # The expression to evaluate only one time
1994 var n_expr: AExpr is writable, noinit
1995 end
1996
1997 # A polymorphic invocation of a method
1998 # The form of the invocation (name, arguments, etc.) are specific
1999 abstract class ASendExpr
2000 super AExpr
2001 # The receiver of the method invocation
2002 var n_expr: AExpr is writable, noinit
2003 end
2004
2005 # A binary operation on a method
2006 abstract class ABinopExpr
2007 super ASendExpr
2008
2009 # The operator
2010 var n_op: Token is writable, noinit
2011
2012 # The second operand of the operation
2013 # Note: the receiver (`n_expr`) is the first operand
2014 var n_expr2: AExpr is writable, noinit
2015
2016 # The name of the operator (eg '+')
2017 fun operator: String is abstract
2018 end
2019
2020 # Something that is boolean expression
2021 abstract class ABoolExpr
2022 super AExpr
2023 end
2024
2025 # Something that is binary boolean expression
2026 abstract class ABinBoolExpr
2027 super ABoolExpr
2028
2029 # The first boolean operand
2030 var n_expr: AExpr is writable, noinit
2031
2032 # The operator
2033 var n_op: Token is writable, noinit
2034
2035 # The second boolean operand
2036 var n_expr2: AExpr is writable, noinit
2037 end
2038
2039 # A `or` expression
2040 class AOrExpr
2041 super ABinBoolExpr
2042 end
2043
2044 # A `and` expression
2045 class AAndExpr
2046 super ABinBoolExpr
2047 end
2048
2049 # A `or else` expression
2050 class AOrElseExpr
2051 super ABinBoolExpr
2052
2053 # The `else` keyword
2054 var n_kwelse: TKwelse is writable, noinit
2055 end
2056
2057 # A `implies` expression
2058 class AImpliesExpr
2059 super ABinBoolExpr
2060 end
2061
2062 # A `not` expression
2063 class ANotExpr
2064 super ABoolExpr
2065
2066 # The `not` keyword
2067 var n_kwnot: TKwnot is writable, noinit
2068
2069 # The boolean operand of the `not`
2070 var n_expr: AExpr is writable, noinit
2071 end
2072
2073 # A `==` or a `!=` expression
2074 #
2075 # Both have a similar effect on adaptive typing, so this class factorizes the common behavior.
2076 class AEqFormExpr
2077 super ABinopExpr
2078 end
2079
2080 # A `==` expression
2081 class AEqExpr
2082 super AEqFormExpr
2083 redef fun operator do return "=="
2084 end
2085
2086 # A `!=` expression
2087 class ANeExpr
2088 super AEqFormExpr
2089 redef fun operator do return "!="
2090 end
2091
2092 # A `<` expression
2093 class ALtExpr
2094 super ABinopExpr
2095 redef fun operator do return "<"
2096 end
2097
2098 # A `<=` expression
2099 class ALeExpr
2100 super ABinopExpr
2101 redef fun operator do return "<="
2102 end
2103
2104 # A `<<` expression
2105 class ALlExpr
2106 super ABinopExpr
2107 redef fun operator do return "<<"
2108 end
2109
2110 # A `>` expression
2111 class AGtExpr
2112 super ABinopExpr
2113 redef fun operator do return ">"
2114 end
2115
2116 # A `>=` expression
2117 class AGeExpr
2118 super ABinopExpr
2119 redef fun operator do return ">="
2120 end
2121
2122 # A `>>` expression
2123 class AGgExpr
2124 super ABinopExpr
2125 redef fun operator do return ">>"
2126 end
2127
2128 # A type-ckeck expression. eg `x isa T`
2129 class AIsaExpr
2130 super ABoolExpr
2131
2132 # The expression to check
2133 var n_expr: AExpr is writable, noinit
2134
2135 # The `isa` keyword
2136 var n_kwisa: TKwisa is writable, noinit
2137
2138 # The destination type to check to
2139 var n_type: AType is writable, noinit
2140 end
2141
2142 # A `+` expression
2143 class APlusExpr
2144 super ABinopExpr
2145 redef fun operator do return "+"
2146 end
2147
2148 # A `-` expression
2149 class AMinusExpr
2150 super ABinopExpr
2151 redef fun operator do return "-"
2152 end
2153
2154 # A `<=>` expression
2155 class AStarshipExpr
2156 super ABinopExpr
2157 redef fun operator do return "<=>"
2158 end
2159
2160 # A `*` expression
2161 class AStarExpr
2162 super ABinopExpr
2163 redef fun operator do return "*"
2164 end
2165
2166 # A `**` expression
2167 class AStarstarExpr
2168 super ABinopExpr
2169 redef fun operator do return "**"
2170 end
2171
2172 # A `/` expression
2173 class ASlashExpr
2174 super ABinopExpr
2175 redef fun operator do return "/"
2176 end
2177
2178 # A `%` expression
2179 class APercentExpr
2180 super ABinopExpr
2181 redef fun operator do return "%"
2182 end
2183
2184 # A `|` expression
2185 class APipeExpr
2186 super ABinopExpr
2187 redef fun operator do return "|"
2188 end
2189
2190 # A `^` expression
2191 class ACaretExpr
2192 super ABinopExpr
2193 redef fun operator do return "^"
2194 end
2195
2196 # A `&` expression
2197 class AAmpExpr
2198 super ABinopExpr
2199 redef fun operator do return "&"
2200 end
2201
2202 # A unary operation on a method
2203 abstract class AUnaryopExpr
2204 super ASendExpr
2205
2206 # The operator
2207 var n_op: Token is writable, noinit
2208
2209 # The name of the operator (eg '+')
2210 fun operator: String is abstract
2211 end
2212
2213 # A unary minus expression. eg `-x`
2214 class AUminusExpr
2215 super AUnaryopExpr
2216 redef fun operator do return "-"
2217 end
2218
2219 # A unary plus expression. eg `+x`
2220 class AUplusExpr
2221 super AUnaryopExpr
2222 redef fun operator do return "+"
2223 end
2224
2225 # A unary `~` expression
2226 class AUtildeExpr
2227 super AUnaryopExpr
2228 redef fun operator do return "~"
2229 end
2230
2231 # An explicit instantiation. eg `new T`
2232 class ANewExpr
2233 super AExpr
2234
2235 # The `new` keyword
2236 var n_kwnew: TKwnew is writable, noinit
2237
2238 # The `type` keyword
2239 var n_type: AType is writable, noinit
2240
2241 # The name of the named-constructor, if any
2242 var n_qid: nullable AQid = null is writable
2243
2244 # The arguments of the `new`
2245 var n_args: AExprs is writable, noinit
2246 end
2247
2248 # Whatever is a old-style attribute access
2249 abstract class AAttrFormExpr
2250 super AExpr
2251
2252 # The receiver of the attribute
2253 var n_expr: AExpr is writable, noinit
2254
2255 # The name of the attribute
2256 var n_id: TAttrid is writable, noinit
2257
2258 end
2259
2260 # The read of an attribute. eg `x._a`
2261 class AAttrExpr
2262 super AAttrFormExpr
2263 end
2264
2265 # The assignment of an attribute. eg `x._a=y`
2266 class AAttrAssignExpr
2267 super AAttrFormExpr
2268 super AAssignFormExpr
2269 end
2270
2271 # Whatever looks-like a call with a standard method and any number of arguments.
2272 abstract class ACallFormExpr
2273 super ASendExpr
2274
2275 # The name of the method
2276 var n_qid: AQid is writable, noinit
2277
2278 # The arguments of the call
2279 var n_args: AExprs is writable, noinit
2280 end
2281
2282 # A complex setter call (standard or brackets)
2283 abstract class ASendReassignFormExpr
2284 super ASendExpr
2285 super AReassignFormExpr
2286 end
2287
2288 # A complex attribute assignment. eg `x._a+=y`
2289 class AAttrReassignExpr
2290 super AAttrFormExpr
2291 super AReassignFormExpr
2292 end
2293
2294 # A call with a standard method-name and any number of arguments. eg `x.m(y)`. OR just a simple id
2295 # 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`.
2296 # Semantic analysis have to transform them to instance of `AVarExpr`.
2297 class ACallExpr
2298 super ACallFormExpr
2299 end
2300
2301 # A setter call with a standard method-name and any number of arguments. eg `x.m(y)=z`. OR just a simple assignment.
2302 # 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`.
2303 # Semantic analysis have to transform them to instance of `AVarAssignExpr`.
2304 class ACallAssignExpr
2305 super ACallFormExpr
2306 super AAssignFormExpr
2307 end
2308
2309 # 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.
2310 # 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`.
2311 # Semantic analysis have to transform them to instance of `AVarReassignExpr`.
2312 class ACallReassignExpr
2313 super ACallFormExpr
2314 super ASendReassignFormExpr
2315 end
2316
2317 # A call to `super`. OR a call of a super-constructor
2318 class ASuperExpr
2319 super AExpr
2320
2321 # The qualifier part before the super (currenlty unused)
2322 var n_qualified: nullable AQualified = null is writable
2323
2324 # The `super` keyword
2325 var n_kwsuper: TKwsuper is writable, noinit
2326
2327 # The arguments of the super
2328 var n_args: AExprs is writable, noinit
2329 end
2330
2331 # A call to the `init` constructor.
2332 # Note: because `init` is a keyword and not a `TId`, the explicit call to init cannot be a `ACallFormExpr`.
2333 class AInitExpr
2334 super ASendExpr
2335
2336 # The `init` keyword
2337 var n_kwinit: TKwinit is writable, noinit
2338
2339 # The arguments of the init
2340 var n_args: AExprs is writable, noinit
2341 end
2342
2343 # Whatever looks-like a call of the brackets `[]` operator.
2344 abstract class ABraFormExpr
2345 super ASendExpr
2346
2347 # The arguments inside the brackets
2348 var n_args: AExprs is writable, noinit
2349 end
2350
2351 # A call of the brackets operator. eg `x[y,z]`
2352 class ABraExpr
2353 super ABraFormExpr
2354 end
2355
2356 # A setter call of the bracket operator. eg `x[y,z]=t`
2357 class ABraAssignExpr
2358 super ABraFormExpr
2359 super AAssignFormExpr
2360 end
2361
2362 # Whatever is an access to a local variable
2363 abstract class AVarFormExpr
2364 super AExpr
2365
2366 # The name of the attribute
2367 var n_id: TId is writable, noinit
2368 end
2369
2370 # A complex setter call of the bracket operator. eg `x[y,z]+=t`
2371 class ABraReassignExpr
2372 super ABraFormExpr
2373 super ASendReassignFormExpr
2374 end
2375
2376 # A local variable read access.
2377 # The parser cannot instantiate them, see `ACallExpr`.
2378 class AVarExpr
2379 super AVarFormExpr
2380 end
2381
2382 # A local variable simple assignment access
2383 # The parser cannot instantiate them, see `ACallAssignExpr`.
2384 class AVarAssignExpr
2385 super AVarFormExpr
2386 super AAssignFormExpr
2387 end
2388
2389 # A local variable complex assignment access
2390 # The parser cannot instantiate them, see `ACallReassignExpr`.
2391 class AVarReassignExpr
2392 super AVarFormExpr
2393 super AReassignFormExpr
2394 end
2395
2396 # A literal range, open or closed
2397 abstract class ARangeExpr
2398 super AExpr
2399
2400 # The left (lower) element of the range
2401 var n_expr: AExpr is writable, noinit
2402
2403 # The `..`
2404 var n_dotdot: TDotdot is writable, noinit
2405
2406 # The right (upper) element of the range
2407 var n_expr2: AExpr is writable, noinit
2408 end
2409
2410 # A closed literal range. eg `[x..y]`
2411 class ACrangeExpr
2412 super ARangeExpr
2413
2414 # The opening bracket `[`
2415 var n_obra: TObra is writable, noinit
2416
2417 # The closing bracket `]`
2418 var n_cbra: TCbra is writable, noinit
2419 end
2420
2421 # An open literal range. eg `[x..y[`
2422 class AOrangeExpr
2423 super ARangeExpr
2424
2425 # The opening bracket `[`
2426 var n_obra: TObra is writable, noinit
2427
2428 # The closing bracket `[` (because open range)
2429 var n_cbra: TObra is writable, noinit
2430 end
2431
2432 # A literal array. eg. `[x,y,z]`
2433 class AArrayExpr
2434 super AExpr
2435
2436 # The opening bracket `[`
2437 var n_obra: TObra is writable, noinit
2438
2439 # The elements of the array
2440 var n_exprs = new ANodes[AExpr](self)
2441
2442 # The type of the element of the array (if any)
2443 var n_type: nullable AType = null is writable
2444
2445 # The closing bracket `]`
2446 var n_cbra: TCbra is writable, noinit
2447 end
2448
2449 # A read of `self`
2450 class ASelfExpr
2451 super AExpr
2452
2453 # The `self` keyword
2454 var n_kwself: nullable TKwself = null is writable
2455 end
2456
2457 # When there is no explicit receiver, `self` is implicit
2458 class AImplicitSelfExpr
2459 super ASelfExpr
2460 end
2461
2462 # A `true` boolean literal constant
2463 class ATrueExpr
2464 super ABoolExpr
2465
2466 # The `true` keyword
2467 var n_kwtrue: TKwtrue is writable, noinit
2468 end
2469
2470 # A `false` boolean literal constant
2471 class AFalseExpr
2472 super ABoolExpr
2473
2474 # The `false` keyword
2475 var n_kwfalse: TKwfalse is writable, noinit
2476 end
2477
2478 # A `null` literal constant
2479 class ANullExpr
2480 super AExpr
2481
2482 # The `null` keyword
2483 var n_kwnull: TKwnull is writable, noinit
2484 end
2485
2486 # An integer literal
2487 class AIntegerExpr
2488 super AExpr
2489
2490 # The integer token
2491 var n_integer: TInteger is writable, noinit
2492 end
2493
2494 # A float literal
2495 class AFloatExpr
2496 super AExpr
2497
2498 # The float token
2499 var n_float: TFloat is writable, noinit
2500 end
2501
2502 # A character literal
2503 class ACharExpr
2504 super AExpr
2505
2506 # The character token
2507 var n_char: TChar is writable, noinit
2508 end
2509
2510 # A string literal
2511 abstract class AStringFormExpr
2512 super AExpr
2513
2514 # The string token
2515 var n_string: Token is writable, noinit
2516 end
2517
2518 # A simple string. eg. `"abc"`
2519 class AStringExpr
2520 super AStringFormExpr
2521 end
2522
2523 # The start of a superstring. eg `"abc{`
2524 class AStartStringExpr
2525 super AStringFormExpr
2526 end
2527
2528 # The middle of a superstring. eg `}abc{`
2529 class AMidStringExpr
2530 super AStringFormExpr
2531 end
2532
2533 # The end of a superstrng. eg `}abc"`
2534 class AEndStringExpr
2535 super AStringFormExpr
2536 end
2537
2538 # A superstring literal. eg `"a{x}b{y}c"`
2539 # Each part is modeled a sequence of expression. eg. `["a{, x, }b{, y, }c"]`
2540 class ASuperstringExpr
2541 super AExpr
2542
2543 # The list of the expressions of the superstring
2544 var n_exprs = new ANodes[AExpr](self)
2545 end
2546
2547 # A simple parenthesis. eg `(x)`
2548 class AParExpr
2549 super AExpr
2550
2551 # The opening parenthesis
2552 var n_opar: TOpar is writable, noinit
2553
2554 # The inner expression
2555 var n_expr: AExpr is writable, noinit
2556
2557 # The closing parenthesis
2558 var n_cpar: TCpar is writable, noinit
2559 end
2560
2561 # A cast, against a type or `not null`
2562 class AAsCastForm
2563 super AExpr
2564
2565 # The expression to cast
2566 var n_expr: AExpr is writable, noinit
2567
2568 # The `as` keyword
2569 var n_kwas: TKwas is writable, noinit
2570
2571 # The opening parenthesis
2572 var n_opar: nullable TOpar = null is writable
2573
2574 # The closing parenthesis
2575 var n_cpar: nullable TCpar = null is writable
2576 end
2577
2578 # A type cast. eg `x.as(T)`
2579 class AAsCastExpr
2580 super AAsCastForm
2581
2582 # The target type to cast to
2583 var n_type: AType is writable, noinit
2584 end
2585
2586 # A as-not-null cast. eg `x.as(not null)`
2587 class AAsNotnullExpr
2588 super AAsCastForm
2589
2590 # The `not` keyword
2591 var n_kwnot: TKwnot is writable, noinit
2592
2593 # The `null` keyword
2594 var n_kwnull: TKwnull is writable, noinit
2595 end
2596
2597 # A is-set check of old-style attributes. eg `isset x._a`
2598 class AIssetAttrExpr
2599 super AAttrFormExpr
2600
2601 # The `isset` keyword
2602 var n_kwisset: TKwisset is writable, noinit
2603 end
2604
2605 # An ellipsis notation used to pass an expression as it, in a vararg parameter
2606 class AVarargExpr
2607 super AExpr
2608
2609 # The passed expression
2610 var n_expr: AExpr is writable, noinit
2611
2612 # The `...` symbol
2613 var n_dotdotdot: TDotdotdot is writable, noinit
2614 end
2615
2616 # An named notation used to pass an expression by name in a parameter
2617 class ANamedargExpr
2618 super AExpr
2619
2620 # The name of the argument
2621 var n_id: TId is writable, noinit
2622
2623 # The `=` synbol
2624 var n_assign: TAssign is writable, noinit
2625
2626 # The passed expression
2627 var n_expr: AExpr is writable, noinit
2628 end
2629
2630 # A list of expression separated with commas (arguments for instance)
2631 class AManyExpr
2632 super AExpr
2633
2634 # The list of expressions
2635 var n_exprs = new ANodes[AExpr](self)
2636 end
2637
2638 # A special expression that encapsulates a static type
2639 # Can only be found in special construction like arguments of annotations.
2640 class ATypeExpr
2641 super AExpr
2642
2643 # The encapsulated type
2644 var n_type: AType is writable, noinit
2645 end
2646
2647 # A special expression that encapsulates a method identifier
2648 # Can only be found in special construction like arguments of annotations.
2649 class AMethidExpr
2650 super AExpr
2651
2652 # The receiver
2653 var n_expr: AExpr is writable, noinit
2654
2655 # The encapsulated method identifier
2656 var n_id: AMethid is writable, noinit
2657 end
2658
2659 # A special expression that encapsulate an annotation
2660 # Can only be found in special construction like arguments of annotations.
2661 #
2662 # The encapsulated annotations are in `n_annotations`
2663 class AAtExpr
2664 super AExpr
2665 end
2666
2667 # A special expression to debug types
2668 class ADebugTypeExpr
2669 super AExpr
2670
2671 # The `debug` keyword
2672 var n_kwdebug: TKwdebug is writable, noinit
2673
2674 # The `type` keyword
2675 var n_kwtype: TKwtype is writable, noinit
2676
2677 # The expression to check
2678 var n_expr: AExpr is writable, noinit
2679
2680 # The type to check
2681 var n_type: AType is writable, noinit
2682 end
2683
2684 # A list of expression separated with commas (arguments for instance)
2685 abstract class AExprs
2686 super Prod
2687
2688 # The list of expressions
2689 var n_exprs = new ANodes[AExpr](self)
2690 end
2691
2692 # A simple list of expressions
2693 class AListExprs
2694 super AExprs
2695 end
2696
2697 # A list of expressions enclosed in parentheses
2698 class AParExprs
2699 super AExprs
2700
2701 # The opening parenthesis
2702 var n_opar: TOpar is writable, noinit
2703
2704 # The closing parenthesis
2705 var n_cpar: TCpar is writable, noinit
2706 end
2707
2708 # A list of expressions enclosed in brackets
2709 class ABraExprs
2710 super AExprs
2711
2712 # The opening bracket
2713 var n_obra: TObra is writable, noinit
2714
2715 # The closing bracket
2716 var n_cbra: TCbra is writable, noinit
2717 end
2718
2719 # A complex assignment operator. (`+=` and `-=`)
2720 abstract class AAssignOp
2721 super Prod
2722
2723 # The combined assignment operator
2724 var n_op: Token is writable, noinit
2725
2726 # The name of the operator without the `=` (eg '+')
2727 fun operator: String is abstract
2728 end
2729
2730 # A `+=` assignment operation
2731 class APlusAssignOp
2732 super AAssignOp
2733
2734 redef fun operator do return "+"
2735 end
2736
2737 # A `-=` assignment operation
2738 class AMinusAssignOp
2739 super AAssignOp
2740
2741 redef fun operator do return "-"
2742 end
2743
2744 # A `*=` assignment operation
2745 class AStarAssignOp
2746 super AAssignOp
2747
2748 redef fun operator do return "*"
2749 end
2750
2751 # A `/=` assignment operation
2752 class ASlashAssignOp
2753 super AAssignOp
2754
2755 redef fun operator do return "/"
2756 end
2757
2758 # A `%=` assignment operation
2759 class APercentAssignOp
2760 super AAssignOp
2761
2762 redef fun operator do return "%"
2763 end
2764
2765 # A `**=` assignment operation
2766 class AStarstarAssignOp
2767 super AAssignOp
2768
2769 redef fun operator do return "**"
2770 end
2771
2772 # A `|=` assignment operation
2773 class APipeAssignOp
2774 super AAssignOp
2775
2776 redef fun operator do return "|"
2777 end
2778
2779 # A `^=` assignment operation
2780 class ACaretAssignOp
2781 super AAssignOp
2782
2783 redef fun operator do return "^"
2784 end
2785
2786 # A `&=` assignment operation
2787 class AAmpAssignOp
2788 super AAssignOp
2789
2790 redef fun operator do return "&"
2791 end
2792
2793 # A `<<=` assignment operation
2794 class ALlAssignOp
2795 super AAssignOp
2796
2797 redef fun operator do return "<<"
2798 end
2799
2800 # A `>>=` assignment operation
2801 class AGgAssignOp
2802 super AAssignOp
2803
2804 redef fun operator do return ">>"
2805 end
2806
2807 # A possibly fully-qualified module identifier
2808 class AModuleName
2809 super Prod
2810
2811 # The starting quad (`::`)
2812 var n_quad: nullable TQuad = null is writable
2813
2814 # The list of quad-separated package/group identifiers
2815 var n_path = new ANodes[TId](self)
2816
2817 # The final module identifier
2818 var n_id: TId is writable, noinit
2819 end
2820
2821 # A language declaration for an extern block
2822 class AInLanguage
2823 super Prod
2824
2825 # The `in` keyword
2826 var n_kwin: TKwin is writable, noinit
2827
2828 # The language name
2829 var n_string: TString is writable, noinit
2830 end
2831
2832 # An full extern block
2833 class AExternCodeBlock
2834 super Prod
2835
2836 # The language declration
2837 var n_in_language: nullable AInLanguage = null is writable
2838
2839 # The block of extern code
2840 var n_extern_code_segment: TExternCodeSegment is writable, noinit
2841 end
2842
2843 # A possible full method qualifier.
2844 class AQualified
2845 super Prod
2846
2847 # The starting quad (`::`)
2848 var n_quad: nullable TQuad = null is writable
2849
2850 # The list of quad-separated package/group/module identifiers
2851 var n_id = new ANodes[TId](self)
2852
2853 # A class identifier
2854 var n_classid: nullable TClassid = null is writable
2855 end
2856
2857 # A documentation of a definition
2858 # It contains the block of comments just above the declaration
2859 class ADoc
2860 super Prod
2861
2862 # A list of lines of comment
2863 var n_comment = new ANodes[TComment](self)
2864 end
2865
2866 # A group of annotation on a node
2867 #
2868 # This same class is used for the 3 kind of annotations:
2869 #
2870 # * *is* annotations. eg `module foo is bar`.
2871 # * *at* annotations. eg `foo@bar` or `foo@(bar,baz)`.
2872 # * *class* annotations, defined in classes.
2873 class AAnnotations
2874 super Prod
2875
2876 # The `is` keyword, for *is* annotations
2877 var n_kwis: nullable TKwis = null is writable
2878
2879 # The `@` symbol, for *at* annotations
2880 var n_at: nullable TAt = null is writable
2881
2882 # The opening parenthesis in *at* annotations
2883 var n_opar: nullable TOpar = null is writable
2884
2885 # The list of annotations
2886 var n_items = new ANodes[AAnnotation](self)
2887
2888 # The closing parenthesis in *at* annotations
2889 var n_cpar: nullable TCpar = null is writable
2890
2891 # The `end` keyword, for *is* annotations
2892 var n_kwend: nullable TKwend = null is writable
2893 end
2894
2895 # A single annotation
2896 class AAnnotation
2897 super ADefinition
2898
2899 # The name of the annotation
2900 var n_atid: AAtid is writable, noinit
2901
2902 # The opening parenthesis of the arguments
2903 var n_opar: nullable TOpar = null is writable
2904
2905 # The list of arguments
2906 var n_args = new ANodes[AExpr](self)
2907
2908 # The closing parenthesis
2909 var n_cpar: nullable TCpar = null is writable
2910
2911 # The name of the annotation
2912 fun name: String
2913 do
2914 return n_atid.n_id.text
2915 end
2916 end
2917
2918 # An annotation name
2919 abstract class AAtid
2920 super Prod
2921
2922 # The identifier of the annotation.
2923 # Can be a TId of a keyword
2924 var n_id: Token is writable, noinit
2925 end
2926
2927 # An annotation name based on an identifier
2928 class AIdAtid
2929 super AAtid
2930 end
2931
2932 # An annotation name based on the keyword `extern`
2933 class AKwexternAtid
2934 super AAtid
2935 end
2936
2937 # An annotation name based on the keyword `import`
2938 class AKwimportAtid
2939 super AAtid
2940 end
2941
2942 # An annotation name based on the keyword `abstract`
2943 class AKwabstractAtid
2944 super AAtid
2945 end
2946
2947 # The root of the AST
2948 class Start
2949 super Prod
2950
2951 # The main module
2952 var n_base: nullable AModule is writable
2953
2954 # The end of file (or error) token
2955 var n_eof: EOF is writable
2956 end