@@ -139,61 +139,70 @@ function leaf_string(ex)
139
139
end
140
140
141
141
function _show_syntax_node (io, current_filename, node:: AbstractSyntaxNode ,
142
- indent, show_byte_offsets)
143
- fname = filename (node)
142
+ indent, show_location, show_kind)
144
143
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 = " "
148
154
end
149
155
val = node. val
150
156
nodestr = is_leaf (node) ? leaf_string (node) : " [$(untokenize (head (node))) ]"
151
157
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))
157
160
end
158
161
println (io, posstr, treestr)
159
162
if ! is_leaf (node)
160
163
new_indent = indent* " "
161
164
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 )
163
166
end
164
167
end
165
168
end
166
169
167
- function _show_syntax_node_sexpr (io, node:: AbstractSyntaxNode )
170
+ function _show_syntax_node_sexpr (io, node:: AbstractSyntaxNode , show_kind )
168
171
if is_leaf (node)
169
172
if is_error (node)
170
173
print (io, " (" , untokenize (head (node)), " )" )
171
174
else
172
175
print (io, leaf_string (node))
176
+ if show_kind
177
+ print (io, " ::" , kind (node))
178
+ end
173
179
end
174
180
else
175
181
print (io, " (" , untokenize (head (node)))
176
182
first = true
177
183
for n in children (node)
178
184
print (io, ' ' )
179
- _show_syntax_node_sexpr (io, n)
185
+ _show_syntax_node_sexpr (io, n, show_kind )
180
186
first = false
181
187
end
182
188
print (io, ' )' )
183
189
end
184
190
end
185
191
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)
189
198
end
190
199
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 )
193
202
end
194
203
195
204
function Base. show (io:: IO , node:: AbstractSyntaxNode )
196
- _show_syntax_node_sexpr (io, node)
205
+ _show_syntax_node_sexpr (io, node, false )
197
206
end
198
207
199
208
function Base. push! (node:: SN , child:: SN ) where SN<: AbstractSyntaxNode
0 commit comments