9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] grep (or perhaps regex(6)) question
@ 2011-07-05  7:56 dexen deVries
  2011-07-05 11:56 ` Rudolf Sykora
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: dexen deVries @ 2011-07-05  7:56 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

on plan9port:
% echo foobar | 9 grep '$JUNK'
 -> foobar

that is, p9p grep matches any line with regular expression in form of
$ANY_REGEX

why is it so?

-- 
dexen deVries

[[[↓][→]]]

For example, if the first thing in the file is:
   <?kzy irefvba="1.0" rapbqvat="ebg13"?>
an XML parser will recognize that the document is stored in the traditional ROT13 encoding.

(( Joe English, http://www.flightlab.com/~joe/sgml/faq-not.txt ))



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [9fans] grep (or perhaps regex(6)) question
  2011-07-05  7:56 [9fans] grep (or perhaps regex(6)) question dexen deVries
@ 2011-07-05 11:56 ` Rudolf Sykora
  2011-07-05 12:13 ` erik quanstrom
  2011-07-11  0:08 ` Russ Cox
  2 siblings, 0 replies; 8+ messages in thread
From: Rudolf Sykora @ 2011-07-05 11:56 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

> that is, p9p grep matches any line with regular expression in form of
> $ANY_REGEX
>
> why is it so?

Why (the very mechanism) is one question. Whether it should or should
not be so is another. Is this subtlety important? (I.e. can't it be
implementation dependent as the correct behaviour seems undefined [to
me]?)

Thanks
Ruda



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [9fans] grep (or perhaps regex(6)) question
  2011-07-05  7:56 [9fans] grep (or perhaps regex(6)) question dexen deVries
  2011-07-05 11:56 ` Rudolf Sykora
@ 2011-07-05 12:13 ` erik quanstrom
  2011-07-05 12:40   ` Rudolf Sykora
  2011-07-11  0:08 ` Russ Cox
  2 siblings, 1 reply; 8+ messages in thread
From: erik quanstrom @ 2011-07-05 12:13 UTC (permalink / raw)
  To: 9fans

On Tue Jul  5 03:57:02 EDT 2011, dexen.devries@gmail.com wrote:
> on plan9port:
> % echo foobar | 9 grep '$JUNK'
>  -> foobar
>
> that is, p9p grep matches any line with regular expression in form of
> $ANY_REGEX
>
> why is it so?

this is a bug.  see the grammar in regexp(6).
plan 9 grep does not have this problem.

- erik



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [9fans] grep (or perhaps regex(6)) question
  2011-07-05 12:13 ` erik quanstrom
@ 2011-07-05 12:40   ` Rudolf Sykora
  2011-07-05 12:58     ` erik quanstrom
  0 siblings, 1 reply; 8+ messages in thread
From: Rudolf Sykora @ 2011-07-05 12:40 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

>> that is, p9p grep matches any line with regular expression in form of
>> $ANY_REGEX
>>
>> why is it so?
>
> this is a bug.  see the grammar in regexp(6).
> plan 9 grep does not have this problem.
>
> - erik

I am sorry, but I don't understand.
What do you mean is wrong, Erik?

Thanks
Ruda



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [9fans] grep (or perhaps regex(6)) question
  2011-07-05 12:40   ` Rudolf Sykora
@ 2011-07-05 12:58     ` erik quanstrom
  2011-07-05 14:01       ` Rudolf Sykora
  0 siblings, 1 reply; 8+ messages in thread
From: erik quanstrom @ 2011-07-05 12:58 UTC (permalink / raw)
  To: 9fans

On Tue Jul  5 08:42:16 EDT 2011, rudolf.sykora@gmail.com wrote:
> >> that is, p9p grep matches any line with regular expression in form of
> >> $ANY_REGEX
> >>
> >> why is it so?
> >
> > this is a bug.  see the grammar in regexp(6).
> > plan 9 grep does not have this problem.
> >
> > - erik
>
> I am sorry, but I don't understand.
> What do you mean is wrong, Erik?

there should be no match to the re $junk.
it's impossible for there to be text after then
end of line.  plan 9 does this correctly,
my version of p9p (which may differ by
being out-of-date) does not.

- erik



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [9fans] grep (or perhaps regex(6)) question
  2011-07-05 12:58     ` erik quanstrom
@ 2011-07-05 14:01       ` Rudolf Sykora
  2011-07-05 14:06         ` erik quanstrom
  0 siblings, 1 reply; 8+ messages in thread
From: Rudolf Sykora @ 2011-07-05 14:01 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

> there should be no match to the re $junk.
> it's impossible for there to be text after then
> end of line.

1) from the regexp grammer, $junk is a valid regexp
2) grep checks input line-by-line
3) the answer to a question whether a *line* complies with '$whatever'
is --- I believe --- undefined. (It definitely should match '$';
however comparing with '$whatever' gets us outside the definitions).

Ruda



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [9fans] grep (or perhaps regex(6)) question
  2011-07-05 14:01       ` Rudolf Sykora
@ 2011-07-05 14:06         ` erik quanstrom
  0 siblings, 0 replies; 8+ messages in thread
From: erik quanstrom @ 2011-07-05 14:06 UTC (permalink / raw)
  To: 9fans

On Tue Jul  5 10:02:56 EDT 2011, rudolf.sykora@gmail.com wrote:
> > there should be no match to the re $junk.
> > it's impossible for there to be text after then
> > end of line.
>
> 1) from the regexp grammer, $junk is a valid regexp

i believe you've read incorrectly.  but if you think it parses,
what production produces e3 en?  but that wasn't actually my point.

> 2) grep checks input line-by-line
> 3) the answer to a question whether a *line* complies with '$whatever'
> is --- I believe --- undefined. (It definitely should match '$';
> however comparing with '$whatever' gets us outside the definitions).

supposing that $whatever does parse, it would match
a line with 'whatever' following the end of the line.
by definition there is no such line.

- erik



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [9fans] grep (or perhaps regex(6)) question
  2011-07-05  7:56 [9fans] grep (or perhaps regex(6)) question dexen deVries
  2011-07-05 11:56 ` Rudolf Sykora
  2011-07-05 12:13 ` erik quanstrom
@ 2011-07-11  0:08 ` Russ Cox
  2 siblings, 0 replies; 8+ messages in thread
From: Russ Cox @ 2011-07-11  0:08 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Tue, Jul 5, 2011 at 3:56 AM, dexen deVries <dexen.devries@gmail.com> wrote:
> on plan9port:
> % echo foobar | 9 grep '$JUNK'
>  -> foobar
>
> that is, p9p grep matches any line with regular expression in form of
> $ANY_REGEX
>
> why is it so?

It's an ancient bug in the Plan 9 grep, a complication
of the way Ken implemented ^ and $: as aliases for \n (!).
It looks like someone added a workaround for this one
case in the Plan 9 sources since I forked them for
plan9port seven years ago.  I pulled it in.

For fun, try seeing what matches '^$^$' across a
variety of grep implementations.

Russ


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2011-07-11  0:08 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-05  7:56 [9fans] grep (or perhaps regex(6)) question dexen deVries
2011-07-05 11:56 ` Rudolf Sykora
2011-07-05 12:13 ` erik quanstrom
2011-07-05 12:40   ` Rudolf Sykora
2011-07-05 12:58     ` erik quanstrom
2011-07-05 14:01       ` Rudolf Sykora
2011-07-05 14:06         ` erik quanstrom
2011-07-11  0:08 ` Russ Cox

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).