aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEduardo Julian2016-04-26 19:04:49 -0400
committerEduardo Julian2016-04-26 19:04:49 -0400
commit2121c6858fc942839070f98b1d1de50c8468199b (patch)
tree5b5de45247dcba5ce940b640f38cde01176084a9 /src
parentf27db1cd6f944de34b74e5098e3b090efd853ea4 (diff)
- Now, the parser no longer ignores uneven-record errors.
Diffstat (limited to 'src')
-rw-r--r--src/lux/base.clj6
-rw-r--r--src/lux/parser.clj28
2 files changed, 23 insertions, 11 deletions
diff --git a/src/lux/base.clj b/src/lux/base.clj
index 5451cf4da..e82143521 100644
--- a/src/lux/base.clj
+++ b/src/lux/base.clj
@@ -614,12 +614,6 @@
)))
))
-(defn repeat% [monad]
- (try-all% (|list (|do [head monad
- tail (repeat% monad)]
- (return ($Cons head tail)))
- (return $Nil))))
-
(defn exhaust% [step]
(fn [state]
(|case (step state)
diff --git a/src/lux/parser.clj b/src/lux/parser.clj
index 4fb42e0fa..e0f35df3d 100644
--- a/src/lux/parser.clj
+++ b/src/lux/parser.clj
@@ -11,33 +11,51 @@
[lexer :as &lexer])))
;; [Utils]
+(def ^:private base-uneven-record-error
+ "[Parser Error] Records must have an even number of elements.")
+
+(defn ^:private repeat% [action]
+ (fn [state]
+ (|case (action state)
+ (&/$Left ^String error)
+ (if (.contains error base-uneven-record-error)
+ (&/$Left error)
+ (&/$Right (&/T [state &/$Nil])))
+
+ (&/$Right state* head)
+ ((|do [tail (repeat% action)]
+ (return (&/$Cons head tail)))
+ state*))))
+
(do-template [<name> <close-tag> <description> <tag>]
(defn <name> [parse]
- (|do [elems (&/repeat% parse)
+ (|do [elems (repeat% parse)
token &lexer/lex]
(|case token
[meta (<close-tag> _)]
(return (<tag> (&/fold &/|++ &/$Nil elems)))
_
- (fail (str "[Parser Error] Unbalanced " <description> ".")))))
+ (fail (str "[Parser Error] Unbalanced " <description> "."))
+ )))
^:private parse-form &lexer/$Close_Paren "parantheses" &/$FormS
^:private parse-tuple &lexer/$Close_Bracket "brackets" &/$TupleS
)
(defn ^:private parse-record [parse]
- (|do [elems* (&/repeat% parse)
+ (|do [elems* (repeat% parse)
token &lexer/lex
:let [elems (&/fold &/|++ &/$Nil elems*)]]
(|case token
[meta (&lexer/$Close_Brace _)]
(if (even? (&/|length elems))
(return (&/$RecordS (&/|as-pairs elems)))
- (fail (str "[Parser Error] Records must have an even number of elements.")))
+ (fail (str base-uneven-record-error)))
_
- (fail (str "[Parser Error] Unbalanced braces.")))))
+ (fail (str "[Parser Error] Unbalanced braces."))
+ )))
;; [Interface]
(def parse