mirror of
https://github.com/logos-storage/questionable.git
synced 2026-01-02 13:53:11 +00:00
Do not edit AST nodes, make a copy first
Fixes error "typechecked nodes may not be modified"
This commit is contained in:
parent
b18444a6d0
commit
8daae27089
@ -22,23 +22,27 @@ template chain(option: typed, identifier: untyped{nkIdent}): untyped =
|
||||
|
||||
macro chain(option: typed, infix: untyped{nkInfix}): untyped =
|
||||
# chain is of shape: option.?left `operator` right
|
||||
let infix = infix.copyNimTree()
|
||||
let left = infix[1]
|
||||
infix[1] = quote do: `option`.?`left`
|
||||
infix
|
||||
|
||||
macro chain(option: typed, bracket: untyped{nkBracketExpr}): untyped =
|
||||
# chain is of shape: option.?left[right]
|
||||
let bracket = bracket.copyNimTree()
|
||||
let left = bracket[0]
|
||||
bracket[0] = quote do: `option`.?`left`
|
||||
bracket
|
||||
|
||||
macro chain(option: typed, dot: untyped{nkDotExpr}): untyped =
|
||||
# chain is of shape: option.?left.right
|
||||
let dot = dot.copyNimTree()
|
||||
let left = dot[0]
|
||||
dot[0] = quote do: `option`.?`left`
|
||||
dot
|
||||
|
||||
macro chain(option: typed, call: untyped{nkCall}): untyped =
|
||||
let call = call.copyNimTree()
|
||||
let procedure = call[0]
|
||||
if call.len == 1:
|
||||
# chain is of shape: option.?procedure()
|
||||
|
||||
@ -12,6 +12,7 @@ proc undoSymbolResolution(expression, ident: NimNode): NimNode =
|
||||
if expression.kind in symbolKinds and eqIdent($expression, $ident):
|
||||
return ident
|
||||
|
||||
let expression = expression.copyNimTree()
|
||||
for i in 0..<expression.len:
|
||||
expression[i] = undoSymbolResolution(expression[i], ident)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user