Probably.

I should have prefaced my example with a note that I wasn't trying to be
efficient.  I use Rebol a lot for these quick-and-dirty, one-off
reformatters.  And, while I was testing it, I had several different layouts
with which to deal.  So, I would read the input file once and play games with
the rule for parsing.  I'm more used to dealing with "list" (i.e., block)
structures than single, long "strings".  As soon as I got my output, I was
happy, and didn't look for other solutions.

[EMAIL PROTECTED] wrote:

> Instead of doing the read/lines into a block and parsing each line,
> could you not just have the line ending be part of the parse rule?
>
> assume data is your whole body of text before you created the block
> called 'tracelines'
> Then, instead of the last line in rule (to end), change that to 'thru
> newline' and do:
>
> parse/all data [
>     some [rule (print rejoin [time s ts s tt s adr s aack s
>     artry s dbg s ta s dh s dl])]
> ]
>
> the parse rule now reads your data from one line and ends by reading
> thru the newline.  Then the print happens and it repeats until all
> lines have been parsed.
>
> This way you don't have to break up the string into a block and write
> a whole loop to iterate over it when parse can do all the iteration
> for you.
>
> Sterling
>
> > Andrew,
> >
> > I used the following snippet to translate logic analyzer trace files
> > (which have fixed width fields, many of which I want to skip) into
> > something that our simulators like.  The file was read using read/lines
> > into a block (tracelines) which was then parsed by the following:
> >
> > rule: [
> >  16 skip copy adr 8 skip
> >  4 skip copy ts 2 skip
> >  6 skip copy tt 4 skip
> >  4 skip copy tbst 4 skip
> >  20 skip copy aack 4 skip
> >  4 skip copy artry 5 skip
> >  11 skip copy dti 6 skip
> >  6 skip copy dbg 3 skip
> >  5 skip copy ta 2 skip
> >  6 skip copy dh 8 skip
> >  4 skip copy dl 8 skip
> >  24 skip copy time 10 skip
> >  to end]
> > s: " "
> > trc: func [] [
> >  foreach l tracelines [
> >   parse/all l rule
> >   print rejoin [time s ts s tt s adr s aack s artry s dbg s ta s dh s dl]
> >
> >   ]
> >  ]
> >
> > Ron
> >

Reply via email to