diff options
author | Eduardo Julian | 2015-08-30 18:36:17 -0400 |
---|---|---|
committer | Eduardo Julian | 2015-08-30 18:36:17 -0400 |
commit | 817d244adff361104ae0aa6ce53efe6c2bc07552 (patch) | |
tree | 816a3d40b74994b51f9acf56fbf6342506aa65aa /src/lux/lexer.clj | |
parent | 0a0fab3581eedbc13df2af40e3db8bc2d2fd8178 (diff) |
- Added unit-tests for lexer.
- Fixed a bug when lexing multi-line comments.
Diffstat (limited to '')
-rw-r--r-- | src/lux/lexer.clj | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/src/lux/lexer.clj b/src/lux/lexer.clj index 4c7741769..b3a47f3e0 100644 --- a/src/lux/lexer.clj +++ b/src/lux/lexer.clj @@ -64,20 +64,12 @@ (defn ^:private lex-multi-line-comment [_] (|do [_ (&reader/read-text "#(") - [meta comment] (&/try-all% (&/|list (|do [[meta comment] (&reader/read-regex #"(?is)^(?!#\()(.*?(?=\)#))") - ;; :let [_ (prn 'immediate comment)] - _ (&reader/read-text ")#")] + [meta comment] (&/try-all% (&/|list (|do [[meta comment] (&reader/read-regex+ #"(?is)^(?!#\()((?!\)#).)*")] (return (&/T meta comment))) - (|do [;; :let [_ (prn 'pre/_0)] - [meta pre] (&reader/read-regex+ #"(?is)^(.*?)(#\(|$)") - ;; :let [_ (prn 'pre pre)] - [_ inner] (lex-multi-line-comment nil) - ;; :let [_ (prn 'inner inner)] - [_ post] (&reader/read-regex #"(?is)^(.+?(?=\)#))") - ;; :let [_ (prn 'post post (str pre "#(" inner ")#" post))] - ] + (|do [[meta pre] (&reader/read-regex+ #"(?is)^((?!#\().)*") + [_ ($Comment inner)] (lex-multi-line-comment nil) + [_ post] (&reader/read-regex+ #"(?is)^((?!\)#).)*")] (return (&/T meta (str pre "#(" inner ")#" post)))))) - ;; :let [_ (prn 'lex-multi-line-comment (str comment ")#"))] _ (&reader/read-text ")#")] (return (&/T meta (&/V $Comment comment))))) @@ -91,8 +83,8 @@ (return (&/T meta (&/V <tag> token))))) ^:private lex-bool $Bool #"^(true|false)" - ^:private lex-int $Int #"^(-?0|-?[1-9][0-9]*)" - ^:private lex-real $Real #"^-?(-?0\.[0-9]+|-?[1-9][0-9]*\.[0-9]+)" + ^:private lex-int $Int #"^-?(0|[1-9][0-9]*)" + ^:private lex-real $Real #"^-?(0\.[0-9]+|[1-9][0-9]*\.[0-9]+)" ) (def ^:private lex-char |