#!/bin/sh # Runs the TopSpeed sidecar front-end (build/TSM2) over a corpus of # .DEF/.MOD files and reports parse coverage. # # A *syntax* error is a Coco/R error (`'x' expected`, `invalid X`); the # sidecar's own `not supported yet` (230) markers are the deliberate # parse-now/lower-later discipline and do NOT count as failures. # # Usage: ./corpus.sh [corpus-dir] (default: the TS-V3 tree) set -e cd "$(dirname "$0")" TSM2="$(pwd)/build/TSM2" CORPUS="${1:-$HOME/bin/Dos/M2/TS-V3}" WORK="/tmp/opencode/tscorpus" [ -x "$TSM2" ] || { echo "build/TSM2 missing -- run ./build.sh"; exit 1; } [ -d "$CORPUS" ] || { echo "corpus not found: $CORPUS"; exit 1; } rm -rf "$WORK"; mkdir -p "$WORK" : > "$WORK/results.txt" n=0 find "$CORPUS" \( -iname '*.DEF' -o -iname '*.MOD' \) 2>/dev/null | sort | while read -r f; do n=$((n+1)) w="$WORK/f$n"; mkdir -p "$w"; base=$(basename "$f") cp "$f" "$w/$base" ( cd "$w" && "$TSM2" "$base" >/dev/null 2>&1 ) lst="$w/$(echo "$base" | sed 's/\.[^.]*$//').LST" if [ ! -f "$lst" ]; then echo "NOLST|$f" >> "$WORK/results.txt"; continue; fi if grep -qE "^\*\*\*\*\*.*(expected|invalid [A-Z])" "$lst"; then m=$(grep -E "^\*\*\*\*\*.*(expected|invalid [A-Z])" "$lst" | head -1 | sed -E 's/^\*\*\*\*\* *[^ ]* *//; s/^\*\*\*\*\* *//') echo "SYN|$m|$f" >> "$WORK/results.txt" else echo "OK|0|$f" >> "$WORK/results.txt" fi done total=$(wc -l < "$WORK/results.txt") ok=$(grep -c '^OK' "$WORK/results.txt" || true) syn=$(grep -c '^SYN' "$WORK/results.txt" || true) echo "corpus: $CORPUS" echo "total : $total" echo "parse-OK (semantic/230 only): $ok" echo "syntax-bad : $syn" echo "=== syntax-error kinds ===" grep '^SYN' "$WORK/results.txt" | cut -d'|' -f2 | sed -E 's/[0-9]+/N/g' | sort | uniq -c | sort -rn echo "=== syntax-bad files ===" grep '^SYN' "$WORK/results.txt" | cut -d'|' -f3 | sed "s|$CORPUS/||"