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