Fork me on GitHub

Hi, anyone has an idea how to generate spec from json-schema?


Oh, I wanted to make a library that does that

👍 1

Last time I checked no solutions existed


I posted the following in #clojure , and @hiredman pointed out clojure-spec satisfies the properties

Consider the problem of String -> AbstractSyntaxTree. Solving this problem is called Parsing, and we can solve it via Regex + LL / LALR / Peg / Parsec / ... . In particular, we can view Regex / Peg as "DSLs" for String -> AbstractSyntaxTree
Now, suppose we are trying to define a DSL -- which can be viewed as a subset of s-exprs. For example, Scheme is a "s-expr DSL"; Lisp is a "s-expr DSL", edn is a "s-expr DSL", clojure is a "s-expr DSL" -- in all 4 cases, all valid data values look like s-exprs.
Question: What is the Regex / Peg equiv for doing "s-expr -> DSLs" ? I.e. what is a "pattern description language" for specifying what subset of s-exprs are valid exprs in the DSL ?


A followup to this then is: Regex is backed by DFA / NFA theory. Other parsing techniques is backed by (limited subset of) Context Free Grammars. Is there a "theory" behind clojure-spec, or is it driven largely by battled tested useful tactics ?


the theory is basically the same as parsing where parsing is sort of logically defined over any sequence of tokens of any type, but we usually think of parsing as over a sequence of character or string tokens


it is parsing but over lazy seqs of lazy seqs (which introduces another novel kind of recursion)


parsing over a complex token type


from a parsing viewpoint spec is usually just used as a recognizer "does this match the grammar or not" but it can be used as a full parser