parser: add qualified module names
[nit.git] / src / parser / parser_prod.nit
index 847a005..9f442dd 100644 (file)
@@ -150,7 +150,7 @@ redef class AModuledecl
     init init_amoduledecl (
             n_doc: nullable ADoc,
             n_kwmodule: nullable TKwmodule,
-            n_id: nullable TId
+            n_name: nullable AModuleName
     )
     do
         empty_init
@@ -160,8 +160,8 @@ redef class AModuledecl
        end
         _n_kwmodule = n_kwmodule.as(not null)
        n_kwmodule.parent = self
-        _n_id = n_id.as(not null)
-       n_id.parent = self
+        _n_name = n_name.as(not null)
+       n_name.parent = self
     end
 
     redef fun replace_child(old_child: ANode, new_child: nullable ANode)
@@ -186,11 +186,11 @@ redef class AModuledecl
             end
             return
        end
-        if _n_id == old_child then
+        if _n_name == old_child then
             if new_child != null then
                 new_child.parent = self
-               assert new_child isa TId
-                _n_id = new_child
+               assert new_child isa AModuleName
+                _n_name = new_child
            else
                abort
             end
@@ -204,7 +204,7 @@ redef class AModuledecl
             v.enter_visit(_n_doc.as(not null))
         end
         v.enter_visit(_n_kwmodule)
-        v.enter_visit(_n_id)
+        v.enter_visit(_n_name)
     end
 end
 redef class AStdImport
@@ -213,7 +213,7 @@ redef class AStdImport
     init init_astdimport (
             n_visibility: nullable AVisibility,
             n_kwimport: nullable TKwimport,
-            n_id: nullable TId
+            n_name: nullable AModuleName
     )
     do
         empty_init
@@ -221,8 +221,8 @@ redef class AStdImport
        n_visibility.parent = self
         _n_kwimport = n_kwimport.as(not null)
        n_kwimport.parent = self
-        _n_id = n_id.as(not null)
-       n_id.parent = self
+        _n_name = n_name.as(not null)
+       n_name.parent = self
     end
 
     redef fun replace_child(old_child: ANode, new_child: nullable ANode)
@@ -247,11 +247,11 @@ redef class AStdImport
             end
             return
        end
-        if _n_id == old_child then
+        if _n_name == old_child then
             if new_child != null then
                 new_child.parent = self
-               assert new_child isa TId
-                _n_id = new_child
+               assert new_child isa AModuleName
+                _n_name = new_child
            else
                abort
             end
@@ -263,7 +263,7 @@ redef class AStdImport
     do
         v.enter_visit(_n_visibility)
         v.enter_visit(_n_kwimport)
-        v.enter_visit(_n_id)
+        v.enter_visit(_n_name)
     end
 end
 redef class ANoImport
@@ -3834,7 +3834,7 @@ redef class AForExpr
 
     init init_aforexpr (
             n_kwfor: nullable TKwfor,
-            n_id: nullable TId,
+            n_ids: Collection[Object], # Should be Collection[TId]
             n_expr: nullable AExpr,
             n_kwdo: nullable TKwdo,
             n_block: nullable AExpr,
@@ -3844,8 +3844,11 @@ redef class AForExpr
         empty_init
         _n_kwfor = n_kwfor.as(not null)
        n_kwfor.parent = self
-        _n_id = n_id.as(not null)
-       n_id.parent = self
+       for n in n_ids do
+               assert n isa TId
+               _n_ids.add(n)
+               n.parent = self
+       end
         _n_expr = n_expr.as(not null)
        n_expr.parent = self
         _n_kwdo = n_kwdo.as(not null)
@@ -3872,16 +3875,18 @@ redef class AForExpr
             end
             return
        end
-        if _n_id == old_child then
-            if new_child != null then
-                new_child.parent = self
-               assert new_child isa TId
-                _n_id = new_child
-           else
-               abort
+        for i in [0.._n_ids.length[ do
+            if _n_ids[i] == old_child then
+                if new_child != null then
+                   assert new_child isa TId
+                    _n_ids[i] = new_child
+                    new_child.parent = self
+                else
+                    _n_ids.remove_at(i)
+                end
+                return
             end
-            return
-       end
+        end
         if _n_expr == old_child then
             if new_child != null then
                 new_child.parent = self
@@ -3927,7 +3932,9 @@ redef class AForExpr
     redef fun visit_all(v: Visitor)
     do
         v.enter_visit(_n_kwfor)
-        v.enter_visit(_n_id)
+            for n in _n_ids do
+                v.enter_visit(n)
+           end
         v.enter_visit(_n_expr)
         v.enter_visit(_n_kwdo)
         if _n_block != null then
@@ -7260,6 +7267,76 @@ redef class ABreakClosureId
         v.enter_visit(_n_kwbreak)
     end
 end
+redef class AModuleName
+    private init empty_init do end
+
+    init init_amodulename (
+            n_quad: nullable TQuad,
+            n_path: Collection[Object], # Should be Collection[TId]
+            n_id: nullable TId
+    )
+    do
+        empty_init
+        _n_quad = n_quad
+       if n_quad != null then
+               n_quad.parent = self
+       end
+       for n in n_path do
+               assert n isa TId
+               _n_path.add(n)
+               n.parent = self
+       end
+        _n_id = n_id.as(not null)
+       n_id.parent = self
+    end
+
+    redef fun replace_child(old_child: ANode, new_child: nullable ANode)
+    do
+        if _n_quad == old_child then
+            if new_child != null then
+                new_child.parent = self
+               assert new_child isa TQuad
+                _n_quad = new_child
+           else
+               _n_quad = null
+            end
+            return
+       end
+        for i in [0.._n_path.length[ do
+            if _n_path[i] == old_child then
+                if new_child != null then
+                   assert new_child isa TId
+                    _n_path[i] = new_child
+                    new_child.parent = self
+                else
+                    _n_path.remove_at(i)
+                end
+                return
+            end
+        end
+        if _n_id == old_child then
+            if new_child != null then
+                new_child.parent = self
+               assert new_child isa TId
+                _n_id = new_child
+           else
+               abort
+            end
+            return
+       end
+    end
+
+    redef fun visit_all(v: Visitor)
+    do
+        if _n_quad != null then
+            v.enter_visit(_n_quad.as(not null))
+        end
+            for n in _n_path do
+                v.enter_visit(n)
+           end
+        v.enter_visit(_n_id)
+    end
+end
 redef class AQualified
     private init empty_init do end