-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathevaluate-examples.clj
40 lines (38 loc) · 1.37 KB
/
evaluate-examples.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
(defn evaluate [input]
"\nLOL EVALUATED\n")
(defn parse [content]
(let [lines (clojure.string/split content #"\n")
lines# (count lines)]
(clojure.string/join
""
(loop [blocks []
current-block ""
state :out
line# 0]
(if (= line# lines#)
(conj blocks (str current-block "\n"))
(let [current-line (get lines line#)
next-line# (inc line#)
result-block (str current-block "\n" current-line)]
(case state
:out (if (= current-line "~~~ {.clojure}")
(recur (conj blocks result-block)
""
:in
next-line#)
(recur blocks
result-block
state
next-line#))
:in (if (= current-line "~~~")
(recur (conj blocks (evaluate result-block))
current-line
:out
next-line#)
(recur blocks
result-block
state
next-line#)))))))))
(let [file-name (first *command-line-args*)]
(println "Parsing " file-name)
(println (parse (slurp file-name))))