grammar: introduce AAnnotPropdef for annotation in classes
[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 for na in nas.n_items do
319 if na.name != name then continue
320 res.add(na)
321 end
322 if self isa AClassdef then for na in n_propdefs do
323 if na isa AAnnotPropdef then
324 if na.name != name then continue
325 res.add na
326 end
327 end
328
329 return res
330 end
331
332 redef fun replace_with(n: ANode)
333 do
334 super
335 assert n isa Prod
336 if not isset n._location and isset _location then n._location = _location
337 end
338 end
339
340 # Abstract standard visitor on the AST
341 abstract class Visitor
342 # What the visitor do when a node is visited
343 # Concrete visitors should implement this method.
344 # @toimplement
345 protected fun visit(e: ANode) is abstract
346
347 # Ask the visitor to visit a given node.
348 # Usually automatically called by visit_all* methods.
349 # This method should not be redefined
350 fun enter_visit(e: nullable ANode)
351 do
352 if e == null then return
353 var old = _current_node
354 _current_node = e
355 visit(e)
356 _current_node = old
357 end
358
359 # The current visited node
360 var current_node: nullable ANode = null is writable
361 end
362
363 # Token of end of line (basically `\n`)
364 class TEol
365 super Token
366 redef fun to_s
367 do
368 return "end of line"
369 end
370 end
371
372 # Token of a line of comments
373 # Starts with the `#` and contains the final end-of-line (if any)
374 class TComment
375 super Token
376 end
377
378 # A token associated with a keyword
379 abstract class TokenKeyword
380 super Token
381 redef fun to_s
382 do
383 return "keyword '{text}'"
384 end
385 end
386
387 # The deprecated keyword `package`.
388 class TKwpackage
389 super TokenKeyword
390 end
391
392 # The keyword `module`
393 class TKwmodule
394 super TokenKeyword
395 end
396
397 # The keyword `import`
398 class TKwimport
399 super TokenKeyword
400 end
401
402 # The keyword `class`
403 class TKwclass
404 super TokenKeyword
405 end
406
407 # The keyword `abstract`
408 class TKwabstract
409 super TokenKeyword
410 end
411
412 # The keyword `interface`
413 class TKwinterface
414 super TokenKeyword
415 end
416
417 # The keywords `enum` ane `universal`
418 class TKwenum
419 super TokenKeyword
420 end
421
422 # The keyword `end`
423 class TKwend
424 super TokenKeyword
425 end
426
427 # The keyword `fun`
428 class TKwmeth
429 super TokenKeyword
430 end
431
432 # The keyword `type`
433 class TKwtype
434 super TokenKeyword
435 end
436
437 # The keyword `init`
438 class TKwinit
439 super TokenKeyword
440 end
441
442 # The keyword `redef`
443 class TKwredef
444 super TokenKeyword
445 end
446
447 # The keyword `is`
448 class TKwis
449 super TokenKeyword
450 end
451
452 # The keyword `do`
453 class TKwdo
454 super TokenKeyword
455 end
456
457 # The keyword `var`
458 class TKwvar
459 super TokenKeyword
460 end
461
462 # The keyword `extern`
463 class TKwextern
464 super TokenKeyword
465 end
466
467 # The keyword `public`
468 class TKwpublic
469 super TokenKeyword
470 end
471
472 # The keyword `protected`
473 class TKwprotected
474 super TokenKeyword
475 end
476
477 # The keyword `private`
478 class TKwprivate
479 super TokenKeyword
480 end
481
482 # The keyword `intrude`
483 class TKwintrude
484 super TokenKeyword
485 end
486
487 # The keyword `if`
488 class TKwif
489 super TokenKeyword
490 end
491
492 # The keyword `then`
493 class TKwthen
494 super TokenKeyword
495 end
496
497 # The keyword `else`
498 class TKwelse
499 super TokenKeyword
500 end
501
502 # The keyword `while`
503 class TKwwhile
504 super TokenKeyword
505 end
506
507 # The keyword `loop`
508 class TKwloop
509 super TokenKeyword
510 end
511
512 # The keyword `for`
513 class TKwfor
514 super TokenKeyword
515 end
516
517 # The keyword `in`
518 class TKwin
519 super TokenKeyword
520 end
521
522 # The keyword `and`
523 class TKwand
524 super TokenKeyword
525 end
526
527 # The keyword `or`
528 class TKwor
529 super TokenKeyword
530 end
531
532 # The keyword `implies`
533 class TKwimplies
534 super TokenKeyword
535 end
536
537 # The keyword `not`
538 class TKwnot
539 super TokenKeyword
540 end
541
542 # The keyword `return`
543 class TKwreturn
544 super TokenKeyword
545 end
546
547 # The keyword `continue`
548 class TKwcontinue
549 super TokenKeyword
550 end
551
552 # The keyword `break`
553 class TKwbreak
554 super TokenKeyword
555 end
556
557 # The keyword `abort`
558 class TKwabort
559 super TokenKeyword
560 end
561
562 # The keyword `assert`
563 class TKwassert
564 super TokenKeyword
565 end
566
567 # The keyword `new`
568 class TKwnew
569 super TokenKeyword
570 end
571
572 # The keyword `isa`
573 class TKwisa
574 super TokenKeyword
575 end
576
577 # The keyword `once`
578 class TKwonce
579 super TokenKeyword
580 end
581
582 # The keyword `super`
583 class TKwsuper
584 super TokenKeyword
585 end
586
587 # The keyword `self`
588 class TKwself
589 super TokenKeyword
590 end
591
592 # The keyword `true`
593 class TKwtrue
594 super TokenKeyword
595 end
596
597 # The keyword `false`
598 class TKwfalse
599 super TokenKeyword
600 end
601
602 # The keyword `null`
603 class TKwnull
604 super TokenKeyword
605 end
606
607 # The keyword `as`
608 class TKwas
609 super TokenKeyword
610 end
611
612 # The keyword `nullable`
613 class TKwnullable
614 super TokenKeyword
615 end
616
617 # The keyword `isset`
618 class TKwisset
619 super TokenKeyword
620 end
621
622 # The keyword `label`
623 class TKwlabel
624 super TokenKeyword
625 end
626
627 # The special keyword `__DEBUG__`
628 class TKwdebug
629 super Token
630 end
631
632 # The symbol `(`
633 class TOpar
634 super Token
635 end
636
637 # The symbol `)`
638 class TCpar
639 super Token
640 end
641
642 # The symbol `[`
643 class TObra
644 super Token
645 end
646
647 # The symbol `]`
648 class TCbra
649 super Token
650 end
651
652 # The symbol `,`
653 class TComma
654 super Token
655 end
656
657 # The symbol `:`
658 class TColumn
659 super Token
660 end
661
662 # The symbol `::`
663 class TQuad
664 super Token
665 end
666
667 # The symbol `=`
668 class TAssign
669 super Token
670 end
671
672 # A token associated with an operator (and other lookalike symbols)
673 abstract class TokenOperator
674 super Token
675 redef fun to_s
676 do
677 return "operator '{text}'"
678 end
679 end
680
681 # The operator `+=`
682 class TPluseq
683 super TokenOperator
684 end
685
686 # The operator `-=`
687 class TMinuseq
688 super TokenOperator
689 end
690
691 # The symbol `...`
692 class TDotdotdot
693 super Token
694 end
695
696 # The symbol `..`
697 class TDotdot
698 super Token
699 end
700
701 # The symbol `.`
702 class TDot
703 super Token
704 end
705
706 # The operator `+`
707 class TPlus
708 super TokenOperator
709 end
710
711 # The operator `-`
712 class TMinus
713 super TokenOperator
714 end
715
716 # The operator `*`
717 class TStar
718 super TokenOperator
719 end
720
721 # The operator `**`
722 class TStarstar
723 super TokenOperator
724 end
725
726 # The operator `/`
727 class TSlash
728 super TokenOperator
729 end
730
731 # The operator `+%
732 class TPercent
733 super TokenOperator
734 end
735
736 # The operator `==`
737 class TEq
738 super TokenOperator
739 end
740
741 # The operator `!=`
742 class TNe
743 super TokenOperator
744 end
745
746 # The operator `<`
747 class TLt
748 super TokenOperator
749 end
750
751 # The operator `<=`
752 class TLe
753 super TokenOperator
754 end
755
756 # The operator `<<`
757 class TLl
758 super TokenOperator
759 end
760
761 # The operator `>`
762 class TGt
763 super TokenOperator
764 end
765
766 # The operator `>=`
767 class TGe
768 super TokenOperator
769 end
770
771 # The operator `>>`
772 class TGg
773 super TokenOperator
774 end
775
776 # The operator `<=>`
777 class TStarship
778 super TokenOperator
779 end
780
781 # The operator `!`
782 class TBang
783 super TokenOperator
784 end
785
786 # The symbol `@`
787 class TAt
788 super Token
789 end
790
791 # A class (or formal type) identifier. They start with an uppercase.
792 class TClassid
793 super Token
794 redef fun to_s
795 do
796 do return "type identifier '{text}'"
797 end
798 end
799
800 # A standard identifier (variable, method...). They start with a lowercase.
801 class TId
802 super Token
803 redef fun to_s
804 do
805 do return "identifier '{text}'"
806 end
807 end
808
809 # An attribute identifier. They start with an underscore.
810 class TAttrid
811 super Token
812 redef fun to_s
813 do
814 do return "attribute '{text}'"
815 end
816 end
817
818 # A token of a literal value (string, integer, etc).
819 abstract class TokenLiteral
820 super Token
821 redef fun to_s
822 do
823 do return "literal value '{text}'"
824 end
825 end
826
827 # A literal decimal integer
828 class TNumber
829 super TokenLiteral
830 end
831
832 # A literal hexadecimal integer
833 class THexNumber
834 super TokenLiteral
835 end
836
837 # A literal floating point number
838 class TFloat
839 super TokenLiteral
840 end
841
842 # A literal character
843 class TChar
844 super TokenLiteral
845 end
846
847 # A literal string
848 class TString
849 super TokenLiteral
850 end
851
852 # The starting part of a super string (between `"` and `{`)
853 class TStartString
854 super TokenLiteral
855 end
856
857 # The middle part of a super string (between `}` and `{`)
858 class TMidString
859 super TokenLiteral
860 end
861
862 # The final part of a super string (between `}` and `"`)
863 class TEndString
864 super TokenLiteral
865 end
866
867 # A malformed string
868 class TBadString
869 super Token
870 redef fun to_s
871 do
872 do return "malformed string {text}"
873 end
874 end
875
876 # A malformed char
877 class TBadChar
878 super Token
879 redef fun to_s
880 do
881 do return "malformed character {text}"
882 end
883 end
884
885 # A extern code block
886 class TExternCodeSegment
887 super Token
888 end
889
890 # A end of file
891 class EOF
892 super Token
893 redef fun to_s
894 do
895 return "end of file"
896 end
897 end
898
899 # A mark of an error
900 class AError
901 super EOF
902 end
903 # A lexical error (unexpected character)
904 class ALexerError
905 super AError
906 end
907 # A syntactic error (unexpected token)
908 class AParserError
909 super AError
910 end
911
912 # The main node of a Nit source-file
913 class AModule
914 super Prod
915
916 # The declaration part of the module
917 var n_moduledecl: nullable AModuledecl = null is writable
918
919 # List of importation clauses
920 var n_imports = new ANodes[AImport](self)
921
922 # List of extern blocks
923 var n_extern_code_blocks = new ANodes[AExternCodeBlock](self)
924
925 # List of class definition (including top-level methods and the main)
926 var n_classdefs = new ANodes[AClassdef](self)
927 end
928
929 # Abstract class for definition of entities
930 abstract class ADefinition
931 super Prod
932 # The documentation
933 var n_doc: nullable ADoc = null is writable
934
935 # The `redef` keyword
936 var n_kwredef: nullable TKwredef = null is writable
937
938 # The declared visibility
939 var n_visibility: nullable AVisibility = null is writable
940 end
941
942 # The declaration of the module with the documentation, name, and annotations
943 class AModuledecl
944 super ADefinition
945
946 # The `module` keyword
947 var n_kwmodule: TKwmodule is writable, noinit
948
949 # The declared module name
950 var n_name: AModuleName is writable, noinit
951 end
952
953 # A import clause of a module
954 abstract class AImport
955 super Prod
956
957 # The declared visibility
958 var n_visibility: AVisibility is writable, noinit
959
960 # The `import` keyword
961 var n_kwimport: TKwimport is writable, noinit
962 end
963
964 # A standard import clause. eg `import x`
965 class AStdImport
966 super AImport
967 # The imported module name
968 var n_name: AModuleName is writable, noinit
969 end
970
971 # The special import clause of the kernel module. eg `import end`
972 class ANoImport
973 super AImport
974 # The `end` keyword, that indicate the root module
975 var n_kwend: TKwend is writable, noinit
976 end
977
978 # A visibility modifier
979 #
980 # The public visibility is an empty production (no keyword).
981 #
982 # Note: even if some visibilities are only valid on some placse (for instance, no `protected` class or no `intrude` method)
983 # the parser has no such a restriction, therefore the semantic phases has to check that the visibilities make sense.
984 abstract class AVisibility
985 super Prod
986 end
987
988 # An implicit or explicit public visibility modifier
989 class APublicVisibility
990 super AVisibility
991 # The `public` keyword, if any
992 var n_kwpublic: nullable TKwpublic is writable
993 end
994 # An explicit private visibility modifier
995 class APrivateVisibility
996 super AVisibility
997 # The `private` keyword
998 var n_kwprivate: TKwprivate is writable, noinit
999 end
1000 # An explicit protected visibility modifier
1001 class AProtectedVisibility
1002 super AVisibility
1003 # The `protected` keyword
1004 var n_kwprotected: TKwprotected is writable, noinit
1005 end
1006 # An explicit intrude visibility modifier
1007 class AIntrudeVisibility
1008 super AVisibility
1009 # The `intrude` keyword
1010 var n_kwintrude: TKwintrude is writable, noinit
1011 end
1012
1013 # A class definition
1014 # While most definition are `AStdClassdef`
1015 # There is tow special case of class definition
1016 abstract class AClassdef
1017 super Prod
1018 # All the declared properties (including the main method)
1019 var n_propdefs = new ANodes[APropdef](self)
1020 end
1021
1022 # A standard class definition with a name, superclasses and properties
1023 class AStdClassdef
1024 super AClassdef
1025 super ADefinition
1026
1027 # The class kind (interface, abstract class, etc.)
1028 var n_classkind: AClasskind is writable, noinit
1029
1030 # The name of the class
1031 var n_id: nullable TClassid = null is writable
1032
1033 # The list of formal parameter types
1034 var n_formaldefs = new ANodes[AFormaldef](self)
1035
1036 # The extern block code
1037 var n_extern_code_block: nullable AExternCodeBlock = null is writable
1038
1039 # The `end` keyword
1040 var n_kwend: TKwend is writable, noinit
1041
1042 fun n_superclasses: Array[ASuperPropdef] do
1043 return [for d in n_propdefs do if d isa ASuperPropdef then d]
1044 end
1045
1046 redef fun hot_location do return n_id.location
1047 end
1048
1049 # The implicit class definition of the implicit main method
1050 class ATopClassdef
1051 super AClassdef
1052 end
1053
1054 # The implicit class definition of the top-level methods
1055 class AMainClassdef
1056 super AClassdef
1057 end
1058
1059 # The modifier for the kind of class (abstract, interface, etc.)
1060 abstract class AClasskind
1061 super Prod
1062 end
1063
1064 # A default, or concrete class modifier (just `class`)
1065 class AConcreteClasskind
1066 super AClasskind
1067
1068 # The `class` keyword.
1069 var n_kwclass: TKwclass is writable, noinit
1070 end
1071
1072 # An abstract class modifier (`abstract class`)
1073 class AAbstractClasskind
1074 super AClasskind
1075
1076 # The `abstract` keyword.
1077 var n_kwabstract: TKwabstract is writable, noinit
1078
1079 # The `class` keyword.
1080 var n_kwclass: TKwclass is writable, noinit
1081 end
1082
1083 # An interface class modifier (`interface`)
1084 class AInterfaceClasskind
1085 super AClasskind
1086
1087 # The `interface` keyword.
1088 var n_kwinterface: TKwinterface is writable, noinit
1089 end
1090
1091 # An enum/universal class modifier (`enum class`)
1092 class AEnumClasskind
1093 super AClasskind
1094
1095 # The `enum` keyword.
1096 var n_kwenum: TKwenum is writable, noinit
1097 end
1098
1099 # An extern class modifier (`extern class`)
1100 class AExternClasskind
1101 super AClasskind
1102
1103 # The `extern` keyword.
1104 var n_kwextern: TKwextern is writable, noinit
1105
1106 # The `class` keyword.
1107 var n_kwclass: nullable TKwclass = null is writable
1108 end
1109
1110 # The definition of a formal generic parameter type. eg `X: Y`
1111 class AFormaldef
1112 super Prod
1113
1114 # The name of the parameter type
1115 var n_id: TClassid is writable, noinit
1116
1117 # The bound of the parameter type
1118 var n_type: nullable AType = null is writable
1119 end
1120
1121 # The definition of a property
1122 abstract class APropdef
1123 super ADefinition
1124 end
1125
1126 # A definition of an attribute
1127 # For historical reason, old-syle and new-style attributes use the same `ANode` sub-class
1128 class AAttrPropdef
1129 super APropdef
1130
1131 # The identifier for a old-style attribute (null if new-style)
1132 var n_kwvar: TKwvar is writable, noinit
1133
1134 # The identifier for a new-style attribute (null if old-style)
1135 var n_id2: TId is writable, noinit
1136
1137 # The declared type of the attribute
1138 var n_type: nullable AType = null is writable
1139
1140 # The initial value, if any (set with `=`)
1141 var n_expr: nullable AExpr = null is writable
1142
1143 # The initial value, if any (set with `do return`)
1144 var n_block: nullable AExpr = null is writable
1145
1146 redef fun hot_location
1147 do
1148 return n_id2.location
1149 end
1150 end
1151
1152 # A definition of all kind of method (including constructors)
1153 class AMethPropdef
1154 super APropdef
1155
1156 # The `fun` keyword, if any
1157 var n_kwmeth: nullable TKwmeth = null is writable
1158
1159 # The `init` keyword, if any
1160 var n_kwinit: nullable TKwinit = null is writable
1161
1162 # The `new` keyword, if any
1163 var n_kwnew: nullable TKwnew = null is writable
1164
1165 # The name of the method, if any
1166 var n_methid: nullable AMethid = null is writable
1167
1168 # The signature of the method, if any
1169 var n_signature: nullable ASignature = null is writable
1170
1171 # The body (in Nit) of the method, if any
1172 var n_block: nullable AExpr = null is writable
1173
1174 # The list of declared callbacks (for extern methods)
1175 var n_extern_calls: nullable AExternCalls = null is writable
1176
1177 # The body (in extern code) of the method, if any
1178 var n_extern_code_block: nullable AExternCodeBlock = null is writable
1179
1180 redef fun hot_location
1181 do
1182 if n_methid != null then
1183 return n_methid.location
1184 else if n_kwinit != null then
1185 return n_kwinit.location
1186 else if n_kwnew != null then
1187 return n_kwnew.location
1188 else
1189 return location
1190 end
1191 end
1192 end
1193
1194 # The implicit main method
1195 class AMainMethPropdef
1196 super AMethPropdef
1197 end
1198
1199 class AAnnotPropdef
1200 super APropdef
1201 super AAnnotation
1202 end
1203
1204 # A super-class. eg `super X`
1205 class ASuperPropdef
1206 super APropdef
1207
1208 # The super keyword
1209 var n_kwsuper: TKwsuper is writable, noinit
1210
1211 # The super-class (indicated as a type)
1212 var n_type: AType is writable, noinit
1213 end
1214
1215
1216 # Declaration of callbacks for extern methods
1217 class AExternCalls
1218 super Prod
1219
1220 # The `import` keyword
1221 var n_kwimport: TKwimport is writable, noinit
1222
1223 # The list of declared callbacks
1224 var n_extern_calls: ANodes[AExternCall] = new ANodes[AExternCall](self)
1225 end
1226
1227 # A single callback declaration
1228 abstract class AExternCall
1229 super Prod
1230 end
1231
1232 # A single callback declaration on a method
1233 abstract class APropExternCall
1234 super AExternCall
1235 end
1236
1237 # A single callback declaration on a method on the current receiver
1238 class ALocalPropExternCall
1239 super APropExternCall
1240
1241 # The name of the called-back method
1242 var n_methid: AMethid is writable, noinit
1243 end
1244
1245 # A single callback declaration on a method on an explicit receiver type.
1246 class AFullPropExternCall
1247 super APropExternCall
1248
1249 # The type of the receiver of the called-back method
1250 var n_type: AType is writable, noinit
1251
1252 # The dot `.`
1253 var n_dot: nullable TDot = null is writable
1254
1255 # The name of the called-back method
1256 var n_methid: AMethid is writable, noinit
1257 end
1258
1259 # A single callback declaration on a method on a constructor
1260 class AInitPropExternCall
1261 super APropExternCall
1262
1263 # The allocated type
1264 var n_type: AType is writable, noinit
1265 end
1266
1267 # A single callback declaration on a `super` call
1268 class ASuperExternCall
1269 super AExternCall
1270
1271 # The `super` keyword
1272 var n_kwsuper: TKwsuper is writable, noinit
1273 end
1274
1275 # A single callback declaration on a cast
1276 abstract class ACastExternCall
1277 super AExternCall
1278 end
1279
1280 # A single callback declaration on a cast to a given type
1281 class ACastAsExternCall
1282 super ACastExternCall
1283
1284 # The origin type of the cast
1285 var n_from_type: AType is writable, noinit
1286
1287 # The dot (`.`)
1288 var n_dot: nullable TDot = null is writable
1289
1290 # The `as` keyword
1291 var n_kwas: TKwas is writable, noinit
1292
1293 # The destination of the cast
1294 var n_to_type: AType is writable, noinit
1295 end
1296
1297 # A single callback declaration on a cast to a nullable type
1298 class AAsNullableExternCall
1299 super ACastExternCall
1300
1301 # The origin type to cast as nullable
1302 var n_type: AType is writable, noinit
1303
1304 # The `as` keyword
1305 var n_kwas: TKwas is writable, noinit
1306
1307 # The `nullable` keyword
1308 var n_kwnullable: TKwnullable is writable, noinit
1309 end
1310
1311 # A single callback declaration on a cast to a non-nullable type
1312 class AAsNotNullableExternCall
1313 super ACastExternCall
1314
1315 # The destination type on a cast to not nullable
1316 var n_type: AType is writable, noinit
1317
1318 # The `as` keyword.
1319 var n_kwas: TKwas is writable, noinit
1320
1321 # The `not` keyword
1322 var n_kwnot: TKwnot is writable, noinit
1323
1324 # The `nullable` keyword
1325 var n_kwnullable: TKwnullable is writable, noinit
1326 end
1327
1328 # A definition of a virtual type
1329 class ATypePropdef
1330 super APropdef
1331
1332 # The `type` keyword
1333 var n_kwtype: TKwtype is writable, noinit
1334
1335 # The name of the virtual type
1336 var n_id: TClassid is writable, noinit
1337
1338 # The bound of the virtual type
1339 var n_type: AType is writable, noinit
1340 end
1341
1342 # The identifier of a method in a method declaration.
1343 # There is a specific class because of operator and setters.
1344 abstract class AMethid
1345 super Prod
1346 end
1347
1348 # A method name with a simple identifier
1349 class AIdMethid
1350 super AMethid
1351
1352 # The simple identifier
1353 var n_id: TId is writable, noinit
1354 end
1355
1356 # A method name `+`
1357 class APlusMethid
1358 super AMethid
1359
1360 # The `+` symbol
1361 var n_plus: TPlus is writable, noinit
1362 end
1363
1364 # A method name `-`
1365 class AMinusMethid
1366 super AMethid
1367
1368 # The `-` symbol
1369 var n_minus: TMinus is writable, noinit
1370 end
1371
1372 # A method name `*`
1373 class AStarMethid
1374 super AMethid
1375
1376 # The `*` symbol
1377 var n_star: TStar is writable, noinit
1378 end
1379
1380 # A method name `**`
1381 class AStarstarMethid
1382 super AMethid
1383
1384 # The `**` symbol
1385 var n_starstar: TStarstar is writable, noinit
1386 end
1387
1388 # A method name `/`
1389 class ASlashMethid
1390 super AMethid
1391
1392 # The `/` symbol
1393 var n_slash: TSlash is writable, noinit
1394 end
1395
1396 # A method name `%`
1397 class APercentMethid
1398 super AMethid
1399
1400 # The `%` symbol
1401 var n_percent: TPercent is writable, noinit
1402 end
1403
1404 # A method name `==`
1405 class AEqMethid
1406 super AMethid
1407
1408 # The `==` symbol
1409 var n_eq: TEq is writable, noinit
1410 end
1411
1412 # A method name `!=`
1413 class ANeMethid
1414 super AMethid
1415
1416 # The `!=` symbol
1417 var n_ne: TNe is writable, noinit
1418 end
1419
1420 # A method name `<=`
1421 class ALeMethid
1422 super AMethid
1423
1424 # The `<=` symbol
1425 var n_le: TLe is writable, noinit
1426 end
1427
1428 # A method name `>=`
1429 class AGeMethid
1430 super AMethid
1431
1432 # The `>=` symbol
1433 var n_ge: TGe is writable, noinit
1434 end
1435
1436 # A method name `<`
1437 class ALtMethid
1438 super AMethid
1439
1440 # The `<` symbol
1441 var n_lt: TLt is writable, noinit
1442 end
1443
1444 # A method name `>`
1445 class AGtMethid
1446 super AMethid
1447
1448 # The `>` symbol
1449 var n_gt: TGt is writable, noinit
1450 end
1451
1452 # A method name `<<`
1453 class ALlMethid
1454 super AMethid
1455
1456 # The `<<` symbol
1457 var n_ll: TLl is writable, noinit
1458 end
1459
1460 # A method name `>>`
1461 class AGgMethid
1462 super AMethid
1463
1464 # The `>>` symbol
1465 var n_gg: TGg is writable, noinit
1466 end
1467
1468 # A method name `[]`
1469 class ABraMethid
1470 super AMethid
1471
1472 # The `[` symbol
1473 var n_obra: TObra is writable, noinit
1474
1475 # The `]` symbol
1476 var n_cbra: TCbra is writable, noinit
1477 end
1478
1479 # A method name `<=>`
1480 class AStarshipMethid
1481 super AMethid
1482
1483 # The `<=>` symbol
1484 var n_starship: TStarship is writable, noinit
1485 end
1486
1487 # A setter method name with a simple identifier (with a `=`)
1488 class AAssignMethid
1489 super AMethid
1490
1491 # The base identifier
1492 var n_id: TId is writable, noinit
1493
1494 # The `=` symbol
1495 var n_assign: TAssign is writable, noinit
1496 end
1497
1498 # A method name `[]=`
1499 class ABraassignMethid
1500 super AMethid
1501
1502 # The `[` symbol
1503 var n_obra: TObra is writable, noinit
1504
1505 # The `]` symbol
1506 var n_cbra: TCbra is writable, noinit
1507
1508 # The `=` symbol
1509 var n_assign: TAssign is writable, noinit
1510 end
1511
1512 # A signature in a method definition. eg `(x,y:X,z:Z):T`
1513 class ASignature
1514 super Prod
1515
1516 # The `(` symbol
1517 var n_opar: nullable TOpar = null is writable
1518
1519 # The list of parameters
1520 var n_params = new ANodes[AParam](self)
1521
1522 # The `)` symbol
1523 var n_cpar: nullable TCpar = null is writable
1524
1525 # The return type
1526 var n_type: nullable AType = null is writable
1527 end
1528
1529 # A parameter definition in a signature. eg `x:X`
1530 class AParam
1531 super Prod
1532
1533 # The name of the parameter
1534 var n_id: TId is writable, noinit
1535
1536 # The type of the parameter, if any
1537 var n_type: nullable AType = null is writable
1538
1539 # The `...` symbol to indicate varargs
1540 var n_dotdotdot: nullable TDotdotdot = null is writable
1541 end
1542
1543 # A static type. eg `nullable X[Y]`
1544 class AType
1545 super Prod
1546 # The `nullable` keyword
1547 var n_kwnullable: nullable TKwnullable = null is writable
1548
1549 # The name of the class or of the formal type
1550 var n_id: TClassid is writable, noinit
1551
1552 # Type arguments for a generic type
1553 var n_types = new ANodes[AType](self)
1554 end
1555
1556 # A label at the end of a block or in a break/continue statement. eg `label x`
1557 class ALabel
1558 super Prod
1559
1560 # The `label` keyword
1561 var n_kwlabel: TKwlabel is writable, noinit
1562
1563 # The name of the label, if any
1564 var n_id: nullable TId is writable
1565 end
1566
1567 # Expression and statements
1568 # From a AST point of view there is no distinction between statement and expressions (even if the parser has to distinguish them)
1569 abstract class AExpr
1570 super Prod
1571 end
1572
1573 # A sequence of `AExpr` (usually statements)
1574 # The last `AExpr` gives the value of the whole block
1575 class ABlockExpr
1576 super AExpr
1577
1578 # The list of statements in the bloc.
1579 # The last element is often considered as an expression that give the value of the whole block.
1580 var n_expr = new ANodes[AExpr](self)
1581
1582 # The `end` keyword
1583 var n_kwend: nullable TKwend = null is writable
1584 end
1585
1586 # A declaration of a local variable. eg `var x: X = y`
1587 class AVardeclExpr
1588 super AExpr
1589
1590 # The `var` keyword
1591 var n_kwvar: TKwvar is writable, noinit
1592
1593 # The name of the local variable
1594 var n_id: TId is writable, noinit
1595
1596 # The declaration type of the local variable
1597 var n_type: nullable AType = null is writable
1598
1599 # The `=` symbol (for the initial value)
1600 var n_assign: nullable TAssign = null is writable
1601
1602 # The initial value, if any
1603 var n_expr: nullable AExpr = null is writable
1604 end
1605
1606 # A `return` statement. eg `return x`
1607 class AReturnExpr
1608 super AExpr
1609
1610 # The `return` keyword
1611 var n_kwreturn: nullable TKwreturn = null is writable
1612
1613 # The return value, if any
1614 var n_expr: nullable AExpr = null is writable
1615 end
1616
1617 # Something that has a label.
1618 abstract class ALabelable
1619 super Prod
1620
1621 # The associated label declatation
1622 var n_label: nullable ALabel = null is writable
1623 end
1624
1625 # A `break` or a `continue`
1626 abstract class AEscapeExpr
1627 super AExpr
1628 super ALabelable
1629
1630 # The return value, if nay (unused currently)
1631 var n_expr: nullable AExpr = null is writable
1632 end
1633
1634 # A `break` statement.
1635 class ABreakExpr
1636 super AEscapeExpr
1637
1638 # The `break` keyword
1639 var n_kwbreak: TKwbreak is writable, noinit
1640 end
1641
1642 # An `abort` statement
1643 class AAbortExpr
1644 super AExpr
1645
1646 # The `abort` keyword
1647 var n_kwabort: TKwabort is writable, noinit
1648 end
1649
1650 # A `continue` statement
1651 class AContinueExpr
1652 super AEscapeExpr
1653
1654 # The `continue` keyword.
1655 var n_kwcontinue: nullable TKwcontinue = null is writable
1656 end
1657
1658 # A `do` statement
1659 class ADoExpr
1660 super AExpr
1661 super ALabelable
1662
1663 # The `do` keyword
1664 var n_kwdo: TKwdo is writable, noinit
1665
1666 # The list of statements of the `do`.
1667 var n_block: nullable AExpr = null is writable
1668 end
1669
1670 # A `if` statement
1671 class AIfExpr
1672 super AExpr
1673
1674 # The `if` keyword
1675 var n_kwif: TKwif is writable, noinit
1676
1677 # The expression used as the condition of the `if`
1678 var n_expr: AExpr is writable, noinit
1679
1680 # The body of the `then` part
1681 var n_then: nullable AExpr = null is writable
1682
1683 # The body of the `else` part
1684 var n_else: nullable AExpr = null is writable
1685 end
1686
1687 # A `if` expression (ternary conditional). eg. `if true then 1 else 0`
1688 class AIfexprExpr
1689 super AExpr
1690
1691 # The `if` keyword
1692 var n_kwif: TKwif is writable, noinit
1693
1694 # The expression used as the condition of the `if`
1695 var n_expr: AExpr is writable, noinit
1696
1697 # The `then` keyword
1698 var n_kwthen: TKwthen is writable, noinit
1699
1700 # The expression in the `then` part
1701 var n_then: AExpr is writable, noinit
1702
1703 # The `else` keyword
1704 var n_kwelse: TKwelse is writable, noinit
1705
1706 # The expression in the `else` part
1707 var n_else: AExpr is writable, noinit
1708 end
1709
1710 # A `while` statement
1711 class AWhileExpr
1712 super AExpr
1713 super ALabelable
1714
1715 # The `while` keyword
1716 var n_kwwhile: TKwwhile is writable, noinit
1717
1718 # The expression used as the condition of the `while`
1719 var n_expr: AExpr is writable, noinit
1720
1721 # The `do` keyword
1722 var n_kwdo: TKwdo is writable, noinit
1723
1724 # The body of the loop
1725 var n_block: nullable AExpr = null is writable
1726 end
1727
1728 # A `loop` statement
1729 class ALoopExpr
1730 super AExpr
1731 super ALabelable
1732
1733 # The `loop` keyword
1734 var n_kwloop: TKwloop is writable, noinit
1735
1736 # The body of the loop
1737 var n_block: nullable AExpr = null is writable
1738 end
1739
1740 # A `for` statement
1741 class AForExpr
1742 super AExpr
1743 super ALabelable
1744
1745 # The `for` keyword
1746 var n_kwfor: TKwfor is writable, noinit
1747
1748 # The list of name of the automatic variables
1749 var n_ids = new ANodes[TId](self)
1750
1751 # The expression used as the collection to iterate on
1752 var n_expr: AExpr is writable, noinit
1753
1754 # The `do` keyword
1755 var n_kwdo: TKwdo is writable, noinit
1756
1757 # The body of the loop
1758 var n_block: nullable AExpr = null is writable
1759 end
1760
1761 # An `assert` statement
1762 class AAssertExpr
1763 super AExpr
1764
1765 # The `assert` keyword
1766 var n_kwassert: TKwassert is writable, noinit
1767
1768 # The name of the assert, if any
1769 var n_id: nullable TId = null is writable
1770
1771 # The expression used as the condition of the `assert`
1772 var n_expr: AExpr is writable, noinit
1773
1774 # The body to execute when the assert fails
1775 var n_else: nullable AExpr = null is writable
1776 end
1777
1778 # Whatever is a simple assignment. eg `= something`
1779 abstract class AAssignFormExpr
1780 super AExpr
1781
1782 # The `=` symbol
1783 var n_assign: TAssign is writable, noinit
1784
1785 # The right-value to assign.
1786 var n_value: AExpr is writable, noinit
1787 end
1788
1789 # Whatever is a combined assignment. eg `+= something`
1790 abstract class AReassignFormExpr
1791 super AExpr
1792
1793 # The combined operator (eg. `+=`)
1794 var n_assign_op: AAssignOp is writable, noinit
1795
1796 # The right-value to apply on the combined operator.
1797 var n_value: AExpr is writable, noinit
1798 end
1799
1800 # A `once` expression. eg `once x`
1801 class AOnceExpr
1802 super AExpr
1803
1804 # The `once` keyword
1805 var n_kwonce: TKwonce is writable, noinit
1806
1807 # The expression to evaluate only one time
1808 var n_expr: AExpr is writable, noinit
1809 end
1810
1811 # A polymorphic invocation of a method
1812 # The form of the invocation (name, arguments, etc.) are specific
1813 abstract class ASendExpr
1814 super AExpr
1815 # The receiver of the method invocation
1816 var n_expr: AExpr is writable, noinit
1817 end
1818
1819 # A binary operation on a method
1820 abstract class ABinopExpr
1821 super ASendExpr
1822 # The second operand of the operation
1823 # Note: the receiver (`n_expr`) is the first operand
1824 var n_expr2: AExpr is writable, noinit
1825 end
1826
1827 # Something that is boolean expression
1828 abstract class ABoolExpr
1829 super AExpr
1830 end
1831
1832 # Something that is binary boolean expression
1833 abstract class ABinBoolExpr
1834 super ABoolExpr
1835
1836 # The first boolean operand
1837 var n_expr: AExpr is writable, noinit
1838
1839 # The second boolean operand
1840 var n_expr2: AExpr is writable, noinit
1841 end
1842
1843 # A `or` expression
1844 class AOrExpr
1845 super ABinBoolExpr
1846 end
1847
1848 # A `and` expression
1849 class AAndExpr
1850 super ABinBoolExpr
1851 end
1852
1853 # A `or else` expression
1854 class AOrElseExpr
1855 super ABinBoolExpr
1856 end
1857
1858 # A `implies` expression
1859 class AImpliesExpr
1860 super ABinBoolExpr
1861 end
1862
1863 # A `not` expression
1864 class ANotExpr
1865 super ABoolExpr
1866
1867 # The `not` keyword
1868 var n_kwnot: TKwnot is writable, noinit
1869
1870 # The boolean operand of the `not`
1871 var n_expr: AExpr is writable, noinit
1872 end
1873
1874 # A `==` expression
1875 class AEqExpr
1876 super ABinopExpr
1877 end
1878
1879 # A `!=` expression
1880 class ANeExpr
1881 super ABinopExpr
1882 end
1883
1884 # A `<` expression
1885 class ALtExpr
1886 super ABinopExpr
1887 end
1888
1889 # A `<=` expression
1890 class ALeExpr
1891 super ABinopExpr
1892 end
1893
1894 # A `<<` expression
1895 class ALlExpr
1896 super ABinopExpr
1897 end
1898
1899 # A `>` expression
1900 class AGtExpr
1901 super ABinopExpr
1902 end
1903
1904 # A `>=` expression
1905 class AGeExpr
1906 super ABinopExpr
1907 end
1908
1909 # A `>>` expression
1910 class AGgExpr
1911 super ABinopExpr
1912 end
1913
1914 # A type-ckeck expression. eg `x isa T`
1915 class AIsaExpr
1916 super ABoolExpr
1917
1918 # The expression to check
1919 var n_expr: AExpr is writable, noinit
1920
1921 # The destination type to check to
1922 var n_type: AType is writable, noinit
1923 end
1924
1925 # A `+` expression
1926 class APlusExpr
1927 super ABinopExpr
1928 end
1929
1930 # A `-` expression
1931 class AMinusExpr
1932 super ABinopExpr
1933 end
1934
1935 # A `<=>` expression
1936 class AStarshipExpr
1937 super ABinopExpr
1938 end
1939
1940 # A `*` expression
1941 class AStarExpr
1942 super ABinopExpr
1943 end
1944
1945 # A `**` expression
1946 class AStarstarExpr
1947 super ABinopExpr
1948 end
1949
1950 # A `/` expression
1951 class ASlashExpr
1952 super ABinopExpr
1953 end
1954
1955 # A `%` expression
1956 class APercentExpr
1957 super ABinopExpr
1958 end
1959
1960 # A unary minus expression. eg `-x`
1961 class AUminusExpr
1962 super ASendExpr
1963
1964 # The `-` symbol
1965 var n_minus: TMinus is writable, noinit
1966 end
1967
1968 # An explicit instantiation. eg `new T`
1969 class ANewExpr
1970 super AExpr
1971
1972 # The `new` keyword
1973 var n_kwnew: TKwnew is writable, noinit
1974
1975 # The `type` keyword
1976 var n_type: AType is writable, noinit
1977
1978 # The name of the named-constructor, if any
1979 var n_id: nullable TId = null is writable
1980
1981 # The arguments of the `new`
1982 var n_args: AExprs is writable, noinit
1983 end
1984
1985 # Whatever is a old-style attribute access
1986 abstract class AAttrFormExpr
1987 super AExpr
1988
1989 # The receiver of the attribute
1990 var n_expr: AExpr is writable, noinit
1991
1992 # The name of the attribute
1993 var n_id: TAttrid is writable, noinit
1994
1995 end
1996
1997 # The read of an attribute. eg `x._a`
1998 class AAttrExpr
1999 super AAttrFormExpr
2000 end
2001
2002 # The assignment of an attribute. eg `x._a=y`
2003 class AAttrAssignExpr
2004 super AAttrFormExpr
2005 super AAssignFormExpr
2006 end
2007
2008 # Whatever looks-like a call with a standard method and any number of arguments.
2009 abstract class ACallFormExpr
2010 super ASendExpr
2011
2012 # The name of the method
2013 var n_id: TId is writable, noinit
2014
2015 # The arguments of the call
2016 var n_args: AExprs is writable, noinit
2017 end
2018
2019 # A complex setter call (standard or brackets)
2020 abstract class ASendReassignFormExpr
2021 super ASendExpr
2022 super AReassignFormExpr
2023 end
2024
2025 # A complex attribute assignment. eg `x._a+=y`
2026 class AAttrReassignExpr
2027 super AAttrFormExpr
2028 super AReassignFormExpr
2029 end
2030
2031 # A call with a standard method-name and any number of arguments. eg `x.m(y)`. OR just a simple id
2032 # 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`.
2033 # Semantic analysis have to transform them to instance of `AVarExpr`.
2034 class ACallExpr
2035 super ACallFormExpr
2036 end
2037
2038 # A setter call with a standard method-name and any number of arguments. eg `x.m(y)=z`. OR just a simple assignment.
2039 # 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`.
2040 # Semantic analysis have to transform them to instance of `AVarAssignExpr`.
2041 class ACallAssignExpr
2042 super ACallFormExpr
2043 super AAssignFormExpr
2044 end
2045
2046 # 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.
2047 # 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`.
2048 # Semantic analysis have to transform them to instance of `AVarReassignExpr`.
2049 class ACallReassignExpr
2050 super ACallFormExpr
2051 super ASendReassignFormExpr
2052 end
2053
2054 # A call to `super`. OR a call of a super-constructor
2055 class ASuperExpr
2056 super AExpr
2057
2058 # The qualifier part before the super (currenlty unused)
2059 var n_qualified: nullable AQualified = null is writable
2060
2061 # The `super` keyword
2062 var n_kwsuper: TKwsuper is writable, noinit
2063
2064 # The arguments of the super
2065 var n_args: AExprs is writable, noinit
2066 end
2067
2068 # A call to the `init` constructor.
2069 # Note: because `init` is a keyword and not a `TId`, the explicit call to init cannot be a `ACallFormExpr`.
2070 class AInitExpr
2071 super ASendExpr
2072
2073 # The `init` keyword
2074 var n_kwinit: TKwinit is writable, noinit
2075
2076 # The arguments of the init
2077 var n_args: AExprs is writable, noinit
2078 end
2079
2080 # Whatever looks-like a call of the brackets `[]` operator.
2081 abstract class ABraFormExpr
2082 super ASendExpr
2083
2084 # The arguments inside the brackets
2085 var n_args: AExprs is writable, noinit
2086 end
2087
2088 # A call of the brackets operator. eg `x[y,z]`
2089 class ABraExpr
2090 super ABraFormExpr
2091 end
2092
2093 # A setter call of the bracket operator. eg `x[y,z]=t`
2094 class ABraAssignExpr
2095 super ABraFormExpr
2096 super AAssignFormExpr
2097 end
2098
2099 # Whatever is an access to a local variable
2100 abstract class AVarFormExpr
2101 super AExpr
2102
2103 # The name of the attribute
2104 var n_id: TId is writable, noinit
2105 end
2106
2107 # A complex setter call of the bracket operator. eg `x[y,z]+=t`
2108 class ABraReassignExpr
2109 super ABraFormExpr
2110 super ASendReassignFormExpr
2111 end
2112
2113 # A local variable read access.
2114 # The parser cannot instantiate them, see `ACallExpr`.
2115 class AVarExpr
2116 super AVarFormExpr
2117 end
2118
2119 # A local variable simple assignment access
2120 # The parser cannot instantiate them, see `ACallAssignExpr`.
2121 class AVarAssignExpr
2122 super AVarFormExpr
2123 super AAssignFormExpr
2124 end
2125
2126 # A local variable complex assignment access
2127 # The parser cannot instantiate them, see `ACallReassignExpr`.
2128 class AVarReassignExpr
2129 super AVarFormExpr
2130 super AReassignFormExpr
2131 end
2132
2133 # A literal range, open or closed
2134 abstract class ARangeExpr
2135 super AExpr
2136
2137 # The left (lower) element of the range
2138 var n_expr: AExpr is writable, noinit
2139
2140 # The right (uppr) element of the range
2141 var n_expr2: AExpr is writable, noinit
2142 end
2143
2144 # A closed literal range. eg `[x..y]`
2145 class ACrangeExpr
2146 super ARangeExpr
2147
2148 # The opening bracket `[`
2149 var n_obra: TObra is writable, noinit
2150
2151 # The closing bracket `]`
2152 var n_cbra: TCbra is writable, noinit
2153 end
2154
2155 # An open literal range. eg `[x..y[`
2156 class AOrangeExpr
2157 super ARangeExpr
2158
2159 # The opening bracket `[`
2160 var n_obra: TObra is writable, noinit
2161
2162 # The closing bracket `[` (because open range)
2163 var n_cbra: TObra is writable, noinit
2164 end
2165
2166 # A literal array. eg. `[x,y,z]`
2167 class AArrayExpr
2168 super AExpr
2169
2170 # The opening bracket `[`
2171 var n_obra: TObra is writable, noinit
2172
2173 # The elements of the array
2174 var n_exprs = new ANodes[AExpr](self)
2175
2176 # The type of the element of the array (if any)
2177 var n_type: nullable AType = null is writable
2178
2179 # The closing bracket `]`
2180 var n_cbra: TCbra is writable, noinit
2181 end
2182
2183 # A read of `self`
2184 class ASelfExpr
2185 super AExpr
2186
2187 # The `self` keyword
2188 var n_kwself: nullable TKwself is writable
2189 end
2190
2191 # When there is no explicit receiver, `self` is implicit
2192 class AImplicitSelfExpr
2193 super ASelfExpr
2194 end
2195
2196 # A `true` boolean literal constant
2197 class ATrueExpr
2198 super ABoolExpr
2199
2200 # The `true` keyword
2201 var n_kwtrue: TKwtrue is writable, noinit
2202 end
2203
2204 # A `false` boolean literal constant
2205 class AFalseExpr
2206 super ABoolExpr
2207
2208 # The `false` keyword
2209 var n_kwfalse: TKwfalse is writable, noinit
2210 end
2211
2212 # A `null` literal constant
2213 class ANullExpr
2214 super AExpr
2215
2216 # The `null` keyword
2217 var n_kwnull: TKwnull is writable, noinit
2218 end
2219
2220 # An integer literal
2221 class AIntExpr
2222 super AExpr
2223 end
2224
2225 # An integer literal in decimal format
2226 class ADecIntExpr
2227 super AIntExpr
2228
2229 # The decimal token
2230 var n_number: TNumber is writable, noinit
2231 end
2232
2233 # An integer literal in hexadecimal format
2234 class AHexIntExpr
2235 super AIntExpr
2236
2237 # The hexadecimal token
2238 var n_hex_number: THexNumber is writable, noinit
2239 end
2240
2241 # A float literal
2242 class AFloatExpr
2243 super AExpr
2244
2245 # The float token
2246 var n_float: TFloat is writable, noinit
2247 end
2248
2249 # A character literal
2250 class ACharExpr
2251 super AExpr
2252
2253 # The character token
2254 var n_char: TChar is writable, noinit
2255 end
2256
2257 # A string literal
2258 abstract class AStringFormExpr
2259 super AExpr
2260
2261 # The string token
2262 var n_string: Token is writable, noinit
2263 end
2264
2265 # A simple string. eg. `"abc"`
2266 class AStringExpr
2267 super AStringFormExpr
2268 end
2269
2270 # The start of a superstring. eg `"abc{`
2271 class AStartStringExpr
2272 super AStringFormExpr
2273 end
2274
2275 # The middle of a superstring. eg `}abc{`
2276 class AMidStringExpr
2277 super AStringFormExpr
2278 end
2279
2280 # The end of a superstrng. eg `}abc"`
2281 class AEndStringExpr
2282 super AStringFormExpr
2283 end
2284
2285 # A superstring literal. eg `"a{x}b{y}c"`
2286 # Each part is modeled a sequence of expression. eg. `["a{, x, }b{, y, }c"]`
2287 class ASuperstringExpr
2288 super AExpr
2289
2290 # The list of the expressions of the superstring
2291 var n_exprs = new ANodes[AExpr](self)
2292 end
2293
2294 # A simple parenthesis. eg `(x)`
2295 class AParExpr
2296 super AExpr
2297
2298 # The opening parenthesis
2299 var n_opar: TOpar is writable, noinit
2300
2301 # The inner expression
2302 var n_expr: AExpr is writable, noinit
2303
2304 # The closing parenthesis
2305 var n_cpar: TCpar is writable, noinit
2306 end
2307
2308 # A cast, against a type or `not null`
2309 class AAsCastForm
2310 super AExpr
2311
2312 # The expression to cast
2313 var n_expr: AExpr is writable, noinit
2314
2315 # The `as` keyword
2316 var n_kwas: TKwas is writable, noinit
2317
2318 # The opening parenthesis
2319 var n_opar: nullable TOpar = null is writable
2320
2321 # The closing parenthesis
2322 var n_cpar: nullable TCpar = null is writable
2323 end
2324
2325 # A type cast. eg `x.as(T)`
2326 class AAsCastExpr
2327 super AAsCastForm
2328
2329 # The target type to cast to
2330 var n_type: AType is writable, noinit
2331 end
2332
2333 # A as-not-null cast. eg `x.as(not null)`
2334 class AAsNotnullExpr
2335 super AAsCastForm
2336
2337 # The `not` keyword
2338 var n_kwnot: TKwnot is writable, noinit
2339
2340 # The `null` keyword
2341 var n_kwnull: TKwnull is writable, noinit
2342 end
2343
2344 # A is-set check of old-style attributes. eg `isset x._a`
2345 class AIssetAttrExpr
2346 super AAttrFormExpr
2347
2348 # The `isset` keyword
2349 var n_kwisset: TKwisset is writable, noinit
2350 end
2351
2352 # An ellipsis notation used to pass an expression as it, in a vararg parameter
2353 class AVarargExpr
2354 super AExpr
2355
2356 # The passed expression
2357 var n_expr: AExpr is writable, noinit
2358
2359 # The `...` symbol
2360 var n_dotdotdot: TDotdotdot is writable, noinit
2361 end
2362
2363 # A list of expression separated with commas (arguments for instance)
2364 class AManyExpr
2365 super AExpr
2366
2367 # The list of expressions
2368 var n_exprs = new ANodes[AExpr](self)
2369 end
2370
2371 # A special expression that encapsulates a static type
2372 # Can only be found in special construction like arguments of annotations.
2373 class ATypeExpr
2374 super AExpr
2375
2376 # The encapsulated type
2377 var n_type: AType is writable, noinit
2378 end
2379
2380 # A special expression that encapsulates a method identifier
2381 # Can only be found in special construction like arguments of annotations.
2382 class AMethidExpr
2383 super AExpr
2384
2385 # The receiver
2386 var n_expr: AExpr is writable, noinit
2387
2388 # The encapsulated method identifier
2389 var n_id: AMethid is writable, noinit
2390 end
2391
2392 # A special expression that encapsulate an annotation
2393 # Can only be found in special construction like arguments of annotations.
2394 #
2395 # The encapsulated annotations are in `n_annotations`
2396 class AAtExpr
2397 super AExpr
2398 end
2399
2400 # A special expression to debug types
2401 class ADebugTypeExpr
2402 super AExpr
2403
2404 # The `debug` keyword
2405 var n_kwdebug: TKwdebug is writable, noinit
2406
2407 # The `type` keyword
2408 var n_kwtype: TKwtype is writable, noinit
2409
2410 # The expression to check
2411 var n_expr: AExpr is writable, noinit
2412
2413 # The type to check
2414 var n_type: AType is writable, noinit
2415 end
2416
2417 # A list of expression separated with commas (arguments for instance)
2418 abstract class AExprs
2419 super Prod
2420
2421 # The list of expressions
2422 var n_exprs = new ANodes[AExpr](self)
2423 end
2424
2425 # A simple list of expressions
2426 class AListExprs
2427 super AExprs
2428 end
2429
2430 # A list of expressions enclosed in parentheses
2431 class AParExprs
2432 super AExprs
2433
2434 # The opening parenthesis
2435 var n_opar: TOpar is writable, noinit
2436
2437 # The closing parenthesis
2438 var n_cpar: TCpar is writable, noinit
2439 end
2440
2441 # A list of expressions enclosed in brackets
2442 class ABraExprs
2443 super AExprs
2444
2445 # The opening bracket
2446 var n_obra: TObra is writable, noinit
2447
2448 # The closing bracket
2449 var n_cbra: TCbra is writable, noinit
2450 end
2451
2452 # A complex assignment operator. (`+=` and `-=`)
2453 abstract class AAssignOp
2454 super Prod
2455 end
2456
2457 # The `+=` assignment operation
2458 class APlusAssignOp
2459 super AAssignOp
2460
2461 # The `+=` operator
2462 var n_pluseq: TPluseq is writable, noinit
2463 end
2464
2465 # The `-=` assignment operator
2466 class AMinusAssignOp
2467 super AAssignOp
2468
2469 # The `-=` operator
2470 var n_minuseq: TMinuseq is writable, noinit
2471 end
2472
2473 # A possibly fully-qualified module identifier
2474 class AModuleName
2475 super Prod
2476
2477 # The starting quad (`::`)
2478 var n_quad: nullable TQuad = null is writable
2479
2480 # The list of quad-separated project/group identifiers
2481 var n_path = new ANodes[TId](self)
2482
2483 # The final module identifier
2484 var n_id: TId is writable, noinit
2485 end
2486
2487 # A language declaration for an extern block
2488 class AInLanguage
2489 super Prod
2490
2491 # The `in` keyword
2492 var n_kwin: TKwin is writable, noinit
2493
2494 # The language name
2495 var n_string: TString is writable, noinit
2496 end
2497
2498 # An full extern block
2499 class AExternCodeBlock
2500 super Prod
2501
2502 # The language declration
2503 var n_in_language: nullable AInLanguage = null is writable
2504
2505 # The block of extern code
2506 var n_extern_code_segment: TExternCodeSegment is writable, noinit
2507 end
2508
2509 # A possible full method qualifier.
2510 class AQualified
2511 super Prod
2512
2513 # The starting quad (`::`)
2514 var n_quad: nullable TQuad = null is writable
2515
2516 # The list of quad-separated project/group/module identifiers
2517 var n_id = new ANodes[TId](self)
2518
2519 # A class identifier
2520 var n_classid: nullable TClassid = null is writable
2521 end
2522
2523 # A documentation of a definition
2524 # It contains the block of comments just above the declaration
2525 class ADoc
2526 super Prod
2527
2528 # A list of lines of comment
2529 var n_comment = new ANodes[TComment](self)
2530 end
2531
2532 # A group of annotation on a node
2533 #
2534 # This same class is used for the 3 kind of annotations:
2535 #
2536 # * *is* annotations. eg `module foo is bar`.
2537 # * *at* annotations. eg `foo@bar` or `foo@(bar,baz)`.
2538 # * *class* annotations, defined in classes.
2539 class AAnnotations
2540 super Prod
2541
2542 # The `@` symbol, for *at* annotations
2543 var n_at: nullable TAt = null is writable
2544
2545 # The opening parenthesis in *at* annotations
2546 var n_opar: nullable TOpar = null is writable
2547
2548 # The list of annotations
2549 var n_items = new ANodes[AAnnotation](self)
2550
2551 # The closing parenthesis in *at* annotations
2552 var n_cpar: nullable TCpar = null is writable
2553 end
2554
2555 # A single annotation
2556 class AAnnotation
2557 super ADefinition
2558
2559 # The name of the annotation
2560 var n_atid: AAtid is writable, noinit
2561
2562 # The opening parenthesis of the arguments
2563 var n_opar: nullable TOpar = null is writable
2564
2565 # The list of arguments
2566 var n_args = new ANodes[AExpr](self)
2567
2568 # The closing parenthesis
2569 var n_cpar: nullable TCpar = null is writable
2570
2571 # The name of the annotation
2572 fun name: String
2573 do
2574 return n_atid.n_id.text
2575 end
2576 end
2577
2578 # An annotation name
2579 abstract class AAtid
2580 super Prod
2581
2582 # The identifier of the annotation.
2583 # Can be a TId of a keyword
2584 var n_id: Token is writable, noinit
2585 end
2586
2587 # An annotation name based on an identifier
2588 class AIdAtid
2589 super AAtid
2590 end
2591
2592 # An annotation name based on the keyword `extern`
2593 class AKwexternAtid
2594 super AAtid
2595 end
2596
2597 # An annotation name based on the keyword `import`
2598 class AKwimportAtid
2599 super AAtid
2600 end
2601
2602 # An annotation name based on the keyword `abstract`
2603 class AKwabstractAtid
2604 super AAtid
2605 end
2606
2607 # The root of the AST
2608 class Start
2609 super Prod
2610
2611 # The main module
2612 var n_base: nullable AModule is writable
2613
2614 # The end of file (or error) token
2615 var n_eof: EOF is writable
2616 end