AtlatestRepositorysigil-doc
1
;;; SD-P8 -- both shipped languages driven END TO END through the real `#lang`2
;;; path, plus the diagnostic each refusal carries at the reader.3
;;;4
;;; WHY BOTH HALVES ARE HERE, AND WHY NEITHER ALONE WOULD DO.5
;;;6
;;; The `#lang` half is the path an author takes: the compiler reads the header,7
;;; resolves `#lang a/b/c` to the module `(a b c reader)`, loads it and calls its8
;;; `read-language-source`. Driving parsed forms through runtime `eval` instead9
;;; would test the harness as much as the product -- SD-P1's headline finding10
;;; about keyword formals turned out to be exactly that instrument artifact. So11
;;; the accept/refuse verdicts below come from `load`.12
;;;13
;;; The reader half exists because of a MEASURED defect in the compiler, not out14
;;; of caution. A root-policy refusal reaching the `#lang` loader is reported as15
;;;16
;;; Error (syntax-error): read-language-source failed for #lang sigil/doc:17
;;;18
;;; with the underlying message EMPTY. The parser's diagnostic -- which names the19
;;; language and the root it wanted -- never reaches the author. Verified20
;;; pre-existing at the base SHA with a two-`@chapter` manuscript under the old21
;;; base profile, so it is not something D8 introduced; it is in the sigil22
;;; compiler's language-loading path, outside this package. It does mean that23
;;; "the refusal names what is wrong" CANNOT be asserted at the `#lang` layer24
;;; today, so each refusal is re-driven through25
;;; `parse-document-parts-with-profile` -- the same source, the same profile the26
;;; `#lang` line selects -- and the real diagnostic is printed for the gate to27
;;; assert on.28
;;;29
;;; Every case prints a line whether it passes or fails, and the completion30
;;; marker carries the count: the output length is the denominator, so a case31
;;; that silently stopped running cannot read as a case that passed.32
(import (sigil core) (sigil fs) (sigil language)33
(sigil doc) (sigil doc reader) (sigil doc book reader))35
(define (message thunk)36
(guard (exn (else (exception-message exn))) (thunk) "NO-RAISE"))38
(define (header-end-of source)39
(let loop ((i 0))40
(cond ((>= i (string-length source)) i)41
((char=? (string-ref source i) #\newline) (+ i 1))42
(else (loop (+ i 1))))))44
(define (profile-for id)45
(cond ((string=? id "sigil/doc") sigil-doc-profile)46
((string=? id "sigil/doc/book") sigil-doc-book-profile)47
(else #f)))49
;; The `#lang` verdict, from `load`. `document` is bound into THIS module by a50
;; successful load, so an accepted manuscript can be asked for its kind.51
(define (lang-verdict path)52
(let ((raised (message (lambda () (load path)))))53
(if (string=? raised "NO-RAISE")54
(cons 'accept (symbol->string (document-kind (eval 'document))))55
(cons 'refuse raised))))57
;; The reader-level diagnostic for the SAME source under the SAME profile the58
;; `#lang` line names -- read out of the manuscript rather than passed in, so a59
;; case cannot be driven through a profile its header does not select.60
(define (reader-diagnostic path)61
(let* ((source (read-file-string path))62
(id (language-header-id (inspect-language-source source path)))63
(profile (profile-for id)))64
(if (not profile) (string-append "NO-PROFILE-FOR " id)65
(message (lambda () (parse-document-parts-with-profile66
profile source path (header-end-of source)))))))68
(define cases69
(list70
;; name path want want-kind71
(list "base-accepts-article" "test/fixtures/sd-p1-article-root.sgd" 'accept "article")72
(list "base-refuses-chapter" "test/fixtures/sd-p8-base-chapter-root.sgd" 'refuse "")73
(list "base-refuses-two" "test/fixtures/sd-p8-base-two-articles.sgd" 'refuse "")74
(list "book-accepts-chapter" "test/fixtures/sd-p8-book-chapter-root.sgd" 'accept "chapter")75
(list "book-refuses-article" "test/fixtures/sd-p8-book-article-root.sgd" 'refuse "")76
(list "book-refuses-two" "test/fixtures/sd-p8-book-two-chapters.sgd" 'refuse "")))78
(define ok 0)79
(define bad 0)81
(for-each82
(lambda (c)83
(let* ((name (car c)) (path (cadr c)) (want (caddr c)) (want-kind (cadddr c))84
(verdict (lang-verdict path))85
(got (car verdict))86
(detail (cdr verdict))87
(matched (and (eq? got want)88
(or (not (eq? want 'accept)) (string=? detail want-kind)))))89
(if matched (set! ok (+ ok 1)) (set! bad (+ bad 1)))90
(display "SD_P8_LANG ") (display name)91
(display " want=") (display want)92
(display " got=") (display got)93
(display (if matched " MATCH" " MISMATCH"))94
(display " kind-or-error=") (write detail)95
(newline)96
;; The reader-level diagnostic, printed for EVERY case rather than only97
;; the refusals: an accepted manuscript must produce `NO-RAISE` here, and98
;; that is the positive control that stops the refusal assertions from99
;; being satisfied by a reader that refuses everything.100
(display "SD_P8_DIAG ") (display name)101
(display " :: ") (write (reader-diagnostic path))102
(newline)))103
cases)105
(display "SD_P8_LANGUAGE_PROBE_COMPLETE cases ")106
(display (length cases))107
(display " matched ") (display ok)108
(display " mismatched ") (display bad)109
(newline)