diff options
author | Eduardo Julian | 2014-12-07 20:13:58 -0400 |
---|---|---|
committer | Eduardo Julian | 2014-12-07 20:13:58 -0400 |
commit | 8f8467773fa2c5fb6556355a826b03050f75824e (patch) | |
tree | 18b61120f162a893ab89b93eae7a6a57391be942 /src/lang/lexer.clj | |
parent | 0dbcec8e727511d71101a705972eb252eec79b9f (diff) |
Fixed the bug that was causing &lexer/lex-form to be used unbound.
Diffstat (limited to '')
-rw-r--r-- | src/lang/lexer.clj | 66 |
1 files changed, 28 insertions, 38 deletions
diff --git a/src/lang/lexer.clj b/src/lang/lexer.clj index 65e57114b..caaa15604 100644 --- a/src/lang/lexer.clj +++ b/src/lang/lexer.clj @@ -4,7 +4,7 @@ [lang.util :as &util :refer [exec return* return fail fail* repeat-m try-m try-all-m]])) -(declare lex-form) +(declare lex-forms lex-list lex-tuple lex-record lex-tag) ;; [Utils] (defn ^:private lex-regex [regex] @@ -22,33 +22,6 @@ ;; [Lexers] (def ^:private lex-white-space (lex-regex #"^(\s+)")) -(def lex-forms - (exec [forms (repeat-m lex-form)] - (return (filter #(match % - [::comment _] - false - _ - true) - forms)))) - -(def ^:private lex-list - (exec [_ (lex-str "(") - members lex-forms - _ (lex-str ")")] - (return [::list members]))) - -(def ^:private lex-tuple - (exec [_ (lex-str "[") - members lex-forms - _ (lex-str "]")] - (return [::tuple members]))) - -(def ^:private lex-record - (exec [_ (lex-str "{") - members lex-forms - _ (lex-str "}")] - (return [::record members]))) - (def +ident-re+ #"^([a-zA-Z\-\+\_\=!@$%^&*<>\.,/\\\|':][0-9a-zA-Z\-\+\_\=!@$%^&*<>\.,/\\\|':]*)") (do-template [<name> <tag> <regex>] @@ -68,8 +41,6 @@ ] (return [::string token]))) -;; (lex "(_. (_.. java.lang.System out) (println \"YOLO\"))") - (def ^:private lex-single-line-comment (exec [_ (lex-str "##") comment (lex-regex #"^([^\n]*)") @@ -98,14 +69,6 @@ ] (return [::comment comment]))) -;; #"^(.*?!(#\()).*#\)" - -;; ;; UP TO #( -;; #"^.+?(?=#\()" - -;; ;; UP TO )# -;; #"^.+?(?=\)#)" - (def ^:private lex-tag (exec [_ (lex-str "#") token (lex-regex +ident-re+)] @@ -127,6 +90,33 @@ _ (try-m lex-white-space)] (return form))) +(def lex-forms + (exec [forms (repeat-m lex-form)] + (return (filter #(match % + [::comment _] + false + _ + true) + forms)))) + +(def ^:private lex-list + (exec [_ (lex-str "(") + members lex-forms + _ (lex-str ")")] + (return [::list members]))) + +(def ^:private lex-tuple + (exec [_ (lex-str "[") + members lex-forms + _ (lex-str "]")] + (return [::tuple members]))) + +(def ^:private lex-record + (exec [_ (lex-str "{") + members lex-forms + _ (lex-str "}")] + (return [::record members]))) + ;; [Interface] (defn lex [text] (match (lex-forms text) |