From: Jean Privat Date: Thu, 9 Feb 2017 17:06:46 +0000 (-0500) Subject: nitc: ASTDump can display aditionnal information X-Git-Url: http://nitlanguage.org nitc: ASTDump can display aditionnal information Signed-off-by: Jean Privat --- diff --git a/src/parser/parser_nodes.nit b/src/parser/parser_nodes.nit index 1d68c6f..5073193 100644 --- a/src/parser/parser_nodes.nit +++ b/src/parser/parser_nodes.nit @@ -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.