diff options
author | Ludovic Courtès | 2009-05-26 18:28:11 +0200 |
---|---|---|
committer | Ludovic Courtès | 2009-05-26 18:29:49 +0200 |
commit | 9a8581b9b056efed763fb6beff15f9d36cf07ee0 (patch) | |
tree | dcd4c129335a5130927029b21d2260d035b2e91a /src | |
parent | f698471f9de9a5b0f853a014fccba1f2aff1b4dd (diff) | |
download | skribilo-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')
-rw-r--r-- | src/guile/skribilo/ast.scm | 25 |
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)))) |