@@ -17,7 +17,7 @@ the last seen LineNumberNode in the pre-order expr traversal).
1717Last-resort option so that, for example, we can lower the output of old
1818Expr-producing macros. Always prefer re-parsing source text over using this.
1919
20- Does not support lowered exprs.
20+ Supports parsed and/or macro-expanded exprs, but not lowered exprs
2121"""
2222function expr_to_syntaxtree (@nospecialize (e), lnn:: Union{LineNumberNode, Nothing} = nothing )
2323 graph = SyntaxGraph ()
@@ -154,11 +154,11 @@ function _insert_convert_expr(@nospecialize(e), graph::SyntaxGraph, src::SourceA
154154 return (st_id, src)
155155 elseif e isa LineNumberNode
156156 return (nothing , e)
157- elseif e isa QuoteNode
158- st_id = _insert_tree_node (graph, K " quote" , src)
159- quote_child, _ = _insert_convert_expr (e. value, graph, src)
160- setchildren! (graph, st_id, NodeId[quote_child])
161- return (st_id, src)
157+ # elseif e isa QuoteNode
158+ # st_id = _insert_tree_node(graph, K"quote", src)
159+ # quote_child, _ = _insert_convert_expr(e.value, graph, src)
160+ # setchildren!(graph, st_id, NodeId[quote_child])
161+ # return (st_id, src)
162162 elseif e isa String
163163 st_id = _insert_tree_node (graph, K " string" , src)
164164 id_inner = _insert_tree_node (graph, K " String" , src)
@@ -211,9 +211,11 @@ function _insert_convert_expr(@nospecialize(e), graph::SyntaxGraph, src::SourceA
211211 end
212212 end
213213 elseif e. head === :macrocall
214- @assert nargs >= 1
214+ @assert nargs >= 2
215215 a1 = e. args[1 ]
216- child_exprs = collect_expr_parameters (e, 2 )
216+ child_exprs = collect_expr_parameters (e, 3 )
217+ # macrocall has a linenode "argument" here. should we set src?
218+ deleteat! (child_exprs, 2 )
217219 if a1 isa Symbol
218220 child_exprs[1 ] = Expr (:MacroName , a1)
219221 elseif a1 isa Expr && a1. head === :(.) && a1. args[2 ] isa QuoteNode
@@ -227,12 +229,20 @@ function _insert_convert_expr(@nospecialize(e), graph::SyntaxGraph, src::SourceA
227229 elseif a1. name === Symbol (" @int128_str" )
228230 elseif a1. name === Symbol (" @big_str" )
229231 end
232+ elseif a1 isa Function
230233 else
231- dump (e)
232- error (" Unknown macrocall form $e " )
234+ error (" Unknown macrocall form $(sprint (dump, e)) " )
233235 end
234236
235237 # TODO node->expr handles do blocks here?
238+ elseif e. head === :escape || e. head === Symbol (" hygienic-scope" )
239+ @assert nargs >= 1
240+ # Existing behaviour appears to just ignore any extra args
241+ return _insert_convert_expr (e. args[1 ], graph, src)
242+ elseif e. head === :meta
243+ @assert nargs <= 2
244+ @assert e. args[1 ] isa Symbol
245+ child_exprs[1 ] = Expr (:sym_not_identifier , e. args[1 ])
236246 elseif e. head === Symbol (" '" )
237247 @assert nargs === 1
238248 st_k = K " call"
@@ -359,13 +369,18 @@ function _insert_convert_expr(@nospecialize(e), graph::SyntaxGraph, src::SourceA
359369 st_id = _insert_tree_node (graph, K " Placeholder" , src, st_flags)
360370 setattr! (graph, st_id, name_val= " " )
361371 return (st_id, src)
372+ elseif e. head === :sym_not_identifier
373+ estr = String (e. args[1 ])
374+ st_k = K " Symbol"
375+ st_id = _insert_tree_node (graph, st_k, src)
376+ setattr! (graph, st_id, name_val= estr)
377+ return (st_id, src)
362378 elseif e. head === :do_lambda
363379 st_k = K " do"
364380 end
365381
366382 if st_k === K " None"
367- dump (e)
368- error (" no kind for $(e. head) " )
383+ error (" no kind for expr head `$(e. head) `\n $(sprint (dump, e)) " )
369384 end
370385
371386 st_flags |= JS. NON_TERMINAL_FLAG
0 commit comments