branch: externals/phps-mode
commit 648d390ad40d12bdfc8d097064898a32deca1058
Author: Christian Johansson <christ...@cvj.se>
Commit: Christian Johansson <christ...@cvj.se>

    Updated parser to PHP 8.4
---
 phps-mode-parser.el | 66 +++++++++++------------------------------------------
 1 file changed, 13 insertions(+), 53 deletions(-)

diff --git a/phps-mode-parser.el b/phps-mode-parser.el
index 637f0161c1..8c28514343 100644
--- a/phps-mode-parser.el
+++ b/phps-mode-parser.el
@@ -23,42 +23,42 @@
 
 (defvar
   phps-mode-parser--action-tables
-  #s(hash-table size 42072 test equal rehash-size 1.5 rehash-threshold 0.8125 
data (0 0 1 1 2 2 3 3 4 4 5 2 6 2 7 2 8 8 9 2 10 10 11 11 12 2 13 13 14 2 15 15 
16 16 17 17 18 2 19 16 20 20 21 15 22 22 23 11 24 24 25 25 26 26 27 2 28 2 29 
11 30 16 31 11 32 32 33 33 34 34 35 35 36 11 37 11 38 38 39 39 40 40 41 16 42 
11 43 11 44 22 45 2 46 2 47 47 48 16 49 2 50 11 51 51 52 11 53 53 54 11 55 55 
56 56 57 57 58 58 59 59 60 60 61 61 62 2 63 2 64 64 65 2 66 2 67 15 68 68 69 69 
70 70 71 2 72 11 73  [...]
+  #s(hash-table size 42072 test equal rehash-size 1.5 rehash-threshold 0.8125 
data (0 0 1 1 2 2 3 3 4 4 5 2 6 2 7 2 8 8 9 2 10 10 11 11 12 2 13 13 14 2 15 15 
16 16 17 17 18 2 19 16 20 20 21 15 22 22 23 11 24 24 25 25 26 26 27 2 28 2 29 
11 30 16 31 11 32 32 33 33 34 34 35 35 36 11 37 11 38 38 39 39 40 40 41 16 42 
11 43 11 44 22 45 2 46 2 47 47 48 16 49 2 50 11 51 51 52 11 53 53 54 11 55 55 
56 56 57 57 58 58 59 59 60 60 61 61 62 2 63 2 64 64 65 65 66 2 67 2 68 15 69 69 
70 70 71 71 72 2 73  [...]
   "The generated action-tables.")
 
 (defvar
   phps-mode-parser--distinct-action-tables
-  #s(hash-table size 12466 test equal rehash-size 1.5 rehash-threshold 0.8125 
data (0 ((("!") reduce 84) (("\"") reduce 84) (($) reduce 84) (("$") reduce 84) 
(("(") reduce 84) (("+") reduce 84) (("-") reduce 84) ((";") reduce 84) (("@") 
reduce 84) ((T_ABSTRACT) reduce 84) ((T_ARRAY) reduce 84) ((T_ARRAY_CAST) 
reduce 84) ((T_ATTRIBUTE) reduce 84) ((T_BOOL_CAST) reduce 84) ((T_BREAK) 
reduce 84) ((T_CLASS) reduce 84) ((T_CLASS_C) reduce 84) ((T_CLONE) reduce 84) 
((T_CONST) reduce 84) ((T_CO [...]
+  #s(hash-table size 12466 test equal rehash-size 1.5 rehash-threshold 0.8125 
data (0 ((("!") reduce 85) (("\"") reduce 85) (($) reduce 85) (("$") reduce 85) 
(("(") reduce 85) (("+") reduce 85) (("-") reduce 85) ((";") reduce 85) (("@") 
reduce 85) ((T_ABSTRACT) reduce 85) ((T_ARRAY) reduce 85) ((T_ARRAY_CAST) 
reduce 85) ((T_ATTRIBUTE) reduce 85) ((T_BOOL_CAST) reduce 85) ((T_BREAK) 
reduce 85) ((T_CLASS) reduce 85) ((T_CLASS_C) reduce 85) ((T_CLONE) reduce 85) 
((T_CONST) reduce 85) ((T_CO [...]
   "The generated distinct action-tables.")
 
 (defvar
   phps-mode-parser--goto-tables
-  #s(hash-table size 42072 test equal rehash-size 1.5 rehash-threshold 0.8125 
data (0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 8 11 10 12 11 13 12 14 13 15 
14 16 15 17 8 18 16 19 17 20 8 21 18 22 19 23 20 24 8 25 8 26 21 27 22 28 23 29 
24 30 25 31 26 32 27 33 8 34 8 35 8 36 28 37 29 38 8 39 8 40 30 41 31 42 32 43 
33 44 34 45 35 46 36 47 8 48 37 49 38 50 39 51 8 52 40 53 8 54 41 55 8 56 42 57 
8 58 8 59 8 60 43 61 8 62 44 63 45 64 46 65 47 66 48 67 49 68 50 69 51 70 52 71 
53 72 54 73 55 74 [...]
+  #s(hash-table size 42072 test equal rehash-size 1.5 rehash-threshold 0.8125 
data (0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 8 11 10 12 11 13 12 14 13 15 
14 16 15 17 8 18 16 19 17 20 8 21 18 22 19 23 20 24 8 25 8 26 21 27 22 28 23 29 
24 30 25 31 26 32 27 33 8 34 8 35 8 36 28 37 29 38 8 39 8 40 30 41 31 42 32 43 
33 44 34 45 35 46 36 47 8 48 37 49 38 50 39 51 8 52 40 53 8 54 41 55 8 56 42 57 
8 58 8 59 8 60 43 61 8 62 44 63 45 64 8 65 46 66 47 67 48 68 49 69 50 70 51 71 
52 72 53 73 54 74  [...]
   "The generated goto-tables.")
 
 (defvar
   phps-mode-parser--distinct-goto-tables
-  #s(hash-table size 18699 test equal rehash-size 1.5 rehash-threshold 0.8125 
data (0 ((top_statement_list 1)) 1 (("!" 2) ("\"" 3) ("$" 4) ("(" 5) ("+" 6) 
("-" 7) (";" 8) ("@" 9) (T_ABSTRACT 10) (T_ARRAY 11) (T_ARRAY_CAST 12) 
(T_ATTRIBUTE 13) (T_BOOL_CAST 14) (T_BREAK 15) (T_CLASS 16) (T_CLASS_C 17) 
(T_CLONE 18) (T_CONST 19) (T_CONSTANT_ENCAPSED_STRING 20) (T_CONTINUE 21) 
(T_DEC 22) (T_DECLARE 23) (T_DIR 24) (T_DNUMBER 25) (T_DO 26) (T_DOUBLE_CAST 
27) (T_ECHO 28) (T_EMPTY 29) (T_ENUM 30) [...]
+  #s(hash-table size 18699 test equal rehash-size 1.5 rehash-threshold 0.8125 
data (0 ((top_statement_list 1)) 1 (("!" 2) ("\"" 3) ("$" 4) ("(" 5) ("+" 6) 
("-" 7) (";" 8) ("@" 9) (T_ABSTRACT 10) (T_ARRAY 11) (T_ARRAY_CAST 12) 
(T_ATTRIBUTE 13) (T_BOOL_CAST 14) (T_BREAK 15) (T_CLASS 16) (T_CLASS_C 17) 
(T_CLONE 18) (T_CONST 19) (T_CONSTANT_ENCAPSED_STRING 20) (T_CONTINUE 21) 
(T_DEC 22) (T_DECLARE 23) (T_DIR 24) (T_DNUMBER 25) (T_DO 26) (T_DOUBLE_CAST 
27) (T_ECHO 28) (T_EMPTY 29) (T_ENUM 30) [...]
   "The generated distinct goto-tables.")
 
 (defvar
   phps-mode-parser--table-productions-number-reverse
-  #s(hash-table size 730 test equal rehash-size 1.5 rehash-threshold 0.8125 
data (0 ((start) (top_statement_list)) 1 ((reserved_non_modifiers) (T_INCLUDE)) 
2 ((reserved_non_modifiers) (T_INCLUDE_ONCE)) 3 ((reserved_non_modifiers) 
(T_EVAL)) 4 ((reserved_non_modifiers) (T_REQUIRE)) 5 ((reserved_non_modifiers) 
(T_REQUIRE_ONCE)) 6 ((reserved_non_modifiers) (T_LOGICAL_OR)) 7 
((reserved_non_modifiers) (T_LOGICAL_XOR)) 8 ((reserved_non_modifiers) 
(T_LOGICAL_AND)) 9 ((reserved_non_modifiers) (T_ [...]
+  #s(hash-table size 730 test equal rehash-size 1.5 rehash-threshold 0.8125 
data (0 ((start) (top_statement_list)) 1 ((reserved_non_modifiers) (T_INCLUDE)) 
2 ((reserved_non_modifiers) (T_INCLUDE_ONCE)) 3 ((reserved_non_modifiers) 
(T_EVAL)) 4 ((reserved_non_modifiers) (T_REQUIRE)) 5 ((reserved_non_modifiers) 
(T_REQUIRE_ONCE)) 6 ((reserved_non_modifiers) (T_LOGICAL_OR)) 7 
((reserved_non_modifiers) (T_LOGICAL_XOR)) 8 ((reserved_non_modifiers) 
(T_LOGICAL_AND)) 9 ((reserved_non_modifiers) (T_ [...]
   "The hash-table indexed by production-number and value is production.")
 
 (defvar
   phps-mode-parser--table-look-aheads
-  #s(hash-table size 217 test equal rehash-size 1.5 rehash-threshold 0.8125 
data (("!") t ("\"") t ($) t ("$") t ("%") t ("(") t (")") t ("*") t ("+") t 
(",") t ("-") t (".") t ("/") t (":") t (";") t ("<") t ("=") t (">") t ("?") t 
("@") t (PREC_ARROW_FUNCTION) t (T_ABSTRACT) t 
(T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG) t 
(T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG) t (T_AND_EQUAL) t (T_ARRAY) t 
(T_ARRAY_CAST) t (T_AS) t (T_ATTRIBUTE) t (T_BOOLEAN_AND) t (T_BOOLEAN_OR) t 
(T_BOOL_CAST) t (T_ [...]
+  #s(hash-table size 217 test equal rehash-size 1.5 rehash-threshold 0.8125 
data (("!") t ("\"") t ($) t ("$") t ("%") t ("(") t (")") t ("*") t ("+") t 
(",") t ("-") t (".") t ("/") t (":") t (";") t ("<") t ("=") t (">") t ("?") t 
("@") t (PREC_ARROW_FUNCTION) t (T_ABSTRACT) t 
(T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG) t 
(T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG) t (T_AND_EQUAL) t (T_ARRAY) t 
(T_ARRAY_CAST) t (T_AS) t (T_ATTRIBUTE) t (T_BOOLEAN_AND) t (T_BOOLEAN_OR) t 
(T_BOOL_CAST) t (T_ [...]
   "The hash-table of valid look-aheads.")
 
 (defvar
   phps-mode-parser--table-terminal-p
-  #s(hash-table size 217 test equal rehash-size 1.5 rehash-threshold 0.8125 
data (T_NUM_STRING t T_CURLY_OPEN t T_STRING_VARNAME t 
T_DOLLAR_OPEN_CURLY_BRACES t "$" t T_NULLSAFE_OBJECT_OPERATOR t 
T_OBJECT_OPERATOR t T_END_HEREDOC t T_START_HEREDOC t T_DNUMBER t T_LNUMBER t 
"\"" t T_CONSTANT_ENCAPSED_STRING t T_ENCAPSED_AND_WHITESPACE t 
PREC_ARROW_FUNCTION t T_YIELD_FROM t "`" t "@" t T_UNSET_CAST t T_BOOL_CAST t 
T_OBJECT_CAST t T_ARRAY_CAST t T_STRING_CAST t T_DOUBLE_CAST t T_INT_CAST t T 
[...]
+  #s(hash-table size 217 test equal rehash-size 1.5 rehash-threshold 0.8125 
data (T_NUM_STRING t T_CURLY_OPEN t T_STRING_VARNAME t 
T_DOLLAR_OPEN_CURLY_BRACES t "$" t T_NULLSAFE_OBJECT_OPERATOR t 
T_OBJECT_OPERATOR t T_END_HEREDOC t T_START_HEREDOC t T_DNUMBER t T_LNUMBER t 
"\"" t T_CONSTANT_ENCAPSED_STRING t T_ENCAPSED_AND_WHITESPACE t 
PREC_ARROW_FUNCTION t T_YIELD_FROM t "`" t "@" t T_UNSET_CAST t T_BOOL_CAST t 
T_OBJECT_CAST t T_ARRAY_CAST t T_STRING_CAST t T_DOUBLE_CAST t T_INT_CAST t T 
[...]
   "The hash-table of valid terminals.")
 
 (defvar
   phps-mode-parser--table-non-terminal-p
-  #s(hash-table size 217 test equal rehash-size 1.5 rehash-threshold 0.8125 
data (isset_variable t isset_variables t encaps_var_offset t encaps_var t 
possible_array_pair t array_pair t non_empty_array_pair_list t static_member t 
function_call t property_name t array_object_dereferenceable t 
callable_variable t fully_dereferenceable t class_constant t constant t 
dereferenceable_scalar t encaps_list t new_variable t callable_expr t 
variable_class_name t member_name t lexical_var t lexical_ [...]
+  #s(hash-table size 217 test equal rehash-size 1.5 rehash-threshold 0.8125 
data (isset_variable t isset_variables t encaps_var_offset t encaps_var t 
possible_array_pair t array_pair t non_empty_array_pair_list t static_member t 
function_call t property_name t array_object_dereferenceable t 
callable_variable t fully_dereferenceable t class_constant t constant t 
dereferenceable_scalar t encaps_list t new_variable t callable_expr t 
variable_class_name t member_name t lexical_var t lexical_ [...]
   "The hash-table of valid non-terminals.")
 
 (defvar
@@ -88,7 +88,7 @@
 
 (defvar
   phps-mode-parser-lex-analyzer--state-init
-  (list 'ST_INITIAL)
+  nil
   "Initial value of state.")
 
 
@@ -121,41 +121,7 @@
 
 (defvar
   phps-mode-parser-lex-analyzer--function
-  (lambda (index old-state)
-    (let* ((lexer-response
-            (phps-mode-lexer--re2c index old-state))
-          (tokens
-            (nth 0 lexer-response))
-          (move-to-index
-            (nth 1 lexer-response))
-          (new-state
-            (nth 2 lexer-response)))
-
-
-        (unless move-to-index
-          (let ((token-type (car (car tokens))))
-            (cond
-
-              ((or
-                (equal token-type 'T_OPEN_TAG)
-                (equal token-type 'T_COMMENT)
-                (equal token-type 'T_DOC_COMMENT)
-              )
-                (setq
-                  move-to-index
-                  (cdr (cdr (car tokens)))))
-
-              ((equal token-type 'T_OPEN_TAG_WITH_ECHO)
-                (setf (car (car tokens)) 'T_ECHO))
-
-              ((equal token-type 'T_CLOSE_TAG)
-                (setf (car (car tokens)) ";"))
-
-              )
-
-            ))
-
-      (list tokens move-to-index new-state)))
+  (lambda (index old-state) (let* ((lexer-response (phps-mode-lexer--re2c 
index old-state)) (tokens (nth 0 lexer-response)) (move-to-index (nth 1 
lexer-response)) (new-state (nth 2 lexer-response))) (if move-to-index nil (let 
((token-type (car (car tokens)))) (cond ((or (equal token-type 'T_OPEN_TAG) 
(equal token-type 'T_COMMENT) (equal token-type 'T_DOC_COMMENT)) (setq 
move-to-index (cdr (cdr (car tokens))))) ((equal token-type 
'T_OPEN_TAG_WITH_ECHO) (let* ((v (car tokens))) (setcar v ' [...]
   "The lex-analyzer function.")
 
 (defvar
@@ -186,8 +152,6 @@
         "Lex-analyze failed to get token meta-data of %s, error: %s"
         token
         (car (cdr error)))))
-    (unless meta-information
-      (error "Could not find any token meta-information for: %s" token))
     meta-information))
 
 (defun
@@ -705,10 +669,6 @@
                               (if
                                   
(phps-mode-parser--get-grammar-translation-by-number
                                    production-number)
-                                   (progn
-                                  ;; (message "Translation: %s" 
production-number)
-                                  ;; (message "args: %S" 
popped-items-meta-contents)
-                                  ;; (message "terminals: %S" 
popped-items-terminals)
                                   (let ((partial-translation
                                          (funcall
                                           
(phps-mode-parser--get-grammar-translation-by-number
@@ -734,7 +694,7 @@
                                          translation-symbol-table)
                                         (setq
                                          translation
-                                         partial-translation)))))
+                                         partial-translation))))
 
                                 ;; When no translation is specified just use 
popped contents as translation
                                 (let ((partial-translation
@@ -832,8 +792,8 @@
      output
      translation
      history)
-  "Perform a LR-parse via lex-analyzer, optionally at INPUT-TAPE-INDEX
-  with PUSHDOWN-LIST, OUTPUT, TRANSLATION and HISTORY."
+  "Perform a LR-parse via lex-analyzer, optionally at INPUT-TAPE-INDEX with
+  PUSHDOWN-LIST, OUTPUT, TRANSLATION and HISTORY."
   (let ((result
          (phps-mode-parser--parse
           nil

Reply via email to