indexing.scm 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. ;;;; (texinfo indexing) -- indexing stexinfo
  2. ;;;;
  3. ;;;; Copyright (C) 2009, 2010 Free Software Foundation, Inc.
  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. ;;; Commentary:
  21. ;;
  22. ;;@c texinfo formatting
  23. ;;Given a piece of stexi, return an index of a specified variety.
  24. ;;
  25. ;;Note that currently, @code{stexi-extract-index} doesn't differentiate
  26. ;;between different kinds of index entries. That's a bug ;)
  27. ;;; Code:
  28. (define-module (texinfo indexing)
  29. #:use-module (sxml simple)
  30. #:use-module (srfi srfi-13)
  31. #:export (stexi-extract-index))
  32. (define defines
  33. '(deftp defcv defivar deftypeivar defop deftypeop defmethod
  34. deftypemethod defopt defvr defvar deftypevr deftypevar deffn
  35. deftypefn defspec defmac defun deftypefun))
  36. (define indices
  37. '(cindex findex vindex kindex pindex tindex))
  38. (define (stexi-extract-index tree manual-name kind)
  39. "Given an stexi tree @var{tree}, index all of the entries of type
  40. @var{kind}. @var{kind} can be one of the predefined texinfo indices
  41. (@code{concept}, @code{variable}, @code{function}, @code{key},
  42. @code{program}, @code{type}) or one of the special symbols @code{auto}
  43. or @code{all}. @code{auto} will scan the stext for a @code{(printindex)}
  44. statement, and @code{all} will generate an index from all entries,
  45. regardless of type.
  46. The returned index is a list of pairs, the @sc{car} of which is the
  47. entry (a string) and the @sc{cdr} of which is a node name (a string)."
  48. (let loop ((in tree) (entries '()))
  49. (cond
  50. ((null? in)
  51. entries)
  52. ((pair? (car in))
  53. (cond
  54. ((and (pair? (cdr in)) (pair? (cadr in))
  55. (eq? (caar in) 'anchor) (memq (caadr in) defines))
  56. (loop (cddr in) (acons (cadr (assq 'name (cdr (cadadr in))))
  57. (cadr (assq 'name (cdadar in)))
  58. entries)))
  59. ((and (pair? (cdr in)) (pair? (cadr in))
  60. (eq? (caar in) 'anchor) (memq (caadr in) indices))
  61. (loop (cddr in) (acons (sxml->string (cadr in))
  62. (cadr (assq 'name (cdadar in)))
  63. entries)))
  64. (else
  65. (loop (cdr in) (loop (car in) entries)))))
  66. (else
  67. (loop (cdr in) entries)))))
  68. ;;; arch-tag: 216d29d3-1ed9-433f-9c19-0dc4d6b439b6