~ubuntu-branches/ubuntu/karmic/mit-scheme/karmic

« back to all changes in this revision

Viewing changes to src/runtime/parser-buffer.scm

  • Committer: Bazaar Package Importer
  • Author(s): Soren Hansen
  • Date: 2007-05-09 10:57:57 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20070509105757-p8focimovgqxaaed
Tags: 7.7.90+20070205-1ubuntu1
* Merge from debian unstable, remaining changes:
  * Bootstrapping done via supplied binary package. See log entry for
    7.7.90+20060906-3ubuntu1 for details.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#| -*-Scheme-*-
2
2
 
3
 
$Id: parser-buffer.scm,v 1.16 2006/06/10 04:06:47 cph Exp $
 
3
$Id: parser-buffer.scm,v 1.20 2007/01/17 03:39:35 cph Exp $
4
4
 
5
 
Copyright 2001,2002,2003,2004,2006 Massachusetts Institute of Technology
 
5
Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
 
6
    1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
 
7
    2006, 2007 Massachusetts Institute of Technology
6
8
 
7
9
This file is part of MIT/GNU Scheme.
8
10
 
18
20
 
19
21
You should have received a copy of the GNU General Public License
20
22
along with MIT/GNU Scheme; if not, write to the Free Software
21
 
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
 
23
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301,
22
24
USA.
23
25
 
24
26
|#
27
29
 
28
30
(declare (usual-integrations))
29
31
 
30
 
;;;; Parser buffer abstraction
31
 
 
32
32
(define-structure parser-buffer
33
33
  ;; The string buffer, as a substring:
34
34
  string
71
71
                                                     'STRING->PARSER-BUFFER))))
72
72
          (make-parser-buffer string start end 0 0 #f #t 0)))))
73
73
 
 
74
(define (utf8-string->parser-buffer string #!optional start end)
 
75
  (let ((ws (utf8-string->wide-string string start end)))
 
76
    (make-parser-buffer ws 0 (%wide-string-length ws) 0 0 #f #t 0)))
 
77
 
74
78
(define (input-port->parser-buffer port)
75
79
  (guarantee-input-port port 'INPUT-PORT->PARSER-BUFFER)
76
80
  (make-parser-buffer (make-wide-string min-length) 0 0 0 0 port #f 0))
77
81
 
78
82
(define-integrable min-length 256)
 
83
 
 
84
(define (complete-*match matcher buffer)
 
85
  (and (matcher buffer)
 
86
       (not (peek-parser-buffer-char buffer))))
 
87
 
 
88
(define (*match-string matcher string #!optional start end)
 
89
  (complete-*match matcher (string->parser-buffer string start end)))
 
90
 
 
91
(define (*match-utf8-string matcher string #!optional start end)
 
92
  (complete-*match matcher (utf8-string->parser-buffer string start end)))
 
93
 
 
94
(define (*match-symbol matcher symbol)
 
95
  (*match-utf8-string matcher (symbol-name symbol)))
 
96
 
 
97
(define (complete-*parse parser buffer)
 
98
  (let ((v (parser buffer)))
 
99
    (and v
 
100
         (not (peek-parser-buffer-char buffer))
 
101
         v)))
 
102
 
 
103
(define (*parse-string parser string #!optional start end)
 
104
  (complete-*parse parser (string->parser-buffer string start end)))
 
105
 
 
106
(define (*parse-utf8-string parser string #!optional start end)
 
107
  (complete-*parse parser (utf8-string->parser-buffer string start end)))
 
108
 
 
109
(define (*parse-symbol parser symbol)
 
110
  (*parse-utf8-string parser (symbol-name symbol)))
79
111
 
80
112
(define-structure parser-buffer-pointer
81
113
  (index #f read-only #t)