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