blob: 5a683ed3c565389e0cf520659f966d229df4135c (
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
|
(.module: {#.doc "Commons syntax readers."}
[lux #*
[abstract
monad]
[control
["p" parser ("#\." monad)
["s" code (#+ Parser)]]]
[data
["." name ("#\." equivalence)]
["." product]
["." maybe]
[collection
["." list]]]
["." meta]]
["." //])
(def: #export annotations
{#.doc "Reader for the common annotations syntax used by def: statements."}
(Parser //.Annotations)
(s.record (p.some (p.and s.tag s.any))))
(def: (flat_list^ _)
(-> Any (Parser (List Code)))
(p.either (do p.monad
[_ (s.tag! (name_of #.Nil))]
(wrap (list)))
(s.form (do p.monad
[_ (s.tag! (name_of #.Cons))
[head tail] (s.tuple (p.and s.any s.any))
tail (s.local (list tail) (flat_list^ []))]
(wrap (#.Cons head tail))))))
(template [<name> <type> <tag> <then>]
[(def: <name>
(Parser <type>)
(<| s.tuple
(p.after s.any)
s.form
(do p.monad
[_ (s.tag! (name_of <tag>))]
<then>)))]
[tuple_meta^ (List Code) #.Tuple (flat_list^ [])]
[text_meta^ Text #.Text s.text]
)
(def: (find_definition_args meta_data)
(-> (List [Name Code]) (List Text))
(<| (maybe.default (list))
(: (Maybe (List Text)))
(case (list.find (|>> product.left (name\= ["lux" "func-args"])) meta_data)
(^multi (#.Some [_ value])
[(p.run tuple_meta^ (list value))
(#.Right [_ args])]
[(p.run (p.some text_meta^) args)
(#.Right [_ args])])
(#.Some args)
_
#.None)))
(def: #export typed_input
{#.doc "Reader for the common typed-argument syntax used by many macros."}
(Parser //.Typed_Input)
(s.record (p.and s.any s.any)))
(def: #export type_variables
{#.doc "Reader for the common type var/param used by many macros."}
(Parser (List Text))
(p.some s.local_identifier))
|