From a748d22350ad6687f107c226733c211c54939aca Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Tue, 11 Jan 2022 12:31:25 +0100 Subject: [PATCH] =?UTF-8?q?Fix:=20ensure=20that=20overridden=20=3D=3F=20op?= =?UTF-8?q?erator=20does=20not=20remain=20in=20scope?= --- questionable/withoutresult.nim | 35 +++++++++++++++++++++++++--------- testmodules/result/test.nim | 22 +++++++++++++++++++++ 2 files changed, 48 insertions(+), 9 deletions(-) diff --git a/questionable/withoutresult.nim b/questionable/withoutresult.nim index 087a3e5..1188db2 100644 --- a/questionable/withoutresult.nim +++ b/questionable/withoutresult.nim @@ -1,22 +1,39 @@ +import std/macros import ./binding import ./without -template without*(expression, errorname, body) = +macro replaceInfix(expression, operator, replacement): untyped = + ## Replaces an infix operator in an expression. The AST of the expression is + ## traversed to find and replace all instances of the operator. + + proc replace(expression, operator, replacement: NimNode): NimNode = + if expression.kind == nnkInfix and eqIdent(expression[0], operator): + expression[0] = replacement + expression[2] = replace(expression[2], operator, replacement) + else: + for i in 0..