|
22 | 22 | ; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
23 | 23 | ; SOFTWARE. |
24 | 24 |
|
25 | | -(ns defold.mini |
| 25 | +(ns dev.atomicptr.mini |
26 | 26 | (:require |
27 | 27 | [clojure.string :as string])) |
28 | 28 |
|
|
67 | 67 | (inc end)] |
68 | 68 | (lexer-error "Unterminated string" current))) |
69 | 69 |
|
70 | | - ; parse numbers |
71 | | - (\0 \1 \2 \3 \4 \5 \6 \7 \8 \9) |
72 | | - (let [start current |
73 | | - [pre post has-dot curr] |
74 | | - (loop [curr (inc current) |
75 | | - pre [c] |
76 | | - post [] |
77 | | - has-dot false] |
78 | | - (if (>= curr len) |
79 | | - [pre post has-dot curr] |
80 | | - |
81 | | - (let [c (nth data curr)] |
82 | | - (case c |
83 | | - (\0 \1 \2 \3 \4 \5 \6 \7 \8 \9) |
84 | | - (if has-dot |
85 | | - (recur (inc curr) pre (conj post c) has-dot) |
86 | | - (recur (inc curr) (conj pre c) post has-dot)) |
87 | | - \. |
88 | | - (if has-dot |
89 | | - (lexer-error "Unexpected character: ." curr) |
90 | | - (recur (inc curr) pre post true)) |
91 | | - [pre post has-dot curr]))))] |
92 | | - (if (and has-dot (empty? post)) |
93 | | - (lexer-error "Trailing dot" current) |
94 | | - (let [num-str (str (string/join pre) (if has-dot "." "") (string/join post))] |
95 | | - (if has-dot |
96 | | - (try [[:number (Double/parseDouble num-str) start] curr] |
97 | | - (catch Exception _ |
98 | | - (lexer-error (str "Could not parse number: " num-str) curr))) |
99 | | - (try [[:number (Integer/parseInt num-str) start] curr] |
100 | | - (catch Exception _ |
101 | | - (lexer-error (str "Could not parse number: " num-str) curr))))))) |
102 | | - |
103 | 70 | (let [start current |
104 | 71 | [ident-str new-current] |
105 | 72 | (loop [curr current |
106 | 73 | chars []] |
107 | 74 | (if (or (>= curr len) |
108 | | - (let [c (nth data curr)] |
109 | | - (or (= c \=) (= c \;) (= c \newline) (= c \]) (= c \[)))) |
| 75 | + (let [c (nth data curr)] |
| 76 | + (or (= c \=) (= c \;) (= c \newline) (= c \]) (= c \[)))) |
110 | 77 | [(string/join chars) curr] |
111 | 78 | (recur (inc curr) (conj chars (nth data curr)))))] |
112 | 79 | [[:ident (string/trim ident-str) start] new-current]))] |
|
124 | 91 | (parser-error "Unexpected end of file" pos) |
125 | 92 |
|
126 | 93 | (and (not (coll? token-type)) |
127 | | - (not= toktype token-type)) |
| 94 | + (not= toktype token-type)) |
128 | 95 | (parser-error (format "Expected token %s but found %s instead" token-type toktype) pos) |
129 | 96 |
|
130 | 97 | (and (coll? token-type) |
131 | | - (not (some #(= toktype %) token-type))) |
| 98 | + (not (some #(= toktype %) token-type))) |
132 | 99 | (parser-error (format "Expected token %s but found %s instead" token-type toktype) pos) |
133 | 100 |
|
134 | 101 | :else |
|
166 | 133 | tokens (expect-token tokens [:newline :eof])] |
167 | 134 | (recur tokens result (string/split ident #"\.") nil)) |
168 | 135 |
|
169 | | - (:ident :number :string) |
| 136 | + (:ident :string) |
170 | 137 | (let [k value |
171 | 138 | tokens (expect-token (rest tokens) :equal) |
172 | 139 | [v tokens] (case (peek-token tokens) |
173 | 140 | :ident (consume-token tokens) |
174 | | - :number (consume-token tokens) |
175 | 141 | :string (consume-token tokens) |
176 | 142 | (parser-error (format "Unexpected token: %s" (ffirst tokens)) (last (first tokens)))) |
177 | 143 | tokens (expect-token tokens [:newline :eof])] |
|
0 commit comments