Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lisp/php-face.el
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@
"PHP Mode face used to object operators (->)."
:tag "PHP Object Op")

(defface php-pipe-op '((t (:inherit php-operator)))
"PHP Mode face used to the pipe operator (|>).
The operator was added in PHP 8.5."
:tag "PHP Pipe Op")

(defface php-paamayim-nekudotayim '((t ()))
"PHP Mode face used to highlight scope resolution operators (::).
The operator is also knows as \"Paamayim Nekudotayim\"."
Expand Down
5 changes: 5 additions & 0 deletions lisp/php-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -1518,6 +1518,11 @@ for \\[find-tag] (which see)."
;; Assignment operators (=, +=, ...)
("\\([^=<!>]+?\\([\-+./%]?=\\)[^=<!]+?\\)" 2 'php-assignment-op)

;; Pipe operator (|>) --- PHP 8.5. Must precede the comparison
;; operators, whose `[<>]=?' alternative would otherwise claim the
;; `>' and leave the `|' unfontified.
("\\(|>\\)" 1 'php-pipe-op)

;; Comparison operators (==, ===, >=, ...)
("\\([!=]=\\{1,2\\}[>]?\\|[<>]=?\\)" 1 'php-comparison-op)

Expand Down
30 changes: 30 additions & 0 deletions tests/php-mode-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,36 @@ path; sending those to an HTML mode would take most PHP files away from
"Test highlighting language constructs added in PHP 8.4."
(with-php-mode-test ("8.4/property-hooks.php" :faces t)))

(defun php-mode-test--faces-of (code token)
"Return the list of faces on TOKEN's characters after fontifying CODE."
(with-temp-buffer
(insert code)
(php-mode)
(font-lock-ensure)
(goto-char (point-min))
(should (search-forward token nil t))
(let ((start (- (point) (length token))))
(mapcar (lambda (i) (get-text-property (+ start i) 'face))
(number-sequence 0 (1- (length token)))))))

(ert-deftest php-mode-test-php85-pipe-op ()
"The PHP 8.5 pipe operator is fontified as `php-pipe-op'.

Both characters must get the face. The comparison-operator matcher
claims a bare `>', so without a rule of its own `|>' came out
half-fontified: the `|' plain and the `>' as `php-comparison-op'."
(should (equal '(php-pipe-op php-pipe-op)
(php-mode-test--faces-of "<?php\n$slug = $title |> trim(...);\n" "|>")))
;; Operators that the new rule must not steal from.
(dolist (probe '(("<?php\n$a = $b || $c;\n" "||" (php-logical-op php-logical-op))
("<?php\n$a = $b >= $c;\n" ">=" (php-comparison-op php-comparison-op))
("<?php\n$a = $b > $c;\n" ">" (php-comparison-op))
("<?php\n$a = $b <=> $c;\n" "<=>" (php-comparison-op php-comparison-op php-comparison-op))
("<?php\n$a = $b | $c;\n" "|" (nil))))
(cl-destructuring-bind (code token expected) probe
(should (equal (cons token expected)
(cons token (php-mode-test--faces-of code token)))))))

(ert-deftest php-mode-test-lang ()
"Test highlighting for language constructs."
(with-php-mode-test ("lang/class/anonymous-class.php" :indent t :magic t :faces t))
Expand Down
Loading