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

(def: (lux_parser 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: project_parser
  (-> Binary (Try Project))
  (|>> (do> try.monad
            [(\ utf8.codec decode)]
            [..lux_parser]
            [(list) (<code>.run //parser.project)])))

(def: #export (read monad fs profile)
  (All [!] (-> (Monad !) (file.System !) Text (! (Try Profile))))
  (|> //project.file
      (\ fs read)
      (\ monad map (|>> (do> try.monad
                             []
                             [..project_parser]
                             [(//project.profile profile)])))))