comments within regexps look too busy 
Author Message
 comments within regexps look too busy


|> What looks better? (A subjective question, to be sure, but...)
|>
|> if (s/^                               (?# anchor to beginning of string)
|>    ([+-]?)                         (?# remember sign into $1        )
|>    0*                              (?# get over any leading zeros   )
|>    (\d+)                           (?# remember digits into $2      )
|>    $                               (?# anchor to end of string      )
|>   /$1$2/x)
|> {
|>      ...
|> }
|>
|>      OR
|>
|> if (s/^                               # anchor to beginning of string
|>    ([+-]?)                         # remember sign into $1      
|>    0*                              # get over any leading zeros
|>    (\d+)                           # remember digits into $2  
|>    $                               # anchor to end of string  
|>   /$1$2/x)
|> {
|>      ...
|> }

I gotta' agree with Paul... the #-only comments look nice.  Considering
that comments in regexes are all new to begin with, I certainly don't think
it breaks anything old to define things this way.

Just gotta' be clear on that the comment leader is... is it "#",
"<ws>#", unescaped-"#", etc.

But I like the unadorned comments.
Larry?

        *jeffrey*
-------------------------------------------------------------------------

See my Jap/Eng dictionary at http://www.*-*-*.com/
                          or http://www.*-*-*.com/ :8001/cgi-bin/j-e



Fri, 02 May 1997 17:16:55 GMT  
 comments within regexps look too busy
Allowing whitespace in a regexp is a great idea -- glad you thought
of it, Larry.

One thing that bothers me is that comments are surrounded by
the same "(? ...)" stuff as normal parts of a regexp.

It does not look like a perl comment to me. A perl comment is

<any text>        # comment

Why can't we keep it that way even in regular expressions. It would
be one more small step with regularization IMHO.

I'm sure that there is a reason why Larry has done it this way but
it should be possible to allow regular type comments within extended
regexps providing that whitespace is enforced before the "#".
                       --------------------------------------

What looks better? (A subjective question, to be sure, but...)

if (s/^                               (?# anchor to beginning of string)
      ([+-]?)                         (?# remember sign into $1        )
      0*                              (?# get over any leading zeros   )
      (\d+)                           (?# remember digits into $2      )
      $                               (?# anchor to end of string      )
     /$1$2/x)
{
        ...

Quote:
}

        OR

if (s/^                               # anchor to beginning of string
      ([+-]?)                         # remember sign into $1      
      0*                              # get over any leading zeros
      (\d+)                           # remember digits into $2  
      $                               # anchor to end of string  
     /$1$2/x)
{
        ...

Quote:
}

---------
Paul E. Maisano
Australian Artificial Intelligence Institute



Fri, 02 May 1997 08:06:14 GMT  
 comments within regexps look too busy

Quote:
>Allowing whitespace in a regexp is a great idea -- glad you thought
>of it, Larry.
>One thing that bothers me is that comments are surrounded by
>the same "(? ...)" stuff as normal parts of a regexp.
>It does not look like a perl comment to me. A perl comment is
><any text>    # comment
>Why can't we keep it that way even in regular expressions. It would
>be one more small step with regularization IMHO.
>I'm sure that there is a reason why Larry has done it this way but
>it should be possible to allow regular type comments within extended
>regexps providing that whitespace is enforced before the "#".
>                       --------------------------------------

One possible problem with this is that many perlers have been using '#'
for the m## or s### delimiter when regexes contain '/'.  You'd really want to
retire '#' as a valid delimiter in this case to avoid confusion.  Consider:

        if (m#
                (\w+)   # first word
                \s*     # optional whitespace
                (\w+)   # second word
        #) {

Doesn't quite cut it.  OTOH, maybe it should be prohibited to use '#' at
all as a delimiter.
--
Wayne Berke



Mon, 05 May 1997 06:11:46 GMT  
 comments within regexps look too busy
|> One possible problem with this is that many perlers have been using '#'
|> for the m## or s### delimiter when regexes contain '/'.

Past history wouldn't matter so much..... this would only take effect
with /x, which is relatively new.

I still like the idea.
        *jeffrey*
-------------------------------------------------------------------------

See my Jap/Eng dictionary at http://www.omron.co.jp/cgi-bin/j-e
                          or http://www.cs.cmu.edu:8001/cgi-bin/j-e



Mon, 05 May 1997 11:41:02 GMT  
 comments within regexps look too busy

: |> What looks better? (A subjective question, to be sure, but...)
: |>
: |> if (s/^                               (?# anchor to beginning of string)
: |>          ([+-]?)                         (?# remember sign into $1        )
: |>          0*                              (?# get over any leading zeros   )
: |>          (\d+)                           (?# remember digits into $2      )
: |>          $                               (?# anchor to end of string      )
: |>         /$1$2/x)
: |> {
: |>            ...
: |> }
: |>
: |>            OR
: |>
: |> if (s/^                               # anchor to beginning of string
: |>          ([+-]?)                         # remember sign into $1      
: |>          0*                              # get over any leading zeros
: |>          (\d+)                           # remember digits into $2  
: |>          $                               # anchor to end of string  
: |>         /$1$2/x)
: |> {
: |>            ...
: |> }
:
: I gotta' agree with Paul... the #-only comments look nice.  Considering
: that comments in regexes are all new to begin with, I certainly don't think
: it breaks anything old to define things this way.
:
: Just gotta' be clear on that the comment leader is... is it "#",
: "<ws>#", unescaped-"#", etc.

I think it'd have to be a bare "#", like in the rest of Perl.  Though
I can see the questions coming: "Why doesn't 'next if /^#/x' work right?"

: But I like the unadorned comments.
: Larry?

Then all we have to do is allow (?#...) in ordinary Perl code, and
everything would be perfectly symmetrical.  :-)

Larry



Tue, 06 May 1997 06:27:35 GMT  
 comments within regexps look too busy

Quote:
>|> One possible problem with this is that many perlers have been using '#'
>|> for the m## or s### delimiter when regexes contain '/'.

>Past history wouldn't matter so much..... this would only take effect
>with /x, which is relatively new.

        Ummm... but the "/x" comes at the end of the string, while the
"#" comments come in the middle!  I know perl is a fantastic
contest-sensitive parser to parse Perl, but this may be pushing it too
far.  On the other hand, if you use a (?x) before the first "#"
comment, you should be safe.

                                        Craig Milo Rogers



Tue, 06 May 1997 03:48:31 GMT  
 comments within regexps look too busy

Quote:


> : But I like the unadorned comments.
> : Larry?
> Then all we have to do is allow (?#...) in ordinary Perl code, and
> everything would be perfectly symmetrical.  :-)

I like this idea!  Then, we can have multi-line comments in Perl, like
"/* ... */" in C.

--
Lloyd Zusman            01234567 <-- The world famous Indent-o-Meter.

   To get my PGP public key automatically mailed to you, please
   send me email with the following string as the subject or on a
   line by itself in the message (leave off the quotation marks):
                    "mail-request public-key"



Tue, 06 May 1997 18:09:31 GMT  
 comments within regexps look too busy

|> I think it'd have to be a bare "#", like in the rest of Perl.  Though
|> I can see the questions coming: "Why doesn't 'next if /^#/x' work right?"

Well, I don't see that as much different from
        Why doesn't '/var *= *val/x' work right?

In both cases, "because you screwed up!" is the answer (-:

|> Then all we have to do is allow (?#...) in ordinary Perl code, and
|> everything would be perfectly symmetrical.  :-)

Hey, now there's an idea..... (-:

Hey, while we're talking about regex enhancements (there's a parallel thread
talking about user-modifible \w type things), what I've really been wishing
for of late is something like

   /(blah blah) more blah $var{$1}/

where $var{$1} is called up dynamically as a result of whatever matched
the first set of parens.

To suck up $var{$1} as a regular expression would be a bit involved, but to
suck it up as raw text would be (should be) trivial (and I'll do it and
send in the patch if you're interested). What would probably be a bit more
involved (at least for me because I don't know perl internals) would be the
communication among the various things that parse the regex, to realize
that $var{$1} was this kind of thing. The $1 is a good indication, but the
thing that sucks up the regex as a constant has to know to leave it there
for the regex part itself.

Similarly, how about &sub($1) !!!!!!

Damn, this could be powerful.

        *jeffrey*
-------------------------------------------------------------------------



Tue, 06 May 1997 13:37:58 GMT  
 comments within regexps look too busy

:>|> One possible problem with this is that many perlers have been using '#'
:>|> for the m## or s### delimiter when regexes contain '/'.
:>
:>Past history wouldn't matter so much..... this would only take effect
:>with /x, which is relatively new.
:
:       Ummm... but the "/x" comes at the end of the string, while the
:"#" comments come in the middle!  I know perl is a fantastic
:contest-sensitive parser to parse Perl, but this may be pushing it too
      ^
      ^
      ^
      ^  that that benchmark-detection code he's talking about, just
         like any good compiler will have. :-)

--tom
--

There's going to be no serious problem after this.  --Ken Thompson



Tue, 06 May 1997 23:35:54 GMT  
 comments within regexps look too busy

Quote:

>Similarly, how about &sub($1) !!!!!!

        Uh, I'm not certain about this, but I think you've just
reinvented SNOBOL. :-)  At least, if Perl is ever enhanced to support
full backtracking. :-)

                                        Craig Milo Rogers



Wed, 07 May 1997 10:01:24 GMT  
 comments within regexps look too busy

Quote:


> : Just gotta' be clear on that the comment leader is... is it "#",
> : "<ws>#", unescaped-"#", etc.

> I think it'd have to be a bare "#", like in the rest of Perl.  Though
> I can see the questions coming: "Why doesn't 'next if /^#/x' work right?"

Yes, perl would need a warning: `No whitespace before comment in regexp'
or something like that.

BTW, one warning I'd really like is `you are not using the -w switch':-)
`-e' would turn it off, as well as -W or -w0 or something like that.

--
Hallvard



Sat, 10 May 1997 23:00:37 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. Making a window (look) busy ?

2. Using boundaries within regexps

3. Q: check for a char within balanced parentheses in regexps

4. comments within complex structures

5. regexps with index(), regexps vs strings, clarify $*

6. Perl regexps compared to Python regexps

7. looking for XML comments

8. - Looking for the following script (user comments)

9. Looking for Perl code to extract comments/tags from a C source file

10. Looking for Perl whitespace/comment stripper

11. Looking for a script to remove comments and useless space

12. Looking for 'user comments' perl script

 

 
Powered by phpBB® Forum Software