(std11-analyze-domain-literal): New function.
[elisp/apel.git] / std11-parse.el
1 ;;; std11-parse.el --- STD 11 parser for GNU Emacs
2
3 ;; Copyright (C) 1995,1996 Free Software Foundation, Inc.
4
5 ;; Author:   MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Keywords: mail, news, RFC 822, STD 11
7 ;; Version: $Id: std11-parse.el,v 0.6 1996-08-28 17:35:10 morioka Exp $
8
9 ;; This file is part of tl (Tiny Library).
10
11 ;; This program is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License as
13 ;; published by the Free Software Foundation; either version 2, or (at
14 ;; your option) any later version.
15
16 ;; This program is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 ;; General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with This program; see the file COPYING.  If not, write to
23 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Code:
27
28 (require 'std11)
29
30
31 ;;; @ lexical analyze
32 ;;;
33
34 (defconst std11-space-chars " \t\n")
35 (defconst std11-spaces-regexp (concat "^[" std11-space-chars "]+"))
36 (defconst std11-special-chars "][()<>@,;:\\<>.\"")
37 (defconst std11-atom-regexp
38   (concat "^[^" std11-special-chars std11-space-chars "]+"))
39
40 (defun std11-analyze-spaces (str)
41   (if (string-match std11-spaces-regexp str)
42       (let ((end (match-end 0)))
43         (cons (cons 'spaces (substring str 0 end))
44               (substring str end)
45               ))))
46
47 (defun std11-analyze-special (str)
48   (if (and (> (length str) 0)
49            (find (aref str 0) std11-special-chars)
50            )
51       (cons (cons 'specials (substring str 0 1))
52             (substring str 1)
53             )))
54
55 (defun std11-analyze-atom (str)
56   (if (string-match std11-atom-regexp str)
57       (let ((end (match-end 0)))
58         (cons (cons 'atom (substring str 0 end))
59               (substring str end)
60               ))))
61
62 (defun std11-analyze-enclosure (str type open close)
63   (let ((len (length str)))
64     (if (and (> len 0)
65              (eq (aref str 0) open))
66         (let ((i 1) chr dest)
67           (catch 'tag
68             (while (< i len)
69               (setq chr (aref str i))
70               (cond ((eq chr ?\\)
71                      (setq i (1+ i))
72                      (if (>= i len)
73                          (throw 'tag nil)
74                        )
75                      (setq dest (concat dest (char-to-string (aref str i))))
76                      )
77                     ((eq chr close)
78                      (throw 'tag
79                             (cons (cons type dest) (substring str (1+ i)))
80                             )
81                      )
82                     (t
83                      (setq dest (concat dest (char-to-string (aref str i))))
84                      ))
85               (setq i (1+ i))
86               ))))))
87
88 (defun std11-analyze-quoted-string (str)
89   (std11-analyze-enclosure str 'quoted-string ?\" ?\")
90   )
91
92 (defun std11-analyze-domain-literal (str)
93   (std11-analyze-enclosure str 'domain-literal ?\[ ?\])
94   )
95
96
97 ;;; @ end
98 ;;;
99
100 (provide 'std11-parse)
101
102 ;;; std11-parse.el ends here