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