help-gnu-emacs
[Top][All Lists]
Advanced

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

Font lock question


From: Joost Kremers
Subject: Font lock question
Date: Wed, 17 Mar 2021 10:40:32 +0100
User-agent: mu4e 1.5.8; emacs 27.1.91

Hi list,

I'm trying to add font lock rules to a package of mine and I'm running into an
issue that I can't figure out how to solve. Schematically, I'm trying to match
instances of the following type:

    [aBc]

Here, the square brackets are obligatory and so is the `B`. `a` and `c` are
optional. `B` can be recognised by its form, `a` and `c` can only be recognised
by the fact that they are in between the opening/closing bracket and `B`.

So far, so good. But the complication is that this pattern of `aBc` can be
repeated *within the brackets*, where each instance is separated by a semicolon:

    [aBc; aBc; aBc]

There is no (theoretical) limit to the number of repetitions.

I have no trouble composing a regex that matches this entire thing. I'd add a
shy group that includes an optional semicolon and that is repeated at least
once:

    \[\(?:\(?1:.*?\)B\(?2:.*?\);?\)+\]

However, this does not work for font-lock, it seems.

At this point, I'm unsure what to try next. Is there a way to deal with such
patterns?

TIA

Joost


-- 
Joost Kremers
Life has its moments



reply via email to

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