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