3 ms·
> changing variadic C++ macros into arithmetic expressions I don't know your exact use case but it sounds a little bit hard to me. I guess you want to change t
by herrington_d 3y ago
> changing variadic C++ macros into arithmetic expressions
I don't know your exact use case but it sounds a little bit hard to me. I guess you want to change things like this.
```cpp
add_macro(a, b, c, d); // before
a + b + c + d; // after
```
It isn't that easy to do in pattern syntax. The pattern/replacement must support repetition and it isn't straightforward as far as I can tell from Rust's macro[0].
That said, if you need to support use cases like this, ast-grep has Python API to support programmatic usage[1].
[0] https://veykril.github.io/tlborm/decl-macros/macros-methodical.html#repetitions https://veykril.github.io/tlborm/decl-macros/macros-methodic...
[1] https://ast-grep.github.io/guide/api-usage/py-api.html https://ast-grep.github.io/guide/api-usage/py-api.html