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