File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -428,15 +428,21 @@ end
428428
429429
430430"""
431- Copy AST `ex` into `ctx`
431+ Recursively copy AST `ex` into `ctx`. The resulting tree contains new nodes
432+ only, and does not contain nodes with multiple parents.
433+
434+ Special provenance handling: If `copy_source` is true, treat the `.source`
435+ attribute as a reference and recurse on its contents. Otherwise, treat it like
436+ any other attribute.
432437"""
433- function copy_ast (ctx, ex)
438+ function copy_ast (ctx, ex; copy_source = true )
434439 # TODO : Do we need to keep a mapping of node IDs to ensure we don't
435440 # double-copy here in the case when some tree nodes are pointed to by
436441 # multiple parents? (How much does this actually happen in practice?)
437- s = ex . source
442+ s = get (ex, : source, nothing )
438443 # TODO : Figure out how to use provenance() here?
439- srcref = s isa NodeId ? copy_ast (ctx, SyntaxTree (ex. _graph, s)) :
444+ srcref = ! copy_source ? s :
445+ s isa NodeId ? copy_ast (ctx, SyntaxTree (ex. _graph, s)) :
440446 s isa Tuple ? map (i-> copy_ast (ctx, SyntaxTree (ex. _graph, i)), s) :
441447 s
442448 if ! is_leaf (ex)
You can’t perform that action at this time.
0 commit comments