diff options
| author | Shagun Agrawal <agrawalshagun07@gmail.com> | 2024-08-16 23:40:18 +0530 |
|---|---|---|
| committer | Shagun Agrawal <agrawalshagun07@gmail.com> | 2024-08-16 23:40:18 +0530 |
| commit | 7db3c0405a7fc2895095e91abe910626aee2bc5d (patch) | |
| tree | 135c019f643c5ca9b43696ad992d6c4404fca5b2 /src/cljcc/lexer.clj | |
| parent | 70a42cd67b8cb6b03a7e00d0d7f1e8e9ce8a121f (diff) | |
Add lexer implementation for ch2
Add lexer implementation
Add reference for base implementation of the lexer
Diffstat (limited to 'src/cljcc/lexer.clj')
| -rw-r--r-- | src/cljcc/lexer.clj | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/cljcc/lexer.clj b/src/cljcc/lexer.clj index 10742f0..9922887 100644 --- a/src/cljcc/lexer.clj +++ b/src/cljcc/lexer.clj @@ -9,10 +9,12 @@ :line 1 :col 1}) +(str \1 nil) + (defn lex ([source] (lex source 0 (lexer-ctx))) - ([[ch :as source] pos {:keys [line col] :as ctx}] + ([[ch pk :as source] pos {:keys [line col] :as ctx}] (cond (empty? source) (update ctx :tokens #(conj % (t/create :eof line col))) (newline? ch) (recur (next source) @@ -21,6 +23,12 @@ (update :line inc) (update :col (fn [_] 1)))) (contains? + t/chrs-kind-map (str ch pk)) (recur (next (next source)) + (+ pos 2) + (-> ctx + (update :col #(+ % 2)) + (update :tokens #(conj % (t/create (get t/chrs-kind-map (str ch pk)) line col))))) + (contains? t/chrs-kind-map ch) (recur (next source) (+ pos 1) (-> ctx |
