# SPDX-License-Identifier: MIT """Print item names and line numbers of a Rust file, and which lines mention given tokens. Never prints a line's text.""" import re, sys path = sys.argv[1]; tokens = sys.argv[2:] lines = open(path).read().split("\n") item = re.compile(r"^\s*(pub(\([a-z]+\))?\s+)?(const|fn|struct|impl|enum|static|trait|mod|type)\s+([A-Za-z_0-9<>]+)") for i, l in enumerate(lines, 1): m = item.match(l) if m: print(f"{i}: {m.group(3)} {m.group(4)} (indent {len(l)-len(l.lstrip())})") for t in tokens: if t in l: kind = "comment" if l.lstrip().startswith("//") else "code" print(f" {i}: mentions {t} ({kind})") print("total lines", len(lines))