@@ -139,61 +139,70 @@ function leaf_string(ex)
139139end
140140
141141function _show_syntax_node (io, current_filename, node:: AbstractSyntaxNode ,
142- indent, show_byte_offsets)
143- fname = filename (node)
142+ indent, show_location, show_kind)
144143 line, col = source_location (node)
145- posstr = " $(lpad (line, 4 )) :$(rpad (col,3 )) │"
146- if show_byte_offsets
147- posstr *= " $(lpad (first_byte (node),6 )) :$(rpad (last_byte (node),6 )) │"
144+ if show_location
145+ fname = filename (node)
146+ # Add filename if it's changed from the previous node
147+ if fname != current_filename[]
148+ println (io, indent, " -file- │ " , repr (fname))
149+ current_filename[] = fname
150+ end
151+ posstr = " $(lpad (line, 4 )) :$(rpad (col,3 )) │$(lpad (first_byte (node),6 )) :$(rpad (last_byte (node),6 )) │"
152+ else
153+ posstr = " "
148154 end
149155 val = node. val
150156 nodestr = is_leaf (node) ? leaf_string (node) : " [$(untokenize (head (node))) ]"
151157 treestr = string (indent, nodestr)
152- # Add filename if it's changed from the previous node
153- if fname != current_filename[]
154- # println(io, "# ", fname)
155- treestr = string (rpad (treestr, 40 ), " │$fname " )
156- current_filename[] = fname
158+ if show_kind && is_leaf (node)
159+ treestr = rpad (treestr, 40 )* " :: " * string (kind (node))
157160 end
158161 println (io, posstr, treestr)
159162 if ! is_leaf (node)
160163 new_indent = indent* " "
161164 for n in children (node)
162- _show_syntax_node (io, current_filename, n, new_indent, show_byte_offsets )
165+ _show_syntax_node (io, current_filename, n, new_indent, show_location, show_kind )
163166 end
164167 end
165168end
166169
167- function _show_syntax_node_sexpr (io, node:: AbstractSyntaxNode )
170+ function _show_syntax_node_sexpr (io, node:: AbstractSyntaxNode , show_kind )
168171 if is_leaf (node)
169172 if is_error (node)
170173 print (io, " (" , untokenize (head (node)), " )" )
171174 else
172175 print (io, leaf_string (node))
176+ if show_kind
177+ print (io, " ::" , kind (node))
178+ end
173179 end
174180 else
175181 print (io, " (" , untokenize (head (node)))
176182 first = true
177183 for n in children (node)
178184 print (io, ' ' )
179- _show_syntax_node_sexpr (io, n)
185+ _show_syntax_node_sexpr (io, n, show_kind )
180186 first = false
181187 end
182188 print (io, ' )' )
183189 end
184190end
185191
186- function Base. show (io:: IO , :: MIME"text/plain" , node:: AbstractSyntaxNode ; show_byte_offsets= false )
187- println (io, " line:col│$(show_byte_offsets ? " byte_range │" : " " ) tree │ file_name" )
188- _show_syntax_node (io, Ref (" " ), node, " " , show_byte_offsets)
192+ function Base. show (io:: IO , :: MIME"text/plain" , node:: AbstractSyntaxNode ; show_location= false , show_kind= true )
193+ println (io, " SyntaxNode:" )
194+ if show_location
195+ println (io, " line:col│ byte_range │ tree" )
196+ end
197+ _show_syntax_node (io, Ref (" " ), node, " " , show_location, show_kind)
189198end
190199
191- function Base. show (io:: IO , :: MIME"text/x.sexpression" , node:: AbstractSyntaxNode )
192- _show_syntax_node_sexpr (io, node)
200+ function Base. show (io:: IO , :: MIME"text/x.sexpression" , node:: AbstractSyntaxNode ; show_kind = false )
201+ _show_syntax_node_sexpr (io, node, show_kind )
193202end
194203
195204function Base. show (io:: IO , node:: AbstractSyntaxNode )
196- _show_syntax_node_sexpr (io, node)
205+ _show_syntax_node_sexpr (io, node, false )
197206end
198207
199208function Base. push! (node:: SN , child:: SN ) where SN<: AbstractSyntaxNode
0 commit comments