aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/program/aedifex/input.lux
blob: ffed02d28e174e47d4e8300475a95da2ed7433b9 (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
(.module:
  [lux #*
   [abstract
    [monad (#+ Monad do)]]
   [control
    [pipe (#+ do>)]
    ["." try (#+ Try)]
    [parser
     ["<c>" code]]
    [security
     ["!" capability]]]
   [data
    [binary (#+ Binary)]
    ["." text
     ["." encoding]]]
   [meta
    ["." location]]
   [tool
    [compiler
     [language
      [lux
       ["." syntax]]]]]
   [world
    ["." file]]]
  ["." // #_
   ["#" profile (#+ Profile)]
   ["#." action (#+ Action)]
   ["#." project (#+ Project)]
   ["#." parser]])

(def: (parse-lux source-code)
  (-> Text (Try Code))
  (let [parse (syntax.parse ""
                            syntax.no-aliases
                            (text.size source-code))]
    (case (parse [location.dummy 0 source-code])
      (#.Left [_ error])
      (#try.Failure error)
      
      (#.Right [_ lux-code])
      (#try.Success lux-code))))

(def: parse-project
  (-> Binary (Try Project))
  (|>> (do> try.monad
            [encoding.from-utf8]
            [..parse-lux]
            [(list) (<c>.run //parser.project)])))

(def: #export (read monad fs profile)
  (All [!] (-> (Monad !) (file.System !) Text (! (Try Profile))))
  (do (try.with monad)
    [project-file (!.use (:: fs file) //project.file)
     project-file (!.use (:: project-file content) [])]
    (:: monad wrap
        (|> project-file
            (do> try.monad
                 [..parse-project]
                 [(//project.profile profile)])))))