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