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