4 ms·
I think what I'd really like is some way to expand format strings into McDermott-style code (and ideally vice versa). I think CL-PPCRE gets this correct for a
by martinflack 4y ago
I think what I'd really like is some way to expand format strings into McDermott-style code (and ideally vice versa).
I think CL-PPCRE gets this correct for a similar domain: regex strings. The library is not pedantic about whether you provide the compact string or an expanded nice version.
PPCRE> (parse-string "(ab)*")
(:GREEDY-REPETITION 0 NIL (:REGISTER "ab"))
PPCRE> (scan '(:greedy-repetition 0 nil (:register "ab")) "ababcd")
0
4
#(2)
#(4)
PPCRE>
- lapsed_lisper 4y agoOut of curiosity, how often do you find yourself using CL-PPCRE's S-expression notation? (This is a genuine question: I've never felt a desire for an S-expression notation for regular expressions, so I'm curious what I'm missing out on.) Anyhow, while it's certainly possible to parse FORMAT control strings into S-expressions, ISTM that if you want them to be invertible back into FORMAT strings, you'll end up with control structure and constant strings being contained within the S-expression, with data extraction as a separate concern. IOW, you won't get McDermott's preferred style of interwoven control, data extraction, and constant strings. For instance, you could have this FORMAT control string "~<~{~A~^, ~}.~:>" parse to something like (:paragraph-fill () (:iterate () (:aesthetic) (:exit-if-list-exhausted) ", ") ".") but this still separates concerns the way FORMAT does, and the way OUT doesn't.
- martinflack 4y agoI never use it for regex, because when using CL, I tend to be authoring the regex from scratch. But I found it elegant and thought it might be useful to interpret someone else's hairy regex. But the reason I mentioned it, was because I thought it might be more useful to me for FORMAT... just because decades of Perl 5 taught me regex really well, but I don't get to use CL's FORMAT syntax every week. ;-) Your further points are well taken.