From 9a8581b9b056efed763fb6beff15f9d36cf07ee0 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Tue, 26 May 2009 18:28:11 +0200 Subject: 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. --- src/guile/skribilo/ast.scm | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'src') 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)))) -- cgit v1.2.3