Yes, you can. See the Elisp manual, node Search-based Fontification.
font-lock-keywords (which you set using font-lock-keywords, e.g. font-lock-add-keywords) can use a FACESPEC expression, which is evaluated to provide the face to use.
FACESPEC is an expression whose value
specifies the face to use for highlighting. In the simplest case,
FACESPEC is a Lisp ...
Also check the variable inhibit-modification-hooks (docs). If your case is like mine, font-lock gets stuck because an error occurs in one of the modification hook functions (... not even necessarily font-lock itself), and, as a consequence:
If an unhandled error happens in running these functions,
the variable's value remains nil. That prevents the error