for parsing a defn with meander, there's the case of the optional docstring. Is it possible to do some kind of (m/? (m/pred string? ?docstring))
that when rewritten will take "no space" if it couldn't be bound to anything?
@dominicm Not yet!
That's okay. I just copy-pasted the rule I had :)
I realized I probably would want slightly special handling for the docstring anyway.
I'm using meander as part of my code formatter. I feel like such a pedant right now 😁. "No more docstrings on the same line as the arglists for you!" "Banish that vertical alignment" (I've decided my code formatter is evil, rather than positive. Just a personality thing.)
That sounds fantastic.
I’d really like to see what you cook up.
FWIW, For things like defn
I tend to write separate rules for each of the cases. In some cases I might use m/with
if its not too complex but I tend to stick with multiple rules because I find it easier to grok.
@noprompt have you started experimenting? I'd be curious to know what you are using in combination.
@dominicm On what?
Also, a gift! 👉 https://github.com/noprompt/meander/blob/epsilon/doc/defsyntax.md
I hope that article helps explain defsyntax
a bit better. It doesn’t go into implementation details or anything like that but I think it does equip folks with enough information to be “dangerous”.
🙂
What are you using meander for so far. I assume you're using it with other libraries. What libraries?
Yeah. I’m mostly messing around with experimental interpreter/compiler stuff. I have a part of a syntax search and replace tool which I need to make a thing.
We’ve made some good use of it at work to do basic/complex stuff. Basic being match
, complex being search
to pull out many things of interest on a single data structure where a maze of mapcat
would pretty much make it unclear what the hell is going on. 🙂
Clojure interpreter? Curious what you're using for whitespace for search replace.
So my search and replace solution is kind of janky insofar as it doesn’t account for whitespace but it should. Essentially its pattern matching and pretty prettying the substitution. The pretty printing is using stock pprint
but what I’d rather do is have rewrite rules turning sexprs into fipp instructions and just have fipp do the work of printing.
I’ve got a small step Clojure interpreter I’m working on and off on but its a mountain of work deriving it.
I’ve also written an interpreter for a language I’ve code named “daft” which is basically a mash up of meander and a specific pattern of core.async use.
These kinds of projects really motivated me to make Meander because often I want to experiment with new ideas but the drudgery of doing it with vanilla Clojure is, frankly, crazy making.
Have you given any thought to using fipp for the work you’re doing?
Fipp isn't really what I'm after I think. My current formatter is an unformatter really. It undoes patterns which are hard to maintain (vertical whitespace), or which violate my personal sensibilities on consistency in a codebase (different namespace aliases). I'm intentionally avoiding things like 2 vs 1 space indents because it's a battle of the editor and context. I suppose you can consider it the set of things which could easily be done manually if you were thinking about it. Eg a newline before the arglist in defn. I'm otherwise trying to preserve everything about the code.
Make sure to use a reader which preserves whitespace. You'll want to make sure you hold onto comments. That's the big problem with pprint approaches :)
That's good. Dangerous capabilities are important.