-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
for a jq code beautifier #8
Comments
Hey! all good here, thanks for asking Yes that would be very nice to have, and i've had thoughts about doing a jqlint/jqfmt tool but not much progress yet. I've asked itchny the gojq author about it some time ago itchyny/gojq#123 itchyny/gojq#62, he had some ideas that might be useful. Off the top of my head there are some tricky things:
BTW there is an old WIP jqjq branch to support serializing back to compact string https://github.com/wader/jqjq/tree/tostring, also a WIP branch to produce graphviz! :) https://github.com/wader/jqjq/tree/dot |
Thanks @wader for this reply. This weekend I worked on your jqjq's tostring branch : It's much more fun than doing everything from scratch! For now I'm not looking to make a perfect beautifier, just a simple way to parse and get the code back. Note: I know that the missing support for "String interpolation expressions" in your jq parser will probably be the first major problem in detecting function calls but never mind! Regards, |
Nice, hope it was in ok shape?
Good strategy i think, its usually what i do also, work on something that feel motivating and fun and while you do that you learn more and get ideas how to do the rest :)
Yeap ignore parsing of string interpolation for now, it will probably involve modifying the lexer a bit... a bit tricky. If you want to write "tostring" code for string interpolation anyway you can always produce an AST manually, or use:
to get gojq's AST as JSON. I've tried to reuse that gojq's structure as much as possible in jqjq. Note also that fq has support for "raw" string literals using `...` which is quite handy in these cases. |
TL;DR
My way to run is ...
You may see the both way ( About the "jq beautifier" idea (and more)... I took your I put them in lex.jq, parse.jq, ast_to_string.jq to be able to easily use them onver my wrapper (jq_stack4). My tests was written in a separated repository "jq-mods-demo" (a sort of poor test suite :-$ ). For now it is easier for me to show you my working space directly, but I can put my Regards, |
👍 I haven't looked closer how the jq shell/mods stuff work yet. I usually run a
It's a bit annoying that jq's standard library is inconsistent with this, i can never make up my mind which one i prefer. I went with without underscore of most of fq but it do feel messy at times so maybe should change it.
Looks good i think! would be nice if there was a more consistent way ppl write jq, so many different styles it seems :) after lots of written jq i've ended up with 2 space indent which aligns nice with pertnesses with multiple lines What happens here https://github.com/tst2005sh/jq-mods/blob/master/lib/jq/ast_to_string.jq#L43 splitting on " "? Have you looked at how jq implements tests? quiet neat. There is implementation of it in jq for jqjq, also one in fq that might be interesting https://github.com/wader/fq/blob/master/pkg/interp/jqtest.jq, but it require some kind of eval.
Great! i'm happy as long as it's consistent inside one project, so just make it look similar to the rest for now, maybe i will change to more underscores and whatnot later :) One thing, i try to keep jqjq compatible with jq 1.6 (the one used on jqplay.org) which most of times usually just means avoid using optional else for if-statements. I wonder if we can figure out some way nice way to have tests for various ast things. Currently jqjq.test won't work as is i think unless we add plumbing so they are available in the jqjq environment, maybe as _jqjq_<func> somehow etc? |
Hello wader,
I hope your are fine.
I discovered your jqjq project late.
I also made my own POSIX Shell wrapper with jq for jq but for another goal with another design (mainly 1 jq to process the code 1 jq to evaluate it).
I've been dreaming of a jq lexer/parser for a while, you did it!
Now I think about a side : a jq code beautifier !
With your
lex
andparse
functions, I get the AST.I need a function to convert back the AST to string.
I plan to write this "AST_to_string" function, but I'd rather ask you if you haven't already done it?
Regards,
The text was updated successfully, but these errors were encountered: