Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix heredoc/nowdoc syntax problem #440

Merged
merged 2 commits into from
Mar 9, 2018
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
4 changes: 4 additions & 0 deletions php-mode-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,10 @@ style from Drupal."
(set-auto-mode)
(should (not (eq 'php-mode major-mode))))))

(ert-deftest php-mode-test-issue-439 ()
"Various heredoc/nowdoc formats are highlighted appropriately."
(with-php-mode-test ("issue-439.php" :faces t)))

(ert-deftest php-mode-test-type-hints ()
"Test highlighting of type hints and return types."
(with-php-mode-test ("type-hints.php" :faces t)))
Expand Down
4 changes: 2 additions & 2 deletions php-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -934,13 +934,13 @@ this ^ lineup"

(eval-and-compile
(defconst php-heredoc-start-re
"<<<\\(?:\\w+\\|'\\w+'\\)$"
"<<<\\(?:\\_<.+?\\_>\\|'\\_<.+?\\_>'\\|\"\\_<.+?\\_>\"\\)$"
"Regular expression for the start of a PHP heredoc."))

(defun php-heredoc-end-re (heredoc-start)
"Build a regular expression for the end of a heredoc started by the string HEREDOC-START."
;; Extract just the identifier without <<< and quotes.
(string-match "\\w+" heredoc-start)
(string-match "\\_<.+?\\_>" heredoc-start)
(concat "^\\(" (match-string 0 heredoc-start) "\\)\\W"))

(defun php-syntax-propertize-function (start end)
Expand Down
33 changes: 33 additions & 0 deletions tests/issue-439.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/**
* GitHub Issue: https://github.com/ejmr/php-mode/issues/439
*/

$a = <<<ABC
Let'go Justin
ABC;

$b = <<<A_B_C
Let'go Justin
A_B_C;

$c = <<<'A_B_C'
Let'go Justin
A_B_C;

$d = <<<"A_B_C"
Let'go Justin
A_B_C;

$e = <<<いろは
Let'go Justin
いろは;

$f = <<<'いろは'
Let'go Justin
いろは;

$g = <<<"いろは"
Let'go Justin
いろは;
42 changes: 42 additions & 0 deletions tests/issue-439.php.faces
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
;; -*- mode: emacs-lisp -*-
(("<?php" . font-lock-preprocessor-face)
("\n\n")
("/**\n * GitHub Issue: " . font-lock-doc-face)
("https://github.com/ejmr/php-mode/issues/439" link font-lock-doc-face)
("\n */" . font-lock-doc-face)
("\n\n")
("$" . php-variable-sigil)
("a" . php-variable-name)
(" = ")
("<<<ABC\nLet'go Justin\nABC" . php-string)
(";\n\n")
("$" . php-variable-sigil)
("b" . php-variable-name)
(" = ")
("<<<A_B_C\nLet'go Justin\nA_B_C" . php-string)
(";\n\n")
("$" . php-variable-sigil)
("c" . php-variable-name)
(" = ")
("<<<'A_B_C'\nLet'go Justin\nA_B_C" . php-string)
(";\n\n")
("$" . php-variable-sigil)
("d" . php-variable-name)
(" = ")
("<<<\"A_B_C\"\nLet'go Justin\nA_B_C" . php-string)
(";\n\n")
("$" . php-variable-sigil)
("e" . php-variable-name)
(" = ")
("<<<いろは\nLet'go Justin\nいろは" . php-string)
(";\n\n")
("$" . php-variable-sigil)
("f" . php-variable-name)
(" = ")
("<<<'いろは'\nLet'go Justin\nいろは" . php-string)
(";\n\n")
("$" . php-variable-sigil)
("g" . php-variable-name)
(" = ")
("<<<\"いろは\"\nLet'go Justin\nいろは" . php-string)
(";\n"))