src: remove remaining references of subclasses on AMethPropdef
[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 var _location: nullable Location = null
24
25 # Location is set during AST building. Once built, location cannon be null.
26 # However, manual instantiated nodes may need more care.
27 fun location: Location do return _location.as(not null)
28
29 # The location of the important part of the node (identifier or whatever)
30 fun hot_location: Location do return location
31
32 # Display a message for the colored location of the node
33 fun debug(message: String)
34 do
35 print "{hot_location} {self.class_name}: {message}\n{hot_location.colored_line("0;32")}"
36 end
37
38 # Parent of the node in the AST
39 var parent: nullable ANode = null
40
41 # Protect form invalid instantiation of nodes
42 private init do end
43
44 # Replace a child with an other node in the AST
45 private fun replace_child(old_child: ANode, new_child: nullable ANode) is abstract
46
47 # Detach a node from its parent
48 # Aborts if the node is not detashable. use `replace_with` instead
49 # REQUIRE: parent != null
50 # REQUIRE: is_detachable
51 # ENDURE: parent == null
52 fun detach
53 do
54 assert parent != null
55 parent.replace_child(self, null)
56 parent = null
57 end
58
59 # Replace itself with an other node in the AST
60 # REQUIRE: parent != null
61 # ENSURE: node.parent == old(parent)
62 # ENSURE: parent == null
63 fun replace_with(node: ANode)
64 do
65 assert parent != null
66 parent.replace_child(self, node)
67 parent = null
68 end
69
70 # Visit all nodes in order.
71 # Thus, call `v.enter_visit(e)` for each child `e`
72 fun visit_all(v: Visitor) is abstract
73 end
74
75 # A sequence of nodes
76 # There is a specifc class (instead of a using Array) to track the parent/child relation when nodes are added or removed
77 class ANodes[E: ANode]
78 super Sequence[E]
79 private var parent: ANode
80 private var items = new Array[E]
81 redef fun iterator do return items.iterator
82 redef fun length do return items.length
83 redef fun is_empty do return items.is_empty
84 redef fun push(e)
85 do
86 hook_add(e)
87 items.push(e)
88 end
89 redef fun pop
90 do
91 var res = items.pop
92 hook_remove(res)
93 return res
94 end
95 redef fun unshift(e)
96 do
97 hook_add(e)
98 items.unshift(e)
99 end
100 redef fun shift
101 do
102 var res = items.shift
103 hook_remove(res)
104 return res
105 end
106 redef fun has(e)
107 do
108 return items.has(e)
109 end
110 redef fun [](index)
111 do
112 return items[index]
113 end
114 redef fun []=(index, e)
115 do
116 hook_remove(self[index])
117 hook_add(e)
118 items[index]=e
119 end
120 redef fun remove_at(index)
121 do
122 hook_remove(items[index])
123 items.remove_at(index)
124 end
125 private fun hook_add(e: E)
126 do
127 #assert e.parent == null
128 e.parent = parent
129 end
130 private fun hook_remove(e: E)
131 do
132 assert e.parent == parent
133 e.parent = null
134 end
135
136 # Used in parent contructor to fill elements
137 private fun unsafe_add_all(nodes: Collection[Object])
138 do
139 var parent = self.parent
140 for n in nodes do
141 assert n isa E
142 add n
143 n.parent = parent
144 end
145 end
146
147 private fun replace_child(old_child: ANode, new_child: nullable ANode): Bool
148 do
149 var parent = self.parent
150 for i in [0..length[ do
151 if self[i] == old_child then
152 if new_child != null then
153 assert new_child isa E
154 self[i] = new_child
155 new_child.parent = parent
156 else
157 self.remove_at(i)
158 end
159 return true
160 end
161 end
162 return false
163 end
164
165 private fun visit_all(v: Visitor)
166 do
167 for n in self do v.enter_visit(n)
168 end
169 end
170
171 # Ancestor of all tokens
172 # A token is a node that has a `text` but no children.
173 abstract class Token
174 super ANode
175
176 # The raw content on the token
177 fun text: String is abstract
178 fun text=(text: String) is abstract
179
180 # The previous token in the Lexer.
181 # May have disapeared in the AST
182 var prev_token: nullable Token
183
184 # The next token in the Lexer.
185 # May have disapeared in the AST
186 var next_token: nullable Token
187
188 redef fun to_s: String do
189 return "'{text}'"
190 end
191
192 redef fun visit_all(v: Visitor) do end
193 redef fun replace_child(old_child: ANode, new_child: nullable ANode) do end
194 end
195
196 # Ancestor of all productions
197 # A production is a node without text but that usually has children.
198 abstract class Prod
199 super ANode
200
201 fun location=(l: Location) do _location = l
202
203 # All the annotations attached directly to the node
204 readable writable var _n_annotations: nullable AAnnotations = null
205
206 redef fun replace_with(n: ANode)
207 do
208 super
209 assert n isa Prod
210 if n._location == null then n._location = _location
211 end
212 end
213
214 # Abstract standard visitor on the AST
215 abstract class Visitor
216 # What the visitor do when a node is visited
217 # Concrete visitors should implement this method.
218 # @toimplement
219 protected fun visit(e: ANode) is abstract
220
221 # Ask the visitor to visit a given node.
222 # Usually automatically called by visit_all* methods.
223 # This method should not be redefined
224 fun enter_visit(e: nullable ANode)
225 do
226 if e == null then return
227 var old = _current_node
228 _current_node = e
229 visit(e)
230 _current_node = old
231 end
232
233 # The current visited node
234 readable writable var _current_node: nullable ANode = null
235 end
236
237 # Token of end of line (basically `\n`)
238 class TEol
239 super Token
240 redef fun to_s
241 do
242 return "end of line"
243 end
244 end
245
246 # Token of a line of comments
247 # Starts with the `#` and contains the final end-of-line (if any)
248 class TComment
249 super Token
250 end
251
252 # A token associated with a keyword
253 abstract class TokenKeyword
254 super Token
255 redef fun to_s
256 do
257 return "keyword '{text}'"
258 end
259 end
260 class TKwpackage
261 super TokenKeyword
262 end
263 class TKwmodule
264 super TokenKeyword
265 end
266 class TKwimport
267 super TokenKeyword
268 end
269 class TKwclass
270 super TokenKeyword
271 end
272 class TKwabstract
273 super TokenKeyword
274 end
275 class TKwinterface
276 super TokenKeyword
277 end
278 class TKwenum
279 super TokenKeyword
280 end
281 class TKwend
282 super TokenKeyword
283 end
284 class TKwmeth
285 super TokenKeyword
286 end
287 class TKwtype
288 super TokenKeyword
289 end
290 class TKwinit
291 super TokenKeyword
292 end
293 class TKwredef
294 super TokenKeyword
295 end
296 class TKwis
297 super TokenKeyword
298 end
299 class TKwdo
300 super TokenKeyword
301 end
302 class TKwreadable
303 super TokenKeyword
304 end
305 class TKwwritable
306 super TokenKeyword
307 end
308 class TKwvar
309 super TokenKeyword
310 end
311 class TKwintern
312 super TokenKeyword
313 end
314 class TKwextern
315 super TokenKeyword
316 end
317 class TKwpublic
318 super TokenKeyword
319 end
320 class TKwprotected
321 super TokenKeyword
322 end
323 class TKwprivate
324 super TokenKeyword
325 end
326 class TKwintrude
327 super TokenKeyword
328 end
329 class TKwif
330 super TokenKeyword
331 end
332 class TKwthen
333 super TokenKeyword
334 end
335 class TKwelse
336 super TokenKeyword
337 end
338 class TKwwhile
339 super TokenKeyword
340 end
341 class TKwloop
342 super TokenKeyword
343 end
344 class TKwfor
345 super TokenKeyword
346 end
347 class TKwin
348 super TokenKeyword
349 end
350 class TKwand
351 super TokenKeyword
352 end
353 class TKwor
354 super TokenKeyword
355 end
356 class TKwimplies
357 super TokenKeyword
358 end
359 class TKwnot
360 super TokenKeyword
361 end
362 class TKwreturn
363 super TokenKeyword
364 end
365 class TKwcontinue
366 super TokenKeyword
367 end
368 class TKwbreak
369 super TokenKeyword
370 end
371 class TKwabort
372 super TokenKeyword
373 end
374 class TKwassert
375 super TokenKeyword
376 end
377 class TKwnew
378 super TokenKeyword
379 end
380 class TKwisa
381 super TokenKeyword
382 end
383 class TKwonce
384 super TokenKeyword
385 end
386 class TKwsuper
387 super TokenKeyword
388 end
389 class TKwself
390 super TokenKeyword
391 end
392 class TKwtrue
393 super TokenKeyword
394 end
395 class TKwfalse
396 super TokenKeyword
397 end
398 class TKwnull
399 super TokenKeyword
400 end
401 class TKwas
402 super TokenKeyword
403 end
404 class TKwnullable
405 super TokenKeyword
406 end
407 class TKwisset
408 super TokenKeyword
409 end
410 class TKwlabel
411 super TokenKeyword
412 end
413 class TKwdebug
414 super Token
415 end
416 class TOpar
417 super Token
418 end
419 class TCpar
420 super Token
421 end
422 class TObra
423 super Token
424 end
425 class TCbra
426 super Token
427 end
428 class TComma
429 super Token
430 end
431 class TColumn
432 super Token
433 end
434 class TQuad
435 super Token
436 end
437 class TAssign
438 super Token
439 end
440
441 # A token associated with an operator (and other lookalike symbols)
442 abstract class TokenOperator
443 super Token
444 redef fun to_s
445 do
446 return "operator '{text}'"
447 end
448 end
449 class TPluseq
450 super TokenOperator
451 end
452 class TMinuseq
453 super TokenOperator
454 end
455 class TDotdotdot
456 super TokenOperator
457 end
458 class TDotdot
459 super TokenOperator
460 end
461 class TDot
462 super TokenOperator
463 end
464 class TPlus
465 super TokenOperator
466 end
467 class TMinus
468 super TokenOperator
469 end
470 class TStar
471 super TokenOperator
472 end
473 class TSlash
474 super TokenOperator
475 end
476 class TPercent
477 super TokenOperator
478 end
479 class TEq
480 super TokenOperator
481 end
482 class TNe
483 super TokenOperator
484 end
485 class TLt
486 super TokenOperator
487 end
488 class TLe
489 super TokenOperator
490 end
491 class TLl
492 super TokenOperator
493 end
494 class TGt
495 super TokenOperator
496 end
497 class TGe
498 super TokenOperator
499 end
500 class TGg
501 super TokenOperator
502 end
503 class TStarship
504 super TokenOperator
505 end
506 class TBang
507 super TokenOperator
508 end
509 class TAt
510 super Token
511 end
512
513 # A class (or formal type) identifier. They start with an uppercase.
514 class TClassid
515 super Token
516 redef fun to_s
517 do
518 do return "type identifier '{text}'"
519 end
520 end
521
522 # A standard identifier (variable, method...). They start with a lowercase.
523 class TId
524 super Token
525 redef fun to_s
526 do
527 do return "identifier '{text}'"
528 end
529 end
530
531 # An attribute identifier. They start with an underscore.
532 class TAttrid
533 super Token
534 redef fun to_s
535 do
536 do return "attribute '{text}'"
537 end
538 end
539
540 # A token of a literal value (string, integer, etc).
541 abstract class TokenLiteral
542 super Token
543 redef fun to_s
544 do
545 do return "literal value '{text}'"
546 end
547 end
548 class TNumber
549 super TokenLiteral
550 end
551 class THexNumber
552 super TokenLiteral
553 end
554 class TFloat
555 super TokenLiteral
556 end
557 class TChar
558 super TokenLiteral
559 end
560 class TString
561 super TokenLiteral
562 end
563 class TStartString
564 super TokenLiteral
565 end
566 class TMidString
567 super TokenLiteral
568 end
569 class TEndString
570 super TokenLiteral
571 end
572
573 # A malformed string
574 class TBadString
575 super Token
576 redef fun to_s
577 do
578 do return "malformed string {text}"
579 end
580 end
581
582 # A malformed char
583 class TBadChar
584 super Token
585 redef fun to_s
586 do
587 do return "malformed character {text}"
588 end
589 end
590
591 class TExternCodeSegment
592 super Token
593 end
594
595 # A end of file
596 class EOF
597 super Token
598 redef fun to_s
599 do
600 return "end of file"
601 end
602 end
603
604 # A mark of an error
605 class AError
606 super EOF
607 end
608 class ALexerError
609 super AError
610 end
611 class AParserError
612 super AError
613 end
614
615 # The main node of a Nit source-file
616 class AModule
617 super Prod
618
619 readable writable var _n_moduledecl: nullable AModuledecl = null
620 readable var _n_imports: ANodes[AImport] = new ANodes[AImport](self)
621 readable var _n_extern_code_blocks: ANodes[AExternCodeBlock] = new ANodes[AExternCodeBlock](self)
622 readable var _n_classdefs: ANodes[AClassdef] = new ANodes[AClassdef](self)
623 end
624
625 # The declaration of the module with the documentation, name, and annotations
626 class AModuledecl
627 super Prod
628 readable writable var _n_doc: nullable ADoc = null
629 readable writable var _n_kwmodule: TKwmodule
630 readable writable var _n_name: AModuleName
631 end
632
633 # A import clause of a module
634 abstract class AImport
635 super Prod
636 end
637
638 # A standard import clause. eg `import x`
639 class AStdImport
640 super AImport
641 readable writable var _n_visibility: AVisibility
642 readable writable var _n_kwimport: TKwimport
643 readable writable var _n_name: AModuleName
644 end
645
646 # The special import clause of the kernel module. eg `import end`
647 class ANoImport
648 super AImport
649 readable writable var _n_visibility: AVisibility
650 readable writable var _n_kwimport: TKwimport
651 readable writable var _n_kwend: TKwend
652 end
653
654 # A visibility modifier
655 #
656 # The public visibility is an empty production (no keyword).
657 #
658 # Note: even if some visibilities are only valid on some placse (for instance, no `protected` class or no `intrude` method)
659 # the parser has no such a restriction, therefore the semantic phases has to check that the visibilities make sense.
660 abstract class AVisibility
661 super Prod
662 end
663 class APublicVisibility
664 super AVisibility
665 end
666 class APrivateVisibility
667 super AVisibility
668 readable writable var _n_kwprivate: TKwprivate
669 end
670 class AProtectedVisibility
671 super AVisibility
672 readable writable var _n_kwprotected: TKwprotected
673 end
674 class AIntrudeVisibility
675 super AVisibility
676 readable writable var _n_kwintrude: TKwintrude
677 end
678
679 # A class definition
680 # While most definition are `AStdClassdef`
681 # There is tow special case of class definition
682 abstract class AClassdef super Prod
683 readable var _n_propdefs: ANodes[APropdef] = new ANodes[APropdef](self)
684 end
685
686 # A standard class definition with a name, superclasses and properties
687 class AStdClassdef
688 super AClassdef
689 readable writable var _n_doc: nullable ADoc = null
690 readable writable var _n_kwredef: nullable TKwredef = null
691 readable writable var _n_visibility: AVisibility
692 readable writable var _n_classkind: AClasskind
693 readable writable var _n_id: nullable TClassid = null
694 readable var _n_formaldefs: ANodes[AFormaldef] = new ANodes[AFormaldef](self)
695 readable writable var _n_extern_code_block: nullable AExternCodeBlock = null
696 readable var _n_superclasses: ANodes[ASuperclass] = new ANodes[ASuperclass](self)
697 readable writable var _n_kwend: TKwend
698 redef fun hot_location do return n_id.location
699 end
700
701 # The implicit class definition of the implicit main method
702 class ATopClassdef
703 super AClassdef
704 end
705
706 # The implicit class definition of the top-level methods
707 class AMainClassdef
708 super AClassdef
709 end
710
711 # The modifier for the kind of class (abstract, interface, etc.)
712 abstract class AClasskind
713 super Prod
714 end
715 class AConcreteClasskind
716 super AClasskind
717 readable writable var _n_kwclass: TKwclass
718 end
719 class AAbstractClasskind
720 super AClasskind
721 readable writable var _n_kwabstract: TKwabstract
722 readable writable var _n_kwclass: TKwclass
723 end
724 class AInterfaceClasskind
725 super AClasskind
726 readable writable var _n_kwinterface: TKwinterface
727 end
728 class AEnumClasskind
729 super AClasskind
730 readable writable var _n_kwenum: TKwenum
731 end
732 class AExternClasskind
733 super AClasskind
734 readable writable var _n_kwextern: TKwextern
735 readable writable var _n_kwclass: nullable TKwclass = null
736 end
737
738 # The definition of a formal generic parameter type. eg `X: Y`
739 class AFormaldef
740 super Prod
741 readable writable var _n_id: TClassid
742 # The bound of the parameter type
743 readable writable var _n_type: nullable AType = null
744 end
745
746 # A super-class. eg `super X`
747 class ASuperclass
748 super Prod
749 readable writable var _n_kwsuper: TKwsuper
750 readable writable var _n_type: AType
751 end
752
753 # The definition of a property
754 abstract class APropdef
755 super Prod
756 readable writable var _n_doc: nullable ADoc = null
757 readable writable var _n_kwredef: nullable TKwredef = null
758 readable writable var _n_visibility: nullable AVisibility = null
759 end
760
761 # A definition of an attribute
762 # For historical reason, old-syle and new-style attributes use the same `ANode` sub-class
763 class AAttrPropdef
764 super APropdef
765 readable writable var _n_kwvar: TKwvar
766
767 # The identifier for an old-style attribute (null if new-style)
768 readable writable var _n_id: nullable TAttrid
769
770 # The identifier for a new-style attribute (null if old-style)
771 readable writable var _n_id2: nullable TId
772
773 readable writable var _n_type: nullable AType = null
774 readable writable var _n_readable: nullable AAble = null
775 readable writable var _n_writable: nullable AAble = null
776
777 # The initial value, if any
778 readable writable var _n_expr: nullable AExpr = null
779 redef fun hot_location
780 do
781 if n_id != null then return n_id.location else return n_id2.location
782 end
783 end
784
785 # A definition of all kind of method (including constructors)
786 abstract class AMethPropdef
787 super APropdef
788 readable writable var _n_kwmeth: nullable TKwmeth
789 readable writable var _n_kwinit: nullable TKwinit
790 readable writable var _n_kwnew: nullable TKwnew
791 readable writable var _n_methid: nullable AMethid = null
792 readable writable var _n_signature: nullable ASignature
793 readable writable var _n_block: nullable AExpr = null
794 readable writable var _n_extern: nullable TString = null
795 readable writable var _n_extern_calls: nullable AExternCalls = null
796 readable writable var _n_extern_code_block: nullable AExternCodeBlock = null
797 redef fun hot_location
798 do
799 if n_methid != null then
800 return n_methid.location
801 else if n_kwinit != null then
802 return n_kwinit.location
803 else if n_kwnew != null then
804 return n_kwnew.location
805 else
806 return location
807 end
808 end
809 end
810
811 # A method marked abstract
812 # *deferred* is a old synonynmous of *abstract* that comes from PRM, that comes from Eiffel.
813 class ADeferredMethPropdef
814 super AMethPropdef
815 end
816
817 # A method marked intern
818 class AInternMethPropdef
819 super AMethPropdef
820 end
821
822 # A method of a constructor marked extern
823 abstract class AExternPropdef
824 super AMethPropdef
825 end
826
827 # A method marked extern
828 class AExternMethPropdef
829 super AExternPropdef
830 end
831
832 # A method with a body
833 class AConcreteMethPropdef
834 super AMethPropdef
835 end
836
837 # A constructor
838 abstract class AInitPropdef
839 super AMethPropdef
840 end
841
842 # A constructor with a body
843 class AConcreteInitPropdef
844 super AConcreteMethPropdef
845 super AInitPropdef
846 end
847
848 # A constructor marked extern (defined with the `new` keyword)
849 class AExternInitPropdef
850 super AExternPropdef
851 super AInitPropdef
852 end
853
854 # The implicit main method
855 class AMainMethPropdef
856 super AConcreteMethPropdef
857 end
858
859 # Declaration of callbacks for extern methods
860 class AExternCalls
861 super Prod
862 readable writable var _n_kwimport: TKwimport
863 readable var _n_extern_calls: ANodes[AExternCall] = new ANodes[AExternCall](self)
864 end
865 abstract class AExternCall
866 super Prod
867 end
868 abstract class APropExternCall
869 super AExternCall
870 end
871 class ALocalPropExternCall
872 super APropExternCall
873 readable writable var _n_methid: AMethid
874 end
875 class AFullPropExternCall
876 super APropExternCall
877 readable writable var _n_type: AType
878 readable writable var _n_dot: nullable TDot = null
879 readable writable var _n_methid: AMethid
880 end
881 class AInitPropExternCall
882 super APropExternCall
883 readable writable var _n_type: AType
884 end
885 class ASuperExternCall
886 super AExternCall
887 readable writable var _n_kwsuper: TKwsuper
888 end
889 abstract class ACastExternCall
890 super AExternCall
891 end
892 class ACastAsExternCall
893 super ACastExternCall
894 readable writable var _n_from_type: AType
895 readable writable var _n_dot: nullable TDot = null
896 readable writable var _n_kwas: TKwas
897 readable writable var _n_to_type: AType
898 end
899 class AAsNullableExternCall
900 super ACastExternCall
901 readable writable var _n_type: AType
902 readable writable var _n_kwas: TKwas
903 readable writable var _n_kwnullable: TKwnullable
904 end
905 class AAsNotNullableExternCall
906 super ACastExternCall
907 readable writable var _n_type: AType
908 readable writable var _n_kwas: TKwas
909 readable writable var _n_kwnot: TKwnot
910 readable writable var _n_kwnullable: TKwnullable
911 end
912
913 # A definition of a virtual type
914 class ATypePropdef
915 super APropdef
916 readable writable var _n_kwtype: TKwtype
917 readable writable var _n_id: TClassid
918 readable writable var _n_type: AType
919 end
920
921 # A `writable` or `readable` modifier
922 abstract class AAble
923 super Prod
924 readable writable var _n_visibility: nullable AVisibility = null
925 readable writable var _n_kwredef: nullable TKwredef = null
926 end
927
928 # A `readable` modifier
929 class AReadAble
930 super AAble
931 readable writable var _n_kwreadable: TKwreadable
932 end
933
934 # A `writable` modifier
935 class AWriteAble
936 super AAble
937 readable writable var _n_kwwritable: TKwwritable
938 end
939
940 # The identifier of a method in a method declaration.
941 # There is a specific class because of operator and setters.
942 abstract class AMethid
943 super Prod
944 end
945 class AIdMethid
946 super AMethid
947 readable writable var _n_id: TId
948 end
949 class APlusMethid
950 super AMethid
951 readable writable var _n_plus: TPlus
952 end
953 class AMinusMethid
954 super AMethid
955 readable writable var _n_minus: TMinus
956 end
957 class AStarMethid
958 super AMethid
959 readable writable var _n_star: TStar
960 end
961 class ASlashMethid
962 super AMethid
963 readable writable var _n_slash: TSlash
964 end
965 class APercentMethid
966 super AMethid
967 readable writable var _n_percent: TPercent
968 end
969 class AEqMethid
970 super AMethid
971 readable writable var _n_eq: TEq
972 end
973 class ANeMethid
974 super AMethid
975 readable writable var _n_ne: TNe
976 end
977 class ALeMethid
978 super AMethid
979 readable writable var _n_le: TLe
980 end
981 class AGeMethid
982 super AMethid
983 readable writable var _n_ge: TGe
984 end
985 class ALtMethid
986 super AMethid
987 readable writable var _n_lt: TLt
988 end
989 class AGtMethid
990 super AMethid
991 readable writable var _n_gt: TGt
992 end
993 class ALlMethid
994 super AMethid
995 readable writable var _n_ll: TLl
996 end
997 class AGgMethid
998 super AMethid
999 readable writable var _n_gg: TGg
1000 end
1001 class ABraMethid
1002 super AMethid
1003 readable writable var _n_obra: TObra
1004 readable writable var _n_cbra: TCbra
1005 end
1006 class AStarshipMethid
1007 super AMethid
1008 readable writable var _n_starship: TStarship
1009 end
1010 class AAssignMethid
1011 super AMethid
1012 readable writable var _n_id: TId
1013 readable writable var _n_assign: TAssign
1014 end
1015 class ABraassignMethid
1016 super AMethid
1017 readable writable var _n_obra: TObra
1018 readable writable var _n_cbra: TCbra
1019 readable writable var _n_assign: TAssign
1020 end
1021
1022 # A signature in a method definition. eg `(x,y:X,z:Z):T`
1023 class ASignature
1024 super Prod
1025 readable writable var _n_opar: nullable TOpar = null
1026 readable var _n_params: ANodes[AParam] = new ANodes[AParam](self)
1027 readable writable var _n_cpar: nullable TCpar = null
1028 readable writable var _n_type: nullable AType = null
1029 end
1030
1031 # A parameter definition in a signature. eg `x:X`
1032 class AParam
1033 super Prod
1034 readable writable var _n_id: TId
1035 readable writable var _n_type: nullable AType = null
1036 readable writable var _n_dotdotdot: nullable TDotdotdot = null
1037 end
1038
1039 # A static type. eg `nullable X[Y]`
1040 class AType
1041 super Prod
1042 readable writable var _n_kwnullable: nullable TKwnullable = null
1043
1044 # The name of the class or of the formal type
1045 readable writable var _n_id: TClassid
1046
1047 # Type arguments for a generic type
1048 readable var _n_types: ANodes[AType] = new ANodes[AType](self)
1049 end
1050
1051 # A label at the end of a block or in a break/continue statement. eg `label x`
1052 class ALabel
1053 super Prod
1054 readable writable var _n_kwlabel: TKwlabel
1055 readable writable var _n_id: TId
1056 end
1057
1058 # Expression and statements
1059 # From a AST point of view there is no distinction between statement and expressions (even if the parser has to distinguish them)
1060 abstract class AExpr
1061 super Prod
1062 end
1063
1064 # A sequence of AExpr (usually statements)
1065 # The last AExpr gives the value of the whole block
1066 class ABlockExpr
1067 super AExpr
1068 readable var _n_expr: ANodes[AExpr] = new ANodes[AExpr](self)
1069 readable writable var _n_kwend: nullable TKwend = null
1070 end
1071
1072 # A declaration of a local variable. eg `var x: X = y`
1073 class AVardeclExpr
1074 super AExpr
1075 readable writable var _n_kwvar: TKwvar
1076 readable writable var _n_id: TId
1077 readable writable var _n_type: nullable AType = null
1078 readable writable var _n_assign: nullable TAssign = null
1079
1080 # The initial value, if any
1081 readable writable var _n_expr: nullable AExpr = null
1082 end
1083
1084 # A `return` statement. eg `return x`
1085 class AReturnExpr
1086 super AExpr
1087 readable writable var _n_kwreturn: nullable TKwreturn = null
1088 readable writable var _n_expr: nullable AExpr = null
1089 end
1090
1091 # Something that has a label.
1092 abstract class ALabelable
1093 super Prod
1094 readable writable var _n_label: nullable ALabel = null
1095 end
1096
1097 # A `break` statement.
1098 class ABreakExpr
1099 super AExpr
1100 super ALabelable
1101 readable writable var _n_kwbreak: TKwbreak
1102 readable writable var _n_expr: nullable AExpr = null
1103 end
1104
1105 # An `abort` statement
1106 class AAbortExpr
1107 super AExpr
1108 readable writable var _n_kwabort: TKwabort
1109 end
1110
1111 # A `continue` statement
1112 class AContinueExpr
1113 super AExpr
1114 super ALabelable
1115 readable writable var _n_kwcontinue: nullable TKwcontinue = null
1116 readable writable var _n_expr: nullable AExpr = null
1117 end
1118
1119 # A `do` statement
1120 class ADoExpr
1121 super AExpr
1122 super ALabelable
1123 readable writable var _n_kwdo: TKwdo
1124 readable writable var _n_block: nullable AExpr = null
1125 end
1126
1127 # A `if` statement
1128 class AIfExpr
1129 super AExpr
1130 readable writable var _n_kwif: TKwif
1131 readable writable var _n_expr: AExpr
1132 readable writable var _n_then: nullable AExpr = null
1133 readable writable var _n_else: nullable AExpr = null
1134 end
1135
1136 # A `if` expression
1137 class AIfexprExpr
1138 super AExpr
1139 readable writable var _n_kwif: TKwif
1140 readable writable var _n_expr: AExpr
1141 readable writable var _n_kwthen: TKwthen
1142 readable writable var _n_then: AExpr
1143 readable writable var _n_kwelse: TKwelse
1144 readable writable var _n_else: AExpr
1145 end
1146
1147 # A `while` statement
1148 class AWhileExpr
1149 super AExpr
1150 super ALabelable
1151 readable writable var _n_kwwhile: TKwwhile
1152 readable writable var _n_expr: AExpr
1153 readable writable var _n_kwdo: TKwdo
1154 readable writable var _n_block: nullable AExpr = null
1155 end
1156
1157 # A `loop` statement
1158 class ALoopExpr
1159 super AExpr
1160 super ALabelable
1161 readable writable var _n_kwloop: TKwloop
1162 readable writable var _n_block: nullable AExpr = null
1163 end
1164
1165 # A `for` statement
1166 class AForExpr
1167 super AExpr
1168 super ALabelable
1169 readable writable var _n_kwfor: TKwfor
1170 readable var _n_ids: ANodes[TId] = new ANodes[TId](self)
1171 readable writable var _n_expr: AExpr
1172 readable writable var _n_kwdo: TKwdo
1173 readable writable var _n_block: nullable AExpr = null
1174 end
1175
1176 # An `assert` statement
1177 class AAssertExpr
1178 super AExpr
1179 readable writable var _n_kwassert: TKwassert
1180 readable writable var _n_id: nullable TId = null
1181 readable writable var _n_expr: AExpr
1182 readable writable var _n_else: nullable AExpr = null
1183 end
1184
1185 # Whatever is a simple assignment. eg `= something`
1186 abstract class AAssignFormExpr
1187 super AExpr
1188 readable writable var _n_assign: TAssign
1189 readable writable var _n_value: AExpr
1190 end
1191
1192 # Whatever is a combined assignment. eg `+= something`
1193 abstract class AReassignFormExpr
1194 super AExpr
1195 readable writable var _n_assign_op: AAssignOp
1196 readable writable var _n_value: AExpr
1197 end
1198
1199 # A `once` expression. eg `once x`
1200 class AOnceExpr
1201 super AProxyExpr
1202 readable writable var _n_kwonce: TKwonce
1203 end
1204
1205 # A polymorphic invocation of a method
1206 # The form of the invocation (name, arguments, etc) are specific
1207 abstract class ASendExpr
1208 super AExpr
1209 # The receiver of the method invocation
1210 readable writable var _n_expr: AExpr
1211 end
1212
1213 # A binary operation on a method
1214 abstract class ABinopExpr
1215 super ASendExpr
1216 # The second operand of the operation
1217 # Note: the receiver (`n_expr`) is the first operand
1218 readable writable var _n_expr2: AExpr
1219 end
1220
1221 # Something that is boolean expression
1222 abstract class ABoolExpr
1223 super AExpr
1224 end
1225
1226 # A `or` expression
1227 class AOrExpr
1228 super ABoolExpr
1229 readable writable var _n_expr: AExpr
1230 readable writable var _n_expr2: AExpr
1231 end
1232
1233 # A `and` expression
1234 class AAndExpr
1235 super ABoolExpr
1236 readable writable var _n_expr: AExpr
1237 readable writable var _n_expr2: AExpr
1238 end
1239
1240 # A `or else` expression
1241 class AOrElseExpr
1242 super ABoolExpr
1243 readable writable var _n_expr: AExpr
1244 readable writable var _n_expr2: AExpr
1245 end
1246
1247 # A `implies` expression
1248 class AImpliesExpr
1249 super ABoolExpr
1250 readable writable var _n_expr: AExpr
1251 readable writable var _n_expr2: AExpr
1252 end
1253
1254 # A `not` expression
1255 class ANotExpr
1256 super ABoolExpr
1257 readable writable var _n_kwnot: TKwnot
1258 readable writable var _n_expr: AExpr
1259 end
1260
1261 # A `==` expression
1262 class AEqExpr
1263 super ABinopExpr
1264 end
1265
1266 # A `!=` expression
1267 class ANeExpr
1268 super ABinopExpr
1269 end
1270
1271 # A `<` expression
1272 class ALtExpr
1273 super ABinopExpr
1274 end
1275
1276 # A `<=` expression
1277 class ALeExpr
1278 super ABinopExpr
1279 end
1280
1281 # A `<<` expression
1282 class ALlExpr
1283 super ABinopExpr
1284 end
1285
1286 # A `>` expression
1287 class AGtExpr
1288 super ABinopExpr
1289 end
1290
1291 # A `>=` expression
1292 class AGeExpr
1293 super ABinopExpr
1294 end
1295
1296 # A `>>` expression
1297 class AGgExpr
1298 super ABinopExpr
1299 end
1300
1301 # A type-ckeck expression. eg `x isa T`
1302 class AIsaExpr
1303 super ABoolExpr
1304 readable writable var _n_expr: AExpr
1305 readable writable var _n_type: AType
1306 end
1307
1308 # A `+` expression
1309 class APlusExpr
1310 super ABinopExpr
1311 end
1312
1313 # A `-` expression
1314 class AMinusExpr
1315 super ABinopExpr
1316 end
1317
1318 # A `<=>` expression
1319 class AStarshipExpr
1320 super ABinopExpr
1321 end
1322
1323 # A `*` expression
1324 class AStarExpr
1325 super ABinopExpr
1326 end
1327
1328 # A `/` expression
1329 class ASlashExpr
1330 super ABinopExpr
1331 end
1332
1333 # A `%` expression
1334 class APercentExpr
1335 super ABinopExpr
1336 end
1337
1338 # A unary minus expression. eg `-x`
1339 class AUminusExpr
1340 super ASendExpr
1341 readable writable var _n_minus: TMinus
1342 end
1343
1344 # An explicit instantiation. eg `new T`
1345 class ANewExpr
1346 super AExpr
1347 readable writable var _n_kwnew: TKwnew
1348 readable writable var _n_type: AType
1349
1350 # The name of the named-constructor, if any
1351 readable writable var _n_id: nullable TId = null
1352 readable writable var _n_args: AExprs
1353 end
1354
1355 # Whatever is a old-style attribute access
1356 abstract class AAttrFormExpr
1357 super AExpr
1358
1359 # The receiver of the attribute
1360 readable writable var _n_expr: AExpr
1361
1362 # The name of the attribute
1363 readable writable var _n_id: TAttrid
1364 end
1365
1366 # The read of an attribute. eg `x._a`
1367 class AAttrExpr
1368 super AAttrFormExpr
1369 end
1370
1371 # The assignment of an attribute. eg `x._a=y`
1372 class AAttrAssignExpr
1373 super AAttrFormExpr
1374 super AAssignFormExpr
1375 end
1376
1377 # Whatever looks-like a call with a standard method and any number of arguments.
1378 abstract class ACallFormExpr
1379 super ASendExpr
1380
1381 # The name of the method
1382 readable writable var _n_id: TId
1383
1384 # The arguments of the call
1385 readable writable var _n_args: AExprs
1386 end
1387
1388 # A complex setter call (standard or brackets)
1389 abstract class ASendReassignFormExpr
1390 super ASendExpr
1391 super AReassignFormExpr
1392 end
1393
1394 # A complex attribute assignment. eg `x._a+=y`
1395 class AAttrReassignExpr
1396 super AAttrFormExpr
1397 super AReassignFormExpr
1398 end
1399
1400 # A call with a standard method-name and any number of arguments. eg `x.m(y)`. OR just a simple id
1401 # 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`.
1402 # Semantic analysis have to transform them to instance of `AVarExpr`.
1403 class ACallExpr
1404 super ACallFormExpr
1405 end
1406
1407 # A setter call with a standard method-name and any number of arguments. eg `x.m(y)=z`. OR just a simple assignment.
1408 # 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`.
1409 # Semantic analysis have to transform them to instance of `AVarAssignExpr`.
1410 class ACallAssignExpr
1411 super ACallFormExpr
1412 super AAssignFormExpr
1413 end
1414
1415 # 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.
1416 # Note: because the parser cannot distinguish a variable write with a compex setter call with an implicit receiver and no arguments, it always returns a `ACallReassignExpr`.
1417 # Semantic analysis have to transform them to instance of `AVarReassignExpr`.
1418 class ACallReassignExpr
1419 super ACallFormExpr
1420 super ASendReassignFormExpr
1421 end
1422
1423 # A call to `super`. OR a call of a super-constructor
1424 class ASuperExpr
1425 super AExpr
1426 readable writable var _n_qualified: nullable AQualified = null
1427 readable writable var _n_kwsuper: TKwsuper
1428 readable writable var _n_args: AExprs
1429 end
1430
1431 # A call to the `init` constructor.
1432 # Note: because `init` is a keyword and not a `TId`, the explicit call to init cannot be a ACallFormExpr.
1433 class AInitExpr
1434 super ASendExpr
1435 readable writable var _n_kwinit: TKwinit
1436 readable writable var _n_args: AExprs
1437 end
1438
1439 # Whatever looks-like a call of the brackets `[]` operator.
1440 abstract class ABraFormExpr
1441 super ASendExpr
1442 readable writable var _n_args: AExprs
1443 end
1444
1445 # A call of the brackets operator. eg `x[y,z]`
1446 class ABraExpr
1447 super ABraFormExpr
1448 end
1449
1450 # A setter call of the bracket operator. eg `x[y,z]=t`
1451 class ABraAssignExpr
1452 super ABraFormExpr
1453 super AAssignFormExpr
1454 end
1455
1456 # Whatever is an access to a local variable
1457 abstract class AVarFormExpr
1458 super AExpr
1459 readable writable var _n_id: TId
1460 end
1461
1462 # A complex setter call of the bracket operator. eg `x[y,z]+=t`
1463 class ABraReassignExpr
1464 super ABraFormExpr
1465 super ASendReassignFormExpr
1466 end
1467
1468 # A local variable read access.
1469 # The parser cannot instantiate them, see `ACallExpr`.
1470 class AVarExpr
1471 super AVarFormExpr
1472 end
1473
1474 # A local variable simple assigment access
1475 # The parser cannot instantiate them, see `ACallAssignExpr`.
1476 class AVarAssignExpr
1477 super AVarFormExpr
1478 super AAssignFormExpr
1479 end
1480
1481 # A local variable complex assignment access
1482 # The parser cannot instantiate them, see `ACallReassignExpr`.
1483 class AVarReassignExpr
1484 super AVarFormExpr
1485 super AReassignFormExpr
1486 end
1487
1488 # A literal range, open or closed
1489 abstract class ARangeExpr
1490 super AExpr
1491 readable writable var _n_expr: AExpr
1492 readable writable var _n_expr2: AExpr
1493 end
1494
1495 # A closed literal range. eg `[x..y]`
1496 class ACrangeExpr
1497 super ARangeExpr
1498 readable writable var _n_obra: TObra
1499 readable writable var _n_cbra: TCbra
1500 end
1501
1502 # An open literal range. eg `[x..y[`
1503 class AOrangeExpr
1504 super ARangeExpr
1505 readable writable var _n_obra: TObra
1506 readable writable var _n_cbra: TObra
1507 end
1508
1509 # A literal array. eg. `[x,y,z]`
1510 class AArrayExpr
1511 super AExpr
1512 readable writable var _n_exprs: AExprs
1513 end
1514
1515 # A read of `self`
1516 class ASelfExpr
1517 super AExpr
1518 readable writable var _n_kwself: nullable TKwself
1519 end
1520
1521 # When there is no explicit receiver, `self` is implicit
1522 class AImplicitSelfExpr
1523 super ASelfExpr
1524 end
1525
1526 # A `true` boolean literal constant
1527 class ATrueExpr
1528 super ABoolExpr
1529 readable writable var _n_kwtrue: TKwtrue
1530 end
1531 # A `false` boolean literal constant
1532 class AFalseExpr
1533 super ABoolExpr
1534 readable writable var _n_kwfalse: TKwfalse
1535 end
1536 # A `null` literal constant
1537 class ANullExpr
1538 super AExpr
1539 readable writable var _n_kwnull: TKwnull
1540 end
1541 # An integer literal
1542 class AIntExpr
1543 super AExpr
1544 end
1545 # An integer literal in decimal format
1546 class ADecIntExpr
1547 super AIntExpr
1548 readable writable var _n_number: TNumber
1549 end
1550 # An integer literal in hexadecimal format
1551 class AHexIntExpr
1552 super AIntExpr
1553 readable writable var _n_hex_number: THexNumber
1554 end
1555 # A float literal
1556 class AFloatExpr
1557 super AExpr
1558 readable writable var _n_float: TFloat
1559 end
1560 # A character literal
1561 class ACharExpr
1562 super AExpr
1563 readable writable var _n_char: TChar
1564 end
1565 # A string literal
1566 abstract class AStringFormExpr
1567 super AExpr
1568 readable writable var _n_string: Token
1569 end
1570
1571 # A simple string. eg. `"abc"`
1572 class AStringExpr
1573 super AStringFormExpr
1574 end
1575
1576 # The start of a superstring. eg `"abc{`
1577 class AStartStringExpr
1578 super AStringFormExpr
1579 end
1580
1581 # The middle of a superstring. eg `}abc{`
1582 class AMidStringExpr
1583 super AStringFormExpr
1584 end
1585
1586 # The end of a superstrng. eg `}abc"`
1587 class AEndStringExpr
1588 super AStringFormExpr
1589 end
1590
1591 # A superstring literal. eg `"a{x}b{y}c"`
1592 # Each part is modelized a sequence of expression. eg. `["a{, x, }b{, y, }c"]`
1593 class ASuperstringExpr
1594 super AExpr
1595 readable var _n_exprs: ANodes[AExpr] = new ANodes[AExpr](self)
1596 end
1597
1598 # A simple parenthesis. eg `(x)`
1599 class AParExpr
1600 super AProxyExpr
1601 readable writable var _n_opar: TOpar
1602 readable writable var _n_cpar: TCpar
1603 end
1604
1605 # Whatevej just contains (and mimic) an other expression
1606 abstract class AProxyExpr
1607 super AExpr
1608 readable writable var _n_expr: AExpr
1609 end
1610
1611 # A type cast. eg `x.as(T)`
1612 class AAsCastExpr
1613 super AExpr
1614 readable writable var _n_expr: AExpr
1615 readable writable var _n_kwas: TKwas
1616 readable writable var _n_opar: nullable TOpar = null
1617 readable writable var _n_type: AType
1618 readable writable var _n_cpar: nullable TCpar = null
1619 end
1620
1621 # A as-not-null cast. eg `x.as(not null)`
1622 class AAsNotnullExpr
1623 super AExpr
1624 readable writable var _n_expr: AExpr
1625 readable writable var _n_kwas: TKwas
1626 readable writable var _n_opar: nullable TOpar = null
1627 readable writable var _n_kwnot: TKwnot
1628 readable writable var _n_kwnull: TKwnull
1629 readable writable var _n_cpar: nullable TCpar = null
1630 end
1631
1632 # A is-set check of old-style attributes. eg `isset x._a`
1633 class AIssetAttrExpr
1634 super AAttrFormExpr
1635 readable writable var _n_kwisset: TKwisset
1636 end
1637
1638 # A list of expression separated with commas (arguments for instance)
1639 abstract class AExprs
1640 super Prod
1641 readable var _n_exprs: ANodes[AExpr] = new ANodes[AExpr](self)
1642 end
1643
1644 class ADebugTypeExpr
1645 super AExpr
1646 readable writable var _n_kwdebug: TKwdebug
1647 readable writable var _n_kwtype: TKwtype
1648 readable writable var _n_expr: AExpr
1649 readable writable var _n_type: AType
1650 end
1651
1652 # A simple list of expressions
1653 class AListExprs
1654 super AExprs
1655 end
1656
1657 # A list of expressions enclosed in parentheses
1658 class AParExprs
1659 super AExprs
1660 readable writable var _n_opar: TOpar
1661 readable writable var _n_cpar: TCpar
1662 end
1663
1664 # A list of expressions enclosed in brackets
1665 class ABraExprs
1666 super AExprs
1667 readable writable var _n_obra: TObra
1668 readable writable var _n_cbra: TCbra
1669 end
1670
1671 # A complex assignment operator. eg `+=`
1672 abstract class AAssignOp
1673 super Prod
1674 end
1675 class APlusAssignOp
1676 super AAssignOp
1677 readable writable var _n_pluseq: TPluseq
1678 end
1679 class AMinusAssignOp
1680 super AAssignOp
1681 readable writable var _n_minuseq: TMinuseq
1682 end
1683
1684 class AModuleName
1685 super Prod
1686 readable writable var _n_quad: nullable TQuad = null
1687 readable var _n_path: ANodes[TId] = new ANodes[TId](self)
1688 readable writable var _n_id: TId
1689 end
1690 class AInLanguage
1691 super Prod
1692 readable writable var _n_kwin: TKwin
1693 readable writable var _n_string: TString
1694 end
1695 class AExternCodeBlock
1696 super Prod
1697 readable writable var _n_in_language: nullable AInLanguage = null
1698 readable writable var _n_extern_code_segment: TExternCodeSegment
1699 end
1700 class AQualified
1701 super Prod
1702 readable writable var _n_quad: nullable TQuad = null
1703 readable var _n_id: ANodes[TId] = new ANodes[TId](self)
1704 readable writable var _n_classid: nullable TClassid = null
1705 end
1706
1707 # A documentation of a definition
1708 # It contains the block of comments just above the declaration
1709 class ADoc
1710 super Prod
1711 readable var _n_comment: ANodes[TComment] = new ANodes[TComment](self)
1712 end
1713
1714 class AAnnotations
1715 super Prod
1716 readable writable var _n_at: nullable TAt = null
1717 readable writable var _n_opar: nullable TOpar = null
1718 readable var _n_items: ANodes[AAnnotation] = new ANodes[AAnnotation](self)
1719 readable writable var _n_cpar: nullable TCpar = null
1720 end
1721 class AAnnotation
1722 super Prod
1723 readable writable var _n_atid: AAtid
1724 readable writable var _n_opar: nullable TOpar = null
1725 readable var _n_args: ANodes[AAtArg] = new ANodes[AAtArg](self)
1726 readable writable var _n_cpar: nullable TCpar = null
1727 end
1728 abstract class AAtArg
1729 super Prod
1730 end
1731 class ATypeAtArg
1732 super AAtArg
1733 readable writable var _n_type: AType
1734 end
1735 class AExprAtArg
1736 super AAtArg
1737 readable writable var _n_expr: AExpr
1738 end
1739 class AAtAtArg
1740 super AAtArg
1741 end
1742 abstract class AAtid
1743 super Prod
1744 readable writable var _n_id: Token
1745 end
1746 class AIdAtid
1747 super AAtid
1748 end
1749 class AKwexternAtid
1750 super AAtid
1751 end
1752 class AKwinternAtid
1753 super AAtid
1754 end
1755 class AKwreadableAtid
1756 super AAtid
1757 end
1758 class AKwwritableAtid
1759 super AAtid
1760 end
1761 class AKwimportAtid
1762 super AAtid
1763 end
1764
1765 # The root of the AST
1766 class Start
1767 super Prod
1768 readable writable var _n_base: nullable AModule
1769 readable writable var _n_eof: EOF
1770 init(n_base: nullable AModule, n_eof: EOF)
1771 do
1772 self._n_base = n_base
1773 self._n_eof = n_eof
1774 end
1775 end