Parse S-Expression with Clojure Spec?

I’m browsing the example of

then I got curious(and tried a bit…) if we can parse S-Expressions with Spec? Does it parse recursively?

2 Likes

Yes, clojure.spec does a decent job as a recursive parser. Some time ago I played around with spec-based parsing of a lisp-like language. It worked like a charm. In case of malformed inputs I got meaningful descriptions of problems. For instance, when the parser ran into an unexpected token it returned an error with a list of tokens which would’ve been legal in the given context. On top of that, the parser came with a test.check integration for free, enabling generation of random syntax trees for testing purposes.

1 Like