[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode 1ee3094 28/96: More refactoring of the parser
From: |
Christian Johansson |
Subject: |
[elpa] externals/phps-mode 1ee3094 28/96: More refactoring of the parsers lex-analyzer |
Date: |
Fri, 29 Oct 2021 11:14:39 -0400 (EDT) |
branch: externals/phps-mode
commit 1ee30940605b550535232299b3a70559b6af2cca
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
More refactoring of the parsers lex-analyzer
---
phps-mode-automation-grammar.el | 123 +++++++++++++++++++++++++++++-----------
1 file changed, 90 insertions(+), 33 deletions(-)
diff --git a/phps-mode-automation-grammar.el b/phps-mode-automation-grammar.el
index ba2030f..572cbdd 100644
--- a/phps-mode-automation-grammar.el
+++ b/phps-mode-automation-grammar.el
@@ -1462,13 +1462,57 @@
(defvar
phps-mode-automation-grammar--lex-analyzer-function
(lambda (buffer-index)
+
+ ;; Create lexer buffer if none exists
+ (unless (get-buffer "*PHPs Lexer*")
+ (generate-new-buffer "*PHPs Lexer*")
+ (let ((old-buffer
+ (buffer-substring-no-properties
+ (point-min)
+ (point-max))))
+ (with-current-buffer "*PHPs Lexer*"
+ (insert old-buffer))))
+
(with-current-buffer "*PHPs Lexer*"
(let ((token-list-index))
;; Unless we have lexed the buffer
- (unless
- phps-mode-lexer--generated-tokens
- ;; TODO Run lexer on entire buffer here
+ (unless phps-mode-lexer--generated-tokens
+
+ ;; Reset lexer
+ (setq-local
+ phps-mode-lexer--generated-tokens
+ nil)
+ (setq-local
+ phps-mode-lexer--state
+ 'ST_INITIAL)
+ (setq-local
+ phps-mode-lexer--states
+ nil)
+ (setq-local
+ phps-mode-lexer--state-stack
+ nil)
+ (setq-local
+ phps-mode-lexer--heredoc-label
+ nil)
+ (setq-local
+ phps-mode-lexer--heredoc-label-stack
+ nil)
+ (setq-local
+ phps-mode-lexer--nest-location-stack
+ nil)
+ (goto-char (point-min))
+
+ ;; Run lexer on entire buffer here
+ (let ((index (point))
+ (max-index (point-max)))
+ (while (< index max-index)
+ (phps-mode-lexer--re2c)
+ (setq
+ index
+ semantic-lex-end-point)))
+
+ ;; Reset buffer-index to token-list-index connections
(setq-local
phps-mode-parser-position
nil))
@@ -1511,36 +1555,44 @@
;; When token starts at cursor we found correct index
;; Save it
(when (= (car (cdr token)) buffer-index)
- ;; TODO Skip T_OPEN_TAG T_CLOSE_TAG T_DOC_COMMENT and
T_COMMENT here
-
- (setq
- token-list-index
- temp-token-list-index)
- (push
- (list
- buffer-index
- temp-token-list-index)
- phps-mode-parser-position)
- (setq
- continue
- nil))
+ (let ((token-type (car token)))
+ (unless (or
+ (equal token-type 'T_OPEN_TAG)
+ (equal token-type 'T_CLOSE_TAG)
+ (equal token-type 'T_DOC_COMMENT)
+ (equal token-type 'T_COMMENT))
+ (setq
+ token-list-index
+ temp-token-list-index)
+ (push
+ (list
+ buffer-index
+ temp-token-list-index)
+ phps-mode-parser-position)
+ (setq
+ continue
+ nil))))
;; When token starts after cursor, flag move of cursor
;; Save it
(when (> (car (cdr token)) buffer-index)
- ;; TODO Skip T_OPEN_TAG T_CLOSE_TAG T_DOC_COMMENT and
T_COMMENT here
-
- (setq-local
- phps-mode-parser-lex-analyzer--move-to-index-flag
- (car (cdr token)))
- (push
- (list
- (car (cdr token))
- temp-token-list-index)
- phps-mode-parser-position)
- (setq
- continue
- nil))
+ (let ((token-type (car token)))
+ (unless (or
+ (equal token-type 'T_OPEN_TAG)
+ (equal token-type 'T_CLOSE_TAG)
+ (equal token-type 'T_DOC_COMMENT)
+ (equal token-type 'T_COMMENT))
+ (setq-local
+ phps-mode-parser-lex-analyzer--move-to-index-flag
+ (car (cdr token)))
+ (push
+ (list
+ (car (cdr token))
+ temp-token-list-index)
+ phps-mode-parser-position)
+ (setq
+ continue
+ nil))))
(setq
temp-token-list-index
@@ -1549,10 +1601,15 @@
(when
token-list-index
- ;; TODO Convert OPEN_TAG_WITH_ECHO to T_ECHO here
- (nth
- token-list-index
- phps-mode-lexer--generated-tokens)))))
+ (let ((token
+ (nth
+ token-list-index
+ phps-mode-lexer--generated-tokens)))
+ (when (equal (car token) 'T_OPEN_TAG_WITH_ECHO)
+ (setf
+ (car token)
+ 'T_ECHO))
+ token)))))
"The custom lex-analyzer.")
(defvar
- [elpa] externals/phps-mode 2b167f3 08/96: Fixes for parsing start and end, (continued)
- [elpa] externals/phps-mode 2b167f3 08/96: Fixes for parsing start and end, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode 376e690 15/96: Verified parse, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode 2a9fb96 16/96: Added more tests for parser, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode 5c7c6f4 14/96: Parser passes basic lexing test, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode 569505e 17/96: Added parser header and fixed byte-compilation for parser, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode 0d1843f 20/96: Started on parser integration, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode b714471 21/96: Added parse function in lex-analyzer and a test for it, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode 50a014a 18/96: Using same lexer buffer for parser as the lex-analyzer is using, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode fb9905f 19/96: Added basic translation test, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode ec18c1e 22/96: Using parser to be able to implement incremental parser, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode 1ee3094 28/96: More refactoring of the parsers lex-analyzer,
Christian Johansson <=
- [elpa] externals/phps-mode 2ceb6e5 23/96: Added potential support for incremental parsing, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode e59d30e 26/96: Improvements in lex-analyzer for parser, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode c62ec64 27/96: Started refactor of parsers lex-analyzer, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode 9acda54 33/96: Added more passing tests for parser, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode c470e37 38/96: More work on grammar parser generator, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode 6b9c1a4 40/96: More pasing of grammar, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode 3fa1b13 41/96: Translation of productions now working, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode b0ad204 44/96: Improved YACC grammar parser for productions, Christian Johansson, 2021/10/29
- [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