This is an archive of the discontinued LLVM Phabricator instance.

[emacs] simplify and improve keyword highlighting in tablegen-mode.el
ClosedPublic

Authored by inglorion on Sep 24 2019, 6:12 PM.

Details

Summary

The keyword and type keyword matchers in tablegen-mode.el checked
for space, newline, tab, or open paren after the regular expression
that matches keywords (or type keywords, respectively). This is
unnecessary, because those regular expressions already include word
boundaries. This change removes the extra check. This also causes
"def" in "def:" to be highlighted as a keyword, which was missed
before.

Diff Detail

Repository
rL LLVM

Event Timeline

inglorion created this revision.Sep 24 2019, 6:12 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 24 2019, 6:12 PM
MaskRay accepted this revision.Sep 24 2019, 10:27 PM

This is unnecessary, because those regular expressions already include word boundaries.

Yes, (regexp-opt ... 'words) includes word boundaries.

Raw type-kw and kw can be used because of this rule in (elisp) Search-based Fontification:

   Each element of ‘font-lock-keywords’ should have one of these forms:

‘REGEXP’
     Highlight all matches for REGEXP using ‘font-lock-keyword-face’.
     For example,

          ;; Highlight occurrences of the word ‘foo’
          ;; using ‘font-lock-keyword-face’.
          "\\<foo\\>"

     Be careful when composing these regular expressions; a poorly
     written pattern can dramatically slow things down!  The function
     ‘regexp-opt’ (*note Regexp Functions::) is useful for calculating
     optimal regular expressions to match several keywords.
This revision is now accepted and ready to land.Sep 24 2019, 10:27 PM
This revision was automatically updated to reflect the committed changes.