Sourceror.postwalk
postwalk
, go back to Sourceror module for more information.
Specs
postwalk(Macro.t(), postwalk_function()) :: Macro.t()
Performs a depth-first post-order traversal of a quoted expression, correcting line numbers as it goes.
See postwalk/3
for more information.
Specs
postwalk(Macro.t(), term(), postwalk_function()) :: {Macro.t(), term()}
Performs a depth-first post-order traversal of a quoted expression with an accumulator, correcting line numbers as it goes.
fun
is a function that will receive the current node as a first argument and
the traversal state as the second one. It must return a {quoted, state}
,
in the same way it would return {quoted, acc}
when using Macro.postwalk/3
.
Before calling fun
in a node, its line numbers will be corrected by the
state.line_correction
. If you need to manually correct the line number of
a node, use correct_lines/2
.
The state is a map with the following keys:
:line_correction
- an integer representing how many lines subsequent nodes should be shifted. If the function adds more nodes to the tree that should go in a new line, the line numbers of the subsequent nodes need to be updated in order for comments to be correctly placed during the formatting process. If the function does this kind of change, it must update the:line_correction
field by adding the amount of lines that should be shifted. Note that this field is cumulative, setting it to 0 will reset it for the whole traversal. Starts at0
.:acc
- The accumulator. Defaults tonil
if none is given.