src/codes.bend

bolt@1.24.0.0 · 103 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.24.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{"doc", "S001", "style"},
46    Entry{"space", "S002", "style"},
47    Entry{"wrap", "S003", "style"},
48    Entry{"param", "S004", "style"},
49    Entry{"noqa", "S005", "style"},
50    Entry{"transcong", "S006", "style"},
51    Entry{"coverage", "L001", "laws"},
52    Entry{"closed", "L002", "laws"},
53    Entry{"unsafe", "L003", "laws"},
54    Entry{"tail", "P001", "pedantic"}]
55
56# this row is the slug
57def find.same(+row: Entry, +slug: String) -> Bool:
58  Entry{+s, _id, _grp} = row
59  String.eq(s, slug)
60
61# the row for a slug
62def find(rows: List<&2, Entry>, +slug: String) -> Maybe<&2, Entry>:
63  match rows:
64    case Nil{}:
65      None{}
66    case Con{+row, rest}:
67      Lazy.stop(Maybe<&2, Entry>, find.same(row, slug), Some{row}, _u => find(rest, slug))
68
69# the stable code; the slug itself when it is not a rule
70def code.at(mm: Maybe<&2, Entry>, +slug: String) -> String:
71  match mm:
72    case None{}:
73      slug
74    case Some{Entry{_s, +id, _grp}}:
75      id
76
77# the stable code; the slug itself when it is not a rule
78def code(+slug: String) -> String:
79  code.at(find(table(), slug), slug)
80
81# the group; empty when the slug is not a rule
82def group.at(mm: Maybe<&2, Entry>) -> String:
83  match mm:
84    case None{}:
85      ""
86    case Some{Entry{_s, _id, +grp}}:
87      grp
88
89# the group; empty when the slug is not a rule
90def group(+slug: String) -> String:
91  group.at(find(table(), slug))
92
93# `bolt(group:slug)`; `bolt` when the slug is not a rule
94def source.at(mm: Maybe<&2, Entry>) -> String:
95  match mm:
96    case None{}:
97      "bolt"
98    case Some{Entry{+s, _id, +grp}}:
99      "bolt(" ++ grp ++ ":" ++ s ++ ")"
100
101# `bolt(group:slug)`; `bolt` when the slug is not a rule
102def source(+slug: String) -> String:
103  source.at(find(table(), slug))