branch: externals/phps-mode commit f7c261cee1cb920502919fae10b750b33208fecb Author: Christian Johansson <christ...@cvj.se> Commit: Christian Johansson <christ...@cvj.se>
Generate parser command now compatible with latest emacs-parser-generator --- admin/phps-mode-automation.el | 17 ++++++---- phps-mode-automation-parser-generator.el | 54 ++++++++++++++++---------------- 2 files changed, 38 insertions(+), 33 deletions(-) diff --git a/admin/phps-mode-automation.el b/admin/phps-mode-automation.el index 35e8fdc7e1..2f23f1754d 100644 --- a/admin/phps-mode-automation.el +++ b/admin/phps-mode-automation.el @@ -20,9 +20,15 @@ ;;; Commentary: -;;; Uses a parser to convert LALR Yacc grammar to Wisent grammar +;;; Uses a parser-generator library to convert LALR(1) YACC grammar into a Canonical LR(1) Parser -;;; AST should be like this: (root (block (rule (logic)))) +;; This does not work if some variables are byte-compiled +;; therefore we delete byte-compiled files in `make parser' command + +;; To resume use command: `make parser &> output.txt' +;; and to extract Emacs-Lisp data to separate file run `cat output.txt | grep -F "-resume" - > resume.el' +;; and then to resume parser-generation run +;; `emacs -Q -batch -L . -L ~/.emacs.d/emacs-parser-generator -l phps-mode-lexer.el -l admin/phps-mode-automation.el -eval "(progn (require 'parser-generator-lr)(require 'parser-generator-lr-export))" -l resume.el -eval "(phps-mode-automation)"' ;;; Code: @@ -199,18 +205,17 @@ "(setq parser-generator-lr--distinct-action-tables-resume %S)" parser-generator-lr--distinct-action-tables)))))))) - ;; NOTE This does not work if functions above are byte-compiled - ;; Export (let ((export (parser-generator-lr-export-to-elisp "phps-mode-parser" phps-mode-automation-grammar--header - phps-mode-automation-grammar--copyright))) + phps-mode-automation-grammar--copyright)) + (parser-file-name (expand-file-name "./phps-mode-parser.el"))) (generate-new-buffer "*PHP Parser*") (switch-to-buffer "*PHP Parser*") (insert export) - (write-file (expand-file-name "./phps-mode-parser.el")) + (write-file parser-file-name) (kill-buffer) (message "export: %s" export)) diff --git a/phps-mode-automation-parser-generator.el b/phps-mode-automation-parser-generator.el index 5a18d8717f..c6cfaafc5d 100644 --- a/phps-mode-automation-parser-generator.el +++ b/phps-mode-automation-parser-generator.el @@ -141,23 +141,23 @@ Productions-Block) (Productions-Block (Productions-Delimiter Productions Productions-Delimiter - (lambda(args) (format "'(\n\n%s\n\n)" (nth 1 args)))) + (lambda(args _terminals) (format "'(\n\n%s\n\n)" (nth 1 args)))) ) (Productions-Delimiter (productions-delimiter - (lambda(args) "")) + (lambda(args _terminals) "")) ) (Productions (Production - (lambda(args) (format "%s" args))) + (lambda(args _terminals) (format "%s" args))) (Productions Production - (lambda(args) (format "%s\n\n%s" (nth 0 args) (nth 1 args)))) + (lambda(args _terminals) (format "%s\n\n%s" (nth 0 args) (nth 1 args)))) ) (Production (Comment Production - (lambda(args) (format "%s" (nth 1 args)))) + (lambda(args _terminals) (format "%s" (nth 1 args)))) (LHS ":" RHSS Production-End - (lambda(args) + (lambda(args _terminals) ;; Store distinct LHS (unless (gethash (intern (nth 0 args)) @@ -180,19 +180,19 @@ (";" ";")) (LHS (Symbol - (lambda(args) (format "%s" args))) + (lambda(args _terminals) (format "%s" args))) ) (RHSS (RHS - (lambda(args) (format "%s" args))) + (lambda(args _terminals) (format "%s" args))) (RHSS "|" RHS - (lambda(args) (format "%s\n %s" (nth 0 args) (nth 2 args)))) + (lambda(args _terminals) (format "%s\n %s" (nth 0 args) (nth 2 args)))) ) (RHS (RHS-Symbol - (lambda(args) (format "%s" args))) + (lambda(args _terminals) (format "%s" args))) (RHS-Symbols - (lambda(args) + (lambda(args _terminals) (if (string-match-p " " args) (format "(%s)" args) (format "%s" args)))) @@ -200,13 +200,13 @@ (RHS-Symbols (RHS-Symbol RHS-Symbols - (lambda (args) + (lambda (args _terminals) (if (string= (nth 1 args) "") (format "%s" (nth 0 args)) (format "%s %s" (nth 0 args) (nth 1 args))))) (RHS-Symbol RHS-Symbol - (lambda (args) + (lambda (args _terminals) (if (string= (nth 1 args) "") (format "%s" (nth 0 args)) (format "%s %s" (nth 0 args) (nth 1 args))))) @@ -217,14 +217,14 @@ Symbol) (Comment (comment - (lambda(args) ""))) + (lambda(args _terminals) ""))) (Logic (logic - (lambda(args) "")) + (lambda(args _terminals) "")) ) (Symbol (symbol - (lambda(args) + (lambda(args _terminals) ;; Store distinct symbols (unless (gethash (intern args) @@ -236,7 +236,7 @@ (format "%s" args))) (literal - (lambda(args) + (lambda(args _terminals) ;; Store distinct symbols (unless (gethash (format "%s" (substring args 1 2)) @@ -492,23 +492,23 @@ ) (Declarations-Block (Declarations - (lambda(args) + (lambda(args _terminals) (format "'(\n%s)" args)))) (Declarations (Declaration - (lambda(args) (format "%s" args))) + (lambda(args _terminals) (format "%s" args))) (Declaration Declarations - (lambda(args) (format "%s%s" (nth 0 args) (nth 1 args)))) + (lambda(args _terminals) (format "%s%s" (nth 0 args) (nth 1 args)))) ) (Declaration (comment - (lambda(args) "")) + (lambda(args _terminals) "")) (Type Symbols - (lambda(args) (format " (%s %s)\n" (nth 0 args) (nth 1 args)))) + (lambda(args _terminals) (format " (%s %s)\n" (nth 0 args) (nth 1 args)))) ) (Type (type - (lambda(args) + (lambda(args _terminals) (unless (gethash args @@ -521,15 +521,15 @@ ) (Symbols (Symbol - (lambda(args) (format "%s" args))) + (lambda(args _terminals) (format "%s" args))) (Symbol Symbols - (lambda(args) (format "%s %s" (nth 0 args) (nth 1 args)))) + (lambda(args _terminals) (format "%s %s" (nth 0 args) (nth 1 args)))) ) (Symbol (symbol - (lambda(args) (format "%s" args))) + (lambda(args _terminals) (format "%s" args))) (literal - (lambda(args) + (lambda(args _terminals) (format "\"%s\"" (substring args 1 2)))) ) )