7 level_re = re.compile(r'''(Forbid|Deny|Warn|Allow)''')
8 conf_re = re.compile(r'''define_Conf! {\n([^}]*)\n}''', re.MULTILINE)
9 confvar_re = re.compile(r'''/// Lint: (\w+). (.*).*\n *\("([^"]*)", (?:[^,]*), (.*) => (.*)\),''')
10 lint_subheadline = re.compile(r'''^\*\*([\w\s]+)[:?.!]\*\*(.*)''')
12 # TODO: actual logging
13 def warn(*args): print(args)
14 def debug(*args): print(args)
15 def info(*args): print(args)
17 def parse_path(p="clippy_lints/src"):
19 for f in os.listdir(p):
21 parse_file(d, os.path.join(p, f))
22 return (d, parse_conf(p))
27 with open(p + '/utils/conf.rs') as f:
30 m = re.search(conf_re, f)
33 m = re.findall(confvar_re, m)
35 for (lint, doc, name, default, ty) in m:
36 c[lint.lower()] = (name, ty, doc, default)
40 def parseLintDef(level, comment, name):
49 if len(line.strip()) == 0:
52 match = re.match(lint_subheadline, line)
54 last_section = match.groups()[0]
56 text = match.groups()[1]
61 warn("Skipping comment line as it was not preceded by a heading")
62 debug("in lint `%s`, line `%s`" % name, line)
64 lint['docs'][last_section] = (lint['docs'].get(last_section, "") + "\n" + text).strip()
75 if line.startswith("///"):
76 if line.startswith("/// "):
77 last_comment.append(line[4:])
79 last_comment.append(line[3:])
80 elif line.startswith("declare_lint!"):
84 elif line.startswith("declare_restriction_lint!"):
88 elif line.startswith("declare_deprecated_lint!"):
95 m = re.search(r"pub\s+([A-Z_][A-Z_0-9]*)", l)
98 name = m.group(1).lower()
100 # Intentionally either a never looping or infinite loop
101 while not deprecated and not restriction:
102 m = re.search(level_re, line)
114 info("found %s with level %s in %s" % (name, level, f))
115 d.append(parseLintDef(level, last_comment, name=name))
119 warn("Warning: Missing Lint-Name in", f)
123 (lints, config) = parse_path()
124 info("got %s lints" % len(lints))
125 with open("util/gh-pages/lints.json", "w") as file:
126 json.dump(lints, file, indent=2)
127 info("wrote JSON for great justice")
129 if __name__ == "__main__":