aboutsummaryrefslogtreecommitdiff
path: root/luxc/src/lux/analyser/meta.clj
blob: 1770372a98a6e494597a32c941cfa3c57af28963 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
(ns lux.analyser.meta
  (:require (clojure [template :refer [do-template]])
            clojure.core.match
            clojure.core.match.array
            (lux [base :as & :refer [|let |do return return* |case]])))

;; [Utils]
(defn ^:private ident= [x y]
  (|let [[px nx] x
         [py ny] y]
    (and (= px py)
         (= nx ny))))

(def ^:private tag-prefix "lux")

;; [Values]
(defn meta-get [ident annotations]
  "(-> Ident Code (Maybe Code))"
  (|case annotations
    [_ (&/$Record dict)]
    (loop [dict dict]
      (|case dict
        (&/$Cons [_k v] dict*)
        (|case _k
          [_ (&/$Tag k)]
          (if (ident= k ident)
            (&/$Some v)
            (recur dict*))

          _
          (recur dict*))

        (&/$Nil)
        &/$None))

    _
    &/$None))

(do-template [<name> <tag-name>]
  (def <name> (&/T [tag-prefix <tag-name>]))

  type?-tag   "type?"
  alias-tag   "alias"
  macro?-tag  "macro?"
  export?-tag "export?"
  tags-tag    "tags"
  imports-tag "imports"
  )