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..