@@ -310,12 +310,6 @@ In that case set to `NIL'."
310
310
:tag " PHP Mode Enable Project Local Variable"
311
311
:type 'boolean )
312
312
313
- (defcustom php-mode-use-php7-syntax-table nil
314
- " When set to `T' , use a syntax table compatible with PHP 7."
315
- :group 'php-mode
316
- :tag " PHP Mode Enable Project Local Variable"
317
- :type 'boolean )
318
-
319
313
(defconst php-mode-cc-vertion
320
314
(eval-when-compile c-version))
321
315
@@ -968,7 +962,12 @@ this ^ lineup"
968
962
969
963
(eval-and-compile
970
964
(defconst php-heredoc-start-re
971
- " <<<[ \t ]*\\ (?:\\ _<.+?\\ _>\\ |'\\ _<.+?\\ _>'\\ |\" \\ _<.+?\\ _>\" \\ )$"
965
+ (rx " <<<"
966
+ (* (syntax whitespace))
967
+ (or (group (+ (or (syntax word) (syntax symbol))))
968
+ (: " \" " (group (+ (or (syntax word) (syntax symbol)))) " \" " )
969
+ (: " '" (group (+ (or (syntax word) (syntax symbol)))) " '" ))
970
+ line-end)
972
971
" Regular expression for the start of a PHP heredoc." ))
973
972
974
973
(defun php-heredoc-end-re (heredoc-start )
@@ -977,54 +976,40 @@ this ^ lineup"
977
976
(string-match " \\ _<.+?\\ _>" heredoc-start)
978
977
(concat " ^\\ s-*\\ (" (match-string 0 heredoc-start) " \\ )\\ W" ))
979
978
980
- (defvar php-syntax-propertize-functions
981
- '(php-syntax-propertize-heredoc
982
- php-syntax-propertize-hash-line-comment
983
- php-syntax-propertize-quotes-in-comment)
984
- " Syntax propertize functions for PHP script." )
985
-
986
- (defun php-syntax-propertize-function (start end )
987
- " Apply propertize rules from START to END."
988
- (dolist (propertizer php-syntax-propertize-functions)
989
- (goto-char start)
990
- (funcall propertizer start end)))
991
-
992
- (defun php-syntax-propertize-heredoc (_start end )
993
- " Apply propertize Heredoc and Nowdoc from START to END."
994
- (while (and (< (point ) end)
995
- (re-search-forward php-heredoc-start-re end t ))
996
- (php-heredoc-syntax)))
997
-
998
- (defun php-syntax-propertize-quotes-in-comment (_start end )
999
- " Apply propertize quotes (' and \" ) from START to END."
1000
- (while (re-search-forward " ['\" ]" end t )
1001
- (when (php-in-comment-p)
1002
- (c-put-char-property (match-beginning 0 )
1003
- 'syntax-table (string-to-syntax " _" )))))
1004
-
1005
- (defun php-syntax-propertize-hash-line-comment (_start end )
1006
- " Apply propertize # comment (without PHP8 Attributes) from START to END."
1007
- (unless php-mode-use-php7-syntax-table
1008
- (let (line-end in-last-line)
1009
- (while (and (< (point ) (min end (point-max )))
1010
- (not in-last-line))
1011
- (setq line-end (line-end-position ))
1012
- (when (and (search-forward " #" line-end t )
1013
- (not (php-in-string-or-comment-p))
1014
- (not (looking-at " [[]" )))
1015
- (c-put-char-property (1- (point )) 'syntax-table (string-to-syntax " < b" )))
1016
- (move-beginning-of-line 2 )
1017
- (setq in-last-line (>= line-end (point )))))))
1018
-
1019
- (defun php-heredoc-syntax ()
1020
- " Mark the boundaries of searched heredoc."
1021
- (goto-char (match-beginning 0 ))
1022
- (c-put-char-property (point ) 'syntax-table (string-to-syntax " |" ))
1023
- (if (re-search-forward (php-heredoc-end-re (match-string 0 )) nil t )
1024
- (goto-char (match-end 1 ))
1025
- ; ; Did not find the delimiter so go to the end of the buffer.
1026
- (goto-char (point-max )))
1027
- (c-put-char-property (1- (point )) 'syntax-table (string-to-syntax " |" )))
979
+ (eval-and-compile
980
+ (defconst php-syntax-propertizers
981
+ `((php-heredoc-start-re
982
+ (0 (ignore (php--syntax-propertize-heredoc
983
+ (match-beginning 0 )
984
+ (or (match-string 1 ) (match-string 2 ) (match-string 3 ))
985
+ (null (match-string 3 ))))))
986
+ (,(rx " #[" )
987
+ (0 (ignore (php--syntax-propertize-attributes (match-beginning 0 )))))
988
+ (,(rx (or " '" " \" " ))
989
+ (0 (ignore (php--syntax-propertize-quotes-in-comment (match-beginning 0 )))))))
990
+
991
+ (defmacro php-build-propertizer ()
992
+ `(syntax-propertize-rules ,@php-syntax-propertizers ))
993
+
994
+ (defalias 'php-syntax-propertize-function (php-build-propertizer)))
995
+
996
+ (defun php--syntax-propertize-heredoc (start id is-heredoc )
997
+ " Apply propertize Heredoc and Nowdoc from START, with ID and IS-HEREDOC."
998
+ (let ((terminator (rx-to-string `(: line-start (* (syntax whitespace)) , id word-boundary))))
999
+ (put-text-property start (1+ start) 'syntax-table (string-to-syntax " |" ))
1000
+ (re-search-forward terminator nil t )
1001
+ (when (match-string 0 )
1002
+ (put-text-property (1- (point )) (point ) 'syntax-table (string-to-syntax " |" )))))
1003
+
1004
+ (defun php--syntax-propertize-quotes-in-comment (pos )
1005
+ " Apply propertize quotes (' and \" ) from POS."
1006
+ (when (php-in-comment-p)
1007
+ (put-text-property pos (1+ pos) 'syntax-table (string-to-syntax " _" ))))
1008
+
1009
+ (defun php--syntax-propertize-attributes (start )
1010
+ " Apply propertize PHP8 #[Attributes] (without # comment) from START."
1011
+ (unless (php-in-string-p)
1012
+ (put-text-property start (1+ start) 'syntax-table (string-to-syntax " ." ))))
1028
1013
1029
1014
(defvar-local php-mode--propertize-extend-region-current nil
1030
1015
" Prevent undesirable recursion in PHP-SYNTAX-PROPERTIZE-EXTEND-REGION" )
@@ -1146,6 +1131,7 @@ After setting the stylevars run hooks according to STYLENAME
1146
1131
(modify-syntax-entry ?_ " _" table)
1147
1132
(modify-syntax-entry ?` " \" " table)
1148
1133
(modify-syntax-entry ?\" " \" " table)
1134
+ (modify-syntax-entry ?# " < b" table)
1149
1135
(modify-syntax-entry ?\n " > b" table)
1150
1136
(modify-syntax-entry ?$ " _" table)
1151
1137
table))
@@ -1201,9 +1187,6 @@ After setting the stylevars run hooks according to STYLENAME
1201
1187
; ; PHP vars are case-sensitive
1202
1188
(setq case-fold-search t )
1203
1189
1204
- (when php-mode-use-php7-syntax-table
1205
- (modify-syntax-entry ?# " < b" php-mode-syntax-table))
1206
-
1207
1190
(when php-mode-enable-project-local-variable
1208
1191
(add-hook 'hack-local-variables-hook #'php-mode-set-local-variable-delay t t ))
1209
1192
0 commit comments