added back stripping of comments which had been lost when switching to regex

This commit is contained in:
Richard Harrington 2013-07-13 13:29:36 -04:00
parent b0c4f798ec
commit 3b03274c2e
2 changed files with 9 additions and 5 deletions

View File

@ -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]

View File

@ -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}