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