Message from discussion
read text from file, a chunk of more lines at a time
Received: by 10.68.16.35 with SMTP id c3mr12924075pbd.6.1320083837904;
Mon, 31 Oct 2011 10:57:17 -0700 (PDT)
MIME-Version: 1.0
Path: p6ni46873pbn.0!nntp.google.com!news1.google.com!goblin1!goblin.stu.neva.ru!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From: Kaz Kylheku <k...@kylheku.com>
Newsgroups: comp.lang.lisp
Subject: Re: read text from file, a chunk of more lines at a time
Date: Mon, 31 Oct 2011 17:57:17 +0000 (UTC)
Organization: A noiseless patient Spider
Lines: 64
Message-ID: <20111031135006.166@kylheku.com>
References: <1d724abb-34e3-449b-bd3d-d530313d20e4@4g2000yqu.googlegroups.com>
<636310359341714115.258400tfb-tfeb.org@news.eternal-september.org>
<20111031025839.922@kylheku.com>
Injection-Date: Mon, 31 Oct 2011 17:57:17 +0000 (UTC)
Injection-Info: mx04.eternal-september.org; posting-host="UCk3K/YilCUd19+i749f3A";
logging-data="32134"; mail-complaints-to="ab...@eternal-september.org"; posting-account="U2FsdGVkX1+DRjNzipuot1jCQXiQR6pryUIs+pCcqPw="
User-Agent: slrn/pre1.0.0-18 (Linux)
Cancel-Lock: sha1:6cHMAir+DEvCKv/dJSZGtS1SKSY=
On 2011-10-31, Kaz Kylheku <k...@kylheku.com> wrote:
> On 2011-10-31, Tim Bradshaw <t...@tfeb.org> wrote:
>> hans <schatzer.joh...@gmail.com> wrote:
>>> How to read a file, one "record" (of more lines, with a consistent
>>> record delimiter) at a time?
>>>
>>
>> I will no doubt be crucified for saying so but: Perl. Read it in Perl, spit
>> out sexps from Perl, and read those with Lisp.
>
> No way. There is a new text mangler with Lisp roots.
>
> http://www.nongnu.org/txr
>
> @(collect)
> RECORD@num
> @ (collect)
> @text
> @ (until)
> RECORD@(skip)
> @ (end)
> @(end)
> @(output)
> @ (repeat)
> (@num @(rep)@text @(last)@text@(end))
> @ (end)
> @(end)
Improved.
- :vars on in inner collect ensure that empty collects still
produces a binding for the text variable (a binding to the empty list nil),
even if there is no match.
- Output simplified.
@(collect)
RECORD@num
@ (collect :vars (text))
@text
@ (until)
RECORD@(skip)
@ (end)
@(end)
@(output)
@ (repeat)
(@num@(rep) @text@(end))
@ (end)
@(end)
$ ./txr rec2sexp.txr -
RECORD1
RECORD2
a
RECORD3
a
b
foo RECORD4
RECORD4
[Ctrl-D]
(1)
(2 a)
(3 a b foo RECORD4)
(4)