mirror of
https://github.com/richardharrington/robotwar.git
synced 2024-05-28 08:41:28 +00:00
halfway towards converting to core.match
This commit is contained in:
parent
896ee4cc52
commit
03a961aac6
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user