2

The bat-mode.el defines the following regexp used by re-search-forward:

"^[ \t]*\\(?:\\(@?r\\)em\\_>\\|\\(?1::\\):\\).*"

What is the meaning of the 1 in \\(?1::\\) inside the regexp?

AFAIK \\(?: ⋯ \\) represents a shy, non-capturing, group. But I did not see a description that identifies a number (a group number?) could be placed there.

1 Answer 1

2

It’s an explicitly–numbered group. From chapter 34.3.1.3 Backslash Constructs in Regular Expressions of the Emacs Lisp manual:

‘\(?: ... \)’
     is the “shy group” construct.  A shy group serves the first two
     purposes of an ordinary group (controlling the nesting of other
     operators), but it does not get a number, so you cannot refer back
     to its value with ‘\DIGIT’.  Shy groups are particularly useful for
     mechanically-constructed regular expressions, because they can be
     added automatically without altering the numbering of ordinary,
     non-shy groups.

     Shy groups are also called “non-capturing” or “unnumbered groups”.

‘\(?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.

For the given example, there are two possibilities for "group 1" (the first being implicitly numbered, and the second explicitly) but only one of them will be present in any given match for the overall regexp. In such a case you can be certain that the subsequent code is doing something with the text for "group 1", which will be whichever of those groups actually matched something. In this case the call to syntax-propertize-rules is declaring that the match for group 1 should have syntax < (meaning "comment starter").

2
  • Thanks. I was always referring to the Emacs chapter 15.7 Backslash in Regular Expression which does not mention it the way the Elisp manual does. Should the Emacs manual be updated or at least refer to the Elisp section?
    – PRouleau
    Oct 2, 2021 at 13:26
  • Good point. Yes, I think it should be.
    – db48x
    Oct 2, 2021 at 15:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.