Re: A Puzzle in Eu -- what would you do?
On 5 Aug 2005, at 16:52, DB James wrote:
>
>
> posted by: DB James <larch at adelphia.net>
>
> DB James wrote:
> >
> > Bernie Ryan wrote:
> > >
> > >
> > > sequence ctr ctr = {1}
> > >
> > > while 1 do
> > > ctr &= match("--",line)
> > > if ctr[&] = 0 then exit endif
> > > end while
> > >
> > > ctr now equals a list of all the locations of the "--" in the line.
> > > so from there you can figure out where the real comment is.
> > >
> > >
> > > Bernie
> > >
> > > My files in archive:
> > > w32engin.ew mixedlib.e eu_engin.e win32eru.exw
> > >
> > > Can be downloaded here:
> > > <a
> > >
> > > href="http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&
> > >
> > > ;lnx=on&gen=on&keywords=bernie+ryan">http://www.rapideuphoria.com/cg
> > > i-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=bernie+ryan</a>
> > >
> >
> > Bernie,
> >
> > I tried responding to this and accidentally hit some magic key combination
> > that sent my post to neverland. Trying again...
> >
> > This is interesting, and simple, but why {1} and what is ctr[&]? Why not
> > jump
> > forward with each match? Something like (hoping this would work):
> >
> > while length(line) and match("--",line) do
> > ctr&=match("--",line)
> > line=line[ctr[$]+1..$]
> > end while
> >
> > --Quark
> >
>
> Groan. Me again. Thanks for not pointing out what I conspiculously forgot to
> do in my example. Here is a complete test for what I was trying to get at:
>
> }}}
<eucode>
> integer x
> sequence line,ctr
>
> line="InnocentRtn(\"--In Eu, a comment begins with 2 hyphens\") --A real
> comment" ctr={} x=match("--",line) while x do
> ctr&=x
> x=match("--",line[x+1..$])
> if x then x+=ctr[$] end if
> end while
>
> ? ctr
> while equal(get_key(),-1) do end while
>
> </eucode>
{{{
>
> This correctly gives {14,57} -- the two wanted numbers.
>
> However, it isn't a great answer to the puzzle, though useful.
Oh, you *wanted* the incorrect comment too?! Well then:
text = replace(text,"\r","\n")
text = replace(text,"\"","\n")
text = replace(text,"\\"","\n")
parsed = parses(text,{"--"})
for loop = 1 to length(parsed) do
place = match("\n",parsed[loop])
if place = 0 then place = length(parsed[loop]) end if
comment &= {parsed[loop][1..place]}
end for
Kat
|
Not Categorized, Please Help
|
|