AtlatestRepositorysigil-doc

sigil-doc / tree / testsd-p3-trim-body-edges-probe.sgl

1;;; SD-P3 -- MEASURED record of the inherited `trim-body-edges` behaviour.
2;;;
3;;; SD-P4 recorded that `trim-body-edges` folds and trims text nodes INCLUDING
4;;; the raw text inside a block-position `@code` body, so `tree-node-text` is
5;;; not the content for raw code. SD-P3 was asked to judge whether fixing that
6;;; is in scope, and DEFERRED it (it changes what `tree-node-text` means on
7;;; SD-P4's already-merged, documented, test-pinned passive contract, while the
8;;; lowering path is provably unaffected because `code-block-content` re-slices
9;;; through `raw-children`).
10;;;
11;;; A deferral still owes a measurement rather than a restatement of somebody
12;;; else's write-up. This probe prints, for a multi-line raw `@code` body:
13;;;
14;;; * `tree-node-text` -- the folded value;
15;;; * the SOURCE SLICE named by the same node's span -- the authoritative text;
16;;; * whether the lowered `code-block-content` matches the slice (it must; that
17;;; is the reason the defect is invisible to every current consumer).
18;;;
19;;; It runs no author code for the passive half; the lowering half evaluates the
20;;; manuscript, which is what a consumer of the semantic model does anyway.
21(import (sigil core) (sigil syntax) (sigil doc) (sigil doc author)
22 (sigil doc private author-runtime)
23 (sigil doc inspect) (sigil doc private parser))
25(define source
26 (string-append
27 "#lang sigil/doc\n"
28 "@chapter[\"Probe\" \"A\"]{\n"
29 "@code[\"sigil\"]{\n"
30 "(define (main)\n"
31 " (display \"one\")\n"
32 "\n"
33 " (display \"two\"))\n"
34 "}\n"
35 "}\n"))
37(define tree (inspect-document-source source "trim-probe.sgd" 16))
39(define (find-code nodes)
40 (let loop ((xs nodes))
41 (cond
42 ((null? xs) #f)
43 ((and (eq? (tree-node-kind (car xs)) 'command)
44 (eq? (tree-node-name (car xs)) 'code))
45 (car xs))
46 (else
47 (let ((inner (find-code (tree-node-children (car xs)))))
48 (or inner (loop (cdr xs))))))))
50(define code-node (find-code (document-tree-roots tree)))
51(define body (car (tree-node-children code-node)))
53(display "PASSIVE tree-node-text ") (write (tree-node-text body)) (newline)
54(display "PASSIVE source slice ")
55(write (substring source (tree-node-start body) (tree-node-end body))) (newline)
56(display "TEXT-EQUALS-SLICE ")
57(display (if (string=? (tree-node-text body)
58 (substring source (tree-node-start body) (tree-node-end body)))
59 "yes" "no"))
60(newline)
62(define doc (eval (parse-document-source source "trim-probe.sgd" 16)))
63(define block (car (document-children doc)))
64(display "LOWERED code-block-content ") (write (code-block-content block)) (newline)
65(display "LOWERED-EQUALS-SLICE ")
66(display (if (string=? (code-block-content block)
67 (substring source (tree-node-start body) (tree-node-end body)))
68 "yes" "no"))
69(newline)
70(display "SD_P3_TRIM_BODY_EDGES_PROBE_COMPLETE")
71(newline)