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