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