diff --git a/php-face.el b/php-face.el index 648c741c..72a85038 100644 --- a/php-face.el +++ b/php-face.el @@ -100,6 +100,10 @@ "PHP Mode face used to highlight sigils($) of $this variable." :group 'php-faces) +(defface php-errorcontrol-op '((t (:inherit font-lock-type-face))) + "PHP Mode face used to highlight errorcontrol operators (@).." + :group 'php-face) + (defface php-php-tag '((t (:inherit font-lock-preprocessor-face))) "PHP Mode face used to highlight PHP tags." :group 'php-faces) diff --git a/php-mode-test.el b/php-mode-test.el index 695b5ed0..1bf09c63 100644 --- a/php-mode-test.el +++ b/php-mode-test.el @@ -984,4 +984,8 @@ Meant for `php-mode-test-issue-503'." "Test highlighting arrow funcsion (short closure syntax) added in PHP 7.4." (with-php-mode-test ("7.4/arrow-function.php" :faces t))) +(ert-deftest php-mode-test-lang () + "Test highlighting for language constructs." + (with-php-mode-test ("lang/errorcontrol.php" :faces t))) + ;;; php-mode-test.el ends here diff --git a/php-mode.el b/php-mode.el index 9a1b5747..2f456e48 100644 --- a/php-mode.el +++ b/php-mode.el @@ -413,6 +413,10 @@ In that case set to `NIL'." (left-assoc "\\" "::" "->") (prefix "\\" "::"))) +(c-lang-defconst c-operators + php (delete '(postfix-if-paren "<" ">") + (c-lang-const c-operators))) + ;; Allow '\' when scanning from open brace back to defining ;; construct like class (c-lang-defconst c-block-prefix-disallowed-chars @@ -469,35 +473,32 @@ PHP does not have an \"enum\"-like keyword." php '("implements" "extends")) (c-lang-defconst c-type-list-kwds - php '("new" "use" "implements" "extends" "namespace" "instanceof" "insteadof")) + php '("@new" ;; @new is *NOT* language construct, it's workaround for coloring. + "new" "use" "implements" "extends" "namespace" "instanceof" "insteadof")) (c-lang-defconst c-ref-list-kwds php nil) (c-lang-defconst c-block-stmt-2-kwds - php (append '("elseif" "foreach" "declare") - (remove "synchronized" (c-lang-const c-block-stmt-2-kwds)))) + php '("catch" "declare" "elseif" "for" "foreach" "if" "switch" "while")) (c-lang-defconst c-simple-stmt-kwds - php (append '("include" "include_once" "require" "require_once" - "echo" "print" "die" "exit") - (c-lang-const c-simple-stmt-kwds))) + php '("break" "continue" "die" "echo" "exit" "goto" "return" "throw" + "include" "include_once" "print" "require" "require_once")) (c-lang-defconst c-constant-kwds - php '("true" - "false" - "null")) + php '("true" "false" "null")) (c-lang-defconst c-lambda-kwds - php '("function" - "use")) + php '("function" "use")) (c-lang-defconst c-other-block-decl-kwds php '("namespace")) (c-lang-defconst c-other-kwds "Keywords not accounted for by any other `*-kwds' language constant." - php '( + php + '( "__halt_compiler" "and" "array" @@ -546,6 +547,12 @@ PHP does not have an \"enum\"-like keyword." (c-lang-defconst c-recognize-<>-arglists php nil) +(c-lang-defconst c-<>-type-kwds + php nil) + +(c-lang-defconst c-inside-<>-type-kwds + php nil) + (c-lang-defconst c-enums-contain-decls php nil) @@ -569,6 +576,13 @@ might be to handle switch and goto labels differently." php (cl-remove-if (lambda (elm) (and (listp elm) (equal (car elm) "\\s|"))) (c-lang-const c-basic-matchers-before php))) +(c-lang-defconst c-basic-matchers-after + php (cl-remove-if (lambda (elm) (and (listp elm) (memq 'c-annotation-face elm))) + (c-lang-const c-basic-matchers-after php))) + +(c-lang-defconst c-opt-<>-sexp-key + php nil) + (defun php-lineup-cascaded-calls (langelem) "Line up chained methods using `c-lineup-cascaded-calls', but only if the setting is enabled" @@ -1431,6 +1445,7 @@ a completion list." ;; already fontified by another pattern. Note that using OVERRIDE ;; is usually overkill. `( + ("\\<\\(@\\)" 1 'php-errorcontrol-op) ;; Highlight all upper-cased symbols as constant ("\\<\\([A-Z_][A-Z0-9_]+\\)\\>" 1 'php-constant) diff --git a/tests/lang/errorcontrol.php b/tests/lang/errorcontrol.php new file mode 100644 index 00000000..ff0af97b --- /dev/null +++ b/tests/lang/errorcontrol.php @@ -0,0 +1,9 @@ +