aboutsummaryrefslogtreecommitdiff
path: root/src/guile
diff options
context:
space:
mode:
authorLudovic Courtès2012-05-14 00:46:59 +0200
committerLudovic Courtès2012-05-14 01:02:46 +0200
commite47dcdb8340d6c24a7f20107b3f199a8f70020a8 (patch)
tree12ea9446c6983f9135202a1200c1f3c403c5b744 /src/guile
parente10677ed464319816d36f1d545c3111f227b7eab (diff)
downloadskribilo-e47dcdb8340d6c24a7f20107b3f199a8f70020a8.tar.gz
skribilo-e47dcdb8340d6c24a7f20107b3f199a8f70020a8.tar.lz
skribilo-e47dcdb8340d6c24a7f20107b3f199a8f70020a8.zip
ast: Add `node-children'.
* src/guile/skribilo/ast.scm (node-children): New procedure. * tests/ast.test ("node-children"): New test.
Diffstat (limited to 'src/guile')
-rw-r--r--src/guile/skribilo/ast.scm17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/guile/skribilo/ast.scm b/src/guile/skribilo/ast.scm
index 140f861..747c364 100644
--- a/src/guile/skribilo/ast.scm
+++ b/src/guile/skribilo/ast.scm
@@ -32,6 +32,7 @@
:autoload (skribilo location) (location?)
+ :use-module (ice-9 match)
:use-module (ice-9 optargs)
:export (<ast> ast? ast-loc ast-loc-set!
@@ -42,6 +43,7 @@
<unresolved> unresolved? unresolved-proc
<handle> handle? handle-ast handle-body
<node> node? node-options node-loc node-body
+ node-children
<processor> processor? processor-combinator processor-engine
<markup> markup? markup-options is-markup?
@@ -274,6 +276,21 @@
(equal? (node-body a)
(node-body b))))
+(define (node-children n)
+ ;; Return the children of N, even those found in sub-lists of N's body.
+ (reverse
+ (let loop ((body (node-body n))
+ (result '()))
+ (match body
+ (()
+ result)
+ (((? node? n) rest ...)
+ (loop rest (cons n result)))
+ (((sub-list ...) rest ...)
+ (loop rest (loop sub-list result)))
+ ((_ rest ...)
+ (loop rest result))))))
+
(define node-loc ast-loc)
(define-method (ast->string (ast <node>))