unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Numbered regexps throw invalid regex error
@ 2012-01-25 10:17 Tom
  2012-01-25 17:21 ` Andreas Röhler
  0 siblings, 1 reply; 10+ messages in thread
From: Tom @ 2012-01-25 10:17 UTC (permalink / raw)
  To: help-gnu-emacs

According to the docs:

  This construct allows you to force a particular
  group number.  There is no particular restriction on the numbering,

but when I try this:

  (looking-at "\\(a\\(?1:b\\)\\)")

then it throws an error.

I know it's possibly a collision with the containing group's number
and I can overcome it by using a larger number, but the doc says
I can use it to force a group number, so why does it throw an error
then?

Is it a bug? I tried it with GNU Emacs 23.2.1






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

* Re: Numbered regexps throw invalid regex error
  2012-01-25 10:17 Numbered regexps throw invalid regex error Tom
@ 2012-01-25 17:21 ` Andreas Röhler
  2012-01-25 17:51   ` Tom
  0 siblings, 1 reply; 10+ messages in thread
From: Andreas Röhler @ 2012-01-25 17:21 UTC (permalink / raw)
  To: help-gnu-emacs@gnu.org List

Am 25.01.2012 11:17, schrieb Tom:
>   (looking-at "\\(a\\(?1:b\\)\\)")
>
AFAIU there are serveral errors,

think you can't refer to first match inside itself

here is a working example matching "aba"

(looking-at "\\(a\\)\\(b\\)\\(\\1\\)")aba



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

* Re: Numbered regexps throw invalid regex error
  2012-01-25 17:21 ` Andreas Röhler
@ 2012-01-25 17:51   ` Tom
  2012-01-25 20:02     ` Andreas Röhler
  0 siblings, 1 reply; 10+ messages in thread
From: Tom @ 2012-01-25 17:51 UTC (permalink / raw)
  To: help-gnu-emacs

Andreas Röhler <andreas.roehler <at> easy-emacs.de> writes:

> 
> Am 25.01.2012 11:17, schrieb Tom:
> >   (looking-at "\\(a\\(?1:b\\)\\)")
> >
> AFAIU there are serveral errors,
> 
> think you can't refer to first match inside itself
> 

You misunderstand the feature.

It's not a backreference. It's an explicit numbering of 
the group, so it doesn't change if you add more parens:

`\(?NUM: ... \)'
     is the "explicitly numbered group" construct.  Normal groups get
     their number implicitly, based on their position, which can be
     inconvenient.  This construct allows you to force a particular
     group number.  There is no particular restriction on the numbering,
     e.g. you can have several groups with the same number in which case
     the last one to match (i.e. the rightmost match) will win.
     Implicitly numbered groups always get the smallest integer larger
     than the one of any previous group.





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

* Re: Numbered regexps throw invalid regex error
  2012-01-25 17:51   ` Tom
@ 2012-01-25 20:02     ` Andreas Röhler
  2012-01-25 20:14       ` Tom
  0 siblings, 1 reply; 10+ messages in thread
From: Andreas Röhler @ 2012-01-25 20:02 UTC (permalink / raw)
  To: help-gnu-emacs

Am 25.01.2012 18:51, schrieb Tom:
> Andreas Röhler<andreas.roehler<at>  easy-emacs.de>  writes:
>
>>
>> Am 25.01.2012 11:17, schrieb Tom:
>>>    (looking-at "\\(a\\c(?1:b\\)\\)")
>>>
>> AFAIU there are serveral errors,
>>
>> think you can't refer to first match inside itself
>>
>
> You misunderstand the feature.
>
> It's not a backreference. It's an explicit numbering of
> the group, so it doesn't change if you add more parens:
>
> `\(?NUM: ... \)'
>       is the "explicitly numbered group" construct.  Normal groups get
>       their number implicitly, based on their position, which can be
>       inconvenient.  This construct allows you to force a particular
>       group number.  There is no particular restriction on the numbering,
>       e.g. you can have several groups with the same number in which case
>       the last one to match (i.e. the rightmost match) will win.
>       Implicitly numbered groups always get the smallest integer larger
>       than the one of any previous group.
>
>
>
>

Okay, next try :)

you can't assign a group number already assigned automatically

that would work:

(looking-at "\\(?2:a\\(?1:b\\)c\\)")







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

* Re: Numbered regexps throw invalid regex error
  2012-01-25 20:02     ` Andreas Röhler
@ 2012-01-25 20:14       ` Tom
  2012-01-25 20:37         ` Andreas Röhler
  0 siblings, 1 reply; 10+ messages in thread
From: Tom @ 2012-01-25 20:14 UTC (permalink / raw)
  To: help-gnu-emacs

Andreas Röhler <andreas.roehler <at> easy-emacs.de> writes:
> 
> you can't assign a group number already assigned automatically
> 

The doc clearly says:

"There is no particular restriction on the numbering,
e.g. you can have several groups with the same number in which case
the last one to match (i.e. the rightmost match) will win."



There is no mention of an automatic assignment. It says the last one
will win, so assigning a number which is already used for 
a previous group should work.






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

* Re: Numbered regexps throw invalid regex error
  2012-01-25 20:14       ` Tom
@ 2012-01-25 20:37         ` Andreas Röhler
  2012-01-26  8:30           ` Tom
  0 siblings, 1 reply; 10+ messages in thread
From: Andreas Röhler @ 2012-01-25 20:37 UTC (permalink / raw)
  To: help-gnu-emacs

Am 25.01.2012 21:14, schrieb Tom:
> Andreas Röhler<andreas.roehler<at>  easy-emacs.de>  writes:
>>
>> you can't assign a group number already assigned automatically
>>
>
> The doc clearly says:
>
> "There is no particular restriction on the numbering,
> e.g. you can have several groups with the same number in which case
> the last one to match (i.e. the rightmost match) will win."
>
>
>
> There is no mention of an automatic assignment. It says the last one
> will win, so assigning a number which is already used for
> a previous group should work.
>

would consider it a bug then - at least a docu bug




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

* Re: Numbered regexps throw invalid regex error
  2012-01-25 20:37         ` Andreas Röhler
