src/codes.bend
bolt@1.27.0.0 · 105 lines · 10 definitions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17import Base
18import bolt@1.27.0.0/src/lazy/lazy.bend as Lazy
19
20
21type Entry is Data:
22 Entry{slug: String, id: String, grp: String}
23
24
25def table() -> List<&2, Entry>:
26 [
27 Entry{"hole", "C002", "correctness"},
28 Entry{"pick", "C003", "correctness"},
29 Entry{"put", "C004", "correctness"},
30 Entry{"arms", "C005", "correctness"},
31 Entry{"escape", "C006", "correctness"},
32 Entry{"twice", "C007", "correctness"},
33 Entry{"setting", "C011", "correctness"},
34 Entry{"unused", "U001", "suspicious"},
35 Entry{"eager", "U003", "suspicious"},
36 Entry{"concat", "U004", "suspicious"},
37 Entry{"thunk", "U015", "suspicious"},
38 Entry{"fromrev", "U016", "suspicious"},
39 Entry{"prefix", "U017", "suspicious"},
40 Entry{"empty", "U018", "suspicious"},
41 Entry{"strings", "C008", "perf"},
42 Entry{"chars", "C009", "perf"},
43 Entry{"doc", "S001", "style"},
44 Entry{"space", "S002", "style"},
45 Entry{"wrap", "S003", "style"},
46 Entry{"param", "S004", "style"},
47 Entry{"noqa", "S005", "style"},
48 Entry{"transcong", "S006", "style"},
49 Entry{"coverage", "L001", "laws"},
50 Entry{"closed", "L002", "laws"},
51 Entry{"foreign", "C010", "pedantic"},
52 Entry{"strict", "U002", "pedantic"},
53 Entry{"fuel", "U006", "pedantic"},
54 Entry{"index", "U007", "pedantic"},
55 Entry{"rewalk", "U011", "pedantic"},
56 Entry{"tail", "P001", "pedantic"}]
57
58
59def find.same(+row: Entry, +slug: String) -> Bool:
60 Entry{+s, _id, _grp} = row
61 String.eq(s, slug)
62
63
64def find(rows: List<&2, Entry>, +slug: String) -> Maybe<&2, Entry>:
65 match rows:
66 case Nil{}:
67 None{}
68 case Con{+row, rest}:
69 Lazy.stop(Maybe<&2, Entry>, find.same(row, slug), Some{row}, _u => find(rest, slug))
70
71
72def code.at(mm: Maybe<&2, Entry>, +slug: String) -> String:
73 match mm:
74 case None{}:
75 slug
76 case Some{Entry{_s, +id, _grp}}:
77 id
78
79
80def code(+slug: String) -> String:
81 code.at(find(table(), slug), slug)
82
83
84def group.at(mm: Maybe<&2, Entry>) -> String:
85 match mm:
86 case None{}:
87 ""
88 case Some{Entry{_s, _id, +grp}}:
89 grp
90
91
92def group(+slug: String) -> String:
93 group.at(find(table(), slug))
94
95
96def source.at(mm: Maybe<&2, Entry>) -> String:
97 match mm:
98 case None{}:
99 "bolt"
100 case Some{Entry{+s, _id, +grp}}:
101 "bolt(" ++ grp ++ ":" ++ s ++ ")"
102
103
104def source(+slug: String) -> String:
105 source.at(find(table(), slug))