@@ -318,6 +318,12 @@ In that case set to `NIL'."
318318 :tag " PHP Mode Enable Project Local Variable"
319319 :type 'boolean )
320320
321+ (defcustom php-mode-use-php7-syntax-table nil
322+ " When set to `T' , use a syntax table compatible with PHP 7."
323+ :group 'php-mode
324+ :tag " PHP Mode Enable Project Local Variable"
325+ :type 'boolean )
326+
321327(defconst php-mode-cc-vertion
322328 (eval-when-compile c-version))
323329
@@ -979,18 +985,45 @@ this ^ lineup"
979985 (string-match " \\ _<.+?\\ _>" heredoc-start)
980986 (concat " ^\\ s-*\\ (" (match-string 0 heredoc-start) " \\ )\\ W" ))
981987
988+ (defvar php-syntax-propertize-functions
989+ '(php-syntax-propertize-heredoc
990+ php-syntax-propertize-hash-line-comment
991+ php-syntax-propertize-quotes-in-comment)
992+ " Syntax propertize functions for PHP script." )
993+
982994(defun php-syntax-propertize-function (start end )
983995 " Apply propertize rules from START to END."
984- (goto-char start)
996+ (dolist (propertizer php-syntax-propertize-functions)
997+ (goto-char start)
998+ (funcall propertizer start end)))
999+
1000+ (defun php-syntax-propertize-heredoc (_start end )
1001+ " Apply propertize Heredoc and Nowdoc from START to END."
9851002 (while (and (< (point ) end)
9861003 (re-search-forward php-heredoc-start-re end t ))
987- (php-heredoc-syntax))
988- (goto-char start)
1004+ (php-heredoc-syntax)))
1005+
1006+ (defun php-syntax-propertize-quotes-in-comment (_start end )
1007+ " Apply propertize quotes (' and \" ) from START to END."
9891008 (while (re-search-forward " ['\" ]" end t )
9901009 (when (php-in-comment-p)
9911010 (c-put-char-property (match-beginning 0 )
9921011 'syntax-table (string-to-syntax " _" )))))
9931012
1013+ (defun php-syntax-propertize-hash-line-comment (_start end )
1014+ " Apply propertize # comment (without PHP8 Attributes) from START to END."
1015+ (unless php-mode-use-php7-syntax-table
1016+ (let (line-end in-last-line)
1017+ (while (and (< (point ) (min end (point-max )))
1018+ (not in-last-line))
1019+ (setq line-end (line-end-position ))
1020+ (when (and (search-forward " #" line-end t )
1021+ (not (php-in-string-or-comment-p))
1022+ (not (looking-at " [[]" )))
1023+ (c-put-char-property (1- (point )) 'syntax-table (string-to-syntax " < b" )))
1024+ (move-beginning-of-line 2 )
1025+ (setq in-last-line (>= line-end (point )))))))
1026+
9941027(defun php-heredoc-syntax ()
9951028 " Mark the boundaries of searched heredoc."
9961029 (goto-char (match-beginning 0 ))
@@ -1121,7 +1154,6 @@ After setting the stylevars run hooks according to STYLENAME
11211154 (modify-syntax-entry ?_ " _" table)
11221155 (modify-syntax-entry ?` " \" " table)
11231156 (modify-syntax-entry ?\" " \" " table)
1124- (modify-syntax-entry ?# " < b" table)
11251157 (modify-syntax-entry ?\n " > b" table)
11261158 (modify-syntax-entry ?$ " _" table)
11271159 table))
@@ -1151,7 +1183,7 @@ After setting the stylevars run hooks according to STYLENAME
11511183 (setq-local comment-start " // " )
11521184 (setq-local comment-start-skip
11531185 (eval-when-compile
1154- (rx (group (or (: " #" )
1186+ (rx (group (or (: " #" ( not (any " [ " )) )
11551187 (: " /" (+ " /" ))
11561188 (: " /*" )))
11571189 (* (syntax whitespace)))))
@@ -1175,6 +1207,9 @@ After setting the stylevars run hooks according to STYLENAME
11751207 ; ; PHP vars are case-sensitive
11761208 (setq case-fold-search t )
11771209
1210+ (when php-mode-use-php7-syntax-table
1211+ (modify-syntax-entry ?# " < b" php-mode-syntax-table))
1212+
11781213 (when php-mode-enable-project-local-variable
11791214 (add-hook 'hack-local-variables-hook #'php-mode-set-local-variable-delay t t ))
11801215
0 commit comments