aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--project.clj2
-rw-r--r--src/lux/base.clj6
-rw-r--r--src/lux/parser.clj28
3 files changed, 24 insertions, 12 deletions
diff --git a/project.clj b/project.clj
index c08d03930..d24d6c31f 100644
--- a/project.clj
+++ b/project.clj
@@ -1,4 +1,4 @@
-(defproject com.github.luxlang/luxc-jvm "0.3.3"
+(defproject com.github.luxlang/luxc-jvm "0.4.0-SNAPSHOT"
:description "The JVM compiler for the Lux programming language."
:url "https://github.com/LuxLang/lux"
:license {:name "Mozilla Public License (Version 2.0)"
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