Re: Using quasi-parsers to parse spece delimited data

"Mark S. Miller" <[email protected]> Thu, 30 Oct 2014 15:23:14 -0700
Newsgroups gmane.comp.lang.e.general
Message-ID <CABHxS9ikwdjGjuBW8W0eHOLTuj9RTOQX0k+Mp_U3O-1uXhKSMQ@mail.gmail.com>
--===============2975620575938764276==
Content-Type: multipart/alternative; boundary=089e0139fc288cc4df0506ab532d

--089e0139fc288cc4df0506ab532d
Content-Type: text/plain; charset=UTF-8

Yes, define a tokenizing quasi parser and use it. Say it is called
token__quasiParser. You'd then say

 if (l2 =~ token`@qso @frequency @mode @date @time @ourcall @ourseq @ourqth
@call @seq @qth`) {


On Thu, Oct 30, 2014 at 3:16 PM, Bill Frantz <[email protected]> wrote:

> I recently had to process a bunch of records of the form:
>
> QSO: 14000 PH 2014-10-05 1650 K6EI        254 KING       KE6JNO       80 UT
>
> to produce another format of the same data. I used a quasi-parser:
>
>   if (l2 =~ `@qso @frequency @mode @date @time @ourcall @ourseq @ourqth
> @call @seq @qth`) {
>
> to break the record into data items.
>
> The problem is that this quasi-parser treats multiple consecutive blanks
> as multiple delimiters. I kluged a solution to the problem with:
>
>     var l1 := line
>     var l2 := ""
>     while (l1 =~ `@word @rest`) {
>         l2 := l2 + " " + word
>         l1 := rest.trim()
>     }
>     l2 := l2.trim()
>     l2 := l2 + " " + l1.trim();
>
> The question is, is there a better way?
>
> Cheers - - Bill
>
> ------------------------------------------------------------
> ---------------
> Bill Frantz        | Re: Computer reliability, performance, and security:
> 408-356-8506       | The guy who *is* wearing a parachute is *not* the
> www.pwpconsult.com | first to reach the ground.  - Terence Kelly
>
>
> _______________________________________________
> e-lang mailing list
> [email protected]
> http://www.eros-os.org/mailman/listinfo/e-lang
>



-- 
    Cheers,
    --MarkM

--089e0139fc288cc4df0506ab532d
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Yes, define a tokenizing quasi parser and use it. Say it i=
s called token__quasiParser. You&#39;d then say<div><br></div><div><span st=
yle=3D"font-family:arial,sans-serif;font-size:13px">=C2=A0if (l2 =3D~ token=
`@qso @frequency @mode @date @time @ourcall @ourseq @ourqth @call @seq @qth=
`) {</span><br></div><div><span style=3D"font-family:arial,sans-serif;font-=
size:13px"><br></span></div></div><div class=3D"gmail_extra"><br><div class=
=3D"gmail_quote">On Thu, Oct 30, 2014 at 3:16 PM, Bill Frantz <span dir=3D"=
ltr">&lt;<a href=3D"mailto:[email protected]" target=3D"_blank">frantz@=
pwpconsult.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" s=
tyle=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I re=
cently had to process a bunch of records of the form:<br>
<br>
QSO: 14000 PH 2014-10-05 1650 K6EI=C2=A0 =C2=A0 =C2=A0 =C2=A0 254 KING=C2=
=A0 =C2=A0 =C2=A0 =C2=A0KE6JNO=C2=A0 =C2=A0 =C2=A0 =C2=A080 UT<br>
<br>
to produce another format of the same data. I used a quasi-parser:<br>
<br>
=C2=A0 if (l2 =3D~ `@qso @frequency @mode @date @time @ourcall @ourseq @our=
qth @call @seq @qth`) {<br>
<br>
to break the record into data items.<br>
<br>
The problem is that this quasi-parser treats multiple consecutive blanks as=
 multiple delimiters. I kluged a solution to the problem with:<br>
<br>
=C2=A0 =C2=A0 var l1 :=3D line<br>
=C2=A0 =C2=A0 var l2 :=3D &quot;&quot;<br>
=C2=A0 =C2=A0 while (l1 =3D~ `@word @rest`) {<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 l2 :=3D l2 + &quot; &quot; + word<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 l1 :=3D rest.trim()<br>
=C2=A0 =C2=A0 }<br>
=C2=A0 =C2=A0 l2 :=3D l2.trim()<br>
=C2=A0 =C2=A0 l2 :=3D l2 + &quot; &quot; + l1.trim();<br>
<br>
The question is, is there a better way?<br>
<br>
Cheers - - Bill<br>
<br>
------------------------------<u></u>------------------------------<u></u>-=
--------------<br>
Bill Frantz=C2=A0 =C2=A0 =C2=A0 =C2=A0 | Re: Computer reliability, performa=
nce, and security:<br>
<a href=3D"tel:408-356-8506" value=3D"+14083568506" target=3D"_blank">408-3=
56-8506</a>=C2=A0 =C2=A0 =C2=A0 =C2=A0| The guy who *is* wearing a parachut=
e is *not* the<br>
<a href=3D"http://www.pwpconsult.com" target=3D"_blank">www.pwpconsult.com<=
/a> | first to reach the ground.=C2=A0 - Terence Kelly<br>
<br>
<br>
______________________________<u></u>_________________<br>
e-lang mailing list<br>
<a href=3D"mailto:[email protected]" target=3D"_blank">[email protected]=
os-os.org</a><br>
<a href=3D"http://www.eros-os.org/mailman/listinfo/e-lang" target=3D"_blank=
">http://www.eros-os.org/<u></u>mailman/listinfo/e-lang</a><br>
</blockquote></div><br><br clear=3D"all"><div><br></div>-- <br>=C2=A0 =C2=
=A0 Cheers,<br>=C2=A0 =C2=A0 --MarkM
</div>

--089e0139fc288cc4df0506ab532d--

--===============2975620575938764276==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
e-lang mailing list
[email protected]
http://www.eros-os.org/mailman/listinfo/e-lang

--===============2975620575938764276==--