AtlatestRepositorysigil-doc
1
;;; SD-P1 -- canonical dump of LOWERED output for real manuscripts.2
;;;3
;;; "sigil/doc's default behaviour is byte-identical to today" is an acceptance4
;;; criterion, and "the existing suites still pass" is weaker evidence for it5
;;; than it looks: a suite asserts the properties someone thought to assert.6
;;; This dumps the whole lowered form sequence -- every datum and every source7
;;; location, including generated-origin chains -- so the BEFORE and AFTER trees8
;;; can be compared for EQUALITY rather than for absence of complaint.9
;;;10
;;; The manuscripts below deliberately EXCLUDE `test/fixtures/sd-p4-collision.sgd`,11
;;; which uses `@text{}`/`@expr{}`. Those two spellings are exactly what this12
;;; phase intends to change, and their before/after is measured separately by13
;;; `test/sd-p1-classification-probe.sgl`. Mixing them in here would turn an14
;;; equality check into a judgement call.15
;;;16
;;; Nothing is evaluated: lowering is a pure source-to-syntax transformation, so17
;;; this runs no author code.18
(import (sigil core) (sigil fs) (sigil language) (sigil doc private parser))20
(define (emit-location loc depth)21
(if (or (not loc) (> depth 40))22
(display "#f")23
(begin24
(display "[") (write (srcloc-file loc))25
(display " ") (display (srcloc-line loc))26
(display ":") (display (srcloc-column loc))27
(display " byte=") (display (srcloc-position loc))28
(display " span=") (display (srcloc-span loc))29
(let ((origin (srcloc-origin loc)))30
(if origin31
(begin (display " <-") (emit-location origin (+ depth 1)))32
#f))33
(display "]"))))35
;; Walk the improper-list structure explicitly. `write` alone would not show36
;; syntax wrappers or locations, which are the part most likely to move.37
(define (emit value)38
(cond39
((syntax? value)40
(display "#<")41
(emit-location (syntax-srcloc value) 0)42
(display " ")43
(emit (syntax-datum value))44
(display ">"))45
((null? value) (display "()"))46
((pair? value)47
(display "(")48
(let loop ((rest value) (first? #t))49
(cond50
((null? rest) #t)51
((pair? rest)52
(if first? #t (display " "))53
(emit (car rest))54
(loop (cdr rest) #f))55
(else (display " . ") (emit rest))))56
(display ")"))57
(else (write value))))59
(define (dump path)60
(let* ((source (read-file-string path))61
(header (inspect-language-source source path))62
(forms (parse-document-forms source path (language-header-end header))))63
(display "=== ") (display path)64
(display " forms=") (display (length forms)) (newline)65
(for-each (lambda (form) (emit form) (newline)) forms)))67
;; Real manuscripts, not synthetic ones: these are what "unchanged" has to mean.68
(define manuscripts69
(list "book/practical-sigil/01-useful-first-script.sgd"70
"book/practical-sigil/02-change-the-question.sgd"71
"test/fixtures/practical-sigil-chapter.sgd"72
"test/fixtures/practical-sigil-change-question.sgd"73
"test/fixtures/minimal.sgd"74
"test/fixtures/semantic-structures.sgd"75
"test/fixtures/glossary-lesson.sgd"76
"test/fixtures/glossary-page.sgd"77
"test/fixtures/d3-examples.sgd"78
"test/fixtures/d3-adversarial.sgd"))80
(for-each dump manuscripts)81
(display "SD_P1_LOWERING_DUMP_COMPLETE ")82
(display (length manuscripts))83
(display " manuscripts")84
(newline)