mirror of
https://github.com/richardharrington/robotwar.git
synced 2024-09-29 07:55:24 +00:00
added back stripping of comments which had been lost when switching to regex
This commit is contained in:
parent
b0c4f798ec
commit
3b03274c2e
@ -31,12 +31,16 @@
|
||||
[s n]
|
||||
{:token-str s, :pos n})
|
||||
|
||||
(def lex-re (re-pattern (str "[" operators "]|[^" operators "\\s]+")))
|
||||
(def lex-re (re-pattern (str "[" operators "]|[^" operators "\\s]+")))
|
||||
|
||||
(defn strip-comments
|
||||
[line]
|
||||
(re-find #"[^;]*" line))
|
||||
|
||||
(defn lex-line
|
||||
[line]
|
||||
(map #(apply build-lex-metadata %)
|
||||
(re-seq-with-pos lex-re line)))
|
||||
(re-seq-with-pos lex-re (strip-comments line))))
|
||||
|
||||
(defn lex
|
||||
[src-code]
|
||||
|
@ -2,9 +2,9 @@
|
||||
(:require [clojure.test :refer :all]
|
||||
[hs-robotwar.core :refer :all]))
|
||||
|
||||
(def line1 "IF DAMAGE # D GOTO MOVE")
|
||||
(def line2 "AIM-17 TO AIM")
|
||||
(def line3 "IF X<-5 GOTO SCAN")
|
||||
(def line1 "IF DAMAGE # D GOTO MOVE ; comment or something")
|
||||
(def line2 "AIM-17 TO AIM ; more comments")
|
||||
(def line3 "IF X<-5 GOTO SCAN ; comments including code: AIM TO RADAR")
|
||||
|
||||
(def lexed-tokens1 [{:token-str "IF", :pos 0}
|
||||
{:token-str "DAMAGE", :pos 3}
|
||||
|
Loading…
Reference in New Issue
Block a user