@Jehan The fact that an arbitrary string is ambiguous without a context is
probably the reason a context is passed as a separate parameter in Rust macros,
I guess. I sometimes miss that possibility in Nim, it would makes tricks
unnecessary and macros would be less of magic, I guess.
Ah, I think I found a solution:
import macros, strutils
macro typecheckedAst(x: typed): untyped =
echo "calling typecheck on expression: ", x.repr
echo "with type: ", x.getType().treeRepr()
# We can build a type specific AST here:
let typ = x.getType()
@planhths: What I'm looking for is the slightly more advanced version of that,
i.e., a macro that generates a different AST depending on the type of that
`parseExpr(v)` in your example.
Here is an example that works:
[plot_eval.nim](https://gist.github.com/konqoro/185337d656f1a2224a2d55391870b0c4)
I don't know what macros.strVal is supposed to do though I' m curious...
Sorry for bumping an old thread, but it's for a good reason (the [string
interpolation PR](https://github.com/nim-lang/Nim/pull/6507)). I'm still
struggling to achieve the same from within a macro:
macro parse(x: string): untyped =
echo "calling parse on: ", x
result = p