Is there a preferred canonical way to parse macro arguments as maybe-string-literals-maybe-variables-or-expressions? I've been using
if (Wikifier.parse(var) != var) {
var = eval (Wikifier.parse(var));
}
which... works for most of my cases, but it has pretty substantial issues when it comes to strings containing "is", "and", that kind of thing, and that's not even bringing up situations like
<<foo ($i + 10)>>
. I've seen some macro code that tests
var[0] == "$"
, but that only really works for variable literals, not expressions.
...then again, probably no one but me would ever want to use complex expressions in macros, so maybe that's the best it gets?
Comments
(I actually ended up still using
parse
because it's a two-arg macro andparser.fullArgs
doesn't provide any way to break the resulting value up into arguments; I just switched my if condition tovar[0] == "$"
to keep it from mangling string literals.)