AtlatestRepositorysigil-doc
1
;;; (sd-p7 folio model) -- a FOLIO-SHAPED stand-in vocabulary, owned by this2
;;; test tree and by nothing else.3
;;;4
;;; WHY THIS EXISTS RATHER THAN AN IMPORT OF `(folio doc model)`.5
;;;6
;;; SD-P7 ships in sigil-doc, which must not depend on folio: sigil-doc is the7
;;; thing folio delegates TO. So the phase cannot demonstrate its seam by8
;;; importing folio's real records. What it can do -- and what this module is --9
;;; is reproduce the SHAPE of the frozen folio vocabulary closely enough that10
;;; the containment rule under test is the same rule.11
;;;12
;;; The shape reproduced here, from folio's `src/folio/doc/model.sgl` as frozen13
;;; by F1a (read 2026-08-11, not guessed):14
;;;15
;;; roots note (project omitted -- one root16
;;; is enough to exercise a root17
;;; set, and SD-P1 already gates18
;;; multi-root parsing)19
;;; structural containers milestone, phase nest downward only20
;;; work items task, update21
;;; relational related22
;;;23
;;; and folio's own `note-child?`, which is the predicate Fable's condition 324
;;; names:25
;;;26
;;; (or (block-node? x) (folio-work-item? x) (folio-relational-node? x))27
;;;28
;;; -- ordinary Sigil Doc blocks, work items and relational nodes, and NEVER a29
;;; structural container. That is what stops a section becoming a laundering30
;;; wrapper that re-nests containers inside work items.31
;;;32
;;; These records are deliberately minimal. They carry an id, a title and33
;;; children, because those are what the containment rule needs; they do NOT34
;;; reproduce folio's status machines, orders, priorities or identity grammars,35
;;; which F1a froze and which this phase has no business restating. A test36
;;; double that copies more than the property under test is a second37
;;; implementation waiting to disagree with the first.38
(define-library (sd-p7 folio model)39
(import (sigil core) (sigil struct) (sigil syntax) (sigil doc model))40
(export note? note-id note-title note-children make-note41
milestone? milestone-id milestone-title milestone-children make-milestone42
phase? phase-id phase-title phase-children make-phase43
task? task-id task-title task-children make-task44
update? update-id update-children make-update45
related? related-target related-kind make-related46
folio-structural-container? folio-work-item? folio-relational-node?47
folio-node? folio-section-child?48
folio-content-profile folio-describe-refusal)49
(begin50
(define-struct note-record (id) (title) (children) (location))51
(define-struct milestone-record (id) (title) (children) (location))52
(define-struct phase-record (id) (title) (children) (location))53
(define-struct task-record (id) (title) (children) (location))54
(define-struct update-record (id) (children) (location))55
(define-struct related-record (target) (kind) (location))57
(define (copy-list xs) (if (null? xs) '() (cons (car xs) (copy-list (cdr xs)))))59
(define note? note-record?)60
(define (note-id x) (string-copy (note-record-id x)))61
(define (note-title x) (string-copy (note-record-title x)))62
(define (note-children x) (copy-list (note-record-children x)))63
(define milestone? milestone-record?)64
(define (milestone-id x) (string-copy (milestone-record-id x)))65
(define (milestone-title x) (string-copy (milestone-record-title x)))66
(define (milestone-children x) (copy-list (milestone-record-children x)))67
(define phase? phase-record?)68
(define (phase-id x) (string-copy (phase-record-id x)))69
(define (phase-title x) (string-copy (phase-record-title x)))70
(define (phase-children x) (copy-list (phase-record-children x)))71
(define task? task-record?)72
(define (task-id x) (string-copy (task-record-id x)))73
(define (task-title x) (string-copy (task-record-title x)))74
(define (task-children x) (copy-list (task-record-children x)))75
(define update? update-record?)76
(define (update-id x) (string-copy (update-record-id x)))77
(define (update-children x) (copy-list (update-record-children x)))78
(define related? related-record?)79
(define (related-target x) (string-copy (related-record-target x)))80
(define related-kind related-record-kind)82
(define (make-note id title children loc)83
(note-record id: (string-copy id) title: (string-copy title)84
children: (copy-list children) location: loc))85
(define (make-milestone id title children loc)86
(milestone-record id: (string-copy id) title: (string-copy title)87
children: (copy-list children) location: loc))88
(define (make-phase id title children loc)89
(phase-record id: (string-copy id) title: (string-copy title)90
children: (copy-list children) location: loc))91
(define (make-task id title children loc)92
(task-record id: (string-copy id) title: (string-copy title)93
children: (copy-list children) location: loc))94
(define (make-update id children loc)95
(update-record id: (string-copy id) children: (copy-list children) location: loc))96
(define (make-related target kind loc)97
(related-record target: (string-copy target) kind: kind location: loc))99
(define (folio-structural-container? x) (or (note? x) (milestone? x) (phase? x)))100
(define (folio-work-item? x) (or (task? x) (update? x)))101
(define (folio-relational-node? x) (related? x))103
;; The language's VOCABULARY: what counts as a document node at all. A104
;; manuscript's `@task{...}` is refused in `author-normalize` against this,105
;; before `make-section` is reached, which is why a content profile carries106
;; it as well as the section-child predicate.107
(define (folio-node? x)108
(or (document-node? x) (folio-structural-container? x)109
(folio-work-item? x) (folio-relational-node? x)))111
;; CONDITION 3, spelled once. Ordinary Sigil Doc blocks, work items and112
;; relational nodes -- and never a structural container.113
(define (folio-section-child? x)114
(or (block-node? x) (folio-work-item? x) (folio-relational-node? x)))116
;; Witness locations. Any valid srcloc will do; the profile validates117
;; predicates, not positions.118
(define witness-location (make-srcloc "sd-p7-folio-witness" 1 1 0 0))120
;; The declared witnesses ARE the enforcement. `make-content-profile`121
;; refuses this profile unless `folio-section-child?` admits every value in122
;; `folio-admitted-witnesses` and REFUSES every value in123
;; `folio-refused-witnesses`, so widening the predicate to admit a milestone124
;; or a phase cannot be done without also deleting the declaration -- which125
;; a diff shows and a sabotage leg pins.126
;;127
;; One witness per line, deliberately: `test/sabotage-sd-p7.sh` replaces128
;; whole lines matched literally and refuses a substitution whose anchor is129
;; absent or ambiguous, so a leg cannot silently become a no-op.130
(define folio-admitted-witnesses131
(list (make-task "t-witness" "an admitted work item" '() witness-location)132
(make-update "u-witness" '() witness-location)133
(make-related "topics/witness" 'mentions witness-location)))134
(define folio-refused-witnesses135
(list (make-milestone "m-witness" "a refused container" '() witness-location)136
(make-phase "p-witness" "a refused container" '() witness-location)))138
;; THE DESCRIBER, AND WHY IT IS THE DELEGATING LANGUAGE THAT OWNS IT.139
;;140
;; Two things the core model cannot do for this diagnostic, both because it141
;; would have to know vocabulary it does not own:142
;;143
;; NAMING. "structural container" is folio's concept. `(sigil doc model)`144
;; knows only that a predicate said no.145
;; LOCATING. `node-location` is a CLOSED ENUMERATION over the core kinds146
;; and RAISES on anything else -- the same shape as the `block-node?`147
;; enumeration this phase exists to open, one layer down. So the core148
;; model can locate a paragraph and cannot locate a milestone, and the149
;; milestone is exactly the child a laundering attempt smuggles in.150
;;151
;; This module can do both, because these are its records. That is the whole152
;; argument for the describer living here rather than there.153
;;154
;; It receives the offending child and returns text. It is called only after155
;; the refusal is already decided; it cannot make a node acceptable.156
(define (folio-node-location node)157
(cond ((milestone? node) (milestone-record-location node))158
((phase? node) (phase-record-location node))159
((task? node) (task-record-location node))160
((update? node) (update-record-location node))161
((related? node) (related-record-location node))162
((note? node) (note-record-location node))163
;; A core node CAN be located by the core model, so ask it -- but164
;; guarded, because `node-location` raises rather than returning #f.165
(else (guard (exn (else #f)) (node-location node)))))167
(define (folio-location-prefix node)168
(let ((loc (folio-node-location node)))169
(if (srcloc? loc)170
(string-append (srcloc-file loc) ":" (number->string (srcloc-line loc))171
":" (number->string (srcloc-column loc)) ": ")172
"")))174
(define (folio-child-class node)175
(cond ((folio-structural-container? node)176
"a structural container; milestones and phases nest downward only and a section may not re-nest one")177
((folio-node? node) "a node this profile does not admit as a section child")178
(else "a value that is not a folio/doc node at all")))180
(define (folio-describe-refusal node)181
(string-append (folio-location-prefix node)182
"folio/doc: a section may not contain " (folio-child-class node)))184
(define folio-content-profile185
(make-content-profile "folio/doc" folio-node? folio-section-child?186
folio-admitted-witnesses folio-refused-witnesses187
describer: folio-describe-refusal))))