Commit 506d70f5 authored by Phil Jones's avatar Phil Jones

first working draft ... cli now in cli.clj

parent 35a03bdd
......@@ -5,5 +5,8 @@
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.9.0"]
[org.clojure/data.finger-tree "0.0.3"]
])
[instaparse "1.4.9"]
]
:aot [mtc-clj.cli]
:main mtc-clj.cli
)
(ns mtc-clj.cli
(:require
[instaparse.core :as insta]
[mtc-clj.core :refer [make-MTC next tail add pull delay done]]
))
;; ========= USER INTERFACE ============================
(defn show-all [mtc]
(doseq [item mtc]
(println item))
)
(defn show-next [mtc]
(println (next mtc)))
(def parse
(insta/parser "
ALL = INS | ARGINS | TODO;
INS = DONE | ENDPULL | DELAY | LIST
| DELAY10 | DELAY50 | DELAY500
| LIST10 | LIST50 | LIST500;
ARGINS = PULL | FRONTADD;
PULL = PLUS SPACE PATTERN;
PATTERN = NOTSPACE;
<FRONTADD> = ENDPULL SPACE FTODO;
<SPACE> = #'\\s+';
<NOTSPACE> = #'\\S+';
<PLUS> = '+';
DELAY500 = '////';
DELAY50 = '///';
DELAY10 = '//';
DELAY = '/';
DONE = '*';
ENDPULL = '\\\\';
TODO = #'.*';
FTODO = #'.*';
LIST = 'l';
LIST10 = 'll';
LIST50 = 'lll';
LIST500 = 'llll';
"))
(defn handle-input [input mtc]
(let [parsed (insta/parses parse input) ]
(if (= 1 (count parsed))
(do
(swap! mtc add input)
(show-next @mtc))
(let [line (second (second parsed))]
(cond (= :INS (first line))
(let [ins (first (second line))]
(cond (= ins :LIST)
(show-all @mtc)
(= ins :LIST10)
(show-all (take 10 @mtc))
(= ins :LIST50)
(show-all (take 50 @mtc))
(= ins :LIST500)
(show-all (take 500 @mtc))
(= ins :DONE)
(swap! mtc done)
(= ins :DELAY)
(swap! mtc delay)
(= ins :DELAY10)
(swap! mtc #(delay % 10))
(= ins :DELAY50)
(swap! mtc #(delay % 50))
(= ins :DELAY500)
(swap! mtc #(delay % 500))
:else
(println "Don't understand " ins))
(show-next @mtc)
))
))))
(defn -main [& args]
(let [mtc (atom (make-MTC '()))]
(println "Welcome to Mind Traffic Control")
(while true
(let [x (read-line)]
(handle-input x mtc)
))))
(ns mtc-clj.core
(:require [clojure.spec.alpha :as s]
; [clojure.data.finger-tree :refer [double-list]]
;; [clojure.data.finger-tree :refer [double-list]]
)
)
......@@ -11,7 +12,9 @@
(defn make-MTC [items]
(s/conform ::MTC items))
(defn next [mtc] (first mtc))
(defn next [mtc]
(if (empty? mtc) "Mind Traffic Control is currently empty"
(first mtc)))
(defn tail [mtc] (rest mtc))
(defn add [mtc item] (lazy-seq (concat mtc (list item) )))
(defn add-first [mtc item] (cons item mtc))
......@@ -34,3 +37,13 @@
]
(lazy-seq (concat match no-match))
))
(defn info [mtc pattern]
(let [nf #(nil? (re-find (re-pattern pattern) %))
no-match (filter nf mtc)
match (filter #(not (nf %)) mtc)
item-filt #(nil? (re-find (re-pattern (str "^&" pattern)) % ) )
items (filter item-filt match)
not-items (filter #(not (item-filt %)) match)
]
(lazy-seq (concat items not-items))))
(ns mtc-clj.core-test
(:require [clojure.test :refer :all]
[mtc-clj.core :refer :all]))
[mtc-clj.core :refer :all]
)
(:gen-class)
)
(deftest basic-queue
......@@ -12,6 +16,7 @@
(is (= (count '()) 0))
(is (= (count mtc) 3))
(is (= (count mtc3) 5))
(is (= (next '()) "Mind Traffic Control is currently empty"))
(is (= (next mtc) "item 1"))
(is (= (tail mtc) '("item 2" "item 3")))
......@@ -30,10 +35,20 @@
)))
(deftest tags
(testing "+project tags"
(testing "+project tags and @places"
(let [mtc (make-MTC '("hello" "teenage +america" "world" "team +america police" "@email me"))]
(is (= (pull mtc #"\+america")
'("teenage +america" "team +america police" "hello" "world" "@email me")) )
(is (= (pull mtc #"@email")
'("@email me" "hello" "teenage +america" "world" "team +america police"))))
))
(deftest infos
(testing "&information tags"
(let [mtc (make-MTC '("item1" "item2 +tag" "&tag info"
"item3" "item4 +tag"))]
(is (= (info mtc #"tag")
'("item2 +tag" "item4 +tag" "&tag info") ))
)
))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment