Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

macro parameter parsing?

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

  • Can't you use Wikifier.prototype.fullArgs() ?
  • Every time I've called that I've gotten a Twine error of "Error executing macro {whatever}: TypeError: 'undefined' is not an object (evaluating 'this.source.indexOf')" with no clear indication of what I'm doing wrong there.
  • Are you calling it as a property of the handler's fourth argument?

    handler: function(a,b,c, parser) {
    var f = parser.fullArgs();
  • I was not! Sorry, I'm kind of clueless about javascript; I haven't used it for much anything before. That helps.

    (I actually ended up still using parse because it's a two-arg macro and parser.fullArgs doesn't provide any way to break the resulting value up into arguments; I just switched my if condition to var[0] == "$" to keep it from mangling string literals.)
Sign In or Register to comment.