parser_util: drop injected tokens
authorJean Privat <jean@pryen.org>
Sat, 31 May 2014 00:59:07 +0000 (20:59 -0400)
committerJean Privat <jean@pryen.org>
Sat, 31 May 2014 02:56:57 +0000 (22:56 -0400)
Do not locate them so they are excluded by the parser.
Remove parents in the result of parse_something so injected tokens
become unaccesible.

Signed-off-by: Jean Privat <jean@pryen.org>

src/parser_util.nit

index 55ff3f7..9652a1f 100644 (file)
@@ -121,6 +121,7 @@ redef class ToolContext
                eof = tree.n_eof
                if not eof isa AError then
                        var ntype = tree.n_base.n_classdefs.first.n_propdefs.first.as(AMethPropdef).n_block.as(ABlockExpr).n_expr.first.as(AVardeclExpr).n_type.n_types.first
+                       ntype.parent = null
                        return ntype
                end
                error = eof
@@ -130,6 +131,7 @@ redef class ToolContext
                if not first isa EOF then
                        var second = lexer.next
                        if second isa EOF and not second isa AError then
+                               first.parent = null
                                return first
                        end
                end
@@ -144,6 +146,7 @@ redef class ToolContext
                eof = tree.n_eof
                if not eof isa AError then
                        var nexpr = tree.n_base.n_classdefs.first.n_propdefs.first.as(AMethPropdef).n_block.as(ABlockExpr).n_expr.first.as(AVardeclExpr).n_expr.as(AParExpr).n_expr
+                       nexpr.parent = null
                        return nexpr
                end
                if eof.location > error.location then error = eof
@@ -158,6 +161,7 @@ redef class ToolContext
                if not eof isa AError then
                        var nblock = tree.n_base.n_classdefs.first.n_propdefs.first.as(AMethPropdef).n_block.as(ABlockExpr).n_expr.first.as(ADoExpr).n_block.as(ABlockExpr)
                        nblock.n_kwend = null # drop injected token
+                       nblock.parent = null
                        return nblock
                end
                if eof.location > error.location then error = eof
@@ -216,7 +220,6 @@ class InjectedLexer
        do
                if not injected_before.is_empty then
                        var tok = injected_before.shift
-                       if tok._location == null then tok._location = new Location(file, 1, 1, 1, 0)
                        return tok
                end
                if not is_finished then
@@ -227,7 +230,6 @@ class InjectedLexer
                end
 
                var tok = injected_after.shift
-               if tok._location == null then tok._location = new Location(file, 1, 1, 1, 0)
                return tok
        end
 end