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