summaryrefslogtreecommitdiff
path: root/src/guile
diff options
context:
space:
mode:
authorLudovic Courtès2009-05-26 18:28:11 +0200
committerLudovic Courtès2009-05-26 18:29:49 +0200
commit9a8581b9b056efed763fb6beff15f9d36cf07ee0 (patch)
treedcd4c129335a5130927029b21d2260d035b2e91a /src/guile
parentf698471f9de9a5b0f853a014fccba1f2aff1b4dd (diff)
downloadskribilo-9a8581b9b056efed763fb6beff15f9d36cf07ee0.tar.gz
skribilo-9a8581b9b056efed763fb6beff15f9d36cf07ee0.tar.lz
skribilo-9a8581b9b056efed763fb6beff15f9d36cf07ee0.zip
resolve: Clarify node bindings in nested documents.
* src/guile/skribilo/ast.scm (document-bind-nodes!): Bind nodes in the innermost document, which may or may not be the root document. * tests/resolve.test ("root document has no parent", "nested document has a parent", "nested document is its own `ast-document'", "nested document bindings"): New tests.
Diffstat (limited to 'src/guile')
-rw-r--r--src/guile/skribilo/ast.scm25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/guile/skribilo/ast.scm b/src/guile/skribilo/ast.scm
index 3de6947..86fa781 100644
--- a/src/guile/skribilo/ast.scm
+++ b/src/guile/skribilo/ast.scm
@@ -496,11 +496,26 @@
(if (document-nodes-bound? doc)
#t
(begin
- (ast-fold (lambda (node result)
- (if (markup? node) (document-bind-node! doc node))
- #t)
- #t ;; unused
- doc)
+ (let loop ((node doc)
+ (doc doc))
+ (cond ((document? node)
+ ;; Bind NODE in its parent's document. This is so
+ ;; that (i) a sub-document is bound in its parent
+ ;; document, and (ii) a node within a sub-document
+ ;; is bound in this sub-document.
+ (document-bind-node! doc node)
+ (loop (markup-body node) node))
+
+ ((markup? node)
+ (document-bind-node! doc node)
+ (loop (markup-body node) doc))
+
+ ((pair? node)
+ (for-each (lambda (n) (loop n doc)) node))
+
+ ((command? node)
+ (loop (command-body node) doc))))
+
(slot-set! doc 'nodes-bound? #t))))