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