From 294e66ba3d84e06d0d63f4edabd174c4e4ade5cb Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Wed, 28 Aug 2019 02:12:20 +0900 Subject: [PATCH] Add font-lock for multiple catch This syntax was added in PHP 7.1. * https://wiki.php.net/rfc/multiple-catch * https://www.php.net/manual/language.exceptions.php * https://www.php.net/manual/migration71.new-features.php#migration71.new-features.mulit-catch-exception-handling The rule allows line breaks, but the pattern is not subject to coloring due to font lock restrictions. In this trial and error, I considered replacing some CC-Mode functions, but I gave up. --- php-mode.el | 9 ++++++- tests/lang/try-cactch/multiple.php | 7 +++++ tests/lang/try-cactch/multiple.php.faces | 34 ++++++++++++++++++++++++ tests/php-mode-test.el | 1 + 4 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 tests/lang/try-cactch/multiple.php create mode 100644 tests/lang/try-cactch/multiple.php.faces diff --git a/php-mode.el b/php-mode.el index 65beeb16..7ba0383f 100644 --- a/php-mode.el +++ b/php-mode.el @@ -1513,7 +1513,14 @@ a completion list." ;; Highlight static method calls as such. This is necessary for method ;; names which are identical to keywords to be highlighted correctly. ("\\sw+::\\(\\sw+\\)(" 1 'php-static-method-call) - + ;; Multiple catch (FooException | BarException $e) + (,(rx symbol-start "catch" symbol-end + (* (syntax whitespace)) "(" (* (syntax whitespace)) + (group (+ (or (syntax word) (syntax symbol))))) + (1 font-lock-type-face) + (,(rx (* (syntax whitespace)) "|" (* (syntax whitespace)) + (group (+ (or (syntax word) (syntax symbol))) symbol-end)) + nil nil (1 font-lock-type-face))) ;; While c-opt-cpp-* highlights the