src/codes.bend

bolt@1.25.0.0 · 104 lines · 0 definitions

1# src/codes: the stable id of every rule. A bolt.bend still names the slug
2# (`wrap`); a diagnostic shows the code (`S003`) and, in an editor, the
3# source `bolt(group:slug)`. Numbers are assigned once, in the group order
4# of src/README.md: do not renumber a rule, and do not reuse a retired code
5# (L004 was `quantify`, now `closed` itself; C001 was `shadow` and U005 was
6# `nat`, whose failures bend 2.0.25 no longer has; U014 was `argv`, retired
7# before its first release, since every reader already drops the program).
8#
9# No law can say this, since it is about versions: a released code is never
10# renumbered or reused, which review of this table keeps.
11import Base
12import bolt@1.25.0.0/src/lazy/lazy.bend as Lazy
13
14# one rule: the slug bolt.bend names, its code, its group
15type Entry is Data:
16  Entry{slug: String, id: String, grp: String}
17
18# every rule, in group order
19def table() -> List<&2, Entry>:
20  [
21    Entry{"hole", "C002", "correctness"},
22    Entry{"pick", "C003", "correctness"},
23    Entry{"put", "C004", "correctness"},
24    Entry{"arms", "C005", "correctness"},
25    Entry{"escape", "C006", "correctness"},
26    Entry{"twice", "C007", "correctness"},
27    Entry{"strings", "C008", "correctness"},
28    Entry{"chars", "C009", "correctness"},
29    Entry{"foreign", "C010", "correctness"},
30    Entry{"setting", "C011", "correctness"},
31    Entry{"unused", "U001", "suspicious"},
32    Entry{"strict", "U002", "suspicious"},
33    Entry{"eager", "U003", "suspicious"},
34    Entry{"concat", "U004", "suspicious"},
35    Entry{"fuel", "U006", "suspicious"},
36    Entry{"index", "U007", "suspicious"},
37    Entry{"table", "U008", "suspicious"},
38    Entry{"hoist", "U009", "suspicious"},
39    Entry{"ring", "U010", "suspicious"},
40    Entry{"rewalk", "U011", "suspicious"},
41    Entry{"unit", "U012", "suspicious"},
42    Entry{"scan", "U013", "suspicious"},
43    Entry{"thunk", "U015", "suspicious"},
44    Entry{"fromrev", "U016", "suspicious"},
45    Entry{"prefix", "U017", "suspicious"},
46    Entry{"doc", "S001", "style"},
47    Entry{"space", "S002", "style"},
48    Entry{"wrap", "S003", "style"},
49    Entry{"param", "S004", "style"},
50    Entry{"noqa", "S005", "style"},
51    Entry{"transcong", "S006", "style"},
52    Entry{"coverage", "L001", "laws"},
53    Entry{"closed", "L002", "laws"},
54    Entry{"unsafe", "L003", "laws"},
55    Entry{"tail", "P001", "pedantic"}]
56
57# this row is the slug
58def find.same(+row: Entry, +slug: String) -> Bool:
59  Entry{+s, _id, _grp} = row
60  String.eq(s, slug)
61
62# the row for a slug
63def find(rows: List<&2, Entry>, +slug: String) -> Maybe<&2, Entry>:
64  match rows:
65    case Nil{}:
66      None{}
67    case Con{+row, rest}:
68      Lazy.stop(Maybe<&2, Entry>, find.same(row, slug), Some{row}, _u => find(rest, slug))
69
70# the stable code; the slug itself when it is not a rule
71def code.at(mm: Maybe<&2, Entry>, +slug: String) -> String:
72  match mm:
73    case None{}:
74      slug
75    case Some{Entry{_s, +id, _grp}}:
76      id
77
78# the stable code; the slug itself when it is not a rule
79def code(+slug: String) -> String:
80  code.at(find(table(), slug), slug)
81
82# the group; empty when the slug is not a rule
83def group.at(mm: Maybe<&2, Entry>) -> String:
84  match mm:
85    case None{}:
86      ""
87    case Some{Entry{_s, _id, +grp}}:
88      grp
89
90# the group; empty when the slug is not a rule
91def group(+slug: String) -> String:
92  group.at(find(table(), slug))
93
94# `bolt(group:slug)`; `bolt` when the slug is not a rule
95def source.at(mm: Maybe<&2, Entry>) -> String:
96  match mm:
97    case None{}:
98      "bolt"
99    case Some{Entry{+s, _id, +grp}}:
100      "bolt(" ++ grp ++ ":" ++ s ++ ")"
101
102# `bolt(group:slug)`; `bolt` when the slug is not a rule
103def source(+slug: String) -> String:
104  source.at(find(table(), slug))