To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.pbforthOpen lugnet.robotics.rcx.pbforth in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / pbFORTH / 223
222  |  224
Subject: 
RE: Whitespace and comment remover in perl
Newsgroups: 
lugnet.robotics.rcx.pbforth
Date: 
Wed, 15 Dec 1999 14:06:21 GMT
Viewed: 
1346 times
  
Carsten wrote:

i've written a little perl script, which removes white spaces and
comments from a forth source code.

<snipped script>

Carsten,

This is a good start. Here's my comments on each of the regexp lines...
By the way, my Tcl script handles most of this stuff properly, but
I'm waiting until the new year to develop XMODEM uploads for it....

     s/\\.*$//g; # remove \ commends
     s/\(.*?\)//g; # remove ( ... )

- Except if comments are nested or a quoted string!!! Remember that
  regexps are greedy, they find the LONGEST match. If you have, say...

  ( some comment string ) CODE IS HERE ( more comments )

  then the entire string is removed..

    s/^\s*//g; # remove leading whitespaces ( \t\r\n\f)
    s/\s+$//g; # remove trailing whitespaces ( \t\r\n\f)

  You might want to remove any sequence of one or more whitespace chars
  unless they are inside quotes, of course...

Cheers,

Ralph Hempel - P.Eng

--------------------------------------------------------
Check out pbFORTH for LEGO Mindstorms at:
<http://www.hempeldesigngroup.com/lego/pbFORTH>
--------------------------------------------------------
Reply to:      rhempel at bmts dot com
--------------------------------------------------------



Message has 1 Reply:
  Re: Whitespace and comment remover in perl
 
(...) Your statement of the LONGEST match may be correct for TCL but not for perl! look at the second regexp: the '?' inside means expand to the smallest match ( this is a perl specialty i think) the only thing is, if you nest comments like ( (...) (25 years ago, 15-Dec-99, to lugnet.robotics.rcx.pbforth)

Message is in Reply To:
  Whitespace and comment remover in perl
 
Hello, i've written a little perl script, which removes white spaces and comments from a forth source code. If called without any parameters, it reads from STDIN and writes to STDOUT. If called with 1 parameter, this parameter is interpreted as an (...) (25 years ago, 15-Dec-99, to lugnet.robotics.rcx.pbforth)

5 Messages in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact

This Message and its Replies on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR