I can highlight text like the following:
constant:'variable,variable'
with code like this which uses the anchored matcher form:
(font-lock-add-keywords
nil
'(("\\(constant\\):'" (1 font-lock-constant-face t)
("\\(variable\\)[,']" nil nil (1 font-lock-variable-name-face t))))
'append)
Which works fine. The 'constant' and 'variable' parts are highlighted correctly.
However, it fails on text like this:
constant:'variable,variable' constant:'variable,variable' constant:''
The first 'constant' is correctly matched by the anchor, the first 2 'variable' are matched by the variable regexp, but then it rampages on to match the other 'variable's, so when the anchor regexp resumes it can't match the second 'constant.
I guess I need to make the 'variable' matcher give up after it matches a closing quote. So I tried this:
(defun my-variable-search (limit)
(if (save-excursion
(re-search-backward "variable'\'" 0 'go))
nil
(re-search-forward "\\(variable\\)[,']" limit 'go)))
(font-lock-add-keywords
nil
'(("\\(constant\\):'" (1 font-lock-constant-face t)
(my-variable-search nil nil (1 font-lock-variable-name-face t))))
'append)
But it doesn't work.
Am I completely off track or have I made a stupid mistake?