Commit 0abceecf authored by Phil Jones's avatar Phil Jones

added pull-one match functionality

parent 524da4f4
......@@ -39,11 +39,12 @@ INS = DONE | ENDPULL | SAVE | COUNT
ARGINS = PULL | PULLONE | REVERSE | PUSHSHORT | PUSHMEDIUM | PUSHLONG | EXTRA | QUERY ;
PULL = PLUS SPACE PATTERN;
PATTERN = NOTSPACE;
PULLONE = PLUS PLUS SPACE PATTERN;
PULLONE = DOUBLEPLUS SPACE PATTERN;
REVERSE = 'r' SPACE NUMBER
<SPACE> = #'\\s+';
<NOTSPACE> = #'\\S+';
<PLUS> = '+';
<DOUBLEPLUS> = '++';
QUERY = '?' SPACE PATTERN;
NUMBER = #'[0-9]+'
DELAYLONG = '////';
......@@ -91,7 +92,6 @@ MORE = #'.*';
(= cmd :PULLONE)
(do
(println "Pull One not currently implemented.")
(swap! mtc #(pull-one % data)))
(= cmd :REVERSE)
......
......@@ -45,8 +45,8 @@
(defn pull-one [mtc pattern]
mtc
)
(let [[before from] (split-with #(not (re-find (re-pattern pattern) %)) mtc)]
(lazy-seq (concat [(first from)] before (rest from) ))))
(defn query [mtc pattern]
(let [nf #(nil? (re-find (re-pattern pattern) %))]
......
......@@ -71,6 +71,13 @@
))
(deftest pull-one-test
(testing "pull a single matching item to the top"
(let [mtc (make-MTC '("i1 a" "i2 +b" "i3 +c" "i4 +c" "i5 bla" "i6"))]
(is (= (pull-one mtc #"\+c")
'("i3 +c" "i1 a" "i2 +b" "i4 +c" "i5 bla" "i6"))))))
(deftest grammar
(testing "grammar"
(let [prs #(insta/parses parse %)]
......@@ -82,6 +89,10 @@
[:ALL [:ARGINS [:PULL "+" " " [:PATTERN "hello"]]]]
)))
(is (= (prs "++ hello")
(list [:ALL [:TODO "++ hello"]]
[:ALL [:ARGINS [:PULLONE "++" " " [:PATTERN "hello"]]]])))
(is (= (prs "-- goodbye")
(list [:ALL [:TODO "-- goodbye"]]
[:ALL [:ARGINS [:PUSHSHORT "--" " " [:PATTERN "goodbye"]]]]
......
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