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