Merge: Locally disable warnings
[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
21 # Root of the AST class-hierarchy
22 abstract class ANode
23 # Location is set during AST building. Once built, location cannon be null.
24 # However, manual instantiated nodes may need more care.
25 var location: Location is writable, noinit
26
27 # The location of the important part of the node (identifier or whatever)
28 fun hot_location: Location do return location
29
30 # Display a message for the colored location of the node
31 fun debug(message: String)
32 do
33 sys.stderr.write "{hot_location} {self.class_name}: {message}\n{hot_location.colored_line("0;32")}\n"
34 end
35
36 # Parent of the node in the AST
37 var parent: nullable ANode = null
38
39 # The topmost ancestor of the element
40 # This just apply `parent` until the first one
41 fun root: ANode
42 do
43 var res = self
44 loop
45 var p = res.parent
46 if p == null then return res
47 res = p
48 end
49 end
50
51 # The most specific common parent between `self` and `other`
52 # Return null if the two node are unrelated (distinct root)
53 fun common_parent(other: ANode): nullable ANode
54 do
55 # First, get the same depth
56 var s: nullable ANode = self
57 var o: nullable ANode = other
58 var d = s.depth - o.depth
59 while d > 0 do
60 s = s.parent
61 d -= 1
62 end
63 while d < 0 do
64 o = o.parent
65 d += 1
66 end
67 assert o.depth == s.depth
68 # Second, go up until same in found
69 while s != o do
70 s = s.parent
71 o = o.parent
72 end
73 return s
74 end
75
76 # Number of nodes between `self` and the `root` of the AST
77 # ENSURE `self == self.root implies result == 0 `
78 # ENSURE `self != self.root implies result == self.parent.depth + 1`
79 fun depth: Int
80 do
81 var n = self
82 var res = 0
83 loop
84 var p = n.parent
85 if p == null then return res
86 n = p
87 res += 1
88 end
89 end
90
91 # Replace a child with an other node in the AST
92 private fun replace_child(old_child: ANode, new_child: nullable ANode) is abstract
93
94 # Detach a node from its parent
95 # Aborts if the node is not detachable. use `replace_with` instead
96 # REQUIRE: parent != null
97 # REQUIRE: is_detachable
98 # ENDURE: parent == null
99 fun detach
100 do
101 assert parent != null
102 parent.replace_child(self, null)
103 parent = null
104 end
105
106 # Replace itself with an other node in the AST
107 # REQUIRE: parent != null
108 # ENSURE: node.parent == old(parent)
109 # ENSURE: parent == null
110 fun replace_with(node: ANode)
111 do
112 assert parent != null
113 parent.replace_child(self, node)
114 parent = null
115 end
116
117 # Visit all nodes in order.
118 # Thus, call `v.enter_visit(e)` for each child `e`
119 fun visit_all(v: Visitor) is abstract
120
121 # Do a deep search and return an array of tokens that match a given text
122 fun collect_tokens_by_text(text: String): Array[Token]
123 do
124 var v = new CollectTokensByTextVisitor(text)
125 v.enter_visit(self)
126 return v.result
127 end
128
129 # Do a deep search and return an array of node that are annotated
130 # The attached node can be retrieved by two invocations of parent
131 fun collect_annotations_by_name(name: String): Array[AAnnotation]
132 do
133 var v = new CollectAnnotationsByNameVisitor(name)
134 v.enter_visit(self)
135 return v.result
136 end
137 end
138
139 private class CollectTokensByTextVisitor
140 super Visitor
141 var text: String
142 var result = new Array[Token]
143 redef fun visit(node)
144 do
145 node.visit_all(self)
146 if node isa Token and node.text == text then result.add(node)
147 end
148 end
149
150 private class CollectAnnotationsByNameVisitor
151 super Visitor
152 var name: String
153 var result = new Array[AAnnotation]
154 redef fun visit(node)
155 do
156 node.visit_all(self)
157 if node isa AAnnotation and node.n_atid.n_id.text == name then result.add(node)
158 end
159 end
160
161
162 # A sequence of nodes
163 # It is a specific class (instead of using a Array) to track the parent/child relation when nodes are added or removed
164 class ANodes[E: ANode]
165 super Sequence[E]
166 private var parent: ANode
167 private var items = new Array[E]
168 redef fun iterator do return items.iterator
169 redef fun length do return items.length
170 redef fun is_empty do return items.is_empty
171 redef fun push(e)
172 do
173 hook_add(e)
174 items.push(e)
175 end
176 redef fun pop
177 do
178 var res = items.pop
179 hook_remove(res)
180 return res
181 end
182 redef fun unshift(e)
183 do
184 hook_add(e)
185 items.unshift(e)
186 end
187 redef fun shift
188 do
189 var res = items.shift
190 hook_remove(res)
191 return res
192 end
193 redef fun has(e)
194 do
195 return items.has(e)
196 end
197 redef fun [](index)
198 do
199 return items[index]
200 end
201 redef fun []=(index, e)
202 do
203 hook_remove(self[index])
204 hook_add(e)
205 items[index]=e
206 end
207 redef fun remove_at(index)
208 do
209 hook_remove(items[index])
210 items.remove_at(index)
211 end
212 private fun hook_add(e: E)
213 do
214 #assert e.parent == null
215 e.parent = parent
216 end
217 private fun hook_remove(e: E)
218 do
219 assert e.parent == parent
220 e.parent = null
221 end
222
223 # Used in parent constructor to fill elements
224 private fun unsafe_add_all(nodes: Collection[Object])
225 do
226 var parent = self.parent
227 for n in nodes do
228 assert n isa E
229 add n
230 n.parent = parent
231 end
232 end
233
234 private fun replace_child(old_child: ANode, new_child: nullable ANode): Bool
235 do
236 var parent = self.parent
237 for i in [0..length[ do
238 if self[i] == old_child then
239 if new_child != null then
240 assert new_child isa E
241 self[i] = new_child
242 new_child.parent = parent
243 else
244 self.remove_at(i)
245 end
246 return true
247 end
248 end
249 return false
250 end
251
252 private fun visit_all(v: Visitor)
253 do
254 for n in self do v.enter_visit(n)
255 end
256 end
257
258 # Ancestor of all tokens
259 # A token is a node that has a `text` but no children.
260 abstract class Token
261 super ANode
262
263 # The raw content on the token
264 fun text: String is abstract
265
266 # The raw content on the token
267 fun text=(text: String) is abstract
268
269 # The previous token in the Lexer.
270 # May have disappeared in the AST
271 var prev_token: nullable Token = null
272
273 # The next token in the Lexer.
274 # May have disappeared in the AST
275 var next_token: nullable Token = null
276
277 # The verbatim blank text between `prev_token` and `self`
278 fun blank_before: String
279 do
280 if prev_token == null then return ""
281 var from = prev_token.location.pend+1
282 var to = location.pstart
283 return location.file.string.substring(from,to-from)
284 end
285
286 redef fun to_s: String do
287 return "'{text}'"
288 end
289
290 redef fun visit_all(v: Visitor) do end
291 redef fun replace_child(old_child: ANode, new_child: nullable ANode) do end
292 end
293
294 redef class SourceFile
295 # The first token parser by the lexer
296 # May have disappeared in the final AST
297 var first_token: nullable Token = null
298
299 # The first token parser by the lexer
300 # May have disappeared in the final AST
301 var last_token: nullable Token = null
302 end
303
304 # Ancestor of all productions
305 # A production is a node without text but that usually has children.
306 abstract class Prod
307 super ANode
308
309 # All the annotations attached directly to the node
310 var n_annotations: nullable AAnnotations = null is writable
311
312 # Return all its annotations of a given name in the order of their declaration
313 # Retun an empty array if no such an annotation.
314 fun get_annotations(name: String): Array[AAnnotation]
315 do
316 var res = new Array[AAnnotation]
317 var nas = n_annotations
318 if nas == null then return res
319 for na in nas.n_items do
320 if na.name != name then continue
321 res.add(na)
322 end
323 return res
324 end
325
326 redef fun replace_with(n: ANode)
327 do
328 super
329 assert n isa Prod
330 if not isset n._location and isset _location then n._location = _location
331 end
332 end
333
334 # Abstract standard visitor on the AST
335 abstract class Visitor
336 # What the visitor do when a node is visited
337 # Concrete visitors should implement this method.
338 # @toimplement
339 protected fun visit(e: ANode) is abstract
340
341 # Ask the visitor to visit a given node.
342 # Usually automatically called by visit_all* methods.
343 # This method should not be redefined
344 fun enter_visit(e: nullable ANode)
345 do
346 if e == null then return
347 var old = _current_node
348 _current_node = e
349 visit(e)
350 _current_node = old
351 end
352
353 # The current visited node
354 var current_node: nullable ANode = null is writable
355 end
356
357 # Token of end of line (basically `\n`)
358 class TEol
359 super Token
360 redef fun to_s
361 do
362 return "end of line"
363 end
364 end
365
366 # Token of a line of comments
367 # Starts with the `#` and contains the final end-of-line (if any)
368 class TComment
369 super Token
370 end
371
372 # A token associated with a keyword
373 abstract class TokenKeyword
374 super Token
375 redef fun to_s
376 do
377 return "keyword '{text}'"
378 end
379 end
380
381 # The deprecated keyword `package`.
382 class TKwpackage
383 super TokenKeyword
384 end
385
386 # The keyword `module`
387 class TKwmodule
388 super TokenKeyword
389 end
390
391 # The keyword `import`
392 class TKwimport
393 super TokenKeyword
394 end
395
396 # The keyword `class`
397 class TKwclass
398 super TokenKeyword
399 end
400
401 # The keyword `abstract`
402 class TKwabstract
403 super TokenKeyword
404 end
405
406 # The keyword `interface`
407 class TKwinterface
408 super TokenKeyword
409 end
410
411 # The keywords `enum` ane `universal`
412 class TKwenum
413 super TokenKeyword
414 end
415
416 # The keyword `end`
417 class TKwend
418 super TokenKeyword
419 end
420
421 # The keyword `fun`
422 class TKwmeth
423 super TokenKeyword
424 end
425
426 # The keyword `type`
427 class TKwtype
428 super TokenKeyword
429 end
430
431 # The keyword `init`
432 class TKwinit
433 super TokenKeyword
434 end
435
436 # The keyword `redef`
437 class TKwredef
438 super TokenKeyword
439 end
440
441 # The keyword `is`
442 class TKwis
443 super TokenKeyword
444 end
445
446 # The keyword `do`
447 class TKwdo
448 super TokenKeyword
449 end
450
451 # The keyword `var`
452 class TKwvar
453 super TokenKeyword
454 end
455
456 # The keyword `extern`
457 class TKwextern
458 super TokenKeyword
459 end
460
461 # The keyword `public`
462 class TKwpublic
463 super TokenKeyword
464 end
465
466 # The keyword `protected`
467 class TKwprotected
468 super TokenKeyword
469 end
470
471 # The keyword `private`
472 class TKwprivate
473 super TokenKeyword
474 end
475
476 # The keyword `intrude`
477 class TKwintrude
478 super TokenKeyword
479 end
480
481 # The keyword `if`
482 class TKwif
483 super TokenKeyword
484 end
485
486 # The keyword `then`
487 class TKwthen
488 super TokenKeyword
489 end
490
491 # The keyword `else`
492 class TKwelse
493 super TokenKeyword
494 end
495
496 # The keyword `while`
497 class TKwwhile
498 super TokenKeyword
499 end
500
501 # The keyword `loop`
502 class TKwloop
503 super TokenKeyword
504 end
505
506 # The keyword `for`
507 class TKwfor
508 super TokenKeyword
509 end
510
511 # The keyword `in`
512 class TKwin
513 super TokenKeyword
514 end
515
516 # The keyword `and`
517 class TKwand
518 super TokenKeyword
519 end
520
521 # The keyword `or`
522 class TKwor
523 super TokenKeyword
524 end
525
526 # The keyword `implies`
527 class TKwimplies
528 super TokenKeyword
529 end
530
531 # The keyword `not`
532 class TKwnot
533 super TokenKeyword
534 end
535
536 # The keyword `return`
537 class TKwreturn
538 super TokenKeyword
539 end
540
541 # The keyword `continue`
542 class TKwcontinue
543 super TokenKeyword
544 end
545
546 # The keyword `break`
547 class TKwbreak
548 super TokenKeyword
549 end
550
551 # The keyword `abort`
552 class TKwabort
553 super TokenKeyword
554 end
555
556 # The keyword `assert`
557 class TKwassert
558 super TokenKeyword
559 end
560
561 # The keyword `new`
562 class TKwnew
563 super TokenKeyword
564 end
565
566 # The keyword `isa`
567 class TKwisa
568 super TokenKeyword
569 end
570
571 # The keyword `once`
572 class TKwonce
573 super TokenKeyword
574 end
575
576 # The keyword `super`
577 class TKwsuper
578 super TokenKeyword
579 end
580
581 # The keyword `self`
582 class TKwself
583 super TokenKeyword
584 end
585
586 # The keyword `true`
587 class TKwtrue
588 super TokenKeyword
589 end
590
591 # The keyword `false`
592 class TKwfalse
593 super TokenKeyword
594 end
595
596 # The keyword `null`
597 class TKwnull
598 super TokenKeyword
599 end
600
601 # The keyword `as`
602 class TKwas
603 super TokenKeyword
604 end
605
606 # The keyword `nullable`
607 class TKwnullable
608 super TokenKeyword
609 end
610
611 # The keyword `isset`
612 class TKwisset
613 super TokenKeyword
614 end
615
616 # The keyword `label`
617 class TKwlabel
618 super TokenKeyword
619 end
620
621 # The special keyword `__DEBUG__`
622 class TKwdebug
623 super Token
624 end
625
626 # The symbol `(`
627 class TOpar
628 super Token
629 end
630
631 # The symbol `)`
632 class TCpar
633 super Token
634 end
635
636 # The symbol `[`
637 class TObra
638 super Token
639 end
640
641 # The symbol `]`
642 class TCbra
643 super Token
644 end
645
646 # The symbol `,`
647 class TComma
648 super Token
649 end
650
651 # The symbol `:`
652 class TColumn
653 super Token
654 end
655
656 # The symbol `::`
657 class TQuad
658 super Token
659 end
660
661 # The symbol `=`
662 class TAssign
663 super Token
664 end
665
666 # A token associated with an operator (and other lookalike symbols)
667 abstract class TokenOperator
668 super Token
669 redef fun to_s
670 do
671 return "operator '{text}'"
672 end
673 end
674
675 # The operator `+=`
676 class TPluseq
677 super TokenOperator
678 end
679
680 # The operator `-=`
681 class TMinuseq
682 super TokenOperator
683 end
684
685 # The symbol `...`
686 class TDotdotdot
687 super Token
688 end
689
690 # The symbol `..`
691 class TDotdot
692 super Token
693 end
694
695 # The symbol `.`
696 class TDot
697 super Token
698 end
699
700 # The operator `+`
701 class TPlus
702 super TokenOperator
703 end
704
705 # The operator `-`
706 class TMinus
707 super TokenOperator
708 end
709
710 # The operator `*`
711 class TStar
712 super TokenOperator
713 end
714
715 # The operator `**`
716 class TStarstar
717 super TokenOperator
718 end
719
720 # The operator `/`
721 class TSlash
722 super TokenOperator
723 end
724
725 # The operator `+%
726 class TPercent
727 super TokenOperator
728 end
729
730 # The operator `==`
731 class TEq
732 super TokenOperator
733 end
734
735 # The operator `!=`
736 class TNe
737 super TokenOperator
738 end
739
740 # The operator `<`
741 class TLt
742 super TokenOperator
743 end
744
745 # The operator `<=`
746 class TLe
747 super TokenOperator
748 end
749
750 # The operator `<<`
751 class TLl
752 super TokenOperator
753 end
754
755 # The operator `>`
756 class TGt
757 super TokenOperator
758 end
759
760 # The operator `>=`
761 class TGe
762 super TokenOperator
763 end
764
765 # The operator `>>`
766 class TGg
767 super TokenOperator
768 end
769
770 # The operator `<=>`
771 class TStarship
772 super TokenOperator
773 end
774
775 # The operator `!`
776 class TBang
777 super TokenOperator
778 end
779
780 # The symbol `@`
781 class TAt
782 super Token
783 end
784
785 # A class (or formal type) identifier. They start with an uppercase.
786 class TClassid
787 super Token
788 redef fun to_s
789 do
790 do return "type identifier '{text}'"
791 end
792 end
793
794 # A standard identifier (variable, method...). They start with a lowercase.
795 class TId
796 super Token
797 redef fun to_s
798 do
799 do return "identifier '{text}'"
800 end
801 end
802
803 # An attribute identifier. They start with an underscore.
804 class TAttrid
805 super Token
806 redef fun to_s
807 do
808 do return "attribute '{text}'"
809 end
810 end
811
812 # A token of a literal value (string, integer, etc).
813 abstract class TokenLiteral
814 super Token
815 redef fun to_s
816 do
817 do return "literal value '{text}'"
818 end
819 end
820
821 # A literal decimal integer
822 class TNumber
823 super TokenLiteral
824 end
825
826 # A literal hexadecimal integer
827 class THexNumber
828 super TokenLiteral
829 end
830
831 # A literal floating point number
832 class TFloat
833 super TokenLiteral
834 end
835
836 # A literal character
837 class TChar
838 super TokenLiteral
839 end
840
841 # A literal string
842 class TString
843 super TokenLiteral
844 end
845
846 # The starting part of a super string (between `"` and `{`)
847 class TStartString
848 super TokenLiteral
849 end
850
851 # The middle part of a super string (between `}` and `{`)
852 class TMidString
853 super TokenLiteral
854 end
855
856 # The final part of a super string (between `}` and `"`)
857 class TEndString
858 super TokenLiteral
859 end
860
861 # A malformed string
862 class TBadString
863 super Token
864 redef fun to_s
865 do
866 do return "malformed string {text}"
867 end
868 end
869
870 # A malformed char
871 class TBadChar
872 super Token
873 redef fun to_s
874 do
875 do return "malformed character {text}"
876 end
877 end
878
879 # A extern code block
880 class TExternCodeSegment
881 super Token
882 end
883
884 # A end of file
885 class EOF
886 super Token
887 redef fun to_s
888 do
889 return "end of file"
890 end
891 end
892
893 # A mark of an error
894 class AError
895 super EOF
896 end
897 # A lexical error (unexpected character)
898 class ALexerError
899 super AError
900 end
901 # A syntactic error (unexpected token)
902 class AParserError
903 super AError
904 end
905
906 # The main node of a Nit source-file
907 class AModule
908 super Prod
909
910 var n_moduledecl: nullable AModuledecl = null is writable
911 var n_imports = new ANodes[AImport](self)
912 var n_extern_code_blocks = new ANodes[AExternCodeBlock](self)
913 var n_classdefs = new ANodes[AClassdef](self)
914 end
915
916 # The declaration of the module with the documentation, name, and annotations
917 class AModuledecl
918 super Prod
919 var n_doc: nullable ADoc = null is writable
920 var n_kwredef: nullable TKwredef = null is writable
921 var n_visibility: AVisibility is writable, noinit
922 var n_kwmodule: TKwmodule is writable, noinit
923 var n_name: AModuleName is writable, noinit
924 end
925
926 # A import clause of a module
927 abstract class AImport
928 super Prod
929 end
930
931 # A standard import clause. eg `import x`
932 class AStdImport
933 super AImport
934 var n_visibility: AVisibility is writable, noinit
935 var n_kwimport: TKwimport is writable, noinit
936 var n_name: AModuleName is writable, noinit
937 end
938
939 # The special import clause of the kernel module. eg `import end`
940 class ANoImport
941 super AImport
942 var n_visibility: AVisibility is writable, noinit
943 var n_kwimport: TKwimport is writable, noinit
944 var n_kwend: TKwend is writable, noinit
945 end
946
947 # A visibility modifier
948 #
949 # The public visibility is an empty production (no keyword).
950 #
951 # Note: even if some visibilities are only valid on some placse (for instance, no `protected` class or no `intrude` method)
952 # the parser has no such a restriction, therefore the semantic phases has to check that the visibilities make sense.
953 abstract class AVisibility
954 super Prod
955 end
956
957 # An implicit or explicit public visibility modifier
958 class APublicVisibility
959 super AVisibility
960 var n_kwpublic: nullable TKwpublic is writable
961 end
962 # An explicit private visibility modifier
963 class APrivateVisibility
964 super AVisibility
965 var n_kwprivate: TKwprivate is writable, noinit
966 end
967 # An explicit protected visibility modifier
968 class AProtectedVisibility
969 super AVisibility
970 var n_kwprotected: TKwprotected is writable, noinit
971 end
972 # An explicit intrude visibility modifier
973 class AIntrudeVisibility
974 super AVisibility
975 var n_kwintrude: TKwintrude is writable, noinit
976 end
977
978 # A class definition
979 # While most definition are `AStdClassdef`
980 # There is tow special case of class definition
981 abstract class AClassdef
982 super Prod
983 var n_propdefs = new ANodes[APropdef](self)
984 end
985
986 # A standard class definition with a name, superclasses and properties
987 class AStdClassdef
988 super AClassdef
989 var n_doc: nullable ADoc = null is writable
990 var n_kwredef: nullable TKwredef = null is writable
991 var n_visibility: AVisibility is writable, noinit
992 var n_classkind: AClasskind is writable, noinit
993 var n_id: nullable TClassid = null is writable
994 var n_formaldefs = new ANodes[AFormaldef](self)
995 var n_extern_code_block: nullable AExternCodeBlock = null is writable
996 var n_superclasses = new ANodes[ASuperclass](self)
997 var n_kwend: TKwend is writable, noinit
998 redef fun hot_location do return n_id.location
999 end
1000
1001 # The implicit class definition of the implicit main method
1002 class ATopClassdef
1003 super AClassdef
1004 end
1005
1006 # The implicit class definition of the top-level methods
1007 class AMainClassdef
1008 super AClassdef
1009 end
1010
1011 # The modifier for the kind of class (abstract, interface, etc.)
1012 abstract class AClasskind
1013 super Prod
1014 end
1015
1016 # A default, or concrete class modifier (just `class`)
1017 class AConcreteClasskind
1018 super AClasskind
1019 var n_kwclass: TKwclass is writable, noinit
1020 end
1021
1022 # An abstract class modifier (`abstract class`)
1023 class AAbstractClasskind
1024 super AClasskind
1025 var n_kwabstract: TKwabstract is writable, noinit
1026 var n_kwclass: TKwclass is writable, noinit
1027 end
1028
1029 # An interface class modifier (`interface`)
1030 class AInterfaceClasskind
1031 super AClasskind
1032 var n_kwinterface: TKwinterface is writable, noinit
1033 end
1034
1035 # An enum/universal class modifier (`enum class`)
1036 class AEnumClasskind
1037 super AClasskind
1038 var n_kwenum: TKwenum is writable, noinit
1039 end
1040
1041 # An extern class modifier (`extern class`)
1042 class AExternClasskind
1043 super AClasskind
1044 var n_kwextern: TKwextern is writable, noinit
1045 var n_kwclass: nullable TKwclass = null is writable
1046 end
1047
1048 # The definition of a formal generic parameter type. eg `X: Y`
1049 class AFormaldef
1050 super Prod
1051 var n_id: TClassid is writable, noinit
1052 # The bound of the parameter type
1053 var n_type: nullable AType = null is writable
1054 end
1055
1056 # A super-class. eg `super X`
1057 class ASuperclass
1058 super Prod
1059 var n_kwsuper: TKwsuper is writable, noinit
1060 var n_type: AType is writable, noinit
1061 end
1062
1063 # The definition of a property
1064 abstract class APropdef
1065 super Prod
1066 var n_doc: nullable ADoc = null is writable
1067 var n_kwredef: nullable TKwredef = null is writable
1068 var n_visibility: nullable AVisibility = null is writable
1069 end
1070
1071 # A definition of an attribute
1072 # For historical reason, old-syle and new-style attributes use the same `ANode` sub-class
1073 class AAttrPropdef
1074 super APropdef
1075 var n_kwvar: TKwvar is writable, noinit
1076
1077 # The identifier for a new-style attribute (null if old-style)
1078 var n_id2: TId is writable, noinit
1079
1080 var n_type: nullable AType = null is writable
1081
1082 # The initial value, if any
1083 var n_expr: nullable AExpr = null is writable
1084
1085 var n_block: nullable AExpr = null is writable
1086
1087 redef fun hot_location
1088 do
1089 return n_id2.location
1090 end
1091 end
1092
1093 # A definition of all kind of method (including constructors)
1094 class AMethPropdef
1095 super APropdef
1096 var n_kwmeth: nullable TKwmeth = null is writable
1097 var n_kwinit: nullable TKwinit = null is writable
1098 var n_kwnew: nullable TKwnew = null is writable
1099 var n_methid: nullable AMethid = null is writable
1100 var n_signature: nullable ASignature = null is writable
1101 var n_block: nullable AExpr = null is writable
1102 var n_extern_calls: nullable AExternCalls = null is writable
1103 var n_extern_code_block: nullable AExternCodeBlock = null is writable
1104 redef fun hot_location
1105 do
1106 if n_methid != null then
1107 return n_methid.location
1108 else if n_kwinit != null then
1109 return n_kwinit.location
1110 else if n_kwnew != null then
1111 return n_kwnew.location
1112 else
1113 return location
1114 end
1115 end
1116 end
1117
1118 # The implicit main method
1119 class AMainMethPropdef
1120 super AMethPropdef
1121 end
1122
1123 # Declaration of callbacks for extern methods
1124 class AExternCalls
1125 super Prod
1126 var n_kwimport: TKwimport is writable, noinit
1127 var n_extern_calls: ANodes[AExternCall] = new ANodes[AExternCall](self)
1128 end
1129
1130 # A single callback declaration
1131 abstract class AExternCall
1132 super Prod
1133 end
1134
1135 # A single callback declaration on a method
1136 abstract class APropExternCall
1137 super AExternCall
1138 end
1139
1140 # A single callback declaration on a method on the current receiver
1141 class ALocalPropExternCall
1142 super APropExternCall
1143 var n_methid: AMethid is writable, noinit
1144 end
1145
1146 # A single callback declaration on a method on an explicit receiver type.
1147 class AFullPropExternCall
1148 super APropExternCall
1149 var n_type: AType is writable, noinit
1150 var n_dot: nullable TDot = null is writable
1151 var n_methid: AMethid is writable, noinit
1152 end
1153
1154 # A single callback declaration on a method on a constructor
1155 class AInitPropExternCall
1156 super APropExternCall
1157 var n_type: AType is writable, noinit
1158 end
1159
1160 # A single callback declaration on a `super` call
1161 class ASuperExternCall
1162 super AExternCall
1163 var n_kwsuper: TKwsuper is writable, noinit
1164 end
1165
1166 # A single callback declaration on a cast
1167 abstract class ACastExternCall
1168 super AExternCall
1169 end
1170
1171 # A single callback declaration on a cast to a given type
1172 class ACastAsExternCall
1173 super ACastExternCall
1174 var n_from_type: AType is writable, noinit
1175 var n_dot: nullable TDot = null is writable
1176 var n_kwas: TKwas is writable, noinit
1177 var n_to_type: AType is writable, noinit
1178 end
1179
1180 # A single callback declaration on a cast to a nullable type
1181 class AAsNullableExternCall
1182 super ACastExternCall
1183 var n_type: AType is writable, noinit
1184 var n_kwas: TKwas is writable, noinit
1185 var n_kwnullable: TKwnullable is writable, noinit
1186 end
1187
1188 # A single callback declaration on a cast to a non-nullable type
1189 class AAsNotNullableExternCall
1190 super ACastExternCall
1191 var n_type: AType is writable, noinit
1192 var n_kwas: TKwas is writable, noinit
1193 var n_kwnot: TKwnot is writable, noinit
1194 var n_kwnullable: TKwnullable is writable, noinit
1195 end
1196
1197 # A definition of a virtual type
1198 class ATypePropdef
1199 super APropdef
1200 var n_kwtype: TKwtype is writable, noinit
1201 var n_id: TClassid is writable, noinit
1202 var n_type: AType is writable, noinit
1203 end
1204
1205 # The identifier of a method in a method declaration.
1206 # There is a specific class because of operator and setters.
1207 abstract class AMethid
1208 super Prod
1209 end
1210
1211 # A method name with a simple identifier
1212 class AIdMethid
1213 super AMethid
1214 var n_id: TId is writable, noinit
1215 end
1216
1217 # A method name `+`
1218 class APlusMethid
1219 super AMethid
1220 var n_plus: TPlus is writable, noinit
1221 end
1222
1223 # A method name `-`
1224 class AMinusMethid
1225 super AMethid
1226 var n_minus: TMinus is writable, noinit
1227 end
1228
1229 # A method name `*`
1230 class AStarMethid
1231 super AMethid
1232 var n_star: TStar is writable, noinit
1233 end
1234
1235 # A method name `**`
1236 class AStarstarMethid
1237 super AMethid
1238 var n_starstar: TStarstar is writable, noinit
1239 end
1240
1241 # A method name `/`
1242 class ASlashMethid
1243 super AMethid
1244 var n_slash: TSlash is writable, noinit
1245 end
1246
1247 # A method name `%`
1248 class APercentMethid
1249 super AMethid
1250 var n_percent: TPercent is writable, noinit
1251 end
1252
1253 # A method name `==`
1254 class AEqMethid
1255 super AMethid
1256 var n_eq: TEq is writable, noinit
1257 end
1258
1259 # A method name `!=`
1260 class ANeMethid
1261 super AMethid
1262 var n_ne: TNe is writable, noinit
1263 end
1264
1265 # A method name `<=`
1266 class ALeMethid
1267 super AMethid
1268 var n_le: TLe is writable, noinit
1269 end
1270
1271 # A method name `>=`
1272 class AGeMethid
1273 super AMethid
1274 var n_ge: TGe is writable, noinit
1275 end
1276
1277 # A method name `<`
1278 class ALtMethid
1279 super AMethid
1280 var n_lt: TLt is writable, noinit
1281 end
1282
1283 # A method name `>`
1284 class AGtMethid
1285 super AMethid
1286 var n_gt: TGt is writable, noinit
1287 end
1288
1289 # A method name `<<`
1290 class ALlMethid
1291 super AMethid
1292 var n_ll: TLl is writable, noinit
1293 end
1294
1295 # A method name `>>`
1296 class AGgMethid
1297 super AMethid
1298 var n_gg: TGg is writable, noinit
1299 end
1300
1301 # A method name `[]`
1302 class ABraMethid
1303 super AMethid
1304 var n_obra: TObra is writable, noinit
1305 var n_cbra: TCbra is writable, noinit
1306 end
1307
1308 # A method name `<=>`
1309 class AStarshipMethid
1310 super AMethid
1311 var n_starship: TStarship is writable, noinit
1312 end
1313
1314 # A setter method name with a simple identifier (with a `=`)
1315 class AAssignMethid
1316 super AMethid
1317 var n_id: TId is writable, noinit
1318 var n_assign: TAssign is writable, noinit
1319 end
1320
1321 # A method name `[]=`
1322 class ABraassignMethid
1323 super AMethid
1324 var n_obra: TObra is writable, noinit
1325 var n_cbra: TCbra is writable, noinit
1326 var n_assign: TAssign is writable, noinit
1327 end
1328
1329 # A signature in a method definition. eg `(x,y:X,z:Z):T`
1330 class ASignature
1331 super Prod
1332 var n_opar: nullable TOpar = null is writable
1333 var n_params = new ANodes[AParam](self)
1334 var n_cpar: nullable TCpar = null is writable
1335 var n_type: nullable AType = null is writable
1336 end
1337
1338 # A parameter definition in a signature. eg `x:X`
1339 class AParam
1340 super Prod
1341 var n_id: TId is writable, noinit
1342 var n_type: nullable AType = null is writable
1343 var n_dotdotdot: nullable TDotdotdot = null is writable
1344 end
1345
1346 # A static type. eg `nullable X[Y]`
1347 class AType
1348 super Prod
1349 var n_kwnullable: nullable TKwnullable = null is writable
1350
1351 # The name of the class or of the formal type
1352 var n_id: TClassid is writable, noinit
1353
1354 # Type arguments for a generic type
1355 var n_types = new ANodes[AType](self)
1356 end
1357
1358 # A label at the end of a block or in a break/continue statement. eg `label x`
1359 class ALabel
1360 super Prod
1361 var n_kwlabel: TKwlabel is writable, noinit
1362 var n_id: nullable TId is writable
1363 end
1364
1365 # Expression and statements
1366 # From a AST point of view there is no distinction between statement and expressions (even if the parser has to distinguish them)
1367 abstract class AExpr
1368 super Prod
1369 end
1370
1371 # A sequence of `AExpr` (usually statements)
1372 # The last `AExpr` gives the value of the whole block
1373 class ABlockExpr
1374 super AExpr
1375 var n_expr = new ANodes[AExpr](self)
1376 var n_kwend: nullable TKwend = null is writable
1377 end
1378
1379 # A declaration of a local variable. eg `var x: X = y`
1380 class AVardeclExpr
1381 super AExpr
1382 var n_kwvar: TKwvar is writable, noinit
1383 var n_id: TId is writable, noinit
1384 var n_type: nullable AType = null is writable
1385 var n_assign: nullable TAssign = null is writable
1386
1387 # The initial value, if any
1388 var n_expr: nullable AExpr = null is writable
1389 end
1390
1391 # A `return` statement. eg `return x`
1392 class AReturnExpr
1393 super AExpr
1394 var n_kwreturn: nullable TKwreturn = null is writable
1395 var n_expr: nullable AExpr = null is writable
1396 end
1397
1398 # Something that has a label.
1399 abstract class ALabelable
1400 super Prod
1401 var n_label: nullable ALabel = null is writable
1402 end
1403
1404 # A `break` or a `continue`
1405 abstract class AEscapeExpr
1406 super AExpr
1407 super ALabelable
1408 var n_expr: nullable AExpr = null is writable
1409 end
1410
1411 # A `break` statement.
1412 class ABreakExpr
1413 super AEscapeExpr
1414 var n_kwbreak: TKwbreak is writable, noinit
1415 end
1416
1417 # An `abort` statement
1418 class AAbortExpr
1419 super AExpr
1420 var n_kwabort: TKwabort is writable, noinit
1421 end
1422
1423 # A `continue` statement
1424 class AContinueExpr
1425 super AEscapeExpr
1426 var n_kwcontinue: nullable TKwcontinue = null is writable
1427 end
1428
1429 # A `do` statement
1430 class ADoExpr
1431 super AExpr
1432 super ALabelable
1433 var n_kwdo: TKwdo is writable, noinit
1434 var n_block: nullable AExpr = null is writable
1435 end
1436
1437 # A `if` statement
1438 class AIfExpr
1439 super AExpr
1440 var n_kwif: TKwif is writable, noinit
1441 var n_expr: AExpr is writable, noinit
1442 var n_then: nullable AExpr = null is writable
1443 var n_else: nullable AExpr = null is writable
1444 end
1445
1446 # A `if` expression
1447 class AIfexprExpr
1448 super AExpr
1449 var n_kwif: TKwif is writable, noinit
1450 var n_expr: AExpr is writable, noinit
1451 var n_kwthen: TKwthen is writable, noinit
1452 var n_then: AExpr is writable, noinit
1453 var n_kwelse: TKwelse is writable, noinit
1454 var n_else: AExpr is writable, noinit
1455 end
1456
1457 # A `while` statement
1458 class AWhileExpr
1459 super AExpr
1460 super ALabelable
1461 var n_kwwhile: TKwwhile is writable, noinit
1462 var n_expr: AExpr is writable, noinit
1463 var n_kwdo: TKwdo is writable, noinit
1464 var n_block: nullable AExpr = null is writable
1465 end
1466
1467 # A `loop` statement
1468 class ALoopExpr
1469 super AExpr
1470 super ALabelable
1471 var n_kwloop: TKwloop is writable, noinit
1472 var n_block: nullable AExpr = null is writable
1473 end
1474
1475 # A `for` statement
1476 class AForExpr
1477 super AExpr
1478 super ALabelable
1479 var n_kwfor: TKwfor is writable, noinit
1480 var n_ids = new ANodes[TId](self)
1481 var n_expr: AExpr is writable, noinit
1482 var n_kwdo: TKwdo is writable, noinit
1483 var n_block: nullable AExpr = null is writable
1484 end
1485
1486 # An `assert` statement
1487 class AAssertExpr
1488 super AExpr
1489 var n_kwassert: TKwassert is writable, noinit
1490 var n_id: nullable TId = null is writable
1491 var n_expr: AExpr is writable, noinit
1492 var n_else: nullable AExpr = null is writable
1493 end
1494
1495 # Whatever is a simple assignment. eg `= something`
1496 abstract class AAssignFormExpr
1497 super AExpr
1498 var n_assign: TAssign is writable, noinit
1499 var n_value: AExpr is writable, noinit
1500 end
1501
1502 # Whatever is a combined assignment. eg `+= something`
1503 abstract class AReassignFormExpr
1504 super AExpr
1505 var n_assign_op: AAssignOp is writable, noinit
1506 var n_value: AExpr is writable, noinit
1507 end
1508
1509 # A `once` expression. eg `once x`
1510 class AOnceExpr
1511 super AExpr
1512 var n_kwonce: TKwonce is writable, noinit
1513 var n_expr: AExpr is writable, noinit
1514 end
1515
1516 # A polymorphic invocation of a method
1517 # The form of the invocation (name, arguments, etc.) are specific
1518 abstract class ASendExpr
1519 super AExpr
1520 # The receiver of the method invocation
1521 var n_expr: AExpr is writable, noinit
1522 end
1523
1524 # A binary operation on a method
1525 abstract class ABinopExpr
1526 super ASendExpr
1527 # The second operand of the operation
1528 # Note: the receiver (`n_expr`) is the first operand
1529 var n_expr2: AExpr is writable, noinit
1530 end
1531
1532 # Something that is boolean expression
1533 abstract class ABoolExpr
1534 super AExpr
1535 end
1536
1537 # A `or` expression
1538 class AOrExpr
1539 super ABoolExpr
1540 var n_expr: AExpr is writable, noinit
1541 var n_expr2: AExpr is writable, noinit
1542 end
1543
1544 # A `and` expression
1545 class AAndExpr
1546 super ABoolExpr
1547 var n_expr: AExpr is writable, noinit
1548 var n_expr2: AExpr is writable, noinit
1549 end
1550
1551 # A `or else` expression
1552 class AOrElseExpr
1553 super ABoolExpr
1554 var n_expr: AExpr is writable, noinit
1555 var n_expr2: AExpr is writable, noinit
1556 end
1557
1558 # A `implies` expression
1559 class AImpliesExpr
1560 super ABoolExpr
1561 var n_expr: AExpr is writable, noinit
1562 var n_expr2: AExpr is writable, noinit
1563 end
1564
1565 # A `not` expression
1566 class ANotExpr
1567 super ABoolExpr
1568 var n_kwnot: TKwnot is writable, noinit
1569 var n_expr: AExpr is writable, noinit
1570 end
1571
1572 # A `==` expression
1573 class AEqExpr
1574 super ABinopExpr
1575 end
1576
1577 # A `!=` expression
1578 class ANeExpr
1579 super ABinopExpr
1580 end
1581
1582 # A `<` expression
1583 class ALtExpr
1584 super ABinopExpr
1585 end
1586
1587 # A `<=` expression
1588 class ALeExpr
1589 super ABinopExpr
1590 end
1591
1592 # A `<<` expression
1593 class ALlExpr
1594 super ABinopExpr
1595 end
1596
1597 # A `>` expression
1598 class AGtExpr
1599 super ABinopExpr
1600 end
1601
1602 # A `>=` expression
1603 class AGeExpr
1604 super ABinopExpr
1605 end
1606
1607 # A `>>` expression
1608 class AGgExpr
1609 super ABinopExpr
1610 end
1611
1612 # A type-ckeck expression. eg `x isa T`
1613 class AIsaExpr
1614 super ABoolExpr
1615 var n_expr: AExpr is writable, noinit
1616 var n_type: AType is writable, noinit
1617 end
1618
1619 # A `+` expression
1620 class APlusExpr
1621 super ABinopExpr
1622 end
1623
1624 # A `-` expression
1625 class AMinusExpr
1626 super ABinopExpr
1627 end
1628
1629 # A `<=>` expression
1630 class AStarshipExpr
1631 super ABinopExpr
1632 end
1633
1634 # A `*` expression
1635 class AStarExpr
1636 super ABinopExpr
1637 end
1638
1639 # A `**` expression
1640 class AStarstarExpr
1641 super ABinopExpr
1642 end
1643
1644 # A `/` expression
1645 class ASlashExpr
1646 super ABinopExpr
1647 end
1648
1649 # A `%` expression
1650 class APercentExpr
1651 super ABinopExpr
1652 end
1653
1654 # A unary minus expression. eg `-x`
1655 class AUminusExpr
1656 super ASendExpr
1657 var n_minus: TMinus is writable, noinit
1658 end
1659
1660 # An explicit instantiation. eg `new T`
1661 class ANewExpr
1662 super AExpr
1663 var n_kwnew: TKwnew is writable, noinit
1664 var n_type: AType is writable, noinit
1665
1666 # The name of the named-constructor, if any
1667 var n_id: nullable TId = null is writable
1668 var n_args: AExprs is writable, noinit
1669 end
1670
1671 # Whatever is a old-style attribute access
1672 abstract class AAttrFormExpr
1673 super AExpr
1674
1675 # The receiver of the attribute
1676 var n_expr: AExpr is writable, noinit
1677
1678 # The name of the attribute
1679 var n_id: TAttrid is writable, noinit
1680
1681 end
1682
1683 # The read of an attribute. eg `x._a`
1684 class AAttrExpr
1685 super AAttrFormExpr
1686 end
1687
1688 # The assignment of an attribute. eg `x._a=y`
1689 class AAttrAssignExpr
1690 super AAttrFormExpr
1691 super AAssignFormExpr
1692 end
1693
1694 # Whatever looks-like a call with a standard method and any number of arguments.
1695 abstract class ACallFormExpr
1696 super ASendExpr
1697
1698 # The name of the method
1699 var n_id: TId is writable, noinit
1700
1701 # The arguments of the call
1702 var n_args: AExprs is writable, noinit
1703 end
1704
1705 # A complex setter call (standard or brackets)
1706 abstract class ASendReassignFormExpr
1707 super ASendExpr
1708 super AReassignFormExpr
1709 end
1710
1711 # A complex attribute assignment. eg `x._a+=y`
1712 class AAttrReassignExpr
1713 super AAttrFormExpr
1714 super AReassignFormExpr
1715 end
1716
1717 # A call with a standard method-name and any number of arguments. eg `x.m(y)`. OR just a simple id
1718 # 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`.
1719 # Semantic analysis have to transform them to instance of `AVarExpr`.
1720 class ACallExpr
1721 super ACallFormExpr
1722 end
1723
1724 # A setter call with a standard method-name and any number of arguments. eg `x.m(y)=z`. OR just a simple assignment.
1725 # 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`.
1726 # Semantic analysis have to transform them to instance of `AVarAssignExpr`.
1727 class ACallAssignExpr
1728 super ACallFormExpr
1729 super AAssignFormExpr
1730 end
1731
1732 # 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.
1733 # 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`.
1734 # Semantic analysis have to transform them to instance of `AVarReassignExpr`.
1735 class ACallReassignExpr
1736 super ACallFormExpr
1737 super ASendReassignFormExpr
1738 end
1739
1740 # A call to `super`. OR a call of a super-constructor
1741 class ASuperExpr
1742 super AExpr
1743 var n_qualified: nullable AQualified = null is writable
1744 var n_kwsuper: TKwsuper is writable, noinit
1745 var n_args: AExprs is writable, noinit
1746 end
1747
1748 # A call to the `init` constructor.
1749 # Note: because `init` is a keyword and not a `TId`, the explicit call to init cannot be a `ACallFormExpr`.
1750 class AInitExpr
1751 super ASendExpr
1752 var n_kwinit: TKwinit is writable, noinit
1753 var n_args: AExprs is writable, noinit
1754 end
1755
1756 # Whatever looks-like a call of the brackets `[]` operator.
1757 abstract class ABraFormExpr
1758 super ASendExpr
1759 var n_args: AExprs is writable, noinit
1760 end
1761
1762 # A call of the brackets operator. eg `x[y,z]`
1763 class ABraExpr
1764 super ABraFormExpr
1765 end
1766
1767 # A setter call of the bracket operator. eg `x[y,z]=t`
1768 class ABraAssignExpr
1769 super ABraFormExpr
1770 super AAssignFormExpr
1771 end
1772
1773 # Whatever is an access to a local variable
1774 abstract class AVarFormExpr
1775 super AExpr
1776 var n_id: TId is writable, noinit
1777 end
1778
1779 # A complex setter call of the bracket operator. eg `x[y,z]+=t`
1780 class ABraReassignExpr
1781 super ABraFormExpr
1782 super ASendReassignFormExpr
1783 end
1784
1785 # A local variable read access.
1786 # The parser cannot instantiate them, see `ACallExpr`.
1787 class AVarExpr
1788 super AVarFormExpr
1789 end
1790
1791 # A local variable simple assignment access
1792 # The parser cannot instantiate them, see `ACallAssignExpr`.
1793 class AVarAssignExpr
1794 super AVarFormExpr
1795 super AAssignFormExpr
1796 end
1797
1798 # A local variable complex assignment access
1799 # The parser cannot instantiate them, see `ACallReassignExpr`.
1800 class AVarReassignExpr
1801 super AVarFormExpr
1802 super AReassignFormExpr
1803 end
1804
1805 # A literal range, open or closed
1806 abstract class ARangeExpr
1807 super AExpr
1808 var n_expr: AExpr is writable, noinit
1809 var n_expr2: AExpr is writable, noinit
1810 end
1811
1812 # A closed literal range. eg `[x..y]`
1813 class ACrangeExpr
1814 super ARangeExpr
1815 var n_obra: TObra is writable, noinit
1816 var n_cbra: TCbra is writable, noinit
1817 end
1818
1819 # An open literal range. eg `[x..y[`
1820 class AOrangeExpr
1821 super ARangeExpr
1822 var n_obra: TObra is writable, noinit
1823 var n_cbra: TObra is writable, noinit
1824 end
1825
1826 # A literal array. eg. `[x,y,z]`
1827 class AArrayExpr
1828 super AExpr
1829 var n_obra: TObra is writable, noinit
1830 var n_exprs = new ANodes[AExpr](self)
1831 var n_type: nullable AType = null is writable
1832 var n_cbra: TCbra is writable, noinit
1833 end
1834
1835 # A read of `self`
1836 class ASelfExpr
1837 super AExpr
1838 var n_kwself: nullable TKwself is writable
1839 end
1840
1841 # When there is no explicit receiver, `self` is implicit
1842 class AImplicitSelfExpr
1843 super ASelfExpr
1844 end
1845
1846 # A `true` boolean literal constant
1847 class ATrueExpr
1848 super ABoolExpr
1849 var n_kwtrue: TKwtrue is writable, noinit
1850 end
1851 # A `false` boolean literal constant
1852 class AFalseExpr
1853 super ABoolExpr
1854 var n_kwfalse: TKwfalse is writable, noinit
1855 end
1856 # A `null` literal constant
1857 class ANullExpr
1858 super AExpr
1859 var n_kwnull: TKwnull is writable, noinit
1860 end
1861 # An integer literal
1862 class AIntExpr
1863 super AExpr
1864 end
1865 # An integer literal in decimal format
1866 class ADecIntExpr
1867 super AIntExpr
1868 var n_number: TNumber is writable, noinit
1869 end
1870 # An integer literal in hexadecimal format
1871 class AHexIntExpr
1872 super AIntExpr
1873 var n_hex_number: THexNumber is writable, noinit
1874 end
1875 # A float literal
1876 class AFloatExpr
1877 super AExpr
1878 var n_float: TFloat is writable, noinit
1879 end
1880 # A character literal
1881 class ACharExpr
1882 super AExpr
1883 var n_char: TChar is writable, noinit
1884 end
1885 # A string literal
1886 abstract class AStringFormExpr
1887 super AExpr
1888 var n_string: Token is writable, noinit
1889 end
1890
1891 # A simple string. eg. `"abc"`
1892 class AStringExpr
1893 super AStringFormExpr
1894 end
1895
1896 # The start of a superstring. eg `"abc{`
1897 class AStartStringExpr
1898 super AStringFormExpr
1899 end
1900
1901 # The middle of a superstring. eg `}abc{`
1902 class AMidStringExpr
1903 super AStringFormExpr
1904 end
1905
1906 # The end of a superstrng. eg `}abc"`
1907 class AEndStringExpr
1908 super AStringFormExpr
1909 end
1910
1911 # A superstring literal. eg `"a{x}b{y}c"`
1912 # Each part is modeled a sequence of expression. eg. `["a{, x, }b{, y, }c"]`
1913 class ASuperstringExpr
1914 super AExpr
1915 var n_exprs = new ANodes[AExpr](self)
1916 end
1917
1918 # A simple parenthesis. eg `(x)`
1919 class AParExpr
1920 super AExpr
1921 var n_opar: TOpar is writable, noinit
1922 var n_expr: AExpr is writable, noinit
1923 var n_cpar: TCpar is writable, noinit
1924 end
1925
1926 # A type cast. eg `x.as(T)`
1927 class AAsCastExpr
1928 super AExpr
1929 var n_expr: AExpr is writable, noinit
1930 var n_kwas: TKwas is writable, noinit
1931 var n_opar: nullable TOpar = null is writable
1932 var n_type: AType is writable, noinit
1933 var n_cpar: nullable TCpar = null is writable
1934 end
1935
1936 # A as-not-null cast. eg `x.as(not null)`
1937 class AAsNotnullExpr
1938 super AExpr
1939 var n_expr: AExpr is writable, noinit
1940 var n_kwas: TKwas is writable, noinit
1941 var n_opar: nullable TOpar = null is writable
1942 var n_kwnot: TKwnot is writable, noinit
1943 var n_kwnull: TKwnull is writable, noinit
1944 var n_cpar: nullable TCpar = null is writable
1945 end
1946
1947 # A is-set check of old-style attributes. eg `isset x._a`
1948 class AIssetAttrExpr
1949 super AAttrFormExpr
1950 var n_kwisset: TKwisset is writable, noinit
1951 end
1952
1953 # An ellipsis notation used to pass an expression as it, in a vararg parameter
1954 class AVarargExpr
1955 super AExpr
1956 var n_expr: AExpr is writable, noinit
1957 var n_dotdotdot: TDotdotdot is writable, noinit
1958 end
1959
1960 # A list of expression separated with commas (arguments for instance)
1961 class AManyExpr
1962 super AExpr
1963 var n_exprs = new ANodes[AExpr](self)
1964 end
1965
1966 # A special expression that encapsulates a static type
1967 # Can only be found in special construction like arguments of annotations.
1968 class ATypeExpr
1969 super AExpr
1970 var n_type: AType is writable, noinit
1971 end
1972
1973 # A special expression that encapsulates a method identifier
1974 # Can only be found in special construction like arguments of annotations.
1975 class AMethidExpr
1976 super AExpr
1977 # The receiver, is any
1978 var n_expr: AExpr is writable, noinit
1979 var n_id: AMethid is writable, noinit
1980 end
1981
1982 # A special expression that encapsulate an annotation
1983 # Can only be found in special construction like arguments of annotations.
1984 class AAtExpr
1985 super AExpr
1986 end
1987
1988 # A special expression to debug types
1989 class ADebugTypeExpr
1990 super AExpr
1991 var n_kwdebug: TKwdebug is writable, noinit
1992 var n_kwtype: TKwtype is writable, noinit
1993 var n_expr: AExpr is writable, noinit
1994 var n_type: AType is writable, noinit
1995 end
1996
1997 # A list of expression separated with commas (arguments for instance)
1998 abstract class AExprs
1999 super Prod
2000 var n_exprs = new ANodes[AExpr](self)
2001 end
2002
2003 # A simple list of expressions
2004 class AListExprs
2005 super AExprs
2006 end
2007
2008 # A list of expressions enclosed in parentheses
2009 class AParExprs
2010 super AExprs
2011 var n_opar: TOpar is writable, noinit
2012 var n_cpar: TCpar is writable, noinit
2013 end
2014
2015 # A list of expressions enclosed in brackets
2016 class ABraExprs
2017 super AExprs
2018 var n_obra: TObra is writable, noinit
2019 var n_cbra: TCbra is writable, noinit
2020 end
2021
2022 # A complex assignment operator. (`+=` and `-=`)
2023 abstract class AAssignOp
2024 super Prod
2025 end
2026
2027 # The `+=` assignment operation
2028 class APlusAssignOp
2029 super AAssignOp
2030 var n_pluseq: TPluseq is writable, noinit
2031 end
2032
2033 # The `-=` assignment operator
2034 class AMinusAssignOp
2035 super AAssignOp
2036 var n_minuseq: TMinuseq is writable, noinit
2037 end
2038
2039 # A possibly fully-qualified module identifier
2040 class AModuleName
2041 super Prod
2042 var n_quad: nullable TQuad = null is writable
2043 var n_path = new ANodes[TId](self)
2044 var n_id: TId is writable, noinit
2045 end
2046
2047 # A language declaration for an extern block
2048 class AInLanguage
2049 super Prod
2050 var n_kwin: TKwin is writable, noinit
2051 var n_string: TString is writable, noinit
2052 end
2053
2054 # An full extern block
2055 class AExternCodeBlock
2056 super Prod
2057 var n_in_language: nullable AInLanguage = null is writable
2058 var n_extern_code_segment: TExternCodeSegment is writable, noinit
2059 end
2060
2061 # A possible full method qualifier.
2062 class AQualified
2063 super Prod
2064 var n_quad: nullable TQuad = null is writable
2065 var n_id = new ANodes[TId](self)
2066 var n_classid: nullable TClassid = null is writable
2067 end
2068
2069 # A documentation of a definition
2070 # It contains the block of comments just above the declaration
2071 class ADoc
2072 super Prod
2073 var n_comment = new ANodes[TComment](self)
2074 end
2075
2076 # A group of annotation on a node
2077 class AAnnotations
2078 super Prod
2079 var n_at: nullable TAt = null is writable
2080 var n_opar: nullable TOpar = null is writable
2081 var n_items = new ANodes[AAnnotation](self)
2082 var n_cpar: nullable TCpar = null is writable
2083 end
2084
2085 # A single annotation
2086 class AAnnotation
2087 super Prod
2088 var n_doc: nullable ADoc = null is writable
2089 var n_kwredef: nullable TKwredef = null is writable
2090 var n_visibility: nullable AVisibility is writable
2091 var n_atid: AAtid is writable, noinit
2092 var n_opar: nullable TOpar = null is writable
2093 var n_args = new ANodes[AExpr](self)
2094 var n_cpar: nullable TCpar = null is writable
2095
2096 # The name of the annotation
2097 fun name: String
2098 do
2099 return n_atid.n_id.text
2100 end
2101 end
2102
2103 # An annotation name
2104 abstract class AAtid
2105 super Prod
2106 var n_id: Token is writable, noinit
2107 end
2108
2109 # An annotation name based on an identifier
2110 class AIdAtid
2111 super AAtid
2112 end
2113
2114 # An annotation name based on the keyword `extern`
2115 class AKwexternAtid
2116 super AAtid
2117 end
2118
2119 # An annotation name based on the keyword `import`
2120 class AKwimportAtid
2121 super AAtid
2122 end
2123
2124 # An annotation name based on the keyword `abstract`
2125 class AKwabstractAtid
2126 super AAtid
2127 end
2128
2129 # The root of the AST
2130 class Start
2131 super Prod
2132 var n_base: nullable AModule is writable
2133 var n_eof: EOF is writable
2134 end