[lug] XEmacs quoting madness!

David dajo at frii.com
Mon Aug 20 16:55:53 MDT 2001


I have found your comments on this subject to be very interesting
(what do you do in your spare time =8-).  There are two things that I
should like to mention.  First, I think that you have demonstrated
that, if one has to get involved with nuts and bolts like this, then
the syntax does not matter so much, because the subject immersion
required means that one understands what is happening regardless of
the syntax.  Although I do accknowledge that, in your examples, the
perl looks easier to read - that is one of the things that I find
interesting.

However, the second point is the important one - you actually write
comments so that there is a clue to what is happening!  This might
even count as maintainable code.

dajo


> | (while (re-search-forward 
> |         (concat "^\\\""           ; beginning of line + initial quote
> |                 "\\([^\\\"]+\\)"  ; software bit
> |                 "[\\\",]+"        ; intervening commas and quotes
> |                 "\\([^\\\"]+\\)"  ; description
> |                 ".*$")            ; rest of line.
> |         (point-max) t) ;
> |   (replace-match (concat "part=\\1\n"
> |                          "  description=\\2\n"))))))
> 
> i thought it'd be interesting to do a perl version of it:
> 
> | s/^"([^"]+)[",]+([^"]+).*$/part=$1\n  description=$2\n/g;
> 
> a relatively recent addition to perl allows you to comment a regex
> pattern, which is nice:
> 
> | s/^"          # beginning of line + initial quote
> |   ([^"]+)     # software bit
> |   [",]+       # intervening commas and quotes
> |   ([^"]+)     # description
> |   .*$         # rest of line
> |  /part=$1\n  description=$2\n/gx;
> 
> this becomes particularly helpful when the patterns get out of
> control.  here's a snippit from a cheesy HTML parser i wrote (when i
> was in a situation where i couldn't install HTML::Parser from CPAN):
> 
> | if ($t =~ m{\G
> |       (                   # (whole thing is in $1)
> |        <([^/]\w*)         # start of tag ($2)
> |        \s*
> |        ((?:               # attribute list ($3)
> |          (?:[^>\s=]+      #   the attribute itself
> |           (?:\s*=\s*      #   maybe followed by an equals sign and
> |            (?:\"[^\"]*\"| #     double-quoted, or
> |             \'[^\']*\'|   #     single-quoted, or
> |             [^>\s]+)      #     plain value
> |           )?              #   or maybe not.
> |           \s*             #   and a bit of whitespace
> |          ))*)             # we can have 0 or more attributes
> |        \s*>)}gcx)



More information about the LUG mailing list