[plt-scheme] regexp-match a full line

From: Eli Nistal (chico.mono at gmail.com)
Date: Mon Oct 6 22:12:36 EDT 2008

On Mon, Oct 6, 2008 at 7:25 PM, Eli Barzilay <eli at barzilay.org> wrote:

> On Oct  7, Noel Welsh wrote:
> > You could make your regexp match to the end of the line (using the $
> > symbol IIRC) or you could convert the file to a list of strings and
> > match on those.  For the later the port->string-list function in the
> > port.plt package on PLaneT will help.
>
> As a side note, that function is easy to define using either
> `for/list':
>
>  (define (port->string-list port)
>    (for/list ([l (in-lines port)]) l))
>
> or `regexp-split':
>
>  (define (port->string-list port)
>    (map bytes->string/utf-8 (regexp-split #rx"\r?\n" port)))
>
>
> And, as long as I'm looking at that file, the quick-n-dirty hack can
> fail in unexpected ways:
>
>  > (port->sexp-list (open-input-string "1 2 3) 4"))
>  (1 2 3)
>  > (port->sexp-list (open-input-string "#z 1 2 3"))
>  UNKNOWN::1: read: bad syntax `#z'
>
> the location is off-by-1 in that last example.
>
>  > (port->sexp-list (open-input-string "1 2 3 #"))
>  UNKNOWN::7: read: bad syntax `#)'
>  > (port->sexp-list (open-input-string "1 2 3 ["))
>  UNKNOWN::8: read: unexpected `)'
>
> these examples expose the fake parens.
>
> And finally, all of these:
>
>  (port->sexp-list (open-input-string "1 2 3 ("))
>  (port->sexp-list (open-input-string "1 2 3 #\"))
>  (port->sexp-list (open-input-string "1 2 3 \\"))
>  (port->sexp-list (open-input-string "1 2 3 \""))
>
> will just get stuck.
>
> --
>          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
>                  http://www.barzilay.org/                 Maze is Life!
>

Thanks for the info. I'll go play with this now.

-- Eli

You can meet at his location,
but you better come with cash.
-- Cake
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20081006/92e0b97c/attachment.html>

Posted on the users mailing list.