-
Notifications
You must be signed in to change notification settings - Fork 93
/
spec.clj
72 lines (52 loc) · 1.53 KB
/
spec.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
(ns ^:no-doc etaoin.ide.impl.spec
"
Parsing IDE flow with spec.
"
(:require
[clojure.spec.alpha :as s]))
(set! *warn-on-reflection* true)
(def control-flow-commands
#{:do :times :while :forEach :if :elseIf :else :end :repeatIf})
(defn cmd? [cmd]
(fn [command]
(some-> command :command (= cmd))))
(s/def ::command-if
(s/cat :if (s/cat :this (cmd? :if)
:branch ::commands)
:else-if (s/* (s/cat :this (cmd? :elseIf)
:branch ::commands))
:else (s/? (s/cat :this (cmd? :else)
:branch ::commands))
:end (cmd? :end)))
(s/def ::command-times
(s/cat :this (cmd? :times)
:branch ::commands
:end (cmd? :end)))
(s/def ::command-while
(s/cat :this (cmd? :while)
:branch ::commands
:end (cmd? :end)))
(s/def ::command-do
(s/cat :this (cmd? :do)
:branch ::commands
:repeat-if (cmd? :repeatIf)))
(s/def ::command-for-each
(s/cat :this (cmd? :forEach)
:branch ::commands
:end (cmd? :end)))
(s/def ::cmd-with-open-window
(fn [{:keys [opensWindow]}]
(true? opensWindow)))
(s/def ::command
(fn [{:keys [command]}]
(and (some? command)
(nil? (get control-flow-commands command)))))
(s/def ::commands
(s/+ (s/alt
:if ::command-if
:times ::command-times
:while ::command-while
:do ::command-do
:for-each ::command-for-each
:cmd-with-open-window ::cmd-with-open-window
:cmd ::command)))