[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gawk] In Regexps, Extra (Unmatched) Closing Parentheses Does No

From: Wolfgang Laun
Subject: Re: [bug-gawk] In Regexps, Extra (Unmatched) Closing Parentheses Does Not Produce Error Message, Treated Literally
Date: Mon, 10 Jun 2019 09:40:54 +0200

On Mon, 10 Jun 2019 at 08:13, <address@hidden> wrote:

> Hi.
> Things are indeed working as they're supposed to be. I will add a note
> in the manual about how unmatched parentheses work.

The next request will be to add a note about unmatched ']'. And unmatched
'}'. And an unescaped '-' right after '['? And why it is not necessary to
escape '+', '*', '?' and not even '|' between '[' and ']'? Don't we need an
explanation why '^' doesn't need escaping when not immediately following
the opening bracket '['? Shouldn't there be an explanation why 'x{,n}' is
the same as 'x{0,n}'? And wouldn't we welcome a statement that 'x{,}' is
just another way of writing 'x*'? - Would you really consider documenting
all of that, and (very likely) more?

After using regular expressions for several dozens of years in many
different environments, one thing remains: no documentation of regular
expressions covers all intricacies. Writing a regexp parser will tell you
that you either invest a lot of time and effort in error messages that will
hardly ever see the light of stderr, or decide to accept off-beat "magic"
characters by demoting them. The single unwritten rule to cover all of the
above is, "if a magic character isn't used as intended it isn't magic any

gawk maintainers:
There might be one argument for indicating an error for an unmatched
closing parenthesis: pairs of parentheses can be nested, and this makes a
stray ')' easy to overlook. (At least /usr/bin/mawk does this.)

Running GNU Awk 4.1.4.

> Thanks,
> Arnold
> "Neil R. Ormos" <address@hidden> wrote:
> > In a regexp, an unmatched left parenthesis
> > provokes an error message.
> >
> >  > ./gawk '/(abc/{ print "ok" };'
> >  gawk: cmd. line:1: error: Unmatched ( or \(: /(abc/
> >
> > An unmatched right parenthesis does not provoke an
> > error message, and it must be matched literally.
> >
> >  > echo "/abc"  | gawk '/abc)/{ print "ok" };'
> >  [no output]
> >
> >  > echo "/abc)" | gawk '/abc)/{ print "ok" };'
> >  ok
> >
> > This behavior is the same as grep's, so I assume
> > this is not an error, but rather an intended
> > behavior of the regexp library...
> >
> > ... but it would be nice if there were some hint
> > in the manual that a right parenthesis is treated
> > as special only when there's a matching left
> > parenthesis.  (Apologies in advance if it's there,
> > and I just missed it.)
> >

reply via email to

[Prev in Thread] Current Thread [Next in Thread]