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