Guidelines on syntax checking for macros

Currently I’m developing a few macros that behave a bit like language keywords (there is no public non-macro interface). I’ve been leaning towards aggressively checking the syntax/expressions that the user provides and throwing informative errors if they don’t use the right syntax.

Is this a reasonable approach? Are there any guidelines on whether one should or should not do verification of the input syntax in macros?

Perhaps if you’re writing a macro that does some fairly simple syntax transformations and then calls a function that is part of your public API, then maybe it’s reasonable to just assume correct syntax and let the public function throw errors on bad input? (Which is not my situation—as mentioned above my macros behave more like language keywords.)

1 Like

Aggressively validate input syntax. You may find reading the various JuMP macros helpful:

3 Likes