astutil: do not crash if the AST is just a token
authorJean Privat <jean@pryen.org>
Sat, 31 May 2014 01:01:30 +0000 (21:01 -0400)
committerJean Privat <jean@pryen.org>
Sat, 31 May 2014 02:56:57 +0000 (22:56 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

src/astutil.nit

index c671e87..7257c3f 100644 (file)
@@ -278,13 +278,13 @@ private class PTokenVisitor
                else
                        p = last_token.common_parent(n)
                end
-               assert p isa Prod
-
-               # And apply it to detached tokens between `last_token` and `n`
-               var c = n.prev_token
-               while c != null and c.parent == null do
-                       c.parent = p
-                       c = c.prev_token
+               if p isa Prod then
+                       # And apply it to detached tokens between `last_token` and `n`
+                       var c = n.prev_token
+                       while c != null and c.parent == null do
+                               c.parent = p
+                               c = c.prev_token
+                       end
                end
 
                self.last_token = n