Skip to content

Commit b936aeb

Browse files
committed
update mini.clj to fix some more bugs
1 parent 19a3221 commit b936aeb

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

src/defold/mini.clj

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
data (vec source)
3737
len (count data)]
3838
(loop [current 0
39-
tokens []]
39+
tokens []
40+
state :key]
4041
(if (>= current len)
4142
(conj tokens [:eof])
4243
(let [c (nth data current)
@@ -68,16 +69,25 @@
6869
(lexer-error "Unterminated string" current)))
6970

7071
(let [start current
72+
stop-chars (if (= state :key)
73+
#{\= \; \newline \] \[}
74+
#{\; \newline \] \[})
7175
[ident-str new-current]
7276
(loop [curr current
7377
chars []]
7478
(if (or (>= curr len)
75-
(let [c (nth data curr)]
76-
(or (= c \=) (= c \;) (= c \newline) (= c \]) (= c \[))))
79+
(stop-chars (nth data curr)))
7780
[(string/join chars) curr]
7881
(recur (inc curr) (conj chars (nth data curr)))))]
79-
[[:ident (string/trim ident-str) start] new-current]))]
80-
(recur new-current (if token (conj tokens token) tokens)))))))
82+
[[:ident (string/trim ident-str) start] new-current]))
83+
next-state (if token
84+
(let [tok-type (first token)]
85+
(cond
86+
(= tok-type :equal) :value
87+
(#{:newline :rbracket} tok-type) :key
88+
:else state))
89+
state)]
90+
(recur new-current (if token (conj tokens token) tokens) next-state))))))
8191

8292
(defn- parser-error [message pos]
8393
(throw (ex-info (format "Parser Error: %s" message) {:position pos})))

0 commit comments

Comments
 (0)