@ 2012-01-26  8:30           ` Tom
  2012-01-26  9:29             ` Andreas Röhler
  2012-01-26 11:52             ` Tim Landscheidt
  0 siblings, 2 replies; 10+ messages in thread
From: Tom @ 2012-01-26  8:30 UTC (permalink / raw)
  To: help-gnu-emacs

Andreas Röhler <andreas.roehler <at> easy-emacs.de> writes:
> >
> > There is no mention of an automatic assignment. It says the last one
> > will win, so assigning a number which is already used for
> > a previous group should work.
> >
> 
> would consider it a bug then - at least a docu bug
> 

I don't think it's a doc bug. The whole point of the feature is that
you can assign constant numbers to groups, so they don't change if you
add/remove parens.

If it can suddenly throw a regexp error, just because you've added 
a paren around an other paren then it pretty much defeats the
prupose of the feature.





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

* Re: Numbered regexps throw invalid regex error
  2012-01-26  8:30           ` Tom
@ 2012-01-26  9:29             ` Andreas Röhler
  2012-01-26 11:52             ` Tim Landscheidt
  1 sibling, 0 replies; 10+ messages in thread
From: Andreas Röhler @ 2012-01-26  9:29 UTC (permalink / raw)
  To: help-gnu-emacs

Am 26.01.2012 09:30, schrieb Tom:
> Andreas Röhler<andreas.roehler<at>  easy-emacs.de>  writes:
>>>
>>> There is no mention of an automatic assignment. It says the last one
>>> will win, so assigning a number which is already used for
>>> a previous group should work.
>>>
>>
>> would consider it a bug then - at least a docu bug
>>
>
> I don't think it's a doc bug. The whole point of the feature is that
> you can assign constant numbers to groups, so they don't change if you
> add/remove parens.
>
> If it can suddenly throw a regexp error, just because you've added
> a paren around an other paren then it pretty much defeats the
> prupose of the feature.
>
>
>
>

Probably. OTOH one may arg the error message helps counting.

Could think of a static variant --as is-- as it provides some security.

OTOH one may think at dynamic environments which can't be handled that way.

Anyway in favor of a bug report.






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

* Re: Numbered regexps throw invalid regex error
  2012-01-26  8:30           ` Tom
  2012-01-26  9:29             ` Andreas Röhler
@ 2012-01-26 11:52             ` Tim Landscheidt
  2012-01-26 14:36               ` Tom
  1 sibling, 1 reply; 10+ messages in thread
From: Tim Landscheidt @ 2012-01-26 11:52 UTC (permalink / raw)
  To: help-gnu-emacs

Tom <adatgyujto@gmail.com> wrote:

>> > There is no mention of an automatic assignment. It says the last one
>> > will win, so assigning a number which is already used for
>> > a previous group should work.

>> would consider it a bug then - at least a docu bug

> I don't think it's a doc bug. The whole point of the feature is that
> you can assign constant numbers to groups, so they don't change if you
> add/remove parens.

> If it can suddenly throw a regexp error, just because you've added
> a paren around an other paren then it pretty much defeats the
> prupose of the feature.

I'd agree that the documentation should be more verbose, but
I don't think that your argument that it'd be a bug is va-
lid.  If someone added another pair of parentheses around
"a\\(?1:b\\)", either they don't want to refer to it, thus
using "\\(?:", or if they want to refer to it, they have to
think about how to do that anyhow.

  How would you rephrase the documentation so that the cur-
rent behaviour is more comprehensibly described?

Tim




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

* Re: Numbered regexps throw invalid regex error
  2012-01-26 11:52             ` Tim Landscheidt
@ 2012-01-26 14:36               ` Tom
  0 siblings, 0 replies; 10+ messages in thread
From: Tom @ 2012-01-26 14:36 UTC (permalink / raw)
  To: help-gnu-emacs

Tim Landscheidt <tim <at> tim-landscheidt.de> writes:

> 
> I'd agree that the documentation should be more verbose, but
> I don't think that your argument that it'd be a bug is va-
> lid.  If someone added another pair of parentheses around
> "a\\(?1:b\\)", either they don't want to refer to it, thus
> using "\\(?:"


Why should they use "\\(?:" explicitly if they don't care about it?

I personally never use the shy group construct, because
if I don't want to use a groups' value then I simply ignore it.
It will capture some data, but who cares?

That's what the explicit numbering of groups is about that I can 
number those groups which I'm interested in and I can simply ignore
the others, beause I know that adding and removing groups should not
affect my explicitly numbered groups.

The proper solution is fixing the implementation, so it honors
the user's explicit choices, not forcing the user to change the
regexp.





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

end of thread, other threads:[~2012-01-26 14:36 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-25 10:17 Numbered regexps throw invalid regex error Tom
2012-01-25 17:21 ` Andreas Röhler
2012-01-25 17:51   ` Tom
2012-01-25 20:02     ` Andreas Röhler
2012-01-25 20:14       ` Tom
2012-01-25 20:37         ` Andreas Röhler
2012-01-26  8:30           ` Tom
2012-01-26  9:29             ` Andreas Röhler
2012-01-26 11:52             ` Tim Landscheidt
2012-01-26 14:36               ` Tom

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 read-only IMAP folder(s) and NNTP newsgroup(s).