halfway towards converting to core.match

This commit is contained in:
Richard Harrington 2013-07-05 17:58:35 -04:00
parent 896ee4cc52
commit 03a961aac6
2 changed files with 26 additions and 1 deletions

View File

@ -3,5 +3,6 @@
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.5.1"]]
:dependencies [[org.clojure/clojure "1.5.1"]
[org.clojure/core.match "0.2.0-rc3"]]
:main hs-robotwar.core)

View File

@ -26,8 +26,32 @@
current-pos (- (count initial-line) (count line))
previous-token (:string (last result) "")
parsing-token? (not (empty? partial-token))
; a binary operator is any character on the operator list,
; unless it's a minus sign that is actually a unary operator
; because the token before it could not be a number
binary-op? #(and (operators %)
(or (not= % "-")
(digit? (last previous-token))
(register previous-token)))
head (str (first line))
tail (rest line)]
(match [head parsing-token?]
["" true ] (close-partial-token)
["" false] result
[(:or " " "\t") true ] (recur tail "" saved-pos (close-partial-token))
[(:or " " "\t") false] (recur tail "" saved-pos result)
[(_ :guard binary-op?) true ] (recur line "" saved-pos (close-partial-token))
[(_ :guard binary-op?) false] (recur tail
""
current-pos
(conj-with-metadata result head current-pos))
:else (recur tail (str partial-token head) saved-pos result)))))
(cond
(or (empty? line) (= ";" head)) (if parsing-token?
(close-partial-token)