@@ -126,63 +126,72 @@ byte_range(node::AbstractSyntaxNode) = node.position:(node.position + span(node)
126126sourcefile (node:: AbstractSyntaxNode ) = node. source
127127
128128function _show_syntax_node (io, current_filename, node:: AbstractSyntaxNode ,
129- indent, show_byte_offsets)
130- fname = filename (node)
129+ indent, show_location, show_kind)
131130 line, col = source_location (node)
132- posstr = " $(lpad (line, 4 )) :$(rpad (col,3 )) │"
133- if show_byte_offsets
134- posstr *= " $(lpad (first_byte (node),6 )) :$(rpad (last_byte (node),6 )) │"
131+ if show_location
132+ fname = filename (node)
133+ # Add filename if it's changed from the previous node
134+ if fname != current_filename[]
135+ println (io, indent, " -file- │ " , repr (fname))
136+ current_filename[] = fname
137+ end
138+ posstr = " $(lpad (line, 4 )) :$(rpad (col,3 )) │$(lpad (first_byte (node),6 )) :$(rpad (last_byte (node),6 )) │"
139+ else
140+ posstr = " "
135141 end
136142 val = node. val
137143 nodestr = ! is_leaf (node) ? " [$(untokenize (head (node))) ]" :
138- isa (val, Symbol) ? string (val) : repr (val)
144+ ( isa (val, Symbol) ? string (val) : repr (val) )
139145 treestr = string (indent, nodestr)
140- # Add filename if it's changed from the previous node
141- if fname != current_filename[]
142- # println(io, "# ", fname)
143- treestr = string (rpad (treestr, 40 ), " │$fname " )
144- current_filename[] = fname
146+ if show_kind && is_leaf (node)
147+ treestr = rpad (treestr, 40 )* " :: " * string (kind (node))
145148 end
146149 println (io, posstr, treestr)
147150 if ! is_leaf (node)
148151 new_indent = indent* " "
149152 for n in children (node)
150- _show_syntax_node (io, current_filename, n, new_indent, show_byte_offsets )
153+ _show_syntax_node (io, current_filename, n, new_indent, show_location, show_kind )
151154 end
152155 end
153156end
154157
155- function _show_syntax_node_sexpr (io, node:: AbstractSyntaxNode )
158+ function _show_syntax_node_sexpr (io, node:: AbstractSyntaxNode , show_kind )
156159 if is_leaf (node)
157160 if is_error (node)
158161 print (io, " (" , untokenize (head (node)), " )" )
159162 else
160163 val = node. val
161164 print (io, val isa Symbol ? string (val) : repr (val))
165+ if show_kind
166+ print (io, " ::" , kind (node))
167+ end
162168 end
163169 else
164170 print (io, " (" , untokenize (head (node)))
165171 first = true
166172 for n in children (node)
167173 print (io, ' ' )
168- _show_syntax_node_sexpr (io, n)
174+ _show_syntax_node_sexpr (io, n, show_kind )
169175 first = false
170176 end
171177 print (io, ' )' )
172178 end
173179end
174180
175- function Base. show (io:: IO , :: MIME"text/plain" , node:: AbstractSyntaxNode ; show_byte_offsets= false )
176- println (io, " line:col│$(show_byte_offsets ? " byte_range │" : " " ) tree │ file_name" )
177- _show_syntax_node (io, Ref (" " ), node, " " , show_byte_offsets)
181+ function Base. show (io:: IO , :: MIME"text/plain" , node:: AbstractSyntaxNode ; show_location= false , show_kind= true )
182+ println (io, " SyntaxNode:" )
183+ if show_location
184+ println (io, " line:col│ byte_range │ tree" )
185+ end
186+ _show_syntax_node (io, Ref (" " ), node, " " , show_location, show_kind)
178187end
179188
180- function Base. show (io:: IO , :: MIME"text/x.sexpression" , node:: AbstractSyntaxNode )
181- _show_syntax_node_sexpr (io, node)
189+ function Base. show (io:: IO , :: MIME"text/x.sexpression" , node:: AbstractSyntaxNode ; show_kind = false )
190+ _show_syntax_node_sexpr (io, node, show_kind )
182191end
183192
184193function Base. show (io:: IO , node:: AbstractSyntaxNode )
185- _show_syntax_node_sexpr (io, node)
194+ _show_syntax_node_sexpr (io, node, false )
186195end
187196
188197function Base. push! (node:: SN , child:: SN ) where SN<: AbstractSyntaxNode
0 commit comments