got rid of core.match

This commit is contained in:
Richard Harrington 2015-07-22 17:52:48 -04:00
parent 90e31a4b22
commit e9eb478a54
2 changed files with 10 additions and 10 deletions

View File

@ -6,7 +6,6 @@
:min-lein-version "2.0.0"
:javac-target "1.7"
:dependencies [[org.clojure/clojure "1.5.1"]
[org.clojure/core.match "0.2.0-rc5"]
[clj-time "0.5.1"]
[ring/ring-json "0.3.1"]
[ring/ring-core "1.3.1"]]

View File

@ -1,6 +1,5 @@
(ns robotwar.assembler
(:use (clojure [string :only [split join]])
[clojure.core.match :only [match]]))
(:use (clojure [string :only [split join]])))
(def op-commands [ "-" "+" "*" "/" "=" "#" "<" ">" ])
(def word-commands [ "TO" "IF" "GOTO" "GOSUB" "ENDSUB" ])
@ -138,13 +137,15 @@
result []]
(if (empty? tokens)
result
(match [token]
[{:type (:or :number :register)}]
(recur tail (conj result [(into token {:val ",", :type :command}) token]))
[(:or {:type :label} {:type :command, :val "ENDSUB"})]
(recur tail (conj result [token nil]))
[{:type :command}]
(recur (rest tail) (conj result [token (first tail)]))))))
(let [{:keys [type val]} token]
(cond
(or (= type :number) (= type :register))
(recur tail (conj result [(into token {:val ",", :type :command}) token]))
(or (= type :label) (and (= type :command) (= val "ENDSUB")))
(recur tail (conj result [token nil]))
(= type :command)
(recur (rest tail) (conj result [token (first tail)])))))))
; TODO: preserve :line and :pos metadata with labels,
; when labels are transferred from the instruction list to the label map