src/pub/blurb.bend
ezx@1.11.0.0 · 124 lines · 14 definitions
1
2
3
4
5
6
7
8
9
10
11
12
13
14import Base
15import ezx@1.11.0.0/src/pkg/pkg.bend as K
16import ezx@1.11.0.0/src/pkg/path.bend as Path
17
18
19
20def nl.step(here: Bool, rest: Unit -> Bool) -> Bool:
21 match here:
22 case True{}:
23 True{}
24 case False{}:
25 rest(Unit{})
26
27
28def has.nl(text: String) -> Bool:
29 match text:
30 case SNil{}:
31 False{}
32 case SCon{+h, t}:
33 nl.step(Char.is_eq(h, '\n'), _u => has.nl(t))
34
35
36
37def line.step(end: Bool, +head: Char, rest: Unit -> String) -> String:
38 match end:
39 case True{}:
40 SNil{}
41 case False{}:
42 SCon{head, rest(Unit{})}
43
44
45
46def line.first(text: String) -> String:
47 match text:
48 case SNil{}:
49 SNil{}
50 case SCon{+h, t}:
51 line.step(Char.is_eq(h, '\n'), h, _u => line.first(t))
52
53
54def lic(file: K.Source) -> Bool:
55 K.Source{at, _text} = file
56 String.eq(Path.base(at), "LICENSE")
57
58
59def at(file: K.Source) -> String:
60 K.Source{a, _text} = file
61 a
62
63
64
65def least.vs(cur: Maybe<&2, K.Source>, +next: K.Source) -> Maybe<&2, K.Source>:
66 match cur:
67 case None{}:
68 Some{next}
69 case Some{+c}:
70 Bool.pick(Maybe<&2, K.Source>, String.is_le(at(c), at(next)), Some{c}, Some{next})
71
72
73
74def least.pick(skip: Bool, cur: Maybe<&2, K.Source>, +next: K.Source) -> Maybe<&2, K.Source>:
75 match skip:
76 case True{}:
77 cur
78 case False{}:
79 least.vs(cur, next)
80
81
82
83def least(fs: List<&2, K.Source>, cur: Maybe<&2, K.Source>) -> Maybe<&2, K.Source>:
84 match fs:
85 case []:
86 cur
87 case +h <> t:
88 least(t, least.pick(lic(h), cur, h))
89
90
91def line.file(file: K.Source) -> String:
92 K.Source{_at, text} = file
93 line.first(text)
94
95
96def line.of(got: Maybe<&2, K.Source>) -> String:
97 match got:
98 case None{}:
99 ""
100 case Some{f}:
101 line.file(f)
102
103
104
105def blurb(fs: List<&2, K.Source>) -> String:
106 line.of(least(fs, None{}))
107
108
109
110def after.step(here: Bool, rest: Unit -> Bool) -> Bool:
111 match here:
112 case True{}:
113 rest(Unit{})
114 case False{}:
115 False{}
116
117
118
119def after(+path: String, fs: List<&2, K.Source>) -> Bool:
120 match fs:
121 case []:
122 True{}
123 case +h <> t:
124 after.step(String.is_le(path, at(h)), _u => after(path, t))