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