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