/usr/share/guile/site/texinfo/nodal-tree.scm is in guile-library 0.2.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | ;; (texinfo nodal-tree) -- rendering stexinfo to a nodal tree
;; Copyright (C) 2003,2004 Andy Wingo <wingo at pobox dot com>
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;
;;This module exports a procedure to chunk a stexi doument into pieces,
;;delimited by sectioning commands (@code{@@chapter},
;;@code{@@appendixsec}, etc.). Note that the sectioning commands must be
;;preceded by a @code{@@node}, a condition that the output of
;;@code{(sxml texinfo)} respects.
;;
;;The output is a nodal tree (see (container nodal-tree)), with the
;;following fields defined for each node:
;;
;;; Code:
(define-module (texinfo nodal-tree)
#:use-module (container nodal-tree)
#:use-module (sxml simple)
#:use-module (scheme kwargs)
#:use-module (texinfo) ;; texi-command-depth
#:export (stexi->nodal-tree))
(define (node? elt)
(and (pair? elt) (eq? (car elt) 'node)))
(define (chunking-section? elt max-depth)
(and (pair? elt) (texi-command-depth (car elt) max-depth)))
(define (append-child! parent kid)
(if parent
(node-set! parent 'children
(append! (node-ref parent 'children) (list kid)))))
(define (find-parent node)
(or (and=> (node-ref node 'parent) find-parent) node))
;; There has to be a more functional way to do this! Probably involves
;; building up from the leaves, instead of building down from the root.
;; Thankfully, the ugliness of this code isn't exported.
(define/kwargs (stexi->nodal-tree (stexi #f) (max-depth 4) (initial-depth 0))
"Break @var{stexi} into a nodal tree. Only break until sectioning
identifiers of depth @var{max-depth}. The following fields are defined
for each node:
@table @code
@item name
The name of the section.
@item value
The content of the section, as @code{stexi}. The containing element is
@code{texinfo}.
@item parent
A reference to the parent node.
@item children
A list of subnodes, corresponding to the subsections of the current
section.
@end table"
(define (make-node* parent tree-title)
(let ((node (make-node
'name (sxml->string tree-title)
'value #f
'parent parent
'children '())))
(append-child! parent node)
node))
(or (eq? (car stexi) 'texinfo) (error "Invalid stexi"))
(let lp ((in stexi)
(val '())
(node (make-node* #f (cadr stexi)))
(parent #f)
(depth initial-depth))
;(pk (or (null? in) (car in)) val node parent depth)
(cond
((null? in)
(node-set! node 'value (reverse! val))
(find-parent node))
((or (chunking-section? (car in) max-depth)
(and (node? (car in)) (pair? in) (pair? (cdr in))
(chunking-section? (cadr in) max-depth)))
(node-set! node 'value (reverse! val))
(let* ((node-statement (if (node? (car in)) (car in) #f))
(in (if node-statement (cdr in) in))
(new-depth (texi-command-depth (caar in) max-depth)))
(let new-parent ((parent node) (diff (- new-depth depth)))
(cond
((not parent) (error "invalid stexi"))
((positive? diff)
(or (eq? diff 1)
(error "can only descend by one depth level at a time"
(car in)))
(lp (cdr in)
`(,(car in)
,@(if node-statement (list node-statement) '())
(% (title ,(sxml->string (car in)))) texinfo)
(make-node* parent (car in)) parent new-depth))
(else
(new-parent (node-ref parent 'parent) (1+ diff)))))))
(else
(lp (cdr in) (cons (car in) val) node parent depth)))))
;;; arch-tag: aff19153-493d-4755-ba6f-22cc7fb43c60
|