Fork me on GitHub
#clojure-spec
<
2021-11-03
>
timo15:11:17

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

vlaaad15:11:05

Oh, I wanted to make a library that does that

👍 1
vlaaad15:11:38

Last time I checked no solutions existed

qqq20:11:15

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 ?

qqq20:11:10

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 ?

hiredman20:11:53

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

hiredman20:11:25

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

hiredman20:11:46

parsing over a complex token type

hiredman20:11:39

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