bcbacb31987709f87c37f6cc201f83fb9875bffb
[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 #
1215 # While most definitions are `AStdClassdef`s,
1216 # there are 2 special cases of class definitions.
1217 abstract class AClassdef
1218 super Prod
1219 # All the declared properties (including the main method)
1220 var n_propdefs = new ANodes[APropdef](self)
1221 end
1222
1223 # A standard class definition with a name, superclasses and properties
1224 class AStdClassdef
1225 super AClassdef
1226 super ADefinition
1227
1228 # The class kind (interface, abstract class, etc.)
1229 var n_classkind: AClasskind is writable, noinit
1230
1231 # The name of the class
1232 var n_qid: nullable AQclassid = null is writable
1233
1234 # The `[` symbol
1235 var n_obra: nullable TObra = null is writable
1236
1237 # The list of formal parameter types
1238 var n_formaldefs = new ANodes[AFormaldef](self)
1239
1240 # The `]` symbol
1241 var n_cbra: nullable TCbra = null is writable
1242
1243 # The extern block code
1244 var n_extern_code_block: nullable AExternCodeBlock = null is writable
1245
1246 # The `end` keyword
1247 var n_kwend: TKwend is writable, noinit
1248
1249 fun n_superclasses: Array[ASuperPropdef] do
1250 return [for d in n_propdefs do if d isa ASuperPropdef then d]
1251 end
1252
1253 redef fun hot_location do return n_qid.location
1254 end
1255
1256 # The implicit class definition of the implicit main method
1257 class ATopClassdef
1258 super AClassdef
1259 end
1260
1261 # The implicit class definition of the top-level methods
1262 class AMainClassdef
1263 super AClassdef
1264 end
1265
1266 # The modifier for the kind of class (abstract, interface, etc.)
1267 abstract class AClasskind
1268 super Prod
1269 end
1270
1271 # A default, or concrete class modifier (just `class`)
1272 class AConcreteClasskind
1273 super AClasskind
1274
1275 # The `class` keyword.
1276 var n_kwclass: TKwclass is writable, noinit
1277 end
1278
1279 # An abstract class modifier (`abstract class`)
1280 class AAbstractClasskind
1281 super AClasskind
1282
1283 # The `abstract` keyword.
1284 var n_kwabstract: TKwabstract is writable, noinit
1285
1286 # The `class` keyword.
1287 var n_kwclass: TKwclass is writable, noinit
1288 end
1289
1290 # An interface class modifier (`interface`)
1291 class AInterfaceClasskind
1292 super AClasskind
1293
1294 # The `interface` keyword.
1295 var n_kwinterface: TKwinterface is writable, noinit
1296 end
1297
1298 # An enum/universal class modifier (`enum class`)
1299 class AEnumClasskind
1300 super AClasskind
1301
1302 # The `enum` keyword.
1303 var n_kwenum: TKwenum is writable, noinit
1304 end
1305
1306 # An extern class modifier (`extern class`)
1307 class AExternClasskind
1308 super AClasskind
1309
1310 # The `extern` keyword.
1311 var n_kwextern: TKwextern is writable, noinit
1312
1313 # The `class` keyword.
1314 var n_kwclass: nullable TKwclass = null is writable
1315 end
1316
1317 # The definition of a formal generic parameter type. eg `X: Y`
1318 class AFormaldef
1319 super Prod
1320
1321 # The name of the parameter type
1322 var n_id: TClassid is writable, noinit
1323
1324 # The bound of the parameter type
1325 var n_type: nullable AType = null is writable
1326 end
1327
1328 # The definition of a property
1329 abstract class APropdef
1330 super ADefinition
1331 end
1332
1333 # A definition of an attribute
1334 # For historical reason, old-syle and new-style attributes use the same `ANode` sub-class
1335 class AAttrPropdef
1336 super APropdef
1337
1338 # The `var` keyword
1339 var n_kwvar: TKwvar is writable, noinit
1340
1341 # The identifier for a new-style attribute
1342 var n_id2: TId is writable, noinit
1343
1344 # The declared type of the attribute
1345 var n_type: nullable AType = null is writable
1346
1347 # The `=` symbol
1348 var n_assign: nullable TAssign = null is writable
1349
1350 # The initial value, if any (set with `=`)
1351 var n_expr: nullable AExpr = null is writable
1352
1353 # The `do` keyword
1354 var n_kwdo: nullable TKwdo = null is writable
1355
1356 # The initial value, if any (set with `do return`)
1357 var n_block: nullable AExpr = null is writable
1358
1359 # The `end` keyword
1360 var n_kwend: nullable TKwend = null is writable
1361
1362 redef fun hot_location
1363 do
1364 return n_id2.location
1365 end
1366 end
1367
1368 # A definition of all kind of method (including constructors)
1369 class AMethPropdef
1370 super APropdef
1371
1372 # The `fun` keyword, if any
1373 var n_kwmeth: nullable TKwmeth = null is writable
1374
1375 # The `init` keyword, if any
1376 var n_kwinit: nullable TKwinit = null is writable
1377
1378 # The `new` keyword, if any
1379 var n_kwnew: nullable TKwnew = null is writable
1380
1381 # The name of the method, if any
1382 var n_methid: nullable AMethid = null is writable
1383
1384 # The signature of the method, if any
1385 var n_signature: nullable ASignature = null is writable
1386
1387 # The `do` keyword
1388 var n_kwdo: nullable TKwdo = null is writable
1389
1390 # The body (in Nit) of the method, if any
1391 var n_block: nullable AExpr = null is writable
1392
1393 # The `end` keyword
1394 var n_kwend: nullable TKwend = null is writable
1395
1396 # The list of declared callbacks (for extern methods)
1397 var n_extern_calls: nullable AExternCalls = null is writable
1398
1399 # The body (in extern code) of the method, if any
1400 var n_extern_code_block: nullable AExternCodeBlock = null is writable
1401
1402 redef fun hot_location
1403 do
1404 if n_methid != null then
1405 return n_methid.location
1406 else if n_kwinit != null then
1407 return n_kwinit.location
1408 else if n_kwnew != null then
1409 return n_kwnew.location
1410 else
1411 return location
1412 end
1413 end
1414 end
1415
1416 # The implicit main method
1417 class AMainMethPropdef
1418 super AMethPropdef
1419 end
1420
1421 class AAnnotPropdef
1422 super APropdef
1423 super AAnnotation
1424 end
1425
1426 # A super-class. eg `super X`
1427 class ASuperPropdef
1428 super APropdef
1429
1430 # The super keyword
1431 var n_kwsuper: TKwsuper is writable, noinit
1432
1433 # The super-class (indicated as a type)
1434 var n_type: AType is writable, noinit
1435 end
1436
1437
1438 # Declaration of callbacks for extern methods
1439 class AExternCalls
1440 super Prod
1441
1442 # The `import` keyword
1443 var n_kwimport: TKwimport is writable, noinit
1444
1445 # The list of declared callbacks
1446 var n_extern_calls: ANodes[AExternCall] = new ANodes[AExternCall](self)
1447 end
1448
1449 # A single callback declaration
1450 abstract class AExternCall
1451 super Prod
1452 end
1453
1454 # A single callback declaration on a method
1455 abstract class APropExternCall
1456 super AExternCall
1457 end
1458
1459 # A single callback declaration on a method on the current receiver
1460 class ALocalPropExternCall
1461 super APropExternCall
1462
1463 # The name of the called-back method
1464 var n_methid: AMethid is writable, noinit
1465 end
1466
1467 # A single callback declaration on a method on an explicit receiver type.
1468 class AFullPropExternCall
1469 super APropExternCall
1470
1471 # The type of the receiver of the called-back method
1472 var n_type: AType is writable, noinit
1473
1474 # The dot `.`
1475 var n_dot: nullable TDot = null is writable
1476
1477 # The name of the called-back method
1478 var n_methid: AMethid is writable, noinit
1479 end
1480
1481 # A single callback declaration on a method on a constructor
1482 class AInitPropExternCall
1483 super APropExternCall
1484
1485 # The allocated type
1486 var n_type: AType is writable, noinit
1487 end
1488
1489 # A single callback declaration on a `super` call
1490 class ASuperExternCall
1491 super AExternCall
1492
1493 # The `super` keyword
1494 var n_kwsuper: TKwsuper is writable, noinit
1495 end
1496
1497 # A single callback declaration on a cast
1498 abstract class ACastExternCall
1499 super AExternCall
1500 end
1501
1502 # A single callback declaration on a cast to a given type
1503 class ACastAsExternCall
1504 super ACastExternCall
1505
1506 # The origin type of the cast
1507 var n_from_type: AType is writable, noinit
1508
1509 # The dot (`.`)
1510 var n_dot: nullable TDot = null is writable
1511
1512 # The `as` keyword
1513 var n_kwas: TKwas is writable, noinit
1514
1515 # The destination of the cast
1516 var n_to_type: AType is writable, noinit
1517 end
1518
1519 # A single callback declaration on a cast to a nullable type
1520 class AAsNullableExternCall
1521 super ACastExternCall
1522
1523 # The origin type to cast as nullable
1524 var n_type: AType is writable, noinit
1525
1526 # The `as` keyword
1527 var n_kwas: TKwas is writable, noinit
1528
1529 # The `nullable` keyword
1530 var n_kwnullable: TKwnullable is writable, noinit
1531 end
1532
1533 # A single callback declaration on a cast to a non-nullable type
1534 class AAsNotNullableExternCall
1535 super ACastExternCall
1536
1537 # The destination type on a cast to not nullable
1538 var n_type: AType is writable, noinit
1539
1540 # The `as` keyword.
1541 var n_kwas: TKwas is writable, noinit
1542
1543 # The `not` keyword
1544 var n_kwnot: TKwnot is writable, noinit
1545
1546 # The `nullable` keyword
1547 var n_kwnullable: TKwnullable is writable, noinit
1548 end
1549
1550 # A definition of a virtual type
1551 class ATypePropdef
1552 super APropdef
1553
1554 # The `type` keyword
1555 var n_kwtype: TKwtype is writable, noinit
1556
1557 # The name of the virtual type
1558 var n_qid: AQclassid is writable, noinit
1559
1560 # The bound of the virtual type
1561 var n_type: AType is writable, noinit
1562 end
1563
1564 # The identifier of a method in a method declaration.
1565 # There is a specific class because of operator and setters.
1566 abstract class AMethid
1567 super Prod
1568 end
1569
1570 # A method name with a simple identifier
1571 class AIdMethid
1572 super AMethid
1573
1574 # The simple identifier
1575 var n_id: TId is writable, noinit
1576 end
1577
1578 # A method name for an operator
1579 class AOperatorMethid
1580 super AMethid
1581
1582 # The associated operator symbol
1583 var n_op: Token is writable, noinit
1584 end
1585 # A method name `+`
1586 class APlusMethid
1587 super AOperatorMethid
1588 end
1589
1590 # A method name `-`
1591 class AMinusMethid
1592 super AOperatorMethid
1593 end
1594
1595 # A method name `*`
1596 class AStarMethid
1597 super AOperatorMethid
1598 end
1599
1600 # A method name `**`
1601 class AStarstarMethid
1602 super AOperatorMethid
1603 end
1604
1605 # A method name `/`
1606 class ASlashMethid
1607 super AOperatorMethid
1608 end
1609
1610 # A method name `%`
1611 class APercentMethid
1612 super AOperatorMethid
1613 end
1614
1615 # A method name `|`
1616 class APipeMethid
1617 super AOperatorMethid
1618 end
1619
1620 # A method name `^`
1621 class ACaretMethid
1622 super AOperatorMethid
1623 end
1624
1625 # A method name `&`
1626 class AAmpMethid
1627 super AOperatorMethid
1628 end
1629
1630 # A method name `~`
1631 class ATildeMethid
1632 super AOperatorMethid
1633 end
1634
1635 # A method name `==`
1636 class AEqMethid
1637 super AOperatorMethid
1638 end
1639
1640 # A method name `!=`
1641 class ANeMethid
1642 super AOperatorMethid
1643 end
1644
1645 # A method name `<=`
1646 class ALeMethid
1647 super AOperatorMethid
1648 end
1649
1650 # A method name `>=`
1651 class AGeMethid
1652 super AOperatorMethid
1653 end
1654
1655 # A method name `<`
1656 class ALtMethid
1657 super AOperatorMethid
1658 end
1659
1660 # A method name `>`
1661 class AGtMethid
1662 super AOperatorMethid
1663 end
1664
1665 # A method name `<<`
1666 class ALlMethid
1667 super AOperatorMethid
1668 end
1669
1670 # A method name `>>`
1671 class AGgMethid
1672 super AOperatorMethid
1673 end
1674
1675 # A method name `<=>`
1676 class AStarshipMethid
1677 super AOperatorMethid
1678 end
1679
1680 # A method name `[]`
1681 class ABraMethid
1682 super AMethid
1683
1684 # The `[` symbol
1685 var n_obra: TObra is writable, noinit
1686
1687 # The `]` symbol
1688 var n_cbra: TCbra is writable, noinit
1689 end
1690
1691 # A setter method name with a simple identifier (with a `=`)
1692 class AAssignMethid
1693 super AMethid
1694
1695 # The base identifier
1696 var n_id: TId is writable, noinit
1697
1698 # The `=` symbol
1699 var n_assign: TAssign is writable, noinit
1700 end
1701
1702 # A method name `[]=`
1703 class ABraassignMethid
1704 super AMethid
1705
1706 # The `[` symbol
1707 var n_obra: TObra is writable, noinit
1708
1709 # The `]` symbol
1710 var n_cbra: TCbra is writable, noinit
1711
1712 # The `=` symbol
1713 var n_assign: TAssign is writable, noinit
1714 end
1715
1716 # A potentially qualified simple identifier `foo::bar::baz`
1717 class AQid
1718 super Prod
1719 # The qualifier, if any
1720 var n_qualified: nullable AQualified = null is writable
1721
1722 # The final identifier
1723 var n_id: TId is writable, noinit
1724
1725 redef fun is_structural do return true
1726 end
1727
1728 # A potentially qualified class identifier `foo::bar::Baz`
1729 class AQclassid
1730 super Prod
1731 # The qualifier, if any
1732 var n_qualified: nullable AQualified = null is writable
1733
1734 # The final identifier
1735 var n_id: TClassid is writable, noinit
1736
1737 redef fun is_structural do return true
1738 end
1739
1740 # A signature in a method definition. eg `(x,y:X,z:Z):T`
1741 class ASignature
1742 super Prod
1743
1744 # The `(` symbol
1745 var n_opar: nullable TOpar = null is writable
1746
1747 # The list of parameters
1748 var n_params = new ANodes[AParam](self)
1749
1750 # The `)` symbol
1751 var n_cpar: nullable TCpar = null is writable
1752
1753 # The return type
1754 var n_type: nullable AType = null is writable
1755 end
1756
1757 # A parameter definition in a signature. eg `x:X`
1758 class AParam
1759 super Prod
1760
1761 # The name of the parameter
1762 var n_id: TId is writable, noinit
1763
1764 # The type of the parameter, if any
1765 var n_type: nullable AType = null is writable
1766
1767 # The `...` symbol to indicate varargs
1768 var n_dotdotdot: nullable TDotdotdot = null is writable
1769 end
1770
1771 # A static type. eg `nullable X[Y]`
1772 class AType
1773 super Prod
1774 # The `nullable` keyword
1775 var n_kwnullable: nullable TKwnullable = null is writable
1776
1777 # The name of the class or of the formal type
1778 var n_qid: AQclassid is writable, noinit
1779
1780 # The opening bracket
1781 var n_obra: nullable TObra = null is writable
1782
1783 # Type arguments for a generic type
1784 var n_types = new ANodes[AType](self)
1785
1786 # The closing bracket
1787 var n_cbra: nullable TCbra = null is writable
1788 end
1789
1790 # A label at the end of a block or in a break/continue statement. eg `label x`
1791 class ALabel
1792 super Prod
1793
1794 # The `label` keyword
1795 var n_kwlabel: TKwlabel is writable, noinit
1796
1797 # The name of the label, if any
1798 var n_id: nullable TId is writable, noinit
1799 end
1800
1801 # Expression and statements
1802 # From a AST point of view there is no distinction between statement and expressions (even if the parser has to distinguish them)
1803 abstract class AExpr
1804 super Prod
1805 end
1806
1807 # A sequence of `AExpr` (usually statements)
1808 # The last `AExpr` gives the value of the whole block
1809 class ABlockExpr
1810 super AExpr
1811
1812 # The list of statements in the bloc.
1813 # The last element is often considered as an expression that give the value of the whole block.
1814 var n_expr = new ANodes[AExpr](self)
1815
1816 # The `end` keyword
1817 var n_kwend: nullable TKwend = null is writable
1818 end
1819
1820 # A declaration of a local variable. eg `var x: X = y`
1821 class AVardeclExpr
1822 super AExpr
1823
1824 # The `var` keyword
1825 var n_kwvar: nullable TKwvar = null is writable
1826
1827 # The name of the local variable
1828 var n_id: TId is writable, noinit
1829
1830 # The declaration type of the local variable
1831 var n_type: nullable AType = null is writable
1832
1833 # The `=` symbol (for the initial value)
1834 var n_assign: nullable TAssign = null is writable
1835
1836 # The initial value, if any
1837 var n_expr: nullable AExpr = null is writable
1838 end
1839
1840 # A `return` statement. eg `return x`
1841 class AReturnExpr
1842 super AEscapeExpr
1843
1844 # The `return` keyword
1845 var n_kwreturn: nullable TKwreturn = null is writable
1846 end
1847
1848 # A `yield` statement. eg `yield x`
1849 class AYieldExpr
1850 super AExpr
1851
1852 # The `yield` keyword
1853 var n_kwyield: nullable TKwyield = null is writable
1854
1855 # The return value, if any
1856 var n_expr: nullable AExpr = null is writable
1857 end
1858
1859 # Something that has a label.
1860 abstract class ALabelable
1861 super Prod
1862
1863 # The associated label declatation
1864 var n_label: nullable ALabel = null is writable
1865 end
1866
1867 # A `break` or a `continue`
1868 abstract class AEscapeExpr
1869 super AExpr
1870 super ALabelable
1871
1872 # The return value, if nay (unused currently)
1873 var n_expr: nullable AExpr = null is writable
1874 end
1875
1876 # A `break` statement.
1877 class ABreakExpr
1878 super AEscapeExpr
1879
1880 # The `break` keyword
1881 var n_kwbreak: TKwbreak is writable, noinit
1882 end
1883
1884 # An `abort` statement
1885 class AAbortExpr
1886 super AExpr
1887
1888 # The `abort` keyword
1889 var n_kwabort: TKwabort is writable, noinit
1890 end
1891
1892 # A `continue` statement
1893 class AContinueExpr
1894 super AEscapeExpr
1895
1896 # The `continue` keyword.
1897 var n_kwcontinue: nullable TKwcontinue = null is writable
1898 end
1899
1900 # A `do` statement
1901 class ADoExpr
1902 super AExpr
1903 super ALabelable
1904
1905 # The `do` keyword
1906 var n_kwdo: TKwdo is writable, noinit
1907
1908 # The list of statements of the `do`.
1909 var n_block: nullable AExpr = null is writable
1910
1911 # The `catch` keyword
1912 var n_kwcatch: nullable TKwcatch = null is writable
1913
1914 # The do catch block
1915 var n_catch: nullable AExpr = null is writable
1916 end
1917
1918 # A `if` statement
1919 class AIfExpr
1920 super AExpr
1921
1922 # The `if` keyword
1923 var n_kwif: TKwif is writable, noinit
1924
1925 # The expression used as the condition of the `if`
1926 var n_expr: AExpr is writable, noinit
1927
1928 # The `then` keyword
1929 var n_kwthen: TKwthen is writable, noinit
1930
1931 # The body of the `then` part
1932 var n_then: nullable AExpr = null is writable
1933
1934 # The `else` keyword
1935 var n_kwelse: nullable TKwelse = null is writable
1936
1937 # The body of the `else` part
1938 var n_else: nullable AExpr = null is writable
1939 end
1940
1941 # A `if` expression (ternary conditional). eg. `if true then 1 else 0`
1942 class AIfexprExpr
1943 super AExpr
1944
1945 # The `if` keyword
1946 var n_kwif: TKwif is writable, noinit
1947
1948 # The expression used as the condition of the `if`
1949 var n_expr: AExpr is writable, noinit
1950
1951 # The `then` keyword
1952 var n_kwthen: TKwthen is writable, noinit
1953
1954 # The expression in the `then` part
1955 var n_then: AExpr is writable, noinit
1956
1957 # The `else` keyword
1958 var n_kwelse: TKwelse is writable, noinit
1959
1960 # The expression in the `else` part
1961 var n_else: AExpr is writable, noinit
1962 end
1963
1964 # A `while` statement
1965 class AWhileExpr
1966 super AExpr
1967 super ALabelable
1968
1969 # The `while` keyword
1970 var n_kwwhile: TKwwhile is writable, noinit
1971
1972 # The expression used as the condition of the `while`
1973 var n_expr: AExpr is writable, noinit
1974
1975 # The `do` keyword
1976 var n_kwdo: TKwdo is writable, noinit
1977
1978 # The body of the loop
1979 var n_block: nullable AExpr = null is writable
1980 end
1981
1982 # A `loop` statement
1983 class ALoopExpr
1984 super AExpr
1985 super ALabelable
1986
1987 # The `loop` keyword
1988 var n_kwloop: TKwloop is writable, noinit
1989
1990 # The body of the loop
1991 var n_block: nullable AExpr = null is writable
1992 end
1993
1994 # A `for` statement
1995 class AForExpr
1996 super AExpr
1997 super ALabelable
1998
1999 # The `for` keyword
2000 var n_kwfor: TKwfor is writable, noinit
2001
2002 # The list of groups to iterate
2003 var n_groups = new ANodes[AForGroup](self)
2004
2005 # The `do` keyword
2006 var n_kwdo: TKwdo is writable, noinit
2007
2008 # The body of the loop
2009 var n_block: nullable AExpr = null is writable
2010 end
2011
2012 # A collection iterated by a for, its automatic variables and its implicit iterator.
2013 #
2014 # Standard `for` iterate on a single collection.
2015 # Multiple `for` can iterate on more than one collection at once.
2016 class AForGroup
2017 super Prod
2018
2019 # The list of name of the automatic variables
2020 var n_ids = new ANodes[TId](self)
2021
2022 # The `in` keyword
2023 var n_kwin: TKwin is writable, noinit
2024
2025 # The expression used as the collection to iterate on
2026 var n_expr: AExpr is writable, noinit
2027 end
2028
2029 # A `with` statement
2030 class AWithExpr
2031 super AExpr
2032 super ALabelable
2033
2034 # The `with` keyword
2035 var n_kwwith: TKwwith is writable, noinit
2036
2037 # The expression used to get the value to control
2038 var n_expr: AExpr is writable, noinit
2039
2040 # The `do` keyword
2041 var n_kwdo: TKwdo is writable, noinit
2042
2043 # The body of the loop
2044 var n_block: nullable AExpr = null is writable
2045 end
2046
2047 # An `assert` statement
2048 class AAssertExpr
2049 super AExpr
2050
2051 # The `assert` keyword
2052 var n_kwassert: TKwassert is writable, noinit
2053
2054 # The name of the assert, if any
2055 var n_id: nullable TId = null is writable
2056
2057 # The expression used as the condition of the `assert`
2058 var n_expr: AExpr is writable, noinit
2059
2060 # The `else` keyword
2061 var n_kwelse: nullable TKwelse = null is writable
2062
2063 # The body to execute when the assert fails
2064 var n_else: nullable AExpr = null is writable
2065 end
2066
2067 # Whatever is a simple assignment. eg `= something`
2068 abstract class AAssignFormExpr
2069 super AExpr
2070
2071 # The `=` symbol
2072 var n_assign: TAssign is writable, noinit
2073
2074 # The right-value to assign.
2075 var n_value: AExpr is writable, noinit
2076 end
2077
2078 # Whatever is a combined assignment. eg `+= something`
2079 abstract class AReassignFormExpr
2080 super AExpr
2081
2082 # The combined operator (eg. `+=`)
2083 var n_assign_op: AAssignOp is writable, noinit
2084
2085 # The right-value to apply on the combined operator.
2086 var n_value: AExpr is writable, noinit
2087 end
2088
2089 # A `once` expression. eg `once x`
2090 class AOnceExpr
2091 super AExpr
2092
2093 # The `once` keyword
2094 var n_kwonce: TKwonce is writable, noinit
2095
2096 # The expression to evaluate only one time
2097 var n_expr: AExpr is writable, noinit
2098 end
2099
2100 # A polymorphic invocation of a method
2101 # The form of the invocation (name, arguments, etc.) are specific
2102 abstract class ASendExpr
2103 super AExpr
2104 # The receiver of the method invocation
2105 var n_expr: AExpr is writable, noinit
2106 end
2107
2108 # A binary operation on a method
2109 abstract class ABinopExpr
2110 super ASendExpr
2111
2112 # The operator
2113 var n_op: Token is writable, noinit
2114
2115 # The second operand of the operation
2116 # Note: the receiver (`n_expr`) is the first operand
2117 var n_expr2: AExpr is writable, noinit
2118
2119 # The name of the operator (eg '+')
2120 fun operator: String is abstract
2121 end
2122
2123 # Something that is boolean expression
2124 abstract class ABoolExpr
2125 super AExpr
2126 end
2127
2128 # Something that is binary boolean expression
2129 abstract class ABinBoolExpr
2130 super ABoolExpr
2131
2132 # The first boolean operand
2133 var n_expr: AExpr is writable, noinit
2134
2135 # The operator
2136 var n_op: Token is writable, noinit
2137
2138 # The second boolean operand
2139 var n_expr2: AExpr is writable, noinit
2140 end
2141
2142 # A `or` expression
2143 class AOrExpr
2144 super ABinBoolExpr
2145 end
2146
2147 # A `and` expression
2148 class AAndExpr
2149 super ABinBoolExpr
2150 end
2151
2152 # A `or else` expression
2153 class AOrElseExpr
2154 super ABinBoolExpr
2155
2156 # The `else` keyword
2157 var n_kwelse: TKwelse is writable, noinit
2158 end
2159
2160 # A `implies` expression
2161 class AImpliesExpr
2162 super ABinBoolExpr
2163 end
2164
2165 # A `not` expression
2166 class ANotExpr
2167 super ABoolExpr
2168
2169 # The `not` keyword
2170 var n_kwnot: TKwnot is writable, noinit
2171
2172 # The boolean operand of the `not`
2173 var n_expr: AExpr is writable, noinit
2174 end
2175
2176 # A `==` or a `!=` expression
2177 #
2178 # Both have a similar effect on adaptive typing, so this class factorizes the common behavior.
2179 class AEqFormExpr
2180 super ABinopExpr
2181 end
2182
2183 # A `==` expression
2184 class AEqExpr
2185 super AEqFormExpr
2186 redef fun operator do return "=="
2187 end
2188
2189 # A `!=` expression
2190 class ANeExpr
2191 super AEqFormExpr
2192 redef fun operator do return "!="
2193 end
2194
2195 # A `<` expression
2196 class ALtExpr
2197 super ABinopExpr
2198 redef fun operator do return "<"
2199 end
2200
2201 # A `<=` expression
2202 class ALeExpr
2203 super ABinopExpr
2204 redef fun operator do return "<="
2205 end
2206
2207 # A `<<` expression
2208 class ALlExpr
2209 super ABinopExpr
2210 redef fun operator do return "<<"
2211 end
2212
2213 # A `>` expression
2214 class AGtExpr
2215 super ABinopExpr
2216 redef fun operator do return ">"
2217 end
2218
2219 # A `>=` expression
2220 class AGeExpr
2221 super ABinopExpr
2222 redef fun operator do return ">="
2223 end
2224
2225 # A `>>` expression
2226 class AGgExpr
2227 super ABinopExpr
2228 redef fun operator do return ">>"
2229 end
2230
2231 # A type-ckeck expression. eg `x isa T`
2232 class AIsaExpr
2233 super ABoolExpr
2234
2235 # The expression to check
2236 var n_expr: AExpr is writable, noinit
2237
2238 # The `isa` keyword
2239 var n_kwisa: TKwisa is writable, noinit
2240
2241 # The destination type to check to
2242 var n_type: AType is writable, noinit
2243 end
2244
2245 # A `+` expression
2246 class APlusExpr
2247 super ABinopExpr
2248 redef fun operator do return "+"
2249 end
2250
2251 # A `-` expression
2252 class AMinusExpr
2253 super ABinopExpr
2254 redef fun operator do return "-"
2255 end
2256
2257 # A `<=>` expression
2258 class AStarshipExpr
2259 super ABinopExpr
2260 redef fun operator do return "<=>"
2261 end
2262
2263 # A `*` expression
2264 class AStarExpr
2265 super ABinopExpr
2266 redef fun operator do return "*"
2267 end
2268
2269 # A `**` expression
2270 class AStarstarExpr
2271 super ABinopExpr
2272 redef fun operator do return "**"
2273 end
2274
2275 # A `/` expression
2276 class ASlashExpr
2277 super ABinopExpr
2278 redef fun operator do return "/"
2279 end
2280
2281 # A `%` expression
2282 class APercentExpr
2283 super ABinopExpr
2284 redef fun operator do return "%"
2285 end
2286
2287 # A `|` expression
2288 class APipeExpr
2289 super ABinopExpr
2290 redef fun operator do return "|"
2291 end
2292
2293 # A `^` expression
2294 class ACaretExpr
2295 super ABinopExpr
2296 redef fun operator do return "^"
2297 end
2298
2299 # A `&` expression
2300 class AAmpExpr
2301 super ABinopExpr
2302 redef fun operator do return "&"
2303 end
2304
2305 # A unary operation on a method
2306 abstract class AUnaryopExpr
2307 super ASendExpr
2308
2309 # The operator
2310 var n_op: Token is writable, noinit
2311
2312 # The name of the operator (eg '+')
2313 fun operator: String is abstract
2314 end
2315
2316 # A unary minus expression. eg `-x`
2317 class AUminusExpr
2318 super AUnaryopExpr
2319 redef fun operator do return "-"
2320 end
2321
2322 # A unary plus expression. eg `+x`
2323 class AUplusExpr
2324 super AUnaryopExpr
2325 redef fun operator do return "+"
2326 end
2327
2328 # A unary `~` expression
2329 class AUtildeExpr
2330 super AUnaryopExpr
2331 redef fun operator do return "~"
2332 end
2333
2334 # An explicit instantiation. eg `new T`
2335 class ANewExpr
2336 super AExpr
2337
2338 # The `new` keyword
2339 var n_kwnew: TKwnew is writable, noinit
2340
2341 # The `type` keyword
2342 var n_type: AType is writable, noinit
2343
2344 # The name of the named-constructor, if any
2345 var n_qid: nullable AQid = null is writable
2346
2347 # The arguments of the `new`
2348 var n_args: AExprs is writable, noinit
2349 end
2350
2351 # Whatever is a old-style attribute access
2352 abstract class AAttrFormExpr
2353 super AExpr
2354
2355 # The receiver of the attribute
2356 var n_expr: AExpr is writable, noinit
2357
2358 # The name of the attribute
2359 var n_id: TAttrid is writable, noinit
2360
2361 end
2362
2363 # The read of an attribute. eg `x._a`
2364 class AAttrExpr
2365 super AAttrFormExpr
2366 end
2367
2368 # The assignment of an attribute. eg `x._a=y`
2369 class AAttrAssignExpr
2370 super AAttrFormExpr
2371 super AAssignFormExpr
2372 end
2373
2374 # Whatever looks-like a call with a standard method and any number of arguments.
2375 abstract class ACallFormExpr
2376 super ASendExpr
2377
2378 # The name of the method
2379 var n_qid: AQid is writable, noinit
2380
2381 # The arguments of the call
2382 var n_args: AExprs is writable, noinit
2383 end
2384
2385 # A complex setter call (standard or brackets)
2386 abstract class ASendReassignFormExpr
2387 super ASendExpr
2388 super AReassignFormExpr
2389 end
2390
2391 # A complex attribute assignment. eg `x._a+=y`
2392 class AAttrReassignExpr
2393 super AAttrFormExpr
2394 super AReassignFormExpr
2395 end
2396
2397 # A call with a standard method-name and any number of arguments. eg `x.m(y)`. OR just a simple id
2398 # 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`.
2399 # Semantic analysis have to transform them to instance of `AVarExpr`.
2400 class ACallExpr
2401 super ACallFormExpr
2402 end
2403
2404 # A setter call with a standard method-name and any number of arguments. eg `x.m(y)=z`. OR just a simple assignment.
2405 # 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`.
2406 # Semantic analysis have to transform them to instance of `AVarAssignExpr`.
2407 class ACallAssignExpr
2408 super ACallFormExpr
2409 super AAssignFormExpr
2410 end
2411
2412 # 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.
2413 # 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`.
2414 # Semantic analysis have to transform them to instance of `AVarReassignExpr`.
2415 class ACallReassignExpr
2416 super ACallFormExpr
2417 super ASendReassignFormExpr
2418 end
2419
2420 # A call to `super`. OR a call of a super-constructor
2421 class ASuperExpr
2422 super AExpr
2423
2424 # The qualifier part before the super (currenlty unused)
2425 var n_qualified: nullable AQualified = null is writable
2426
2427 # The `super` keyword
2428 var n_kwsuper: TKwsuper is writable, noinit
2429
2430 # The arguments of the super
2431 var n_args: AExprs is writable, noinit
2432 end
2433
2434 # A call to the `init` constructor.
2435 # Note: because `init` is a keyword and not a `TId`, the explicit call to init cannot be a `ACallFormExpr`.
2436 class AInitExpr
2437 super ASendExpr
2438
2439 # The `init` keyword
2440 var n_kwinit: TKwinit is writable, noinit
2441
2442 # The arguments of the init
2443 var n_args: AExprs is writable, noinit
2444 end
2445
2446 # Whatever looks-like a call of the brackets `[]` operator.
2447 abstract class ABraFormExpr
2448 super ASendExpr
2449
2450 # The arguments inside the brackets
2451 var n_args: AExprs is writable, noinit
2452 end
2453
2454 # A call of the brackets operator. eg `x[y,z]`
2455 class ABraExpr
2456 super ABraFormExpr
2457 end
2458
2459 # A setter call of the bracket operator. eg `x[y,z]=t`
2460 class ABraAssignExpr
2461 super ABraFormExpr
2462 super AAssignFormExpr
2463 end
2464
2465 # Whatever is an access to a local variable
2466 abstract class AVarFormExpr
2467 super AExpr
2468
2469 # The name of the attribute
2470 var n_id: TId is writable, noinit
2471 end
2472
2473 # A complex setter call of the bracket operator. eg `x[y,z]+=t`
2474 class ABraReassignExpr
2475 super ABraFormExpr
2476 super ASendReassignFormExpr
2477 end
2478
2479 # A local variable read access.
2480 # The parser cannot instantiate them, see `ACallExpr`.
2481 class AVarExpr
2482 super AVarFormExpr
2483 end
2484
2485 # A local variable simple assignment access
2486 # The parser cannot instantiate them, see `ACallAssignExpr`.
2487 class AVarAssignExpr
2488 super AVarFormExpr
2489 super AAssignFormExpr
2490 end
2491
2492 # A local variable complex assignment access
2493 # The parser cannot instantiate them, see `ACallReassignExpr`.
2494 class AVarReassignExpr
2495 super AVarFormExpr
2496 super AReassignFormExpr
2497 end
2498
2499 # A literal range, open or closed
2500 abstract class ARangeExpr
2501 super AExpr
2502
2503 # The left (lower) element of the range
2504 var n_expr: AExpr is writable, noinit
2505
2506 # The `..`
2507 var n_dotdot: TDotdot is writable, noinit
2508
2509 # The right (upper) element of the range
2510 var n_expr2: AExpr is writable, noinit
2511 end
2512
2513 # A closed literal range. eg `[x..y]`
2514 class ACrangeExpr
2515 super ARangeExpr
2516
2517 # The opening bracket `[`
2518 var n_obra: TObra is writable, noinit
2519
2520 # The closing bracket `]`
2521 var n_cbra: TCbra is writable, noinit
2522 end
2523
2524 # An open literal range. eg `[x..y[`
2525 class AOrangeExpr
2526 super ARangeExpr
2527
2528 # The opening bracket `[`
2529 var n_obra: TObra is writable, noinit
2530
2531 # The closing bracket `[` (because open range)
2532 var n_cbra: TObra is writable, noinit
2533 end
2534
2535 # A literal array. eg. `[x,y,z]`
2536 class AArrayExpr
2537 super AExpr
2538
2539 # The opening bracket `[`
2540 var n_obra: TObra is writable, noinit
2541
2542 # The elements of the array
2543 var n_exprs = new ANodes[AExpr](self)
2544
2545 # The type of the element of the array (if any)
2546 var n_type: nullable AType = null is writable
2547
2548 # The closing bracket `]`
2549 var n_cbra: TCbra is writable, noinit
2550 end
2551
2552 # A read of `self`
2553 class ASelfExpr
2554 super AExpr
2555
2556 # The `self` keyword
2557 var n_kwself: nullable TKwself = null is writable
2558 end
2559
2560 # When there is no explicit receiver, `self` is implicit
2561 class AImplicitSelfExpr
2562 super ASelfExpr
2563 end
2564
2565 # A `true` boolean literal constant
2566 class ATrueExpr
2567 super ABoolExpr
2568
2569 # The `true` keyword
2570 var n_kwtrue: TKwtrue is writable, noinit
2571 end
2572
2573 # A `false` boolean literal constant
2574 class AFalseExpr
2575 super ABoolExpr
2576
2577 # The `false` keyword
2578 var n_kwfalse: TKwfalse is writable, noinit
2579 end
2580
2581 # A `null` literal constant
2582 class ANullExpr
2583 super AExpr
2584
2585 # The `null` keyword
2586 var n_kwnull: TKwnull is writable, noinit
2587 end
2588
2589 # An integer literal
2590 class AIntegerExpr
2591 super AExpr
2592
2593 # The integer token
2594 var n_integer: TInteger is writable, noinit
2595 end
2596
2597 # A float literal
2598 class AFloatExpr
2599 super AExpr
2600
2601 # The float token
2602 var n_float: TFloat is writable, noinit
2603 end
2604
2605 # A character literal
2606 class ACharExpr
2607 super AExpr
2608
2609 # The character token
2610 var n_char: TChar is writable, noinit
2611 end
2612
2613 # A string literal
2614 abstract class AStringFormExpr
2615 super AExpr
2616
2617 # The string token
2618 var n_string: Token is writable, noinit
2619 end
2620
2621 # A simple string. eg. `"abc"`
2622 class AStringExpr
2623 super AStringFormExpr
2624 end
2625
2626 # The start of a superstring. eg `"abc{`
2627 class AStartStringExpr
2628 super AStringFormExpr
2629 end
2630
2631 # The middle of a superstring. eg `}abc{`
2632 class AMidStringExpr
2633 super AStringFormExpr
2634 end
2635
2636 # The end of a superstrng. eg `}abc"`
2637 class AEndStringExpr
2638 super AStringFormExpr
2639 end
2640
2641 # A superstring literal. eg `"a{x}b{y}c"`
2642 # Each part is modeled a sequence of expression. eg. `["a{, x, }b{, y, }c"]`
2643 class ASuperstringExpr
2644 super AExpr
2645
2646 # The list of the expressions of the superstring
2647 var n_exprs = new ANodes[AExpr](self)
2648 end
2649
2650 # A simple parenthesis. eg `(x)`
2651 class AParExpr
2652 super AExpr
2653
2654 # The opening parenthesis
2655 var n_opar: TOpar is writable, noinit
2656
2657 # The inner expression
2658 var n_expr: AExpr is writable, noinit
2659
2660 # The closing parenthesis
2661 var n_cpar: TCpar is writable, noinit
2662 end
2663
2664 # A cast, against a type or `not null`
2665 class AAsCastForm
2666 super AExpr
2667
2668 # The expression to cast
2669 var n_expr: AExpr is writable, noinit
2670
2671 # The `as` keyword
2672 var n_kwas: TKwas is writable, noinit
2673
2674 # The opening parenthesis
2675 var n_opar: nullable TOpar = null is writable
2676
2677 # The closing parenthesis
2678 var n_cpar: nullable TCpar = null is writable
2679 end
2680
2681 # A type cast. eg `x.as(T)`
2682 class AAsCastExpr
2683 super AAsCastForm
2684
2685 # The target type to cast to
2686 var n_type: AType is writable, noinit
2687 end
2688
2689 # A as-not-null cast. eg `x.as(not null)`
2690 class AAsNotnullExpr
2691 super AAsCastForm
2692
2693 # The `not` keyword
2694 var n_kwnot: TKwnot is writable, noinit
2695
2696 # The `null` keyword
2697 var n_kwnull: TKwnull is writable, noinit
2698 end
2699
2700 # A is-set check of old-style attributes. eg `isset x._a`
2701 class AIssetAttrExpr
2702 super AAttrFormExpr
2703
2704 # The `isset` keyword
2705 var n_kwisset: TKwisset is writable, noinit
2706 end
2707
2708 # An ellipsis notation used to pass an expression as it, in a vararg parameter
2709 class AVarargExpr
2710 super AExpr
2711
2712 # The passed expression
2713 var n_expr: AExpr is writable, noinit
2714
2715 # The `...` symbol
2716 var n_dotdotdot: TDotdotdot is writable, noinit
2717 end
2718
2719 # An named notation used to pass an expression by name in a parameter
2720 class ANamedargExpr
2721 super AExpr
2722
2723 # The name of the argument
2724 var n_id: TId is writable, noinit
2725
2726 # The `=` synbol
2727 var n_assign: TAssign is writable, noinit
2728
2729 # The passed expression
2730 var n_expr: AExpr is writable, noinit
2731 end
2732
2733 # A list of expression separated with commas (arguments for instance)
2734 class AManyExpr
2735 super AExpr
2736
2737 # The list of expressions
2738 var n_exprs = new ANodes[AExpr](self)
2739 end
2740
2741 # A special expression that encapsulates a static type
2742 # Can only be found in special construction like arguments of annotations.
2743 class ATypeExpr
2744 super AExpr
2745
2746 # The encapsulated type
2747 var n_type: AType is writable, noinit
2748 end
2749
2750 # A special expression that encapsulates a method identifier
2751 # Can only be found in special construction like arguments of annotations.
2752 class AMethidExpr
2753 super AExpr
2754
2755 # The receiver
2756 var n_expr: AExpr is writable, noinit
2757
2758 # The encapsulated method identifier
2759 var n_id: AMethid is writable, noinit
2760 end
2761
2762 # A special expression that encapsulate an annotation
2763 # Can only be found in special construction like arguments of annotations.
2764 #
2765 # The encapsulated annotations are in `n_annotations`
2766 class AAtExpr
2767 super AExpr
2768 end
2769
2770 # A special expression to debug types
2771 class ADebugTypeExpr
2772 super AExpr
2773
2774 # The `debug` keyword
2775 var n_kwdebug: TKwdebug is writable, noinit
2776
2777 # The `type` keyword
2778 var n_kwtype: TKwtype is writable, noinit
2779
2780 # The expression to check
2781 var n_expr: AExpr is writable, noinit
2782
2783 # The type to check
2784 var n_type: AType is writable, noinit
2785 end
2786
2787 # A list of expression separated with commas (arguments for instance)
2788 abstract class AExprs
2789 super Prod
2790
2791 # The list of expressions
2792 var n_exprs = new ANodes[AExpr](self)
2793 end
2794
2795 # A simple list of expressions
2796 class AListExprs
2797 super AExprs
2798 end
2799
2800 # A list of expressions enclosed in parentheses
2801 class AParExprs
2802 super AExprs
2803
2804 # The opening parenthesis
2805 var n_opar: TOpar is writable, noinit
2806
2807 # The closing parenthesis
2808 var n_cpar: TCpar is writable, noinit
2809 end
2810
2811 # A list of expressions enclosed in brackets
2812 class ABraExprs
2813 super AExprs
2814
2815 # The opening bracket
2816 var n_obra: TObra is writable, noinit
2817
2818 # The closing bracket
2819 var n_cbra: TCbra is writable, noinit
2820 end
2821
2822 # A complex assignment operator. (`+=` and `-=`)
2823 abstract class AAssignOp
2824 super Prod
2825
2826 # The combined assignment operator
2827 var n_op: Token is writable, noinit
2828
2829 # The name of the operator without the `=` (eg '+')
2830 fun operator: String is abstract
2831 end
2832
2833 # A `+=` assignment operation
2834 class APlusAssignOp
2835 super AAssignOp
2836
2837 redef fun operator do return "+"
2838 end
2839
2840 # A `-=` assignment operation
2841 class AMinusAssignOp
2842 super AAssignOp
2843
2844 redef fun operator do return "-"
2845 end
2846
2847 # A `*=` assignment operation
2848 class AStarAssignOp
2849 super AAssignOp
2850
2851 redef fun operator do return "*"
2852 end
2853
2854 # A `/=` assignment operation
2855 class ASlashAssignOp
2856 super AAssignOp
2857
2858 redef fun operator do return "/"
2859 end
2860
2861 # A `%=` assignment operation
2862 class APercentAssignOp
2863 super AAssignOp
2864
2865 redef fun operator do return "%"
2866 end
2867
2868 # A `**=` assignment operation
2869 class AStarstarAssignOp
2870 super AAssignOp
2871
2872 redef fun operator do return "**"
2873 end
2874
2875 # A `|=` assignment operation
2876 class APipeAssignOp
2877 super AAssignOp
2878
2879 redef fun operator do return "|"
2880 end
2881
2882 # A `^=` assignment operation
2883 class ACaretAssignOp
2884 super AAssignOp
2885
2886 redef fun operator do return "^"
2887 end
2888
2889 # A `&=` assignment operation
2890 class AAmpAssignOp
2891 super AAssignOp
2892
2893 redef fun operator do return "&"
2894 end
2895
2896 # A `<<=` assignment operation
2897 class ALlAssignOp
2898 super AAssignOp
2899
2900 redef fun operator do return "<<"
2901 end
2902
2903 # A `>>=` assignment operation
2904 class AGgAssignOp
2905 super AAssignOp
2906
2907 redef fun operator do return ">>"
2908 end
2909
2910 # A possibly fully-qualified module identifier
2911 class AModuleName
2912 super Prod
2913
2914 # The starting quad (`::`)
2915 var n_quad: nullable TQuad = null is writable
2916
2917 # The list of quad-separated package/group identifiers
2918 var n_path = new ANodes[TId](self)
2919
2920 # The final module identifier
2921 var n_id: TId is writable, noinit
2922 end
2923
2924 # A language declaration for an extern block
2925 class AInLanguage
2926 super Prod
2927
2928 # The `in` keyword
2929 var n_kwin: TKwin is writable, noinit
2930
2931 # The language name
2932 var n_string: TString is writable, noinit
2933 end
2934
2935 # An full extern block
2936 class AExternCodeBlock
2937 super Prod
2938
2939 # The language declration
2940 var n_in_language: nullable AInLanguage = null is writable
2941
2942 # The block of extern code
2943 var n_extern_code_segment: TExternCodeSegment is writable, noinit
2944 end
2945
2946 # A possible full method qualifier.
2947 class AQualified
2948 super Prod
2949
2950 # The starting quad (`::`)
2951 var n_quad: nullable TQuad = null is writable
2952
2953 # The list of quad-separated package/group/module identifiers
2954 var n_id = new ANodes[TId](self)
2955
2956 # A class identifier
2957 var n_classid: nullable TClassid = null is writable
2958 end
2959
2960 # A documentation of a definition
2961 # It contains the block of comments just above the declaration
2962 class ADoc
2963 super Prod
2964
2965 # A list of lines of comment
2966 var n_comment = new ANodes[TComment](self)
2967 end
2968
2969 # A group of annotation on a node
2970 #
2971 # This same class is used for the 3 kind of annotations:
2972 #
2973 # * *is* annotations. eg `module foo is bar`.
2974 # * *at* annotations. eg `foo@bar` or `foo@(bar,baz)`.
2975 # * *class* annotations, defined in classes.
2976 class AAnnotations
2977 super Prod
2978
2979 # The `is` keyword, for *is* annotations
2980 var n_kwis: nullable TKwis = null is writable
2981
2982 # The `@` symbol, for *at* annotations
2983 var n_at: nullable TAt = null is writable
2984
2985 # The opening parenthesis in *at* annotations
2986 var n_opar: nullable TOpar = null is writable
2987
2988 # The list of annotations
2989 var n_items = new ANodes[AAnnotation](self)
2990
2991 # The closing parenthesis in *at* annotations
2992 var n_cpar: nullable TCpar = null is writable
2993
2994 # The `end` keyword, for *is* annotations
2995 var n_kwend: nullable TKwend = null is writable
2996 end
2997
2998 # A single annotation
2999 class AAnnotation
3000 super ADefinition
3001
3002 # The name of the annotation
3003 var n_atid: AAtid is writable, noinit
3004
3005 # The opening parenthesis of the arguments
3006 var n_opar: nullable TOpar = null is writable
3007
3008 # The list of arguments
3009 var n_args = new ANodes[AExpr](self)
3010
3011 # The closing parenthesis
3012 var n_cpar: nullable TCpar = null is writable
3013
3014 # The name of the annotation
3015 fun name: String
3016 do
3017 return n_atid.n_id.text
3018 end
3019 end
3020
3021 # An annotation name
3022 abstract class AAtid
3023 super Prod
3024
3025 # The identifier of the annotation.
3026 # Can be a TId of a keyword
3027 var n_id: Token is writable, noinit
3028 end
3029
3030 # An annotation name based on an identifier
3031 class AIdAtid
3032 super AAtid
3033 end
3034
3035 # An annotation name based on the keyword `extern`
3036 class AKwexternAtid
3037 super AAtid
3038 end
3039
3040 # An annotation name based on the keyword `import`
3041 class AKwimportAtid
3042 super AAtid
3043 end
3044
3045 # An annotation name based on the keyword `abstract`
3046 class AKwabstractAtid
3047 super AAtid
3048 end
3049
3050 # The root of the AST
3051 class Start
3052 super Prod
3053
3054 # The main module
3055 var n_base: nullable AModule is writable
3056
3057 # The end of file (or error) token
3058 var n_eof: EOF is writable
3059 end