refactored to destructure head and tail in lexer

This commit is contained in:
Richard Harrington 2013-07-12 17:41:31 -04:00
parent 8e98cbfe63
commit 1d703dd693

View File

@ -16,16 +16,14 @@
(defn lex-line (defn lex-line
[initial-line] [initial-line]
(loop (loop
[line initial-line [[head & tail :as line] initial-line
partial-token [] partial-token []
saved-pos 0 saved-pos 0
result []] result []]
(let [close-partial-token (fn [] (conj-with-metadata result (apply str partial-token) saved-pos)) (let [close-partial-token (fn [] (conj-with-metadata result (apply str partial-token) saved-pos))
current-pos (- (count initial-line) (count line)) current-pos (- (count initial-line) (count line))
previous-token (:token (last result) "") previous-token (:token (last result) "")
parsing-token? (not (empty? partial-token)) parsing-token? (not (empty? partial-token))]
head (first line)
tail (rest line)]
(match [head parsing-token?] (match [head parsing-token?]
[(:or \; nil) true ] (close-partial-token) [(:or \; nil) true ] (close-partial-token)
[(:or \; nil) false] result [(:or \; nil) false] result