mirror of
https://github.com/logos-storage/questionable.git
synced 2026-01-03 22:33:07 +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 =
|
macro chain(option: typed, infix: untyped{nkInfix}): untyped =
|
||||||
# chain is of shape: option.?left `operator` right
|
# chain is of shape: option.?left `operator` right
|
||||||
|
let infix = infix.copyNimTree()
|
||||||
let left = infix[1]
|
let left = infix[1]
|
||||||
infix[1] = quote do: `option`.?`left`
|
infix[1] = quote do: `option`.?`left`
|
||||||
infix
|
infix
|
||||||
|
|
||||||
macro chain(option: typed, bracket: untyped{nkBracketExpr}): untyped =
|
macro chain(option: typed, bracket: untyped{nkBracketExpr}): untyped =
|
||||||
# chain is of shape: option.?left[right]
|
# chain is of shape: option.?left[right]
|
||||||
|
let bracket = bracket.copyNimTree()
|
||||||
let left = bracket[0]
|
let left = bracket[0]
|
||||||
bracket[0] = quote do: `option`.?`left`
|
bracket[0] = quote do: `option`.?`left`
|
||||||
bracket
|
bracket
|
||||||
|
|
||||||
macro chain(option: typed, dot: untyped{nkDotExpr}): untyped =
|
macro chain(option: typed, dot: untyped{nkDotExpr}): untyped =
|
||||||
# chain is of shape: option.?left.right
|
# chain is of shape: option.?left.right
|
||||||
|
let dot = dot.copyNimTree()
|
||||||
let left = dot[0]
|
let left = dot[0]
|
||||||
dot[0] = quote do: `option`.?`left`
|
dot[0] = quote do: `option`.?`left`
|
||||||
dot
|
dot
|
||||||
|
|
||||||
macro chain(option: typed, call: untyped{nkCall}): untyped =
|
macro chain(option: typed, call: untyped{nkCall}): untyped =
|
||||||
|
let call = call.copyNimTree()
|
||||||
let procedure = call[0]
|
let procedure = call[0]
|
||||||
if call.len == 1:
|
if call.len == 1:
|
||||||
# chain is of shape: option.?procedure()
|
# 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):
|
if expression.kind in symbolKinds and eqIdent($expression, $ident):
|
||||||
return ident
|
return ident
|
||||||
|
|
||||||
|
let expression = expression.copyNimTree()
|
||||||
for i in 0..<expression.len:
|
for i in 0..<expression.len:
|
||||||
expression[i] = undoSymbolResolution(expression[i], ident)
|
expression[i] = undoSymbolResolution(expression[i], ident)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user