[Doc-SIG] Substitution syntax

Alan Jaffray jaffray@pobox.com
Wed, 14 Nov 2001 04:04:52 -0500 (EST)

On Tue, 13 Nov 2001, David Goodger wrote:
> [Tony]
> > Hmm. To me, the slashes remind me of something like::
> > 
> >     s/this/that/g
> > 
> > (I've probably got that slightly wrong)  in ed-like languages
> Me too. (You got it right.)

My experience with ed-like languages is precisely what leads me to
the *wrong* conclusion looking at that syntax.  In ed (and sed and
ex and vi and awk and perl), text between slashes is a regexp.  So
ed has /re/d (delete the next line matching the regexp re), and
g/re/p (global-search for lines matching re, print each one), and
s/re/foo (substitute foo for the first match of re on this line).
Vi is similar.  Awk and Perl both use /re/ throughout the language
to denote regexps, and as a standalone expression meaning "match
the current line against this regexp."

So, seeing the syntax::

    .. /foo/ name:: args

I'd think it had something to do with applying a directive to things
that match the regexp /foo/.  It's similar to "do things when this
matches" constructs in other languages.  IMHO the intended association
is more misleading than useful.

> The only disadvantage with using this
> syntax is that interpreted text and phrase-hyperlink references can't
> start with an unescaped slash. That's a bit of a wart.

Using pipes instead of slashes would be a less ugly wart, as they
rarely start text.  In contrast, absolute paths are quite common.