--
Another approach would be to change the regexp interface. For example,
regexps could operate on string ports--returning some sort of match
structure and consuming the port as you go. Not sure this would be
a good idea, but since you're trying to consume the string with your
lexer, and ports are just right for that sort of thing, it's tempting.
I believe an earlier version of the regexp interface returned matches
as procedures, which could then be called to get at the results of the
match. So you could do something like this:
(call-with-input-string "98 + 12"
(lambda (port)
(let ((r (string->regexp "^[0-9]][0-9]*")))
((r port) 'match))))
... which would _return_ "98" (the string matched by r), and leave
" + 12" to be read from the port.
This is a terrible example, because I'm avoiding the question of how
to deal with failed matches (you don't want it to consume the whole
port while it's looking, because then you lose all the advantage of
having it in a port, but how do you _not_ consume it if it's a file
instead of a string?), but I thought I'd throw it out there as another
way of looking at the problem.
--Erik
Received on Wed Dec 04 1996 - 01:08:38 CET
This archive was generated by hypermail 2.3.0 : Mon Jul 21 2014 - 19:38:59 CEST