[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode 22f0a47 62/96: Parser generator passing byte-
From: |
Christian Johansson |
Subject: |
[elpa] externals/phps-mode 22f0a47 62/96: Parser generator passing byte-compilation |
Date: |
Fri, 29 Oct 2021 11:14:48 -0400 (EDT) |
branch: externals/phps-mode
commit 22f0a471b53892e044651aab7f48ba8ac519553a
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
Parser generator passing byte-compilation
---
admin/phps-mode-automation.el | 22 +-
phps-mode-automation-grammar.el | 5 +
phps-mode-automation-parser-generator.el | 487 ++++++++++++++++---------------
3 files changed, 272 insertions(+), 242 deletions(-)
diff --git a/admin/phps-mode-automation.el b/admin/phps-mode-automation.el
index 7fa5097..eac919e 100644
--- a/admin/phps-mode-automation.el
+++ b/admin/phps-mode-automation.el
@@ -54,17 +54,20 @@
(when (boundp 'parser-generator--context-sensitive-attributes)
(setq
parser-generator--context-sensitive-attributes
- context-sensitive-attributes))
+ context-sensitive-attributes)
+ (message "parser-generator--context-sensitive-attributes: %S"
parser-generator--context-sensitive-attributes))
(when (boundp
'parser-generator-lr--context-sensitive-precedence-attribute)
(setq
parser-generator-lr--context-sensitive-precedence-attribute
- (car context-sensitive-attributes)))
+ (car context-sensitive-attributes))
+ (message
"parser-generator-lr--context-sensitive-precedence-attribute: %S"
parser-generator-lr--context-sensitive-precedence-attribute))
(when (boundp 'parser-generator--global-declaration)
(setq
parser-generator--global-declaration
- global-declaration))
+ global-declaration)
+ (message "parser-generator--global-declaration: %S"
parser-generator--global-declaration))
(when (boundp 'parser-generator--global-attributes)
(setq
@@ -74,13 +77,8 @@
(when (boundp 'parser-generator-lr--global-precedence-attributes)
(setq
parser-generator-lr--global-precedence-attributes
- attributes)))
-
- (message "parser-generator--global-attributes: %S"
parser-generator--global-declaration)
- (message "parser-generator--global-declaration: %S"
parser-generator--global-declaration)
- (message "parser-generator-lr--global-precedence-attributes: %S"
parser-generator-lr--global-precedence-attributes)
- (message "parser-generator-lr--context-sensitive-precedence-attribute:
%S" parser-generator-lr--context-sensitive-precedence-attribute)
- (message "parser-generator--context-sensitive-attributes: %S"
parser-generator--context-sensitive-attributes)
+ attributes)
+ (message "parser-generator-lr--global-precedence-attributes: %S"
parser-generator-lr--global-precedence-attributes)))
(when (fboundp 'parser-generator-set-look-ahead-number)
(parser-generator-set-look-ahead-number
@@ -146,12 +144,16 @@
;; Only generate LR-items, GOTO-tables and ACTION-tables if we are
lacking it
(if (and
+ (boundp 'parser-generator-lr--goto-tables)
(boundp 'parser-generator-lr--goto-tables-resume)
parser-generator-lr--goto-tables-resume
+ (boundp 'parser-generator-lr--distinct-goto-tables)
(boundp 'parser-generator-lr--distinct-goto-tables-resume)
parser-generator-lr--distinct-goto-tables-resume
+ (boundp 'parser-generator-lr--action-tables)
(boundp 'parser-generator-lr--action-tables-resume)
parser-generator-lr--action-tables-resume
+ (boundp 'parser-generator-lr--distinct-action-tables)
(boundp 'parser-generator-lr--distinct-action-tables-resume)
parser-generator-lr--distinct-action-tables-resume)
(progn
diff --git a/phps-mode-automation-grammar.el b/phps-mode-automation-grammar.el
index 2053034..e1c02a5 100644
--- a/phps-mode-automation-grammar.el
+++ b/phps-mode-automation-grammar.el
@@ -48,6 +48,11 @@
"The look-ahead number of grammar.")
(defvar
+ phps-mode-parser-lex-analyzer--move-to-index-flag
+ nil
+ "A dummy flag.")
+
+(defvar
phps-mode-automation-grammar--header
"(require 'phps-mode-lexer)\n(require 'semantic)\n(require
'semantic/lex)\n\n(defvar-local\n phps-mode-parser-position\n nil\n \"Position
of parser.\")\n(defvar-local\n phps-mode-parser-tokens\n nil\n \"Reversed list
of lexer tokens.\")\n"
"Header contents for parser.")
diff --git a/phps-mode-automation-parser-generator.el
b/phps-mode-automation-parser-generator.el
index a513afd..25fc3bf 100644
--- a/phps-mode-automation-parser-generator.el
+++ b/phps-mode-automation-parser-generator.el
@@ -23,6 +23,14 @@
;;; Code:
+
+(autoload 'parser-generator-set-look-ahead-number "parser-generator")
+(autoload 'parser-generator-set-grammar "parser-generator")
+(autoload 'parser-generator-process-grammar "parser-generator")
+
+(autoload 'parser-generator-lr-generate-parser-tables "parser-generator-lr")
+(autoload 'parser-generator-lr-translate "parser-generator-lr")
+
(defvar
phps-mode-automation-parser-generator--attributes
nil
@@ -81,7 +89,6 @@
(defun phps-mode-automation-parser-generator--grammar ()
"Generate productions here."
- (require 'parser-generator-lr)
(phps-mode-automation-parser-generator--ensure-yacc-grammar-is-available)
(setq
@@ -105,21 +112,26 @@
(parser-generator-set-look-ahead-number
1)
- (setq
- parser-generator--e-identifier
- nil)
- (setq
- parser-generator--global-attributes
- nil)
- (setq
- parser-generator-lr--global-precedence-attributes
- nil)
- (setq
- parser-generator-lr--context-sensitive-precedence-attribute
- nil)
- (setq
- parser-generator--global-declaration
- nil)
+ (when (boundp 'parser-generator--e-identifier)
+ (setq
+ parser-generator--e-identifier
+ nil))
+ (when (boundp 'parser-generator--global-attributes)
+ (setq
+ parser-generator--global-attributes
+ nil))
+ (when (boundp 'parser-generator-lr--global-precedence-attributes)
+ (setq
+ parser-generator-lr--global-precedence-attributes
+ nil))
+ (when (boundp 'parser-generator-lr--context-sensitive-precedence-attribute)
+ (setq
+ parser-generator-lr--context-sensitive-precedence-attribute
+ nil))
+ (when (boundp 'parser-generator--global-declaration)
+ (setq
+ parser-generator--global-declaration
+ nil))
(parser-generator-set-grammar
'(
(Start Productions-Block Productions-Delimiter Productions Productions
Production Production-End LHS RHSS RHS RHS-Symbol RHS-Symbols Comment Logic
Symbol)
@@ -239,153 +251,156 @@
)
Start))
- (setq
- parser-generator-lex-analyzer--function
- (lambda (index)
- (with-current-buffer "*buffer*"
- (let ((token))
- (when
- (<
- index
- (point-max))
- (goto-char
- index)
-
- ;; Skip white-space(s)
- (when (looking-at-p "[\t\n ]+")
- (when
- (search-forward-regexp "[^\t\n ]" nil t)
- (forward-char -1)
- (setq-local
- parser-generator-lex-analyzer--move-to-index-flag
- (point))))
-
- (cond
-
- ((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))
+ (when (boundp 'parser-generator-lex-analyzer--function)
+ (setq
+ parser-generator-lex-analyzer--function
+ (lambda (index)
+ (with-current-buffer "*buffer*"
+ (let ((token))
+ (when
+ (<
+ index
+ (point-max))
+ (goto-char
+ index)
+
+ ;; Skip white-space(s)
+ (when (looking-at-p "[\t\n ]+")
+ (when
+ (search-forward-regexp "[^\t\n ]" nil t)
+ (forward-char -1)
+ (when (boundp
'parser-generator-lex-analyzer--move-to-index-flag)
+ (setq-local
+ parser-generator-lex-analyzer--move-to-index-flag
+ (point)))))
+
+ (cond
+
+ ((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
+ (point))))
+
+ ((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 ,logic-start . ,logic-end))))
+
+ ((looking-at "\\(:\\|;\\||\\)")
(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
- (point))))
-
- ((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))
+ `(
+ ,(buffer-substring-no-properties
+ (match-beginning 0)
+ (match-end 0))
+ ,(match-beginning 0)
+ . ,(match-end 0))))
+
+ ((looking-at "\\(%%\\)")
(setq
token
- `(logic ,logic-start . ,logic-end))))
-
- ((looking-at "\\(:\\|;\\||\\)")
- (setq
- token
- `(
- ,(buffer-substring-no-properties
- (match-beginning 0)
- (match-end 0))
- ,(match-beginning 0)
- . ,(match-end 0))))
-
- ((looking-at "\\(%%\\)")
- (setq
- token
- `(productions-delimiter ,(match-beginning 0) . ,(match-end 0))))
-
- ((looking-at "\\(%?[a-zA-Z_]+\\)")
- (setq
- token
- `(symbol ,(match-beginning 0) . ,(match-end 0))))
-
- ((looking-at "\\('.'\\)")
- (setq
- token
- `(literal ,(match-beginning 0) . ,(match-end 0))))
-
- ))
-
- (when token
- (let ((token-data
- (buffer-substring-no-properties
- (car (cdr token))
- (cdr (cdr token)))))
- ;; (message "token-data: %S => %S" token token-data)
- ))
- token))))
+ `(productions-delimiter ,(match-beginning 0) . ,(match-end
0))))
- (setq
- parser-generator-lex-analyzer--get-function
- (lambda (token)
- (with-current-buffer "*buffer*"
- (let ((start (car (cdr token)))
- (end (cdr (cdr token))))
- (when (<= end (point-max))
- (let ((symbol
- (buffer-substring-no-properties start end)))
- (when
- (string-match-p "^\\([0-9]+\\.[0-9]+\\|[0-9]+\\)$" symbol)
+ ((looking-at "\\(%?[a-zA-Z_]+\\)")
(setq
- symbol
- (string-to-number symbol)))
- symbol))))))
+ token
+ `(symbol ,(match-beginning 0) . ,(match-end 0))))
+
+ ((looking-at "\\('.'\\)")
+ (setq
+ token
+ `(literal ,(match-beginning 0) . ,(match-end 0))))
+
+ ))
+
+ (when token
+ (let ((_token-data
+ (buffer-substring-no-properties
+ (car (cdr token))
+ (cdr (cdr token)))))
+ ;; (message "token-data: %S => %S" token _token-data)
+ ))
+ token)))))
+
+ (when (boundp 'parser-generator-lex-analyzer--get-function)
+ (setq
+ parser-generator-lex-analyzer--get-function
+ (lambda (token)
+ (with-current-buffer "*buffer*"
+ (let ((start (car (cdr token)))
+ (end (cdr (cdr token))))
+ (when (<= end (point-max))
+ (let ((symbol
+ (buffer-substring-no-properties start end)))
+ (when
+ (string-match-p "^\\([0-9]+\\.[0-9]+\\|[0-9]+\\)$" symbol)
+ (setq
+ symbol
+ (string-to-number symbol)))
+ symbol)))))))
(parser-generator-process-grammar)
(parser-generator-lr-generate-parser-tables)
(let ((buffer (generate-new-buffer "*buffer*")))
(switch-to-buffer buffer)
- (insert-file (expand-file-name "zend_language_parser.y"))
+ (insert-file-contents (expand-file-name "zend_language_parser.y"))
(goto-char (point-min))
(let ((delimiter-start (search-forward "%%")))
(setq
@@ -454,21 +469,26 @@
(make-hash-table :test 'equal))
(parser-generator-set-look-ahead-number
1)
- (setq
- parser-generator--e-identifier
- nil)
- (setq
- parser-generator--global-attributes
- nil)
- (setq
- parser-generator-lr--global-precedence-attributes
- nil)
- (setq
- parser-generator-lr--context-sensitive-precedence-attribute
- nil)
- (setq
- parser-generator--global-declaration
- nil)
+ (when (boundp 'parser-generator--e-identifier)
+ (setq
+ parser-generator--e-identifier
+ nil))
+ (when (boundp 'parser-generator--global-attributes)
+ (setq
+ parser-generator--global-attributes
+ nil))
+ (when (boundp 'parser-generator-lr--global-precedence-attributes)
+ (setq
+ parser-generator-lr--global-precedence-attributes
+ nil))
+ (when (boundp 'parser-generator-lr--context-sensitive-precedence-attribute)
+ (setq
+ parser-generator-lr--context-sensitive-precedence-attribute
+ nil))
+ (when (boundp 'parser-generator--global-declaration)
+ (setq
+ parser-generator--global-declaration
+ nil))
(parser-generator-set-grammar
'(
(Start Declarations-Block Declarations Declaration Type Symbols Symbol)
@@ -522,82 +542,85 @@
)
Start))
- (setq
- parser-generator-lex-analyzer--function
- (lambda (index)
- (with-current-buffer "*buffer*"
- (let ((token))
- (when
- (<
- index
- (point-max))
- (goto-char
- index)
-
- ;; Skip white-space(s)
- (when (looking-at-p "[\t\n ]+")
- (when
- (search-forward-regexp "[^\t\n ]" nil t)
- (forward-char -1)
- (setq-local
- parser-generator-lex-analyzer--move-to-index-flag
- (point))))
-
- (cond
-
- ((looking-at "\\(%[a-z]+\\)")
- (setq
- token
- `(type ,(match-beginning 0) . ,(match-end 0))))
-
- ((looking-at "\\('.'\\)")
- (setq
- token
- `(literal ,(match-beginning 0) . ,(match-end 0))))
-
- ((looking-at "\\([a-zA-Z_]+\\)")
- (setq
- token
- `(symbol ,(match-beginning 0) . ,(match-end 0))))
-
- ((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))
+ (when (boundp 'parser-generator-lex-analyzer--function)
+ (setq
+ parser-generator-lex-analyzer--function
+ (lambda (index)
+ (with-current-buffer "*buffer*"
+ (let ((token))
+ (when
+ (<
+ index
+ (point-max))
+ (goto-char
+ index)
+
+ ;; Skip white-space(s)
+ (when (looking-at-p "[\t\n ]+")
+ (when
+ (search-forward-regexp "[^\t\n ]" nil t)
+ (forward-char -1)
+ (when (boundp
'parser-generator-lex-analyzer--move-to-index-flag)
+ (setq-local
+ parser-generator-lex-analyzer--move-to-index-flag
+ (point)))))
+
+ (cond
+
+ ((looking-at "\\(%[a-z]+\\)")
(setq
token
- `(comment ,comment-start . ,comment-end))))
-
- ))
+ `(type ,(match-beginning 0) . ,(match-end 0))))
- (when token
- (let ((token-data
- (buffer-substring-no-properties
- (car (cdr token))
- (cdr (cdr token)))))
- ;; (message "token-data: %S" token-data)
- ))
- token))))
+ ((looking-at "\\('.'\\)")
+ (setq
+ token
+ `(literal ,(match-beginning 0) . ,(match-end 0))))
- (setq
- parser-generator-lex-analyzer--get-function
- (lambda (token)
- (with-current-buffer "*buffer*"
- (let ((start (car (cdr token)))
- (end (cdr (cdr token))))
- (when (<= end (point-max))
- (buffer-substring-no-properties start end))))))
+ ((looking-at "\\([a-zA-Z_]+\\)")
+ (setq
+ token
+ `(symbol ,(match-beginning 0) . ,(match-end 0))))
+
+ ((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))))
+
+ ))
+
+ (when token
+ (let ((_token-data
+ (buffer-substring-no-properties
+ (car (cdr token))
+ (cdr (cdr token)))))
+ ;; (message "token-data: %S" token-data)
+ ))
+ token)))))
+
+ (when (boundp 'parser-generator-lex-analyzer--get-function)
+ (setq
+ parser-generator-lex-analyzer--get-function
+ (lambda (token)
+ (with-current-buffer "*buffer*"
+ (let ((start (car (cdr token)))
+ (end (cdr (cdr token))))
+ (when (<= end (point-max))
+ (buffer-substring-no-properties start end)))))))
(parser-generator-process-grammar)
(parser-generator-lr-generate-parser-tables)
(let ((buffer (generate-new-buffer "*buffer*")))
(switch-to-buffer buffer)
- (insert-file (expand-file-name "zend_language_parser.y"))
+ (insert-file-contents (expand-file-name "zend_language_parser.y"))
(goto-char (point-min))
(let ((delimiter-start (search-forward "%precedence")))
(setq
- [elpa] externals/phps-mode 6b3a298 29/96: More work on parsers lex-analyzer refactor, (continued)
- [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, 2021/10/29
- [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 <=
- [elpa] externals/phps-mode 751bece 50/96: Removed terminals, non-terminals and start from automation grammar, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode 4dbd9a2 54/96: Automatically parsing of global declaration from YACC, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode 024e8d4 55/96: Setting up context-sensitive attributes automatically, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode 605b76c 57/96: Removed note, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode 20ad000 68/96: Added another TODO item, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode a6c5db1 45/96: Updated grammar productions based on automatically parsed grammar from YACC, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode 2ac480a 47/96: Started on automatic generation of terminals, non-terminals and start as well, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode eb17d8c 51/96: Improved resuming of parser-generation, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode 6af98c4 56/96: Productions are now read automatically again, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode 212fd7f 63/96: Fixed warning in byte-compilation, Christian Johansson, 2021/10/29