AtlatestRepositorysigil-doc
1
;;; (sd-p7 folio reader) -- `#lang sd-p7/folio`, a DELEGATING language.2
;;;3
;;; This module exists so that SD-P7's end-to-end arm goes through the real4
;;; `#lang` path -- the compiler reads the header, resolves `#lang a/b` to the5
;;; module `(a b reader)`, loads it and calls its `read-language-source` -- and6
;;; not through runtime `eval`. That distinction is not fussiness: SD-P1's7
;;; headline finding about keyword formals turned out to be an INSTRUMENT8
;;; ARTIFACT of driving parsed forms through `eval`, which reaches CPS9
;;; conversion without the top-level macro-expansion pass. An arm built on10
;;; `eval` would be measuring the harness as much as the product.11
;;;12
;;; It is also F1b in miniature. Everything here that is not folio-shaped13
;;; stand-in vocabulary is what `(folio doc reader)` will have to do:14
;;;15
;;; * name its roots through SD-P1's document profile;16
;;; * delegate the WHOLE grammar and every location to `(sigil doc reader)`,17
;;; never forking the parser;18
;;; * emit a prelude that binds the three runtime names the parser calls, so19
;;; its content profile is installed for the manuscript's dynamic extent.20
;;;21
;;; Nothing in this tree ships it; it lives under `test/` and is reached only22
;;; because the suites run with `-L test`.23
(define-library (sd-p7 folio reader)24
(import (sigil core) (sigil syntax) (sigil doc reader))25
(export read-language-source folio-document-profile)26
(begin27
;; SD-P1's parameter. One root, `@note`, exactly one of it.28
(define folio-document-profile29
(make-document-profile "sd-p7/folio" '(note) 'one))31
(define (context-ref context key)32
(let ((entry (assq key context)))33
(if entry (cdr entry) (error "sd-p7/folio reader: incomplete language context"))))35
(define (read-language-source source context)36
(let* ((source-name (context-ref context source-name:))37
(header-end (context-ref context header-end-offset:))38
(parts (parse-document-parts-with-profile39
folio-document-profile source source-name header-end))40
(author-forms (car parts))41
(roots (cadr parts))42
(loc (make-srcloc source-name 1 1 0 header-end)))43
(append44
;; THE PRELUDE IS THE INSTALLATION POINT. `(sd-p7 folio author)` is45
;; imported INSTEAD of `(sigil doc private author-runtime)`, so the46
;; three names the parser emits resolve to wrappers that install this47
;; language's content profile. `(sigil doc author)` is still imported48
;; whole: its `@section`, `@p`, `@code` and the rest are reused49
;; unchanged, which is the point -- `@section` now admits this50
;; language's work items because it asks the ambient profile.51
(list (make-syntax '(import (sigil doc) (sigil doc author)52
(sd-p7 folio author)) loc))53
author-forms54
(list (make-syntax (list 'define 'document (car roots)) loc)55
(make-syntax 'document loc)))))))