Skip to content

Fix heredoc pattern and support 7.3 heredoc #496

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

Merged
merged 4 commits into from
May 8, 2019
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: 0 additions & 4 deletions php-mode-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,3 @@ style from Drupal."
(php-project-get-root-dir))))

;;; php-mode-test.el ends here

;; Local Variables:
;; firestarter: ert-run-tests-interactively
;; End:
13 changes: 6 additions & 7 deletions php-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,10 @@ might be to handle switch and goto labels differently."
(c-lang-const c-constant-kwds))
:test 'string-equal))))

(c-lang-defconst c-basic-matchers-before
php (cl-remove-if (lambda (elm) (and (listp elm) (equal (car elm) "\\s|")))
(c-lang-const c-basic-matchers-before php)))

(defun php-lineup-cascaded-calls (langelem)
"Line up chained methods using `c-lineup-cascaded-calls',
but only if the setting is enabled"
Expand Down Expand Up @@ -984,7 +988,7 @@ this ^ lineup"
"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 "\\_<.+?\\_>" heredoc-start)
(concat "^\\(" (match-string 0 heredoc-start) "\\)\\W"))
(concat "^\\s-*\\(" (match-string 0 heredoc-start) "\\)\\W"))

(defun php-syntax-propertize-function (start end)
"Apply propertize rules from START to END."
Expand All @@ -996,12 +1000,7 @@ this ^ lineup"
(while (re-search-forward "['\"]" end t)
(when (php-in-comment-p)
(c-put-char-property (match-beginning 0)
'syntax-table (string-to-syntax "_"))))
(funcall
(syntax-propertize-rules
("\\(\"\\)\\(\\\\.\\|[^\"\n\\]\\)*\\(\"\\)" (1 "\"") (3 "\""))
("\\('\\)\\(\\\\.\\|[^'\n\\]\\)*\\('\\)" (1 "\"") (3 "\"")))
start end))
'syntax-table (string-to-syntax "_")))))

(defun php-heredoc-syntax ()
"Mark the boundaries of searched heredoc."
Expand Down
10 changes: 10 additions & 0 deletions tests/issue-439.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,13 @@
$g = <<<"いろは"
Let'go Justin
いろは;

var_dump(<<<"ABC"
Let'go Justin
ABC);

if (1 === 1) {
var_dump(<<<"ABC"
Let'go Justin
ABC);
}
9 changes: 8 additions & 1 deletion tests/issue-439.php.faces
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,11 @@
("g" . php-variable-name)
(" = ")
("<<<\"いろは\"\nLet'go Justin\nいろは" . php-string)
(";\n"))
(";\n\nvar_dump(")
("<<<\"ABC\"\nLet'go Justin\nABC" . php-string)
(");\n\n")
("if" . php-keyword)
(" (1 === 1) {\n var_dump(")
("<<<\"ABC\"\n Let'go Justin\n ABC" . php-string)
(");\n}\n")
)