Fork me on GitHub
#clojure-spec
<
2018-06-05
>
Vincent Cantin04:06:51

Hi. I plan to try to use spec for auto-completion. Has it been done before?

Vincent Cantin04:06:08

Are the specs easy to parse /navigate programmatically?

ikitommi06:06:24

@U8MJBRSR5 lot of parsers in 3rd party libs, using s/form. As a sample, one parser and a spec visitor in spec-tools (https://github.com/metosin/spec-tools).

😃 4
ikitommi06:06:27

Also a issue to have a spec walker in the core: https://dev.clojure.org/jira/browse/CLJ-2251

Vincent Cantin05:06:38

… I think that s/explain-data does a lot already.

Vincent Cantin10:06:00

Is there some kind of s/seq-of operator, or a way to build it? The idea is to act as a bridge to spec the chars in a string from the string itself: (s/conform (s/seq-of char?) "abc")

hkjels10:06:59

I don’t have a running repl atm, but I think you can use (coll-of char? :kind string?)

Vincent Cantin10:06:54

It works, thanks. Need to add :into [] to keep the chars order at conform time.

👍 4
Vincent Cantin11:06:49

I still have trouble afterward … I would like to run some regex spec (e.g. s/cat) on the content of a string but without having to apply s/conform on the seq of that string. I don’t know if it is possible.

bbrinck14:06:34

FWIW, the general advice I’ve seen is that spec is not a great fit for parsing strings. Certainly people have done it by turning the string into a sequence with seq, but often people run into further issues. More detail in comments here: https://www.reddit.com/r/Clojure/comments/7vwpu4/parsing_with_clojurespec/

8
👍 4
bbrinck14:06:25

YMMV of course

Vincent Cantin02:06:49

TL;DR : https://clojuredocs.org/clojure.spec.alpha/conformer …with a nice example under the documentation.

bbrinck02:06:50

A good discussion of pitfalls with conformers and how to work around them: https://groups.google.com/d/msg/clojure/Tdb3ksDeVnU/LAdniiZNAgAJ

👍 4
bbrinck02:06:31

“we recommend that you not use conformers for coercion. Conformers were added primarily as a tool for building custom composite spec types”

bbrinck03:06:34

I know people have had success with using spec for parsing strings, just wanted to make you aware of possible issues down the road 🙂

bbrinck03:06:56

if you run into them, it may be worth looking at something like https://github.com/cgrand/regex

Vincent Cantin03:06:03

Ah, Christophe again :-)

😄 4