12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- (define-module (texinfo indexing)
- #:use-module (sxml simple)
- #:use-module (srfi srfi-13)
- #:export (stexi-extract-index))
- (define defines
- '(deftp defcv defivar deftypeivar defop deftypeop defmethod
- deftypemethod defopt defvr defvar deftypevr deftypevar deffn
- deftypefn defspec defmac defun deftypefun))
- (define indices
- '(cindex findex vindex kindex pindex tindex))
- (define (stexi-extract-index tree manual-name kind)
- "Given an stexi tree @var{tree}, index all of the entries of type
- @var{kind}. @var{kind} can be one of the predefined texinfo indices
- (@code{concept}, @code{variable}, @code{function}, @code{key},
- @code{program}, @code{type}) or one of the special symbols @code{auto}
- or @code{all}. @code{auto} will scan the stext for a @code{(printindex)}
- statement, and @code{all} will generate an index from all entries,
- regardless of type.
- The returned index is a list of pairs, the @sc{car} of which is the
- entry (a string) and the @sc{cdr} of which is a node name (a string)."
- (let loop ((in tree) (entries '()))
- (cond
- ((null? in)
- entries)
- ((pair? (car in))
- (cond
- ((and (pair? (cdr in)) (pair? (cadr in))
- (eq? (caar in) 'anchor) (memq (caadr in) defines))
- (loop (cddr in) (acons (cadr (assq 'name (cdr (cadadr in))))
- (cadr (assq 'name (cdadar in)))
- entries)))
- ((and (pair? (cdr in)) (pair? (cadr in))
- (eq? (caar in) 'anchor) (memq (caadr in) indices))
- (loop (cddr in) (acons (sxml->string (cadr in))
- (cadr (assq 'name (cdadar in)))
- entries)))
- (else
- (loop (cdr in) (loop (car in) entries)))))
- (else
- (loop (cdr in) entries)))))
|