Skip to content

Instantly share code, notes, and snippets.

@mk12
Last active April 22, 2021 17:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mk12/513b4e00991db27ef50a2829985b371e to your computer and use it in GitHub Desktop.
Save mk12/513b4e00991db27ef50a2829985b371e to your computer and use it in GitHub Desktop.
Lint design-history.md
# Usage: gawk --lint=no-ext -f lint.awk docs/concepts/fidl/design-history.md
BEGIN { m = 0; }
/^## By theme/ { m = 1; next; }
m == 1 && /^### / {
theme = $2;
next_idx[theme] = 0;
next;
}
m == 1 && match($0, /^* .*\[RFC-([0-9]+): ([^]]+)\]\[rfc-([0-9]+)\]/, a) {
if (a[1] != a[3]) {
printf("ERROR: %s != %s\n", a[1], a[3]);
exit 1;
}
indexes[theme, a[1]] = next_idx[theme]++;
titles[a[1]] = a[2];
is_rejected[a[1]] = $0 ~ /Rejected/;
next;
}
/^## By language feature/ {
m = 2;
theme = "features";
next_idx[theme] = 0;
next;
}
m == 2 && match($0, /^\| [^|]+ \| \[RFC-([0-9]+)\] \|/, a) {
indexes[theme, a[1]] = next_idx[theme]++;
next;
}
/^## Current status/ {
m = 3;
for (theme in next_idx) expected_next_idx[theme] = 0;
next;
}
m == 3 && match($0, /^\| \[RFC-([0-9]+)\] \| ([^|]+) \|/, a) {
if (a[1] in titles && a[2] != titles[a[1]]) {
printf("ERROR: '%s' != '%s'\n", a[2], titles[a[1]]);
exit 1;
}
for (theme in next_idx) {
if ((theme, a[1]) in indexes) {
got = indexes[theme, a[1]];
want = expected_next_idx[theme]++;
if (got != want) {
printf("ERROR: %s came #%d in theme '%s' but chrono says #%d\n", a[1], got+1, theme, want+1);
exit 1;
}
}
}
if (a[1] in is_rejected) {
got = is_rejected[a[1]];
want = $0 ~ /Rejected/;
if (got != want) {
printf("ERROR: %s inconsistent rejected state", a[1]);
exit 1;
}
}
next;
}
END { if (m != 3) { printf("ERROR: m=%d at end\n", m); exit 1; } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment