[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode 45508e1 32/96: Reverted integration of parser
From: |
Christian Johansson |
Subject: |
[elpa] externals/phps-mode 45508e1 32/96: Reverted integration of parser into other files due to immaturity |
Date: |
Fri, 29 Oct 2021 11:14:41 -0400 (EDT) |
branch: externals/phps-mode
commit 45508e1394cc9b223e452e319722260cf85ca991
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
Reverted integration of parser into other files due to immaturity
---
phps-mode-lex-analyzer.el | 277 ++++++++++++++----------------------
test/phps-mode-test-lex-analyzer.el | 8 +-
test/phps-mode-test-parser.el | 10 +-
3 files changed, 115 insertions(+), 180 deletions(-)
diff --git a/phps-mode-lex-analyzer.el b/phps-mode-lex-analyzer.el
index 09a7673..b8e00af 100644
--- a/phps-mode-lex-analyzer.el
+++ b/phps-mode-lex-analyzer.el
@@ -34,7 +34,6 @@
(require 'phps-mode-lexer)
(require 'phps-mode-macros)
-(require 'phps-mode-parser)
(require 'phps-mode-serial)
(require 'semantic)
@@ -363,126 +362,6 @@
t
(phps-mode-lexer--re2c))
-(defun phps-mode-lex-analyzer--parse-string
- (
- string
- &optional
- start
- before-lexer-state
- before-parser-state
- )
- "Parse entire STRING, optionally from START and with BEFORE-LEXER-STATE and
BEFORE-PARSER-STATE."
- (interactive)
- (require 'phps-mode-parser)
- (require 'phps-mode-macros)
- (phps-mode-debug-message (message "(phps-mode-lex-analyzer--parse-string)"))
-
- (let ((buffer (generate-new-buffer "*PHPs Lexer*")))
- ;; Create temporary buffer and run lexer in it
- (when (get-buffer buffer)
- (with-current-buffer buffer
- (insert string)
-
- ;; Setup lexer state
- (setq-local
- phps-mode-lexer--states
- (if before-lexer-state
- (nth 0 before-lexer-state)
- nil))
- (setq-local
- phps-mode-lexer--state
- (if
- before-lexer-state
- (nth 1 before-lexer-state)
- 'ST_INITIAL))
- (setq-local
- phps-mode-lexer--state-stack
- (if before-lexer-state
- (nth 2 before-lexer-state)
- nil))
- (setq-local
- phps-mode-lexer--heredoc-label
- (if before-lexer-state
- (nth 3 before-lexer-state)
- nil))
- (setq-local
- phps-mode-lexer--heredoc-label-stack
- (if before-lexer-state
- (nth 4 before-lexer-state)
- nil))
- (setq
- phps-mode-lexer--nest-location-stack
- (if before-lexer-state
- (nth 5 before-lexer-state)
- nil))
- (setq-local
- phps-mode-lexer--generated-tokens
- (if before-lexer-state
- (nth 6 before-lexer-state)
- nil))
-
- ;; Catch errors to kill generated buffer
- (let ((got-error t)
- (after-parser-state)
- (before-parser-input-tape-index)
- (before-parser-pushdown-list)
- (before-parser-output)
- (before-parser-translation)
- (before-parser-translation-symbol-table-list)
- (before-parser-history))
-
- ;; Setup parser state
- (when before-parser-state
- (setq
- before-parser-input-tape-index
- (nth 0 before-parser-state))
- (setq
- before-parser-pushdown-list
- (nth 1 before-parser-state))
- (setq
- before-parser-output
- (nth 2 before-parser-state))
- (setq
- before-parser-translation
- (nth 3 before-parser-state))
- (setq
- before-parser-translation-symbol-table-list
- (nth 4 before-parser-state))
- (setq
- before-parser-history
- (nth 5 before-parser-state)))
-
- (unwind-protect
- ;; Run lexer or incremental lexer
- (progn
- (setq
- after-parser-state
- (phps-mode-parser--parse
- before-parser-input-tape-index
- before-parser-pushdown-list
- before-parser-output
- before-parser-translation
- before-parser-translation-symbol-table-list
- before-parser-history))
- (setq got-error nil))
- (when got-error
- (kill-buffer)))
-
- ;; Copy lexer variables outside of buffer
- (let ((after-lexer-state
- (list
- phps-mode-lexer--states
- phps-mode-lexer--state
- phps-mode-lexer--state-stack
- phps-mode-lexer--heredoc-label
- phps-mode-lexer--heredoc-label-stack
- phps-mode-lexer--nest-location-stack
- (nreverse phps-mode-lexer--generated-tokens))))
- (kill-buffer)
- (list
- after-lexer-state
- after-parser-state)))))))
-
(defun phps-mode-lex-analyzer--re2c-run (&optional force-synchronous)
"Run lexer, optionally FORCE-SYNCHRONOUS."
(interactive)
@@ -501,17 +380,13 @@
buffer-name
(lambda()
- (let* ((parser-results
- (phps-mode-lex-analyzer--parse-string
- buffer-contents))
- (lex-result (nth 0 parser-results))
+ (let* ((lex-result
+ (phps-mode-lex-analyzer--lex-string buffer-contents))
(processed-result
(phps-mode-lex-analyzer--process-tokens-in-string
- (nth 6 lex-result)
+ (nth 0 lex-result)
buffer-contents)))
- (list
- lex-result
- processed-result)))
+ (list lex-result processed-result)))
(lambda(result)
(when (get-buffer buffer-name)
@@ -520,13 +395,13 @@
(processed-result (nth 1 result)))
;; Move variables into this buffers local variables
- (setq phps-mode-lex-analyzer--states (nth 0 lex-result))
- (setq phps-mode-lex-analyzer--state (nth 1 lex-result))
- (setq phps-mode-lex-analyzer--state-stack (nth 2 lex-result))
- (setq phps-mode-lex-analyzer--heredoc-label (nth 3 lex-result))
- (setq phps-mode-lex-analyzer--heredoc-label-stack (nth 4
lex-result))
- (setq phps-mode-lex-analyzer--nest-location-stack (nth 5
lex-result))
- (setq phps-mode-lex-analyzer--tokens (nth 6 lex-result))
+ (setq phps-mode-lex-analyzer--tokens (nth 0 lex-result))
+ (setq phps-mode-lex-analyzer--states (nth 1 lex-result))
+ (setq phps-mode-lex-analyzer--state (nth 2 lex-result))
+ (setq phps-mode-lex-analyzer--state-stack (nth 3 lex-result))
+ (setq phps-mode-lex-analyzer--heredoc-label (nth 4 lex-result))
+ (setq phps-mode-lex-analyzer--heredoc-label-stack (nth 5
lex-result))
+ (setq phps-mode-lex-analyzer--nest-location-stack (nth 6
lex-result))
;; Save processed result
(setq phps-mode-lex-analyzer--processed-buffer-p t)
@@ -589,18 +464,7 @@
(let ((async (and (boundp 'phps-mode-async-process)
phps-mode-async-process))
(async-by-process (and (boundp 'phps-mode-async-process-using-async-el)
- phps-mode-async-process-using-async-el))
- (before-lexer-state
- (list
- head-states
- incremental-state
- incremental-state-stack
- incremental-heredoc-label
- incremental-heredoc-label-stack
- incremental-nest-location-stack
- head-tokens))
- (before-parser-state))
- ;; TODO Build before-parser-state
+ phps-mode-async-process-using-async-el)))
(when force-synchronous
(setq async nil))
(phps-mode-serial-commands
@@ -608,23 +472,23 @@
buffer-name
(lambda()
- (let* ((parser-results
- (phps-mode-lex-analyzer--parse-string
+ (let* ((lex-result
+ (phps-mode-lex-analyzer--lex-string
buffer-contents
incremental-start-new-buffer
- before-lexer-state
- before-parser-state))
- (lex-result
- (nth 0 parser-results))
+ point-max
+ head-states
+ incremental-state
+ incremental-state-stack
+ incremental-heredoc-label
+ incremental-heredoc-label-stack
+ incremental-nest-location-stack
+ head-tokens))
(processed-result
(phps-mode-lex-analyzer--process-tokens-in-string
- (nth 6 lex-result)
+ (nth 0 lex-result)
buffer-contents)))
-
- ;; TODO Add Parser AST as return as well
- (list
- lex-result
- processed-result)))
+ (list lex-result processed-result)))
(lambda(result)
(when (get-buffer buffer-name)
@@ -635,13 +499,13 @@
(phps-mode-debug-message
(message "Incrementally-lexed-string: %s" result))
- (setq phps-mode-lex-analyzer--states (nth 0 lex-result))
- (setq phps-mode-lex-analyzer--state (nth 1 lex-result))
- (setq phps-mode-lex-analyzer--state-stack (nth 2 lex-result))
- (setq phps-mode-lex-analyzer--heredoc-label (nth 3 lex-result))
- (setq phps-mode-lex-analyzer--heredoc-label-stack (nth 4
lex-result))
- (setq phps-mode-lex-analyzer--nest-location-stack (nth 5
lex-result))
- (setq phps-mode-lex-analyzer--tokens (nth 6 lex-result))
+ (setq phps-mode-lex-analyzer--tokens (nth 0 lex-result))
+ (setq phps-mode-lex-analyzer--states (nth 1 lex-result))
+ (setq phps-mode-lex-analyzer--state (nth 2 lex-result))
+ (setq phps-mode-lex-analyzer--state-stack (nth 3 lex-result))
+ (setq phps-mode-lex-analyzer--heredoc-label (nth 4 lex-result))
+ (setq phps-mode-lex-analyzer--heredoc-label-stack (nth 5
lex-result))
+ (setq phps-mode-lex-analyzer--nest-location-stack (nth 6
lex-result))
;; Save processed result
(setq phps-mode-lex-analyzer--processed-buffer-p t)
@@ -1196,9 +1060,8 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL."
(progn
(phps-mode-debug-message
(message
- "\nCalculation indentation and imenu for all lines in
buffer:\n\n%S\n\nTokens:\n\n%S\n\n"
- string
- tokens))
+ "\nCalculation indentation and imenu for all lines in buffer:\n\n%s"
+ string))
(let ((in-heredoc nil)
(in-heredoc-started-this-line nil)
(in-heredoc-ended-this-line nil)
@@ -3261,6 +3124,80 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL."
(unless phps-mode-lex-analyzer--state
(setq phps-mode-lex-analyzer--state 'ST_INITIAL)))
+(defun phps-mode-lex-analyzer--lex-string (contents &optional start end states
state state-stack heredoc-label heredoc-label-stack nest-location-stack tokens)
+ "Run lexer on CONTENTS."
+ ;; Create a separate buffer, run lexer inside of it, catch errors and return
them
+ ;; to enable nice presentation
+ (require 'phps-mode-macros)
+ (let ((buffer (generate-new-buffer "*PHPs Lexer*")))
+
+ ;; Create temporary buffer and run lexer in it
+ (when (get-buffer buffer)
+ (with-current-buffer buffer
+ (insert contents)
+
+ (if tokens
+ (setq
+ phps-mode-lexer--generated-tokens
+ (nreverse tokens))
+ (setq
+ phps-mode-lexer--generated-tokens
+ nil))
+ (if state
+ (setq
+ phps-mode-lexer--state state)
+ (setq
+ phps-mode-lexer--state
+ 'ST_INITIAL))
+
+ (setq
+ phps-mode-lexer--states
+ states)
+ (setq
+ phps-mode-lexer--state-stack
+ state-stack)
+ (setq
+ phps-mode-lexer--heredoc-label
+ heredoc-label)
+ (setq
+ phps-mode-lexer--heredoc-label-stack
+ heredoc-label-stack)
+ (setq
+ phps-mode-lexer--nest-location-stack
+ nest-location-stack)
+
+ ;; Setup lexer settings
+ (when (boundp 'phps-mode-syntax-table)
+ (setq semantic-lex-syntax-table phps-mode-syntax-table))
+ (setq semantic-lex-analyzer #'phps-mode-lex-analyzer--re2c-lex)
+
+ ;; Catch errors to kill generated buffer
+ (let ((got-error t))
+ (unwind-protect
+ ;; Run lexer or incremental lexer
+ (progn
+ (if (and start end)
+ (let ((incremental-tokens (semantic-lex start end)))
+ (setq
+ phps-mode-lex-analyzer--tokens
+ (append tokens incremental-tokens)))
+ (setq
+ phps-mode-lex-analyzer--tokens
+ (semantic-lex-buffer)))
+ (setq got-error nil))
+ (when got-error
+ (kill-buffer))))
+
+ ;; Copy variables outside of buffer
+ (setq state phps-mode-lexer--state)
+ (setq state-stack phps-mode-lexer--state-stack)
+ (setq states phps-mode-lexer--states)
+ (setq tokens (nreverse phps-mode-lexer--generated-tokens))
+ (setq heredoc-label phps-mode-lexer--heredoc-label)
+ (setq heredoc-label-stack phps-mode-lexer--heredoc-label-stack)
+ (kill-buffer))))
+ (list tokens states state state-stack heredoc-label heredoc-label-stack))
+
(provide 'phps-mode-lex-analyzer)
;;; phps-mode-lex-analyzer.el ends here
diff --git a/test/phps-mode-test-lex-analyzer.el
b/test/phps-mode-test-lex-analyzer.el
index 3a1275f..396a026 100644
--- a/test/phps-mode-test-lex-analyzer.el
+++ b/test/phps-mode-test-lex-analyzer.el
@@ -1617,12 +1617,12 @@
(should
(equal
'(80 459 466 411 333 332 154 102 79)
- (car (car (cdr (phps-mode-lex-analyzer--parse-string
+ (car (car (cdr (phps-mode-lex-analyzer--lex-string
"<?php echo 'abc';"))))))
(message "Passed valid parse test")
(should-error
- (phps-mode-lex-analyzer--parse-string
+ (phps-mode-lex-analyzer--lex-string
"<?php echo 'abc'"))
(message "Passed error parse test")
)
@@ -1646,9 +1646,7 @@
(phps-mode-test-lex-analyzer--indent-line)
(phps-mode-test-lex-analyzer--imenu)
(phps-mode-test-lex-analyzer--get-moved-imenu)
- (phps-mode-test-lex-analyzer--comment-uncomment-region)
- (phps-mode-test-lex-analyzer--move-lines-indent)
- (phps-mode-test-lex-analyzer--parse-string))
+ (phps-mode-test-lex-analyzer--comment-uncomment-region))
(phps-mode-test-lex-analyzer)
diff --git a/test/phps-mode-test-parser.el b/test/phps-mode-test-parser.el
index b2b46e6..e761a4f 100644
--- a/test/phps-mode-test-parser.el
+++ b/test/phps-mode-test-parser.el
@@ -134,11 +134,11 @@
(phps-mode-parser-translate)))))
;; TODO Make following test work
- (phps-mode-test-parser--buffer-contents
- "<?php\n\nnamespace myNamespaceA {\n $var = 123;\n class myClassA {\n
private $var2 = 123;\n function myFunctionA($var3) {\n
$var4 = 123;\n if ($var) {\n echo 'Miss';\n
}\n if ($var2) {\n echo 'Miss';\n }\n
if ($var3) {\n echo 'Hit';\n }\n if
($var4) {\n echo 'Hit';\n }\n }\n\n
function myFuncti [...]
- "Object oriented PHP with bracket namespace"
- (lambda()
- (phps-mode-parser-parse)))
+ ;; (phps-mode-test-parser--buffer-contents
+ ;; "<?php\n\nnamespace myNamespaceA {\n $var = 123;\n class myClassA
{\n private $var2 = 123;\n function myFunctionA($var3) {\n
$var4 = 123;\n if ($var) {\n echo 'Miss';\n
}\n if ($var2) {\n echo 'Miss';\n }\n
if ($var3) {\n echo 'Hit';\n }\n
if ($var4) {\n echo 'Hit';\n }\n }\n\n
function myFun [...]
+ ;; "Object oriented PHP with bracket namespace"
+ ;; (lambda()
+ ;; (phps-mode-parser-parse)))
(message "\n-- Ran tests for parser boundaries. --"))
- [elpa] externals/phps-mode 3824d7d 46/96: More work on automatically parsing YACC grammar, (continued)
- [elpa] externals/phps-mode 3824d7d 46/96: More work on automatically parsing YACC grammar, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode 42c4e0e 48/96: Work on automatically generating terminals, non-terminals and start from YACC grammar, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode f56ba64 49/96: Terminals, non-terminals and start is automatically generated from YACC, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode 7323416 31/96: Added failing test for parser, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode 7c66145 30/96: Refactor of parsers lex-analyzer complete, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode 0e89b6e 35/96: Fixed bug in automation grammar, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode 65152f4 36/96: Added TODO item, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode add17a7 24/96: T_COMMENT and T_DOC_COMMENT are excluded from parser, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode f46b98f 25/96: More work on integrating parser, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode 6b3a298 29/96: More work on parsers lex-analyzer refactor, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode 45508e1 32/96: Reverted integration of parser into other files due to immaturity,
Christian Johansson <=
- [elpa] externals/phps-mode 37dda7a 34/96: Added another failing test for parser, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode 339e39b 37/96: Started on YACC grammar parser generator, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode 244a62b 39/96: Parser generator now can parse PHP YACC productions, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode a449b5b 42/96: Improved formatting of generated productions, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode e3d973d 43/96: Improved support for semi-colon in grammar delimiter, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode 962e7c8 52/96: Context-sensitive precedence attribute is automatically parsed from YACC, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode b94cbbf 58/96: Set GB collection in automation, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode bb4858b 61/96: Defined lex-analyzer reset function for parser, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode 22f0a47 62/96: Parser generator passing byte-compilation, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode 751bece 50/96: Removed terminals, non-terminals and start from automation grammar, Christian Johansson, 2021/10/29