Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

BOFH excuse #327: The POP server is out of Coke


comp / comp.lang.lisp / Re: Simple Parser Lisp

SubjectAuthor
o Re: Simple Parser LispB. Pym

1
Subject: Re: Simple Parser Lisp
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Mon, 2 Sep 2024 11:18 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Nobody447095@here-nor-there.org (B. Pym)
Newsgroups: comp.lang.lisp
Subject: Re: Simple Parser Lisp
Date: Mon, 2 Sep 2024 11:18:42 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <vb46ue$2qq0b$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Mon, 02 Sep 2024 13:18:43 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="be16f105eb25ffb81fdb5ad4c116404b";
logging-data="2975755"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19nuX/H12VI+35c1zmIyKW8"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:ufXgYiGbw1GZnyUGEzSxmLEzt+U=
View all headers

> > If I want to parse a file:
> >
> > stuff
> > stuff
> > stuff
> > stuff
> > stuff
> > ...
> > ...
> > //[start]
> > 1. Read This text here
> > 2. Read This text here
> > 3. Read This text here
> > //[end]
> > ...
> > ...
> >
>
> One Way,
>
> (defun read-//[start]-to-//[end] (file)
> (with-open-file (*standard-input* file :direction :input)
> (loop for line = (read-line)
> while (not (string= "//[start]" line :end2 (min (length line) 9))))
> (loop for line = (read-line)
> while (not (string= "//[end]" line :end2 (min 7 (length line)))) collect
> line)))
>
> CL-USER 1 > (read-//[start]-to-//[end] "test.txt")
> ("1. Read This text here" "2. Read This text here" "3. Read This text here")

Gauche Scheme

(use srfi-42) ;; list-ec

(define (read-start-to-end file)
(with-input-from-file file (lambda()
(until (equal? "//[start]" (read-line)))
(list-ec (:while (:generator line read-line)
(not (equal? line "//[end]")))
line))))

1

rocksolid light 0.9.8
clearnet tor