AtlatestRepositorysigil-doc
1
;;; SD-P1 -- head-symbol vs slot-count classification probe.2
;;;3
;;; This probe ASSERTS NOTHING. It RECORDS what the lowering path does with4
;;; `@text{...}` and `@expr{...}`, the two author commands whose head symbol5
;;; collides with the parser's internal five-slot `text`/`expr` pseudo-kinds6
;;; (see docs/passive-parse-api.md and topics/sigil-doc-passive-parse-api).7
;;;8
;;; It exists because "the fix regresses no currently-correct manuscript" is a9
;;; MEASUREMENT, not a premise. Run it against the pre-SD-P1 parser to record the10
;;; BEFORE, and against the post-SD-P1 parser to record the AFTER; the gate and11
;;; the session log carry both transcripts side by side.12
;;;13
;;; Every case prints `SD_P1_CASE <label> :: <outcome>`, where the outcome is14
;;; either the exception message or the lowered document rendered to plain text.15
;;; Cases A-E and I are the COLLIDING spellings, in four distinct positions:16
;;; top level, block, inline, and inside an inline `@code` body. Cases F, G and17
;;; H are POSITIVE CONTROLS -- ordinary commands, ordinary prose, and a genuine18
;;; `@(...)` author expression -- whose behaviour must be IDENTICAL before and19
;;; after, so a transcript in which everything moved is distinguishable from one20
;;; in which only the collisions moved.21
;;; TWO INSTRUMENT DEFECTS were found while building this probe, both worth22
;;; knowing about before you trust any run of it:23
;;;24
;;; 1. Its first version imported neither `(sigil doc author)` nor the author25
;;; runtime, so every lowered document died on `unbound variable26
;;; 'author-at'` -- including the POSITIVE CONTROLS. That is what exposed27
;;; it: a probe whose controls fail is broken, not informative.28
;;; 2. `sigil -L <other>/src` run from THIS package's root does NOT shadow the29
;;; package's own `src/`. A "pre-SD-P1" run driven that way silently30
;;; measures the CURRENT parser. The pristine tree must be run from its own31
;;; package root, and `test/gate-sd-p1.sh` asserts a positive control --32
;;; the pre-SD-P1 parser must NOT resolve `sigil-doc-profile` -- before it33
;;; believes any BEFORE transcript.34
;;; SD-P8 (2026-08-22) MOVED EVERY `@chapter` HERE TO `@article`, because ruling35
;;; D8 made `@article` the root `#lang sigil/doc` admits and this probe drives36
;;; the DEFAULT profile through `parse-document-source`.37
;;;38
;;; THE THREE POSITIVE CONTROLS BELOW STAYED BYTE-IDENTICAL TO THE PINNED39
;;; PRE-SD-P1 TRANSCRIPT, AND THAT IS LUCK, NOT DESIGN. `@article` and40
;;; `@chapter` are both 8 characters, so no byte offset in any case moved.41
;;; `test/gate-sd-p1.sh` arm 2 requires F, G and H to match42
;;; `test/transcripts/sd-p1/classification-before.txt` exactly, so that arm is43
;;; LENGTH-SENSITIVE to this file's root spelling and nothing in it says so. A44
;;; future root rename of a different length will redden it for a reason that45
;;; has nothing to do with the classification it checks. If you are reading this46
;;; because that happened: the controls are still correct, their OFFSETS moved.47
;;;48
(import (sigil core) (sigil doc) (sigil doc author)49
(sigil doc private author-runtime) (sigil doc private parser))51
;; One case must occupy exactly ONE line. `document->plain` emits newlines, and52
;; a multi-line outcome would let the gate's per-line comparison see only each53
;; case's first line -- which for the positive controls is the constant prefix54
;; `OK: <title>` and would therefore match before and after no matter how the55
;; body changed. Flattening is what keeps those controls load-bearing.56
(define (flatten text)57
(let loop ((cs (string->list text)) (out '()))58
(cond59
((null? cs) (list->string (reverse out)))60
((char=? (car cs) #\newline) (loop (cdr cs) (cons #\n (cons #\\ out))))61
(else (loop (cdr cs) (cons (car cs) out))))))63
(define (outcome thunk)64
(flatten65
(guard (exn (else (string-append "RAISED: " (exception-message exn))))66
(thunk))))68
;; Lower and evaluate, then render. Any failure at either step is reported as69
;; the message, so a case that cannot be lowered and a case that cannot be70
;; evaluated are both visible rather than fatal.71
(define (lower-and-render source name)72
(outcome73
(lambda ()74
(let ((document (eval (parse-document-source source name 16))))75
(string-append "OK: " (document->plain document))))))77
(define (lower-only source name)78
(outcome (lambda () (begin (parse-document-source source name 16) "OK: lowered"))))80
(define (report label value)81
(display "SD_P1_CASE ") (display label) (display " :: ") (display value) (newline))83
;; ---------------------------------------------------------------- cases85
;; A. `@text{...}` as the sole top-level node. The root-policy loop filters86
;; empty top-level TEXT nodes with `(trim (caddr node))`; for a COMMAND node87
;; `caddr` is the child list, not a string.88
(report "A-text-command-at-top-level"89
(lower-only "#lang sigil/doc\n@text{a text command}\n" "a.sgd"))91
;; B. `@expr{...}` as the sole top-level node. The same loop treats a node whose92
;; head is `expr` as a hoisted author form and splices `caddr` -- again the93
;; child list -- into the generated form sequence.94
(report "B-expr-command-at-top-level"95
(lower-only "#lang sigil/doc\n@expr{an expr command}\n" "b.sgd"))97
;; C. `@text{...}` at BLOCK position inside a chapter. `lower-block` matches on98
;; the head symbol and runs `paragraph-ranges` over the command's own source.99
(report "C-text-command-at-block-position"100
(lower-and-render101
"#lang sigil/doc\n@article[\"C\" \"A\"]{\n@text{a text command}\n}" "c.sgd"))103
;; D. `@expr{...}` at BLOCK position inside a chapter.104
(report "D-expr-command-at-block-position"105
(lower-and-render106
"#lang sigil/doc\n@article[\"D\" \"A\"]{\n@expr{an expr command}\n}" "d.sgd"))108
;; E. `@text{...}` at INLINE position inside a paragraph.109
(report "E-text-command-inline"110
(lower-and-render111
"#lang sigil/doc\n@article[\"E\" \"A\"]{@p{before @text{inline text} after}}" "e.sgd"))113
;; I. `@text{...}` inside an INLINE `@code{...}` body. `inline-code-content`114
;; concatenates `caddr` of each child; for a five-slot text node that is a115
;; STRING, but for a six-slot command it is the child LIST.116
(report "I-text-command-inside-inline-code"117
(lower-and-render118
"#lang sigil/doc\n@article[\"I\" \"A\"]{@p{@code{@text{x}}}}" "i.sgd"))120
;; F. POSITIVE CONTROL -- an ordinary inline command with no name collision.121
;; This must render identically before and after the change.122
(report "F-control-em-inline"123
(lower-and-render124
"#lang sigil/doc\n@article[\"F\" \"A\"]{@p{before @em{emphasis} after}}" "f.sgd"))126
;; G. POSITIVE CONTROL -- ordinary prose at block position, which is a genuine127
;; five-slot `text` pseudo-node and must keep lowering to a paragraph.128
(report "G-control-bare-prose-block"129
(lower-and-render130
"#lang sigil/doc\n@article[\"G\" \"A\"]{\nbare prose paragraph\n}" "g.sgd"))132
;; H. POSITIVE CONTROL -- a genuine top-level `@(...)` author expression, which133
;; is a five-slot `expr` pseudo-node and must still be hoisted as a form.134
;; Reports the FORM COUNT (one author form plus the root), so this control135
;; observes hoisting succeeding rather than an error message.136
(report "H-control-author-expression-at-top-level"137
(outcome138
(lambda ()139
(string-append140
"OK: forms="141
(number->string142
(length (parse-document-forms143
"#lang sigil/doc\n@(define x 1)\n@article[\"H\" \"A\"]{@p{body}}"144
"h.sgd" 16)))))))146
(display "SD_P1_CLASSIFICATION_PROBE_COMPLETE 9 cases")147
(newline)