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