Skip to content

Commit 94138da

Browse files
trusted-base: walk back through comment blocks for TRUSTED:/AXIOM: magic (closes #296) (#300)
## Summary Replaces the fixed 5-line preceding-comment window in `scripts/check-trusted-base.sh` with a walk-back through the consecutive comment block (lines that start with `--` / `//` / `|||` / `#` / `*` / `(*`). Adds a 15-line hard floor as a sanity bound. ## Why Real Agda / Lean / Idris postulates commonly carry 7-15 line prose justifications labelled `-- AXIOM:` / `-- TRUSTED:` on the *opening* line of the block. The marker (the `postulate` keyword) lands at the *end* of the block — past the 5-line window — and the script reported the escape hatch as undocumented even though the documentation was plainly there. Echidna PR #128 had to insert a redundant `-- AXIOM:` line immediately before each postulate as a workaround. This PR fixes the underlying script behaviour so the natural prose-block placement is recognised estate-wide. ## Behaviour matrix | Block shape | Old (5-line window) | New (walk-back, 15-line floor) | |---|---|---| | Magic word on line N-2, marker on line N | ✅ | ✅ | | Magic word on line N-10, with 10 lines of prose comment, marker on line N | ❌ | ✅ | | Magic word on line N-20, marker on line N (with intervening blank or code line) | ❌ | ❌ (block-aware) | | No magic word in the preceding block | ❌ | ❌ (correctly fails closed) | ## Test plan - [x] Local synthetic test (Agda postulate with 7-line prose block + opening AXIOM: line) now passes the script. - [ ] CI on standards' own .v / .agda / .idr / .rs files. Closes #296. EOF )
1 parent 822fa14 commit 94138da

1 file changed

Lines changed: 35 additions & 4 deletions

File tree

scripts/check-trusted-base.sh

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,41 @@ while IFS=$'\t' read -r f ln kind ctx; do
238238
continue
239239
fi
240240

241-
# 1. Inline TRUSTED:/AXIOM: comment on any of the 5 lines preceding the marker
242-
local_start=$(( ln - 5 ))
243-
[ "$local_start" -lt 1 ] && local_start=1
244-
if sed -n "${local_start},${ln}p" "$f" 2>/dev/null | grep -qE 'TRUSTED:|AXIOM:'; then
241+
# 1. Inline TRUSTED:/AXIOM: comment in the preceding comment block. We walk
242+
# backwards from the marker through consecutive comment lines (-- / // /
243+
# ||| / # / * / (*) until we hit a non-comment line, then check the
244+
# whole block for the magic word. A 5-line ceiling (the historical
245+
# window) was too narrow for real Agda postulates with a 7-15 line
246+
# prose justification labelled `-- AXIOM:` on its opening line. See
247+
# standards#296.
248+
walk_start="$ln"
249+
while [ "$walk_start" -gt 1 ]; do
250+
prev_ln=$(( walk_start - 1 ))
251+
prev_line="$(sed -n "${prev_ln}p" "$f" 2>/dev/null)"
252+
case "$prev_line" in
253+
*[!\ \ ]*) ;; # non-blank — fall through to comment test
254+
*)
255+
# blank line breaks the comment block.
256+
break
257+
;;
258+
esac
259+
trimmed="$(echo "$prev_line" | sed -E 's/^[[:space:]]+//')"
260+
case "$trimmed" in
261+
--*|"|||"*|"|||"|"//"*|"/*"*|"*"*|"(*"*|"#"*)
262+
walk_start="$prev_ln"
263+
;;
264+
*)
265+
break
266+
;;
267+
esac
268+
done
269+
# Also bound by ln-15 as a sanity check — a 15-line "comment block"
270+
# without a magic word is almost certainly something other than a
271+
# documented escape hatch.
272+
hard_floor=$(( ln - 15 ))
273+
[ "$hard_floor" -gt "$walk_start" ] && walk_start="$hard_floor"
274+
[ "$walk_start" -lt 1 ] && walk_start=1
275+
if sed -n "${walk_start},${ln}p" "$f" 2>/dev/null | grep -qE 'TRUSTED:|AXIOM:'; then
245276
continue
246277
fi
247278

0 commit comments

Comments
 (0)