Re: comment removal.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Hayden McKay wrote:
> 
> CChris wrote:
> > 
> > Chris Burch wrote:
> > > 
> > > Hi
> > > 
> > > Why not put this in euwiki - too small for a submission, but useful enough
> > > to
> > > be kept for posterity and reference.
> > > 
> > > Chris
> > > 
> > >
> > > ===================================================================================
> > > There is a train of thought that a generalist knows a little about a lot
> > > of
> > > things, 
> > > and that a specialist knows a lot about very little. 
> > > If you took this to the extreme, you could become so specialised so as to
> > > know
> > > everything there was to know about nothing.
> > >
> > > ===================================================================================
> > > 
> > > <a
> > > href="http://euallegro.wikispaces.com">http://euallegro.wikispaces.com</a>
> > > <a
> > > href="http://members.aol.com/chriscrylex/euphoria.htm">http://members.aol.com/chriscrylex/euphoria.htm</a>
> > > <a
> > > href="http://uboard.proboards32.com/">http://uboard.proboards32.com/</a>
> > > <a
> > > href="http://members.aol.com/chriscrylex/EUSQLite/eusql.html">http://members.aol.com/chriscrylex/EUSQLite/eusql.html</a>
> > 
> > Problem with that piece of code is that, if a quoted string contains the
> >  "--" substring, the remainder of the line will be deleted. Could be a
> >  nuisance.
> > 
> > CChris
> 
> Origionaly I had to remove "//" comments from hundreds and thousands of lines
> of sourcecode, and that piece of code did the trick.
> 
> I thought about adding command line and prompt support and checking for
> various
> other cases but there was no need to do that at the time.
> 
> The code snippet did it's job and then got filed away, and probably never to
> be used again by me.
> 
> Anyone is welcome to modify or complete the code for there needs. If you do,
> I ask that you please share it with others.

Ok...
After removing the quotes around INPUT and OUTPUT, since they cause a bad
 file number (-1) to be reported, I fed a
 file containing

sequence s
s="this line has -- inside it"

 to the code in the original post.

The output file had:
sequence s
s="this line has 

, which I expected from reading the code.

file 1 compiles correctly, file 2 bombs out. This is not expected when
 changing/adding/removing comments.

I remember having trouble writing an uncomment function for my enhanced
 version of Visual Euphoria (Joe aka spent_memory). I'll dig up the code 
and post it. It is definitively longer, but does the job. This is because 
not only you have to take care of (multiple) string(s) inside any given line,
 but locating where they start/end is made trickier if escaped double quotes
 are there as well.

There are two options basically:
1/locate and mask the strings which are not inside a comment, then use
 match(COMMENT,line) and truncate original line;
2/ work as scanner.e does, using a flag to detect whether it is inside a
 string or not, plowing along the line and truncating it when COMMENT is
 found outside a string. 
I never investigated which approach is faster.

Next exercise: also auto uncomment /*...*/ embedded C comments smile

CChris

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu