Merge branch 'master' into gnarly-refactoring

This commit is contained in:
Richard Harrington 2013-08-02 18:12:58 -04:00
commit c43c0113a2

View File

@ -1,8 +1,8 @@
(ns robotwar.foundry (ns robotwar.foundry
(:require [robotwar.kernel-lexicon])
(:use (clojure [string :only [split join]] (:use (clojure [string :only [split join]]
[pprint :only [pprint]]) [pprint :only [pprint]])
[clojure.core.match :only [match]] [clojure.core.match :only [match]]))
[robotwar.kernel-lexicon]))
(defn re-seq-with-pos (defn re-seq-with-pos
"Returns a lazy sequence of successive matches of pattern in string with position. "Returns a lazy sequence of successive matches of pattern in string with position.
@ -22,7 +22,7 @@
(map #(re-find #"[^;]*" %) lines)) (map #(re-find #"[^;]*" %) lines))
(def lex-re (def lex-re
(let [op-string (join op-commands)] (let [op-string (join robotwar.kernel-lexicon/op-commands)]
(re-pattern (str "[" op-string "]|[^" op-string "\\s]+")))) (re-pattern (str "[" op-string "]|[^" op-string "\\s]+"))))
(defn lex-line (defn lex-line
@ -59,11 +59,12 @@
:val and :type, based on sending the :token-str value :val and :type, based on sending the :token-str value
through a series of parsing functions until a match is found." through a series of parsing functions until a match is found."
[reg-names token] [reg-names token]
(let [parser-priority [[(set reg-names) :register] (let [parser-priority
[(set commands) :command] [[(set reg-names) :register]
[str->int :number] [(set robotwar.kernel-lexicon/commands) :command]
[valid-word :label] [str->int :number]
[return-err :error]]] [valid-word :label]
[return-err :error]]]
(loop [[[parser token-type] & tail] parser-priority] (loop [[[parser token-type] & tail] parser-priority]
(if-let [token-val (parser (:token-str token))] (if-let [token-val (parser (:token-str token))]
(dissoc (into token {:val token-val, :type token-type}) (dissoc (into token {:val token-val, :type token-type})