aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/source/luxc/analyser.lux
blob: 2a77d8bb537ec778bebb9f92915f7e722e5d59db (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
(;module:
  lux
  (lux (control monad
                pipe)
       [io #- run]
       (concurrency ["A" atom])
       (data ["E" error]
             [text "T/" Eq<Text>]
             text/format
             (coll [list "L/" Fold<List> Monoid<List> Monad<List>]
                   ["D" dict])
             [number]
             [product])
       [macro #+ Monad<Lux>]
       [type]
       (type ["TC" check]))
  (luxc ["&" base]
        [lang #*]
        ["&;" module]
        ["&;" env])
  (. ["&&;" lux]))

(def: #export (analyse eval ast)
  Analyser
  (case ast
    (^template [<tag> <analyser>]
      [cursor (<tag> value)]
      (<analyser> cursor value))
    ([#;BoolS &&lux;analyse-bool]
     [#;NatS  &&lux;analyse-nat]
     [#;IntS  &&lux;analyse-int]
     [#;DegS  &&lux;analyse-deg]
     [#;RealS &&lux;analyse-real]
     [#;CharS &&lux;analyse-char]
     [#;TextS &&lux;analyse-text])

    (^ [cursor (#;TupleS (list))])
    (&&lux;analyse-unit cursor)

    (^ [cursor (#;TupleS (list singleton))])
    (analyse eval singleton)

    (^ [cursor (#;TupleS elems)])
    (&&lux;analyse-tuple (analyse eval) cursor elems)

    [cursor (#;SymbolS reference)]
    (&&lux;analyse-reference cursor reference)

    (^ [cursor (#;FormS (list [_ (#;SymbolS ["" "_lux_check"])]
                              type
                              value))])
    (&&lux;analyse-check analyse eval cursor type value)

    (^ [cursor (#;FormS (list [_ (#;SymbolS ["" "_lux_coerce"])]
                              type
                              value))])
    (&&lux;analyse-coerce analyse eval cursor type value)

    (^ [cursor (#;FormS (list [_ (#;NatS tag)]
                              value))])
    (&&lux;analyse-variant (analyse eval) cursor tag value)

    _
    (&;fail (format "Unrecognized syntax: " (%ast ast)))
    ))