mirror of
https://github.com/richardharrington/robotwar.git
synced 2024-09-09 14:54:50 +00:00
refactored to destructure head and tail in lexer
This commit is contained in:
parent
8e98cbfe63
commit
1d703dd693
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user