[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode c470e37 38/96: More work on grammar parser ge
From: |
Christian Johansson |
Subject: |
[elpa] externals/phps-mode c470e37 38/96: More work on grammar parser generator |
Date: |
Fri, 29 Oct 2021 11:14:42 -0400 (EDT) |
branch: externals/phps-mode
commit c470e3792a12daa22c0ae797de111f63626f9022
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
More work on grammar parser generator
---
Makefile | 4 +
admin/phps-mode-grammar-parser-generator.el | 123 +++++++++++++++++++++++-----
2 files changed, 106 insertions(+), 21 deletions(-)
diff --git a/Makefile b/Makefile
index 7207e62..f94a48a 100644
--- a/Makefile
+++ b/Makefile
@@ -15,6 +15,10 @@ parser: clean generate-parser
generate-parser:
rm phps-mode-automation-grammar.elc; $(EMACS_CMD) -L
~/.emacs.d/emacs-parser-generator/ -l phps-mode-lexer.el -l
admin/phps-mode-automation.el -eval "(progn (require
'parser-generator-lr-export)(setq debug-on-signal t)(setq debug-on-error
t)(phps-mode-automation))"
+.PHONY: generate-grammar-parser
+generate-grammar-parser:
+ $(EMACS_CMD) -L ~/.emacs.d/emacs-parser-generator/ -l
admin/phps-mode-grammar-parser-generator.el -eval
"(phps-mode-grammar-parser-generator)"
+
.PHONY: compile
compile:
find . -name "*.el" -exec $(EMACS_CMD) -f batch-byte-compile {} \;
diff --git a/admin/phps-mode-grammar-parser-generator.el
b/admin/phps-mode-grammar-parser-generator.el
index fa024e1..cdc6f8e 100644
--- a/admin/phps-mode-grammar-parser-generator.el
+++ b/admin/phps-mode-grammar-parser-generator.el
@@ -26,11 +26,12 @@
(require 'parser-generator-lr)
-(defun phps-mod-grammar-parser-generator()
+(defun phps-mode-grammar-parser-generator()
"Generate parser here."
(parser-generator-set-look-ahead-number
1)
+ (message "set here")
(setq
parser-generator--e-identifier
'%empty)
@@ -48,15 +49,14 @@
nil)
(parser-generator-set-grammar
'(
- (Start Productions-Block Start-Delimiter Productions End-Delimiter
Productions Production LHS RHSS RHS RHS-Symbol Comment Logic Symbol)
- (start-delimiter end-delimiter ":" "|" ";" comment logic symbol)
+ (Start Productions-Block Productions-Delimiter Productions Productions
Production LHS RHSS RHS RHS-Symbol Comment Logic Symbol)
+ (productions-delimiter ":" "|" ";" comment logic symbol)
(
(Start Productions-Block)
- (Productions-Block (Start-Delimiter Productions End-Delimiter))
- (Start-Delimiter start-delimiter)
- (End-Delimiter end-delimiter)
+ (Productions-Block (Productions-Delimiter Productions
Productions-Delimiter))
+ (Productions-Delimiter productions-delimiter)
(Productions Production (Productions Production))
- (Production (LHS ":" RHSS ";"))
+ (Production (Comment Production) (LHS ":" RHSS ";"))
(LHS Symbol)
(RHSS RHS (RHSS "|" RHS))
(RHS RHS-Symbol (RHS RHS-Symbol))
@@ -80,25 +80,82 @@
index)
;; Skip white-space(s)
- (when (looking-at-p "[\t ]+")
+ (when (looking-at-p "[\t\n ]+")
(when
- (search-forward-regexp "[^\t ]" nil t)
+ (search-forward-regexp "[^\t\n ]" nil t)
(forward-char -1)
+ (message "moved to %S" (point))
(setq-local
parser-generator-lex-analyzer--move-to-index-flag
(point))))
(cond
- ((looking-at "\\(/\\*.+\\*/\\)")
- (setq
- token
- `(comment ,(match-beginning 0) . ,(match-end 0))))
-
- ((looking-at "\\({.+}\\)")
+ ((looking-at "\\(/\\*\\)")
+ (let ((comment-start (match-beginning 0))
+ (comment-end
+ (search-forward-regexp "\\(\\*/\\)" nil t)))
+ (unless comment-end
+ (error
+ "Failed to find end of comment started at %S (1)"
+ comment-start))
+ (setq
+ token
+ `(comment ,comment-start . ,comment-end))))
+
+ ((looking-at "\\({\\)")
+ (let ((nesting-stack 1)
+ (logic-start (match-beginning 0))
+ (logic-end)
+ (continue t))
+ (forward-char 1)
+ (while (and
+ continue
+ (> nesting-stack 0)
+ (< (point) (point-max)))
+ (let ((next-stop (search-forward-regexp "\\({\\|}\\|/\\*\\)"
nil t)))
+ (let ((match (buffer-substring-no-properties (match-beginning
0) (match-end 0))))
+ (cond
+
+ ((not next-stop)
+ (setq
+ continue
+ nil))
+
+ ((string= match "{")
+ (setq
+ nesting-stack
+ (1+ nesting-stack)))
+
+ ((string= match "}")
+ (setq
+ nesting-stack
+ (1- nesting-stack))
+ (when
+ (= nesting-stack 0)
+ (setq
+ logic-end
+ (match-end 0))))
+
+ ((string= match "/*")
+ (let (
+ (comment-start (match-beginning 0))
+ (comment-end
+ (search-forward-regexp "\\*/" nil t)))
+ (unless comment-end
+ (error
+ "Failed to find end of comment started at %S (2))"
+ comment-start))))
+
+
+ ))))
+ (unless logic-end
+ (error
+ "Failed to find end of logic started at %S"
+ logic-start))
(setq
token
- `(logic ,(match-beginning 0) . ,(match-end 0))))
+ `(logic ,logic-start . ,logic-end))))
((looking-at "\\(:\\|;\\||\\)")
(setq
@@ -108,10 +165,24 @@
(match-beginning 0)
(match-end 0))
,(match-beginning 0)
- . ,(match-end 0)
- )))
+ . ,(match-end 0))))
+
+ ((looking-at "\\(%%\\)")
+ (setq
+ token
+ `(productions-delimiter ,(match-beginning 0) . ,(match-end 0))))
- (t (error "Unexpected input at %d!" index))))
+ ((looking-at "\\([%a-zA-Z_]+\\|'.{1}'\\)")
+ (setq
+ token
+ `(symbol ,(match-beginning 0) . ,(match-end 0))))))
+
+ (when token
+ (let ((token-data
+ (buffer-substring-no-properties
+ (car (cdr token))
+ (cdr (cdr token)))))
+ (message "Token: %S = %S" token token-data)))
token))))
(setq
@@ -135,8 +206,18 @@
(let ((buffer (generate-new-buffer "*buffer*")))
(switch-to-buffer buffer)
-
- ))
+ (insert-file (expand-file-name "zend_language_parser.y"))
+ (goto-char (point-min))
+ (let ((delimiter-start (search-forward "%%")))
+ (setq
+ delimiter-start
+ (- delimiter-start 2))
+ (kill-region (point-min) delimiter-start))
+ (let ((delimiter-start (search-forward "%%")))
+ (kill-region delimiter-start (point-max)))
+ (goto-char (point-min))
+ (message "Buffer contents:\n\n%S" (buffer-substring-no-properties
(point-min) (point-max)))
+ (parser-generator-lr-parse)))
(provide 'phps-mode-grammar-parser-generator)
;;; phps-mode-grammar-parser-generator.el ends here
- [elpa] externals/phps-mode 0d1843f 20/96: Started on parser integration, (continued)
- [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, 2021/10/29
- [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 <=
- [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
- [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