branch: externals/phps-mode commit e5fda9efb3824719e09da0ad1f94c3c8bef46ebe Author: Christian Johansson <christ...@cvj.se> Commit: Christian Johansson <christ...@cvj.se>
New lexer tokens working after byte-compilation --- phps-mode-lexer.el | 76 ++++++++++++++++++++++------------------------------- phps-mode-macros.el | 2 +- 2 files changed, 33 insertions(+), 45 deletions(-) diff --git a/phps-mode-lexer.el b/phps-mode-lexer.el index a5d2184729..cf97c57235 100644 --- a/phps-mode-lexer.el +++ b/phps-mode-lexer.el @@ -116,24 +116,16 @@ ;; VARIABLES -(defvar phps-mode-lexer--lambdas-by-state #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (ST_IN_SCRIPTING ((lambda nil (when (looking-at "exit") (let ((match-end (match-end 0)) (match-beginning (match-beginning 0))) (let ((matching-length (- match-end match-beginning))) (when (> matching-length 0) (when (or (not phps-mode-lexer--match-length) (> matching-length phps-mode-lexer--match-length)) (setq phps-mode-lexer--match-length matching-length) (setq phps-m [...] -]*" "\\(\\$\\|\\.\\.\\.\\)")) (let ((match-end (match-end 0)) (match-beginning (match-beginning 0))) (let ((matching-length (- match-end match-beginning))) (when (> matching-length 0) (when (or (not phps-mode-lexer--match-length) (> matching-length phps-mode-lexer--match-length)) (setq phps-mode-lexer--match-length matching-length) (setq phps-mode-lexer--match-body (lambda nil (phps-mode-lexer--yyless 1) (phps-mode-lexer--return-token 'T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG (match-beginni [...] - ]*(")) (let ((match-end (match-end 0)) (match-beginning (match-beginning 0))) (let ((matching-length (- match-end match-beginning))) (when (> matching-length 0) (when (or (not phps-mode-lexer--match-length) (> matching-length phps-mode-lexer--match-length)) (setq phps-mode-lexer--match-length matching-length) (setq phps-mode-lexer--match-body (lambda nil (phps-mode-lexer--yyless (length "readonly")) (phps-mode-lexer--return-token-with-indent 'T_READONLY))) (setq phps-mode-lexer--match-da [...] -]*" "\\(\\$\\|\\.\\.\\.\\)")) (let ((match-end (match-end 0)) (match-beginning (match-beginning 0))) (let ((matching-length (- match-end match-beginning))) (when (> matching-length 0) (when (or (not phps-mode-lexer--match-length) (> matching-length phps-mode-lexer--match-length)) (setq phps-mode-lexer--match-length matching-length) (setq phps-mode-lexer--match-body (lambda nil (phps-mode-lexer--yyless 1) (phps-mode-lexer--return-token 'T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG (match-beginni [...] +(defvar phps-mode-lexer--lambdas-by-state #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data (ST_IN_SCRIPTING (((lambda nil (looking-at "exit")) (lambda nil (phps-mode-lexer--return-token-with-indent 'T_EXIT))) ((lambda nil (looking-at "die")) (lambda nil (phps-mode-lexer--return-token-with-indent 'T_EXIT))) ((lambda nil (looking-at "fn")) (lambda nil (phps-mode-lexer--return-token-with-indent 'T_FN))) ((lambda nil (looking-at "function")) (lambda nil (phps-mod [...] + ]*("))) (lambda nil (phps-mode-lexer--yyless (length "readonly")) (phps-mode-lexer--return-token-with-str 'T_STRING 0))) ((lambda nil (looking-at "unset")) (lambda nil (phps-mode-lexer--return-token-with-indent 'T_UNSET))) ((lambda nil (looking-at "=>")) (lambda nil (phps-mode-lexer--return-token 'T_DOUBLE_ARROW))) ((lambda nil (looking-at "list")) (lambda nil (phps-mode-lexer--return-token-with-indent 'T_LIST))) ((lambda nil (looking-at "array")) (lambda nil (phps-mode-lexer--return-tok [...] +]*" "\\(\\$\\|\\.\\.\\.\\)"))) (lambda nil (phps-mode-lexer--yyless 1) (phps-mode-lexer--return-token 'T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG (match-beginning 0) (- (match-end 0) 1)))) ((lambda nil (looking-at "&")) (lambda nil (phps-mode-lexer--return-token 'T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG))) ((lambda nil (looking-at (concat "\\(" "]" "\\|" ")" "\\)"))) (lambda nil (phps-mode-lexer--return-exit-nesting-token))) ((lambda nil (looking-at (concat "\\(" "\\[" "\\|" "(" "\\)"))) (la [...] " phps-mode-lexer--heredoc-label ";? \\|\\$" phps-mode-lexer--label "\\|{\\$" phps-mode-lexer--label "\\|\\${" phps-mode-lexer--label "\\)") nil t))) (if string-start (let* ((start (match-beginning 0)) (end (match-end 0)) (data (buffer-substring-no-properties start end))) (cond ((string-match (concat " " phps-mode-lexer--heredoc-label ";? -") data) (phps-mode-lexer--return-token-with-val 'T_ENCAPSED_AND_WHITESPACE old-end start) (phps-mode-lexer--begin 'ST_END_HEREDOC)) (t (phps-mode-lexer--return-token-with-val 'T_ENCAPSED_AND_WHITESPACE old-end start)))) (progn (signal 'phps-lexer-error (list (format "Found no ending of heredoc starting at %d" old-start) old-start)))))))) (setq phps-mode-lexer--match-data (match-data)))))))) (lambda nil (when (looking-at "\\${") (let ((match-end (match-end 0)) (match-beginning (match-beg [...] -" phps-mode-lexer--heredoc-label ";? -\\|\\$" phps-mode-lexer--label "\\|{\\$" phps-mode-lexer--label "\\|\\${" phps-mode-lexer--label "\\)") nil t))) (if string-start (let* ((start (match-beginning 0)) (end (match-end 0)) (data (buffer-substring-no-properties start end))) (cond ((string-match (concat " -" phps-mode-lexer--heredoc-label ";? -") data) (phps-mode-lexer--return-token-with-val 'T_ENCAPSED_AND_WHITESPACE old-end start) (phps-mode-lexer--begin 'ST_END_HEREDOC)) (t (phps-mode-lexer--return-token-with-val 'T_ENCAPSED_AND_WHITESPACE old-end start)))) (progn (signal 'phps-lexer-error (list (format "Found no ending of heredoc starting at %d" old-start) old-start)))))))) (setq phps-mode-lexer--match-data (match-data))))))))) ST_LOOKING_FOR_VARNAME ((lambda nil (when (looking-at (concat phps-mode-lexer--label "[\\[}]")) [...] - '#]")) (let ((match-end (match-end 0)) (match-beginning (match-beginning 0))) (let ((matching-length (- match-end match-beginning))) (when (> matching-length 0) (when (or (not phps-mode-lexer--match-length) (> matching-length phps-mode-lexer--match-length)) (setq phps-mode-lexer--match-length matching-length) (setq phps-mode-lexer--match-body (lambda nil (phps-mode-lexer--yyless 0) (phps-mode-lexer--yy-pop-state) (phps-mode-lexer--return-token-with-val 'T_ENCAPSED_AND_WHITESPACE))) (setq [...] - '#]")) (let ((match-end (match-end 0)) (match-beginning (match-beginning 0))) (let ((matching-length (- match-end match-beginning))) (when (> matching-length 0) (when (or (not phps-mode-lexer--match-length) (> matching-length phps-mode-lexer--match-length)) (setq phps-mode-lexer--match-length matching-length) (setq phps-mode-lexer--match-body (lambda nil (phps-mode-lexer--yyless 0) (phps-mode-lexer--yy-pop-state) (phps-mode-lexer--return-token-with-val 'T_ENCAPSED_AND_WHITESPACE))) (setq [...] -" phps-mode-lexer--heredoc-label ";?\\ -") nil t))) (if string-start (let* ((start (match-beginning 0)) (end (match-end 0)) (_data (buffer-substring-no-properties start end))) (phps-mode-lexer--return-token-with-val 'T_ENCAPSED_AND_WHITESPACE phps-mode-lexer--generated-new-tokens-index start) (phps-mode-lexer--begin 'ST_END_HEREDOC)) (progn (signal 'phps-lexer-error (list (format "Found no ending of nowdoc starting at %d" start) start)))))))) (setq phps-mode-lexer--match-data (match-data)))))))) (lambda nil (when (looking-at p [...] +") data) (phps-mode-lexer--return-token-with-val 'T_ENCAPSED_AND_WHITESPACE old-end start) (phps-mode-lexer--begin 'ST_END_HEREDOC)) (t (phps-mode-lexer--return-token-with-val 'T_ENCAPSED_AND_WHITESPACE old-end start)))) (progn (signal 'phps-lexer-error (list (format "Found no ending of heredoc starting at %d" old-start) old-start))))))))) ST_LOOKING_FOR_VARNAME (((lambda nil (looking-at (concat phps-mode-lexer--label "[\\[}]"))) (lambda nil (let* ((start (match-beginning 0)) (end (1- (m [...] + '#]"))) (lambda nil (phps-mode-lexer--yyless 0) (phps-mode-lexer--yy-pop-state) (phps-mode-lexer--return-token-with-val 'T_ENCAPSED_AND_WHITESPACE))) ((lambda nil (looking-at phps-mode-lexer--label)) (lambda nil (phps-mode-lexer--return-token-with-str 'T_STRING 0))) ((lambda nil (looking-at phps-mode-lexer--any-char)) (lambda nil (signal 'phps-lexer-error (list (format "Unexpected character at %d" (match-beginning 0)) (match-beginning 0)))))) quote (((lambda nil (looking-at (concat "#!.* [...] " phps-mode-lexer--heredoc-label ";?\\ -") nil t))) (if string-start (let* ((start (match-beginning 0)) (end (match-end 0)) (_data (buffer-substring-no-properties start end))) (phps-mode-lexer--return-token-with-val 'T_ENCAPSED_AND_WHITESPACE phps-mode-lexer--generated-new-tokens-index start) (phps-mode-lexer--begin 'ST_END_HEREDOC)) (progn (signal 'phps-lexer-error (list (format "Found no ending of nowdoc starting at %d" start) start)))))))) (setq phps-mode-lexer--match-data (match-data))))))))))) +") nil t))) (if string-start (let* ((start (match-beginning 0)) (end (match-end 0)) (_data (buffer-substring-no-properties start end))) (phps-mode-lexer--return-token-with-val 'T_ENCAPSED_AND_WHITESPACE phps-mode-lexer--generated-new-tokens-index start) (phps-mode-lexer--begin 'ST_END_HEREDOC)) (progn (signal 'phps-lexer-error (list (format "Found no ending of nowdoc starting at %d" start) start))))))))))) "Hash-table of lex-analyzer rules organized by state.") (defvar-local phps-mode-lexer--generated-tokens nil @@ -376,25 +368,8 @@ (setq old-lambdas (reverse old-lambdas))) - (push - `(lambda() - (when ,conditions - (let ((match-end (match-end 0)) - (match-beginning (match-beginning 0))) - (let ((matching-length (- match-end match-beginning))) - (when (> matching-length 0) - (when (or (not phps-mode-lexer--match-length) - (> matching-length phps-mode-lexer--match-length)) - (setq - phps-mode-lexer--match-length matching-length) - (setq - phps-mode-lexer--match-body (lambda() ,@body)) - (setq - phps-mode-lexer--match-data (match-data)))))))) - old-lambdas) - (setq - old-lambdas - (reverse old-lambdas)) + (push `((lambda() ,conditions) (lambda() ,@body)) old-lambdas) + (setq old-lambdas (reverse old-lambdas)) (puthash state old-lambdas @@ -2060,20 +2035,33 @@ (lambda-length (length lambdas))) (phps-mode-debug-message (message "Found %d lexer rules in state" lambda-length)) + (while (< lambda-i lambda-length) (let ((lambd (nth lambda-i lambdas))) (let ((old-match-length phps-mode-lexer--match-length)) - (funcall lambd) - - ;; Debug new matches - (phps-mode-debug-message - (when (and - old-match-length - (> phps-mode-lexer--match-length old-match-length)) - (message - "Found new match (%d) %s" - phps-mode-lexer--match-length - phps-mode-lexer--match-body))) + + (let ((lambda-result + (funcall (nth 0 lambd)))) + (when lambda-result + (let ((match-end (match-end 0)) + (match-beginning (match-beginning 0))) + (let ((matching-length (- match-end match-beginning))) + (when (> matching-length 0) + (when (or + (not phps-mode-lexer--match-length) + (> matching-length phps-mode-lexer--match-length)) + (setq + phps-mode-lexer--match-length matching-length) + (setq + phps-mode-lexer--match-body (nth 1 lambd)) + (setq + phps-mode-lexer--match-data (match-data)) + ;; Debug new matches + (phps-mode-debug-message + (message + "Found new match (%d) %s" + phps-mode-lexer--match-length + phps-mode-lexer--match-body)))))))) (when (fboundp 'thread-yield) (thread-yield)))) diff --git a/phps-mode-macros.el b/phps-mode-macros.el index 721401aeda..bad8a8a2ca 100644 --- a/phps-mode-macros.el +++ b/phps-mode-macros.el @@ -9,7 +9,7 @@ (defconst phps-mode-macrotime-debug - t + nil "Debug messages during macro expansion time, default nil.") (defmacro phps-mode-debug-message (&rest code)