nitc: ASTDump can display aditionnal information
authorJean Privat <jean@pryen.org>
Thu, 9 Feb 2017 17:06:46 +0000 (12:06 -0500)
committerJean Privat <jean@pryen.org>
Thu, 9 Feb 2017 17:06:46 +0000 (12:06 -0500)
Signed-off-by: Jean Privat <jean@pryen.org>

src/parser/parser_nodes.nit

index 1d68c6f..5073193 100644 (file)
@@ -46,6 +46,11 @@ abstract class ANode
                d.write_to(sys.stdout)
        end
 
+       # Information to display on a node
+       #
+       # Refine this method to add additional information on each node type.
+       fun dump_info(v: ASTDump): String do return ""
+
        # Parent of the node in the AST
        var parent: nullable ANode = null
 
@@ -197,11 +202,7 @@ class ASTDump
 
        redef fun display(n)
        do
-               if n isa Token then
-                       return "{n.class_name} \"{n.text.escape_to_c}\" @{n.location}"
-               else
-                       return "{n.class_name} @{n.location}"
-               end
+               return "{n.class_name} {n.dump_info(self)} @{n.location}"
        end
 end
 
@@ -342,6 +343,8 @@ abstract class Token
 
        redef fun is_structural do return true
 
+       redef fun dump_info(v) do return " {text.escape_to_c}"
+
        # Loose tokens that precede `self`.
        #
        # These tokens start the line or belong to a line with only loose tokens.