aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/program/aedifex/input.lux
blob: cf65de5b6ff551664156b086387fd5c295a5696c (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
(.require
 [library
  [lux (.except)
   [abstract
    ["[0]" monad (.only Monad do)]
    ["[0]" mix]]
   [control
    ["[0]" pipe]
    ["[0]" try (.only Try)]]
   [data
    [binary (.only Binary)]
    ["[0]" text (.only)
     [encoding
      ["[0]" utf8]]]
    [collection
     ["[0]" list]]]
   [meta
    ["[0]" location]
    ["[0]" code (.only)
     ["<[1]>" \\parser]]
    [compiler
     [language
      [lux
       ["[0]" syntax]]]]]
   [world
    ["[0]" file]]]]
 ["[0]" //
  ["[1][0]" profile (.only Name Profile)]
  ["[1][0]" project (.only Project)]
  ["[1][0]" parser]])

(def (lux_parser source_code)
  (-> Text (Try Code))
  (let [parse (syntax.parse ""
                            syntax.no_aliases
                            (text.size source_code))]
    (when (parse [location.dummy 0 source_code])
      {.#Left [_ error]}
      {try.#Failure error}
      
      {.#Right [_ lux_code]}
      {try.#Success lux_code})))

(def project_parser
  (-> Binary (Try Project))
  (|>> (pipe.do try.monad
         [(at utf8.codec decoded)]
         [..lux_parser]
         [(list) (<code>.result //parser.project)])))

(def .public (read monad fs profiles)
  (All (_ !) (-> (Monad !) (file.System !) (List Name) (! (Try Profile))))
  (|> //project.file
      (at fs read)
      (at monad each
          (function (_ it)
            (do [! try.monad]
              [it it
               it (..project_parser it)
               it (monad.each ! (//project.profile it) (list.partial //profile.default profiles))]
              (in (mix.with_monoid //profile.monoid list.mix it)))))))