3 ms·
I've tried using this, but the documentation and learning resources weren't very good (at least at the time ~6 months ago) and structuring refactors with YAML m
by Conscat 3y ago
I've tried using this, but the documentation and learning resources weren't very good (at least at the time ~6 months ago) and structuring refactors with YAML made it very cumbersome for me to write and edit one-off commands.
Tree Sitter also leaves a lot to be desired for C++ editing, but that's a special problem.
- simonw 3y agoLooks like the project is only about 12 months old, so if you last checked it out 6 months ago it's worth taking another look. Was it possible to use it entirely as a CLI tool without any YAML 6 months ago?
- Conscat 3y agoUnless the search/replace is super simple, you need the YAML as far as I can tell. The refactor I gave up on automating had to do with changing variadic C++ macros into arithmetic expressions, which wasn't conceptually very complicated, but felt almost impossible while constantly tripping over YAML syntax errors.
- simonw 3y agoThe YAML syntax I find most useful for this kind of thing is this: something: subkey: | I can put any characters I like in here And they "won't be messed up" by anything Because they are part of a multi-line string
- 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
- herrington_d 3y agoHi! Thanks for trying out ast-grep. I have been improving ast-grep's documentation since the release of the project. It is arguably not that good/abundant for resources compared to eslint/babel. But it has improved a lot (say, example page[0] and deep dive page[1]). The doc site is also carefully crafted to make it accessible, compared to libcst or other similar projects. I also appreciate blogs/introductions to ast-grep if the community can help! Let me know if there are issues/problems when using ast-grep! [0] https://ast-grep.github.io/catalog/ https://ast-grep.github.io/catalog/ [1] https://ast-grep.github.io/advanced/core-concepts.html https://ast-grep.github.io/advanced/core-concepts.html