aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/meta/target/jvm/type/alias.lux
blob: 99d623d5e3b461df2f8961304d10d4be745077ab (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
(.require
 [library
  [lux (.except Type int char parameter)
   [abstract
    ["[0]" monad (.only do)]]
   [control
    ["<>" parser (.only)]
    ["[0]" maybe]
    ["[0]" try]]
   [data
    ["[0]" text (.only)
     ["%" \\format (.only format)]
     ["<[1]>" \\parser (.only Parser)]]
    [collection
     ["[0]" dictionary (.only Dictionary)]]]]]
 ["[0]" // (.only Type)
  [category (.only Void Value Return Method Primitive Object Class Array Var Parameter)]
  ["[1][0]" descriptor]
  ["[1][0]" signature (.only Signature)]
  ["[1][0]" reflection]
  ["[1][0]" parser]])

(type .public Aliasing
  (Dictionary Text Text))

(def .public fresh
  Aliasing
  (dictionary.empty text.hash))

(def (var aliasing)
  (-> Aliasing (Parser (Type Var)))
  (do <>.monad
    [var //parser.var']
    (in (|> aliasing
            (dictionary.value var)
            (maybe.else var)
            //.var))))

(def (class parameter)
  (-> (Parser (Type Parameter)) (Parser (Type Class)))
  (|> (do <>.monad
        [name //parser.class_name
         parameters (|> (<>.some parameter)
                        (<>.after (<text>.this //signature.parameters_start))
                        (<>.before (<text>.this //signature.parameters_end))
                        (<>.else (list)))]
        (in (//.class name parameters)))
      (<>.after (<text>.this //descriptor.class_prefix))
      (<>.before (<text>.this //descriptor.class_suffix))))

(with_template [<name> <prefix> <bound> <constructor>]
  [(def <name>
     (-> (Parser (Type Class)) (Parser (Type Parameter)))
     (|>> (<>.after (<text>.this <prefix>))
          (at <>.monad each <bound>)))]

  [lower //signature.lower_prefix //.lower ..Lower]
  [upper //signature.upper_prefix //.upper ..Upper]
  )

(def (parameter aliasing)
  (-> Aliasing (Parser (Type Parameter)))
  (<>.rec
   (function (_ parameter)
     (let [class (..class parameter)]
       (all <>.either
            (..var aliasing)
            //parser.wildcard
            (..lower class)
            (..upper class)
            class
            )))))

(def (value aliasing)
  (-> Aliasing (Parser (Type Value)))
  (<>.rec
   (function (_ value)
     (all <>.either
          //parser.primitive
          (parameter aliasing)
          (//parser.array' value)
          ))))

(def (inputs aliasing)
  (-> Aliasing (Parser (List (Type Value))))
  (|> (<>.some (..value aliasing))
      (<>.after (<text>.this //signature.arguments_start))
      (<>.before (<text>.this //signature.arguments_end))))

(def (return aliasing)
  (-> Aliasing (Parser (Type Return)))
  (all <>.either
       //parser.void
       (..value aliasing)
       ))

(def (exception aliasing)
  (-> Aliasing (Parser (Type Class)))
  (|> (..class (..parameter aliasing))
      (<>.after (<text>.this //signature.exception_prefix))))

(def (bound aliasing)
  (-> Aliasing (Parser (Type Class)))
  (do <>.monad
    [_ (<text>.this ":")]
    (..class (..parameter aliasing))))

(def (bound_type_var aliasing)
  (-> Aliasing (Parser (Type Var)))
  (|> //parser.var_name
      (at <>.monad each //.var)
      (<>.before (<>.many (..bound aliasing)))))

(def .public (method aliasing)
  (-> Aliasing (-> (Type Method) (Type Method)))
  (|>> //.signature
       //signature.signature
       (<text>.result (do <>.monad
                        [type_variables (|> (<>.some (..bound_type_var aliasing))
                                            (<>.after (<text>.this //signature.parameters_start))
                                            (<>.before (<text>.this //signature.parameters_end))
                                            (<>.else (list)))
                         inputs (..inputs aliasing)
                         return (..return aliasing)
                         exceptions (<>.some (..exception aliasing))]
                        (in (//.method [type_variables inputs return exceptions]))))
       try.trusted))