emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/phps-mode 962e7c8 52/96: Context-sensitive precedence a


From: Christian Johansson
Subject: [elpa] externals/phps-mode 962e7c8 52/96: Context-sensitive precedence attribute is automatically parsed from YACC
Date: Fri, 29 Oct 2021 11:14:45 -0400 (EDT)

branch: externals/phps-mode
commit 962e7c8c14cce27510e31b7dc1a7fe53f425a1b3
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>

    Context-sensitive precedence attribute is automatically parsed from YACC
---
 admin/phps-mode-automation.el            | 11 ++++--
 phps-mode-automation-grammar.el          | 20 +++-------
 phps-mode-automation-parser-generator.el | 63 +++++++++++++++++++++++---------
 3 files changed, 58 insertions(+), 36 deletions(-)

diff --git a/admin/phps-mode-automation.el b/admin/phps-mode-automation.el
index e0fe7cd..93d0322 100644
--- a/admin/phps-mode-automation.el
+++ b/admin/phps-mode-automation.el
@@ -35,7 +35,10 @@
   "Generate parser."
   (if (fboundp 'parser-generator-lr-export-to-elisp)
       (progn
-        ;; TODO Generate precedence here
+        ;; TODO Generate here
+        ;; phps-mode-automation-grammar--global-attributes
+        ;; phps-mode-automation-grammar--lr-global-precedence-attributes
+        ;; phps-mode-automation-grammar--global-declaration
 
         ;; Prepare export
         (when (fboundp 'parser-generator-set-grammar)
@@ -61,6 +64,8 @@
            parser-generator-lex-analyzer--function
            phps-mode-automation-grammar--lex-analyzer-function))
 
+        ;; TODO Make dump of variable above work
+
         (when (boundp 'parser-generator-lex-analyzer--get-function)
           (setq
            parser-generator-lex-analyzer--get-function
@@ -84,12 +89,12 @@
         (when (boundp 'parser-generator--context-sensitive-attributes)
           (setq
            parser-generator--context-sensitive-attributes
-           phps-mode-automation-grammar--context-sensitive-attributes))
+           
phps-mode-automation-parser-generator--context-sensitive-attributes))
 
         (when (boundp 
'parser-generator-lr--context-sensitive-precedence-attribute)
           (setq
            parser-generator-lr--context-sensitive-precedence-attribute
-           
phps-mode-automation-grammar--lr-context-sensitive-precedence-attribute))
+           (car 
phps-mode-automation-parser-generator--context-sensitive-attributes)))
 
         (when (boundp 'parser-generator-lr--precedence-comparison-function)
           (setq
diff --git a/phps-mode-automation-grammar.el b/phps-mode-automation-grammar.el
index f5e63f5..aa1c080 100644
--- a/phps-mode-automation-grammar.el
+++ b/phps-mode-automation-grammar.el
@@ -38,16 +38,6 @@
  "Reversed list of tokens.")
 
 (defvar
-  phps-mode-automation-grammar--context-sensitive-attributes
-  '(%prec)
-  "List of context-sensitive attributes.")
-
-(defvar
-  phps-mode-automation-grammar--lr-context-sensitive-precedence-attribute
-  '%prec
-  "The LR-parser's context-sensitive precedence attribute.")
-
-(defvar
   phps-mode-automation-grammar--global-attributes
   '(%left %nonassoc %precedence %right)
   "List of valid global attributes.")
@@ -58,11 +48,6 @@
   "The LR-parser's list of global precedence attributes.")
 
 (defvar
-  phps-mode-automation-grammar--lr--allow-default-conflict-resolution
-  t
-  "Allow shift resolution to shift/reduce conflicts were precedence is 
missing.")
-
-(defvar
   phps-mode-automation-grammar--global-declaration
   '(
     (%precedence T_THROW)
@@ -101,6 +86,11 @@
   "Declaration for grammar.")
 
 (defvar
+  phps-mode-automation-grammar--lr--allow-default-conflict-resolution
+  t
+  "Allow shift resolution to shift/reduce conflicts were precedence is 
missing.")
+
+(defvar
   phps-mode-automation-grammar--look-ahead-number
   1
   "The look-ahead number of grammar.")
diff --git a/phps-mode-automation-parser-generator.el 
b/phps-mode-automation-parser-generator.el
index 570cf60..f605b41 100644
--- a/phps-mode-automation-parser-generator.el
+++ b/phps-mode-automation-parser-generator.el
@@ -44,6 +44,11 @@
   "Symbols of grammar.")
 
 (defvar
+  phps-mode-automation-parser-generator--context-sensitive-attributes
+  nil
+  "Context-sensitive attributes found in grammar.")
+
+(defvar
   phps-mode-automation-parser-generator--production-lhs
   nil
   "LHS of productions of grammar.")
@@ -58,7 +63,7 @@
     ;; Download YACC if not available
     (unless (file-exists-p php-yacc-file)
       (message
-       "Downloading PHP 8.0 YACC grammar..")
+       "Downloading PHP 8.0 YACC grammar.. since %S does not exists" 
php-yacc-file)
       (url-copy-file
        php-yacc-url php-yacc-file
        t
@@ -89,6 +94,9 @@
   (setq
    phps-mode-automation-parser-generator--symbols
    (make-hash-table :test 'equal))
+  (setq
+   phps-mode-automation-parser-generator--context-sensitive-attributes
+   nil)
 
   (parser-generator-set-look-ahead-number
    1)
@@ -382,23 +390,42 @@
     (goto-char (point-min))
     (let ((productions (eval (car (read-from-string 
(parser-generator-lr-translate))))))
 
-      (maphash
-       (lambda (k _v)
-         (if (gethash
-              k
-              phps-mode-automation-parser-generator--production-lhs)
-             (push
-              k
-              phps-mode-automation-parser-generator--non-terminals)
-           ;; Skip context-sensitive precedence and e-identifier
-           (when
-               (or
-                (stringp k)
-                (not (string-match-p "%" (symbol-name k))))
-             (push
-              k
-              phps-mode-automation-parser-generator--terminals))))
-       phps-mode-automation-parser-generator--symbols)
+      (let ((context-sensitive-attributes)
+            (context-sensitive-attributes-map (make-hash-table :test 'equal)))
+        (maphash
+         (lambda (k _v)
+           (if (gethash
+                k
+                phps-mode-automation-parser-generator--production-lhs)
+               (push
+                k
+                phps-mode-automation-parser-generator--non-terminals)
+
+             ;; Store context-sensitive attributes and terminals
+             (if
+                 (and
+                  (symbolp k)
+                  (string-match-p "%" (symbol-name k)))
+                 (unless
+                     (or
+                      (equal k '%empty)
+                      (gethash
+                       k
+                       context-sensitive-attributes-map))
+                   (push
+                    k
+                    context-sensitive-attributes)
+                   (puthash
+                    k
+                    t
+                    context-sensitive-attributes-map))
+               (push
+                k
+                phps-mode-automation-parser-generator--terminals))))
+         phps-mode-automation-parser-generator--symbols)
+        (setq
+         phps-mode-automation-parser-generator--context-sensitive-attributes
+         context-sensitive-attributes))
 
       (list
        phps-mode-automation-parser-generator--non-terminals



reply via email to

[Prev in Thread] Current Thread [Next in Thread]