# Guidelines on syntax checking for macros

**URL:** <https://discourse.julialang.org/t/guidelines-on-syntax-checking-for-macros/113258>\
**Category:** General Usage\
**Tags:** macros\
**Created:** [April 20, 2024, 12:40am UTC](https://discourse.julialang.org/t/guidelines-on-syntax-checking-for-macros/113258 "2024-04-20T00:40:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![CameronBieganek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cameronbieganek/32/6915_2.png) [@CameronBieganek](https://discourse.julialang.org/u/CameronBieganek)\
**Post date:** [April 20, 2024, 12:40am UTC](https://discourse.julialang.org/t/guidelines-on-syntax-checking-for-macros/113258/1 "2024-04-20T00:40:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [April 20, 2024, 4:51am UTC](https://discourse.julialang.org/t/guidelines-on-syntax-checking-for-macros/113258/2 "2024-04-20T04:51:25Z")

</div>

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

> <https://github.com/jump-dev/JuMP.jl/blob/master/src/macros/%40variable.jl>

> <https://github.com/jump-dev/JuMP.jl/blob/509ab616192bc90891c329010e2205f414c8cf94/src/Containers/macro.jl#L625>
