Fork me on GitHub
#unrepl
<
2017-11-13
>
cgrand11:11:44

Has anybody been working on a spec-guided completion?

cgrand11:11:41

what I mean: you can compute the firsts set of a regular expression and you can also compute its derivative towards a prefix

cgrand11:11:04

(defn firsts 
  ([re] (firsts re (s/form re)))
  ([re form]
    (case (::s/op re)
      ::s/pcat (if-let [[p & ps] (:ps re)]
                 (into (firsts p (first (:forms re)))
                   (when (s/valid? p nil)
                     (firsts (-> re (assoc :ps (vec ps))
                               (update :ks (comp vec next))
                               (update :forms (comp vec next)))
                       ’???)))
                 #{})
      ::s/alt (into #{} (mapcat firsts (:ps re) (:forms re)))
      ::s/accept #{}
      #{form})))

=> (firsts (s/cat :name symbol? :meta map?))
#{clojure.core/symbol?}

=> (firsts (s/cat :name (s/? symbol?) :meta map?))
#{clojure.core/symbol? clojure.core/map?}

cgrand11:11:31

^^ rough poc

pesterhazy13:11:54

what is this sorcery

cgrand14:11:42

@pesterhazy given a regular expression you can know what are the valid inputs for the first transition (“firsts set”)

cgrand14:11:25

given a regular expression and a prefix you can compute the remaining regular expression after having consumed prefix

cgrand14:11:24

together they allow to offer completion on macros that are specced

cgrand14:11:20

you can have the following interactions (pipe being the caret)

(if-l| 
(if-let [|] ; autompletion automatically creates the vector because it’s the only valid input, a hint may say that a binding is epxected
...

cgrand20:11:42

@pesterhazy anything against the use of spec in unravel?

pesterhazy21:11:08

Might slow lumo down significantly

anmonteiro21:11:57

spec is precompiled in Lumo

cgrand21:11:11

so I can use it for cmdline args parsing?

ghadi14:11:04

Beautiful

ghadi22:11:53

(I'm here in the peanut gallery)

cgrand22:11:57

@ghadi wouldn’t spec derivatives be your kind of thing?

ghadi22:11:31

i'm more of a PEG kinda guy

ghadi22:11:00

but yeah, 100% behind what you said

ghadi22:11:42

this is funny to me -- it's like the dual to your original 2010 conj talk on partial parsing

ghadi22:11:51

except it's not parsing, it's partial generation