by martinflack · 4y ago · 0 comments
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>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.Your further points are well taken.