aboutsummaryrefslogtreecommitdiff
path: root/src/lux/analyser/base.clj
diff options
context:
space:
mode:
Diffstat (limited to 'src/lux/analyser/base.clj')
-rw-r--r--src/lux/analyser/base.clj32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/lux/analyser/base.clj b/src/lux/analyser/base.clj
new file mode 100644
index 000000000..713b58f18
--- /dev/null
+++ b/src/lux/analyser/base.clj
@@ -0,0 +1,32 @@
+(ns lux.analyser.base
+ (:require [clojure.core.match :refer [match]]
+ (lux [util :as &util :refer [exec return fail
+ try-all-m map-m mapcat-m reduce-m
+ assert!]])))
+
+;; [Resources]
+(defn expr-type [syntax+]
+ (match syntax+
+ [::Expression _ type]
+ (return type)
+
+ _
+ (fail "Can't retrieve the type of a non-expression.")))
+
+(defn analyse-1 [analyse elem]
+ (exec [output (analyse elem)]
+ (match output
+ ([x] :seq)
+ (return x)
+
+ :else
+ (fail "[Analyser Error] Can't expand to other than 1 element."))))
+
+(defn analyse-2 [analyse el1 el2]
+ (exec [output (mapcat-m analyse (list el1 el2))]
+ (match output
+ ([x y] :seq)
+ (return [x y])
+
+ :else
+ (fail "[Analyser Error] Can't expand to other than 2 elements."))))