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 $
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
7
9
This file is part of MIT/GNU Scheme.
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,
28
30
(declare (usual-integrations))
30
;;;; Parser buffer abstraction
32
32
(define-structure parser-buffer
33
33
;; The string buffer, as a substring:
71
71
'STRING->PARSER-BUFFER))))
72
72
(make-parser-buffer string start end 0 0 #f #t 0)))))
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)))
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))
78
82
(define-integrable min-length 256)
84
(define (complete-*match matcher buffer)
86
(not (peek-parser-buffer-char buffer))))
88
(define (*match-string matcher string #!optional start end)
89
(complete-*match matcher (string->parser-buffer string start end)))
91
(define (*match-utf8-string matcher string #!optional start end)
92
(complete-*match matcher (utf8-string->parser-buffer string start end)))
94
(define (*match-symbol matcher symbol)
95
(*match-utf8-string matcher (symbol-name symbol)))
97
(define (complete-*parse parser buffer)
98
(let ((v (parser buffer)))
100
(not (peek-parser-buffer-char buffer))
103
(define (*parse-string parser string #!optional start end)
104
(complete-*parse parser (string->parser-buffer string start end)))
106
(define (*parse-utf8-string parser string #!optional start end)
107
(complete-*parse parser (utf8-string->parser-buffer string start end)))
109
(define (*parse-symbol parser symbol)
110
(*parse-utf8-string parser (symbol-name symbol)))
80
112
(define-structure parser-buffer-pointer
81
113
(index #f read-only #t)