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