add support for texinfo parsed arguments, like @acronym
[bpt/guile.git] / module / texinfo / indexing.scm
CommitLineData
47f3ce52
AW
1;;;; (texinfo indexing) -- indexing stexinfo
2;;;;
6734191c 3;;;; Copyright (C) 2009, 2010 Free Software Foundation, Inc.
47f3ce52
AW
4;;;; Copyright (C) 2003,2004,2009 Andy Wingo <wingo at pobox dot com>
5;;;;
6;;;; This library is free software; you can redistribute it and/or
7;;;; modify it under the terms of the GNU Lesser General Public
8;;;; License as published by the Free Software Foundation; either
9;;;; version 3 of the License, or (at your option) any later version.
10;;;;
11;;;; This library is distributed in the hope that it will be useful,
12;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14;;;; Lesser General Public License for more details.
15;;;;
16;;;; You should have received a copy of the GNU Lesser General Public
17;;;; License along with this library; if not, write to the Free Software
18;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19;;;;
20\f
21;;; Commentary:
22;;
23;;@c texinfo formatting
24;;Given a piece of stexi, return an index of a specified variety.
25;;
26;;Note that currently, @code{stexi-extract-index} doesn't differentiate
27;;between different kinds of index entries. That's a bug ;)
28;;; Code:
29
30(define-module (texinfo indexing)
31 #:use-module (sxml simple)
32 #:use-module (srfi srfi-13)
33 #:export (stexi-extract-index))
34
47f3ce52
AW
35(define defines
36 '(deftp defcv defivar deftypeivar defop deftypeop defmethod
37 deftypemethod defopt defvr defvar deftypevr deftypevar deffn
38 deftypefn defspec defmac defun deftypefun))
39
40(define indices
41 '(cindex findex vindex kindex pindex tindex))
42
43(define (stexi-extract-index tree manual-name kind)
44 "Given an stexi tree @var{tree}, index all of the entries of type
45@var{kind}. @var{kind} can be one of the predefined texinfo indices
46(@code{concept}, @code{variable}, @code{function}, @code{key},
47@code{program}, @code{type}) or one of the special symbols @code{auto}
48or @code{all}. @code{auto} will scan the stext for a @code{(printindex)}
49statement, and @code{all} will generate an index from all entries,
50regardless of type.
51
52The returned index is a list of pairs, the @sc{car} of which is the
53entry (a string) and the @sc{cdr} of which is a node name (a string)."
54 (let loop ((in tree) (entries '()))
55 (cond
56 ((null? in)
57 entries)
58 ((pair? (car in))
59 (cond
60 ((and (pair? (cdr in)) (pair? (cadr in))
61 (eq? (caar in) 'anchor) (memq (caadr in) defines))
62 (loop (cddr in) (acons (cadr (assq 'name (cdr (cadadr in))))
63 (cadr (assq 'name (cdadar in)))
64 entries)))
65 ((and (pair? (cdr in)) (pair? (cadr in))
66 (eq? (caar in) 'anchor) (memq (caadr in) indices))
67 (loop (cddr in) (acons (sxml->string (cadr in))
68 (cadr (assq 'name (cdadar in)))
69 entries)))
70 (else
71 (loop (cdr in) (loop (car in) entries)))))
72 (else
73 (loop (cdr in) entries)))))
74
75;;; arch-tag: 216d29d3-1ed9-433f-9c19-0dc4d6b439b6