branch: externals/phps-mode
commit 3427bf16654bd391b42028c3ea366830c3032281
Author: Christian Johansson
Commit: Christian Johansson
Added support for alternative newline characters
---
phps-mode-analyzer.el | 87 +--
phps-mode.el | 4 +--
2 files changed, 65 insertions(+), 26 deletions(-)
diff --git a/phps-mode-analyzer.el b/phps-mode-analyzer.el
index d6a523e..6465f40 100644
--- a/phps-mode-analyzer.el
+++ b/phps-mode-analyzer.el
@@ -145,7 +145,7 @@
;; NOTE original is [a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*
;; NOTE Rebuilt for comparability with emacs-lisp
-(defvar phps-mode-lexer-WHITESPACE "[ \n\r\t]+"
+(defvar phps-mode-lexer-WHITESPACE "[ \n\r\t\C-m]+"
"White-space.")
(defvar phps-mode-lexer-TABS_AND_SPACES "[ \t]*"
@@ -156,10 +156,10 @@
;; NOTE Original is [;:,.\[\]()|^&+-/*=%!~$<>?@]
;; NOTE The hyphen moved last since it has special meaning and to avoid it
being interpreted as a range.
-(defvar phps-mode-lexer-ANY_CHAR ".\\|\n"
+(defvar phps-mode-lexer-ANY_CHAR ".\\|\n\\|\C-m"
"Any character. The Zend equivalent is [^] but is not possible in Emacs
Lisp.")
-(defvar phps-mode-lexer-NEWLINE "\\(\r\\|\n\\|\r\n\\)"
+(defvar phps-mode-lexer-NEWLINE "\\(\r\\|\n\\|\C-m\\|\r\n\\)"
"Newline characters.")
@@ -191,6 +191,11 @@
(when (boundp 'semantic-lex-end-point)
(setq semantic-lex-end-point position)))
+(defun phps-mode-lexer-yyless (points)
+ "Move lexer back POINTS."
+ (when (boundp 'semantic-lex-end-point)
+(setq semantic-lex-end-point (- semantic-lex-end-point points
+
(defun phps-mode-lexer-set-region-syntax-color (start end properties)
"Do syntax coloring for region START to END with PROPERTIES."
(with-silent-modifications (set-text-properties start end properties)))
@@ -199,6 +204,14 @@
"Clear region of syntax coloring from START to END."
(with-silent-modifications (set-text-properties start end nil)))
+(defun phps-mode-anaylzer-inline-char-handler ()
+ "Mimic inline_char_handler."
+ (let ((start (match-beginning 0)))
+(let ((string-start (search-forward "\n?"))
+ (and ST_IN_SCRIPTING (looking-at "\\?>\n?\C-m?"))
(lambda()
(let ((start (match-beginning 0))
(end (match-end 0)))
@@ -1626,9 +1665,9 @@
(let ((string-start
(search-forward-regexp
(concat
-"\\(\n"
+"\\(\\(\n\\|\C-m\\)"
heredoc_label
-";?\n\\|\\$"
+";?\\(\n\\|\C-m\\)\\|\\$"
phps-mode-lexer-LABEL
"\\|{\\$"
phps-mode-lexer-LABEL
@@ -1643,7 +1682,7 @@
(cond
-((string-match (concat "\n" heredoc_label ";?\n") data)
+((string-match (concat "\\(\n\\|\C-m\\)" heredoc_label
";?\\(\n\\|\C-m\\)") data)
;, (message "Found heredoc end at
%s-%s" start end)
(phps-mode-lexer-BEGIN 'ST_END_HEREDOC)
(phps-mode-lexer-RETURN_TOKEN 'T_ENCAPSED_AND_WHITESPACE
old-start start))
@@ -1661,7 +1700,7 @@
(phps-mode-lexer-re2c-rule
(and ST_NOWDOC (looking-at phps-mode-lexer-ANY_CHAR))
(lambda()
- (let ((string-start (search-forward-regexp (concat "\n"
heredoc_label ";?\n") nil t)))
+ (let ((string-start (search-forward-regexp (concat
"\\(\n\\|\C-m\\)" heredoc_label ";?\\(\n\\|\C-m\\)") nil t)))
(if string-start
(let* ((start (match-beginning 0))
(end (match-end 0))
@@ -2044,14 +2083,14 @@
curly-bracket-level
square-bracket-level
round-bracket-level)
- "Generate a list of indentation for each line in INLINE-HTML,
-working incrementally on INDENT, TAG-LEVEL, CURLY-BRACKET-LEVEL,
+ "Generate a list of indentation for each line in INLINE-HTML.
+Working incrementally on INDENT, TAG-LEVEL, CURLY-BRACKET-LEVEL,
SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL."
(phps-mode-debug-message
(message "Calculating HTML indent for: '%s'" inline-html))
;; Add trailing newline if missing
- (unless (string-match "\n$" inline-html)
+ (unless (string-match-p "\\(\n\\|\C-m\\)$" inline-html)
(setq inline-html (concat inline-html "\n")))
(let ((start 0)
@@ -2070,7 +2109,7 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL."
(cond
- ((string= string "\n")
+ ((string-match-p "\\(\n\\|\C-m\\)" string)
(let ((temp-indent indent))
(when first-object-is-nesting-decrease
@@ -2123,7 +2162,7 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL."
)
(when first-object-on-line
- (unless (string= string "\n")
+ (unless (string-match-p "\\(\n\\|\C-m\\)" string)
(setq first-object-on-line nil)
(setq indent