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