branch: externals/phps-mode commit 3824d7d24b396b2b64adf687ab9a2eb6f252cbc9 Author: Christian Johansson <christ...@cvj.se> Commit: Christian Johansson <christ...@cvj.se>
More work on automatically parsing YACC grammar --- admin/phps-mode-automation.el | 303 ++++---- admin/phps-mode-grammar-parser-generator.el | 290 -------- phps-mode-automation-grammar.el | 1014 --------------------------- 3 files changed, 144 insertions(+), 1463 deletions(-) diff --git a/admin/phps-mode-automation.el b/admin/phps-mode-automation.el index b8ff9fe..a51318e 100644 --- a/admin/phps-mode-automation.el +++ b/admin/phps-mode-automation.el @@ -27,172 +27,157 @@ ;;; Code: + (require 'phps-mode-automation-grammar) +(require 'phps-mode-automation-parser-generator) (defun phps-mode-automation () "Generate parser." - (when (fboundp 'parser-generator-lr-export-to-elisp) - - (let ((php-yacc-url "https://raw.githubusercontent.com/php/php-src/php-8.0.0/Zend/zend_language_parser.y") - (php-yacc-file (expand-file-name "zend_language_parser.y"))) - - ;; Download Yacc if not available - (unless (file-exists-p php-yacc-file) - (message "Downloading PHP 8.0 YACC grammar..") - (url-copy-file - php-yacc-url php-yacc-file - t - t) - (message "Download of PHP 8.0 YACC grammar completed")) - - ;; TODO Generate precedence, non-terminals, terminals, productions and start here - - ;; Prepare export - (when (fboundp 'parser-generator-set-grammar) - (parser-generator-set-grammar - `( - ,phps-mode-automation-grammar--non-terminals - ,phps-mode-automation-grammar--terminals - ,phps-mode-automation-grammar--productions - ,phps-mode-automation-grammar--start - ) - )) - - (when (fboundp 'parser-generator-set-look-ahead-number) - (parser-generator-set-look-ahead-number - phps-mode-automation-grammar--look-ahead-number)) - - (when (boundp 'parser-generator--e-identifier) - (setq - parser-generator--e-identifier - phps-mode-automation-grammar--e-identifier)) - - (when (boundp 'parser-generator--eof-identifier) - (setq - parser-generator--eof-identifier - phps-mode-automation-grammar--eof-identifier)) - - (when (boundp 'parser-generator-lex-analyzer--function) - (setq - parser-generator-lex-analyzer--function - phps-mode-automation-grammar--lex-analyzer-function)) - - (when (boundp 'parser-generator-lex-analyzer--get-function) - (setq - parser-generator-lex-analyzer--get-function - phps-mode-automation-grammar--lex-analyzer-get-function)) - - (when (boundp 'parser-generator--global-attributes) - (setq - parser-generator--global-attributes - phps-mode-automation-grammar--global-attributes)) - - (when (boundp 'parser-generator-lr--global-precedence-attributes) - (setq - parser-generator-lr--global-precedence-attributes - phps-mode-automation-grammar--lr-global-precedence-attributes)) - - (when (boundp 'parser-generator-lr--allow-default-conflict-resolution) - (setq - parser-generator-lr--allow-default-conflict-resolution - phps-mode-automation-grammar--lr--allow-default-conflict-resolution)) - - (when (boundp 'parser-generator--context-sensitive-attributes) - (setq - parser-generator--context-sensitive-attributes - phps-mode-automation-grammar--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)) - - (when (boundp 'parser-generator-lr--precedence-comparison-function) - (setq - parser-generator-lr--precedence-comparison-function - phps-mode-automation-grammar--precedence-comparison-function)) - - (when (boundp 'parser-generator--global-declaration) - (setq - parser-generator--global-declaration - phps-mode-automation-grammar--global-declaration)) - - (when (fboundp 'parser-generator-process-grammar) - (parser-generator-process-grammar)) - - (when (fboundp 'parser-generator-lr--generate-precedence-tables) - (parser-generator-lr--generate-precedence-tables) - (message "Precedence Tables") - (when (boundp 'parser-generator-lr--symbol-precedence-value) - (message - "parser-generator-lr--symbol-precedence-value: %S" - parser-generator-lr--symbol-precedence-value)) - (when (boundp 'parser-generator-lr--symbol-precedence-type) - (message - "parser-generator-lr--symbol-precedence-type: %S" - parser-generator-lr--symbol-precedence-type)) - (when (boundp 'parser-generator-lr--production-number-precedence-value) - (message - "parser-generator-lr--production-number-precedence-value: %S" - parser-generator-lr--production-number-precedence-value)) - (when (boundp 'parser-generator-lr--production-number-precedence-type) - (message - "parser-generator-lr--production-number-precedence-type: %S" - parser-generator-lr--production-number-precedence-type)) - - ;; Only generate LR-items, GOTO-tables and ACTION-tables if we are lacking it - (if (and - (boundp 'parser-generator-lr--goto-tables) - parser-generator-lr--goto-tables - (boundp 'parser-generator-lr--distinct-goto-tables) - parser-generator-lr--distinct-goto-tables - (boundp 'parser-generator-lr--action-tables) - parser-generator-lr--action-tables - (boundp 'parser-generator-lr--distinct-action-tables) - parser-generator-lr--distinct-action-tables) - (message "Parser tables are defined - skipping generation") - (progn - (message "Parser tables are not defined - generating..") - (when (fboundp 'parser-generator-lr--generate-goto-tables) - (let ((table-lr-items - (parser-generator-lr--generate-goto-tables))) - (message - "table-lr-items: %S" - table-lr-items) - (when (boundp 'parser-generator-lr--goto-tables) - (message - "parser-generator-lr--goto-tables: %S" - parser-generator-lr--goto-tables)) - (when (boundp 'parser-generator-lr--distinct-goto-tables) + (if (fboundp 'parser-generator-lr-export-to-elisp) + (progn + ;; TODO Generate precedence, non-terminals, terminals and start here + + ;; Prepare export + (when (fboundp 'parser-generator-set-grammar) + (parser-generator-set-grammar + (phps-mode-automation-parser-generator--grammar))) + + (when (fboundp 'parser-generator-set-look-ahead-number) + (parser-generator-set-look-ahead-number + phps-mode-automation-grammar--look-ahead-number)) + + (when (boundp 'parser-generator--e-identifier) + (setq + parser-generator--e-identifier + phps-mode-automation-grammar--e-identifier)) + + (when (boundp 'parser-generator--eof-identifier) + (setq + parser-generator--eof-identifier + phps-mode-automation-grammar--eof-identifier)) + + (when (boundp 'parser-generator-lex-analyzer--function) + (setq + parser-generator-lex-analyzer--function + phps-mode-automation-grammar--lex-analyzer-function)) + + (when (boundp 'parser-generator-lex-analyzer--get-function) + (setq + parser-generator-lex-analyzer--get-function + phps-mode-automation-grammar--lex-analyzer-get-function)) + + (when (boundp 'parser-generator--global-attributes) + (setq + parser-generator--global-attributes + phps-mode-automation-grammar--global-attributes)) + + (when (boundp 'parser-generator-lr--global-precedence-attributes) + (setq + parser-generator-lr--global-precedence-attributes + phps-mode-automation-grammar--lr-global-precedence-attributes)) + + (when (boundp 'parser-generator-lr--allow-default-conflict-resolution) + (setq + parser-generator-lr--allow-default-conflict-resolution + phps-mode-automation-grammar--lr--allow-default-conflict-resolution)) + + (when (boundp 'parser-generator--context-sensitive-attributes) + (setq + parser-generator--context-sensitive-attributes + phps-mode-automation-grammar--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)) + + (when (boundp 'parser-generator-lr--precedence-comparison-function) + (setq + parser-generator-lr--precedence-comparison-function + phps-mode-automation-grammar--precedence-comparison-function)) + + (when (boundp 'parser-generator--global-declaration) + (setq + parser-generator--global-declaration + phps-mode-automation-grammar--global-declaration)) + + (when (fboundp 'parser-generator-process-grammar) + (parser-generator-process-grammar)) + + (when (fboundp 'parser-generator-lr--generate-precedence-tables) + (parser-generator-lr--generate-precedence-tables) + (message "Precedence Tables") + (when (boundp 'parser-generator-lr--symbol-precedence-value) + (message + "parser-generator-lr--symbol-precedence-value: %S" + parser-generator-lr--symbol-precedence-value)) + (when (boundp 'parser-generator-lr--symbol-precedence-type) + (message + "parser-generator-lr--symbol-precedence-type: %S" + parser-generator-lr--symbol-precedence-type)) + (when (boundp 'parser-generator-lr--production-number-precedence-value) + (message + "parser-generator-lr--production-number-precedence-value: %S" + parser-generator-lr--production-number-precedence-value)) + (when (boundp 'parser-generator-lr--production-number-precedence-type) + (message + "parser-generator-lr--production-number-precedence-type: %S" + parser-generator-lr--production-number-precedence-type)) + + ;; Only generate LR-items, GOTO-tables and ACTION-tables if we are lacking it + (if (and + (boundp 'parser-generator-lr--goto-tables) + parser-generator-lr--goto-tables + (boundp 'parser-generator-lr--distinct-goto-tables) + parser-generator-lr--distinct-goto-tables + (boundp 'parser-generator-lr--action-tables) + parser-generator-lr--action-tables + (boundp 'parser-generator-lr--distinct-action-tables) + parser-generator-lr--distinct-action-tables) + (message "Parser tables are defined - skipping generation") + (progn + (message "Parser tables are not defined - generating..") + (when (fboundp 'parser-generator-lr--generate-goto-tables) + (let ((table-lr-items + (parser-generator-lr--generate-goto-tables))) (message - "parser-generator-lr--distinct-goto-tables: %S" - parser-generator-lr--distinct-goto-tables)) - (when (fboundp 'parser-generator-lr--generate-action-tables) - (parser-generator-lr--generate-action-tables table-lr-items) - (when (boundp 'parser-generator-lr--action-tables) + "table-lr-items: %S" + table-lr-items) + (when (boundp 'parser-generator-lr--goto-tables) (message - "parser-generator-lr--action-tables: %S" - parser-generator-lr--action-tables)) - (when (boundp 'parser-generator-lr--distinct-action-tables) + "parser-generator-lr--goto-tables: %S" + parser-generator-lr--goto-tables)) + (when (boundp 'parser-generator-lr--distinct-goto-tables) (message - "parser-generator-lr--distinct-action-tables: %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))) - (generate-new-buffer "*PHP Parser*") - (switch-to-buffer "*PHP Parser*") - (insert export) - (write-file (expand-file-name "./phps-mode-parser.el")) - (kill-buffer) - (message "export: %s" export)) - - (message "Automation completed")))) + "parser-generator-lr--distinct-goto-tables: %S" + parser-generator-lr--distinct-goto-tables)) + (when (fboundp 'parser-generator-lr--generate-action-tables) + (parser-generator-lr--generate-action-tables table-lr-items) + (when (boundp 'parser-generator-lr--action-tables) + (message + "parser-generator-lr--action-tables: %S" + parser-generator-lr--action-tables)) + (when (boundp 'parser-generator-lr--distinct-action-tables) + (message + "parser-generator-lr--distinct-action-tables: %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))) + (generate-new-buffer "*PHP Parser*") + (switch-to-buffer "*PHP Parser*") + (insert export) + (write-file (expand-file-name "./phps-mode-parser.el")) + (kill-buffer) + (message "export: %s" export)) + + (message "Automation completed")) + (error "Emacs parser generator must be available!"))) (provide 'phps-mode-automation) ;;; phps-mode-automation.el ends here diff --git a/admin/phps-mode-grammar-parser-generator.el b/admin/phps-mode-grammar-parser-generator.el deleted file mode 100644 index 0ae4a1c..0000000 --- a/admin/phps-mode-grammar-parser-generator.el +++ /dev/null @@ -1,290 +0,0 @@ -;;; phps-mode-grammar-parser-generator --- Generate a parser for PHP YACC grammar -*- lexical-binding: t -*- - -;; Copyright (C) 2018-2021 Free Software Foundation, Inc. - -;; This file is not part of GNU Emacs. - -;; This program is free software; you can redistribute it and/or -;; modify it under the terms of the GNU General Public License as -;; published by the Free Software Foundation; either version 2, or (at -;; your option) any later version. - -;; This program is distributed in the hope that it will be useful, but -;; WITHOUT ANY WARRANTY; without even the implied warranty of -;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -;; General Public License for more details. - -;; You should have received a copy of the GNU General Public License -;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. - - -;;; Commentary: - - -;;; Code: - - -(require 'parser-generator-lr) - -(defun phps-mode-grammar-parser-generator() - "Generate parser here." - - (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) - (parser-generator-set-grammar - '( - (Start Productions-Block Productions-Delimiter Productions Productions Production Production-End LHS RHSS RHS RHS-Symbol RHS-Symbols Comment Logic Symbol) - (productions-delimiter ":" "|" ";" comment logic symbol literal) - ( - (Start - Productions-Block) - (Productions-Block - (Productions-Delimiter Productions Productions-Delimiter - (lambda(args) (format "'(\n\n%s\n\n)" (nth 1 args)))) - ) - (Productions-Delimiter - (productions-delimiter - (lambda(args) "")) - ) - (Productions - (Production - (lambda(args) (format "%s" args))) - (Productions Production - (lambda(args) (format "%s\n\n%s" (nth 0 args) (nth 1 args)))) - ) - (Production - (Comment Production - (lambda(args) (format "%s" (nth 1 args)))) - (LHS ":" RHSS Production-End - (lambda(args) (format " (%s\n %s\n )" (nth 0 args) (nth 2 args)))) - ) - (Production-End - ";" - (";" ";")) - (LHS - (Symbol - (lambda(args) (format "%s" args))) - ) - (RHSS - (RHS - (lambda(args) (format "%s" args))) - (RHSS "|" RHS - (lambda(args) (format "%s\n %s" (nth 0 args) (nth 2 args)))) - ) - (RHS - (RHS-Symbol - (lambda(args) (format "%s" args))) - (RHS-Symbols - (lambda(args) - (if (string-match-p " " args) - (format "(%s)" args) - (format "%s" args)))) - ) - (RHS-Symbols - (RHS-Symbol - RHS-Symbols - (lambda (args) - (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) - (if (string= (nth 1 args) "") - (format "%s" (nth 0 args)) - (format "%s %s" (nth 0 args) (nth 1 args))))) - ) - (RHS-Symbol - Comment - Logic - Symbol) - (Comment - (comment - (lambda(args) ""))) - (Logic - (logic - (lambda(args) "")) - ) - (Symbol - (symbol - (lambda(args) (format "%s" args))) - (literal - (lambda(args) (format "%S" (substring args 1 2)))) - ) - ) - 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)) - (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 - `( - ,(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))))))) - token)))) - - (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")) - (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)) - (let ((translation (parser-generator-lr-translate))) - (message "translation:\n%s" translation)))) - -(provide 'phps-mode-grammar-parser-generator) -;;; phps-mode-grammar-parser-generator.el ends here diff --git a/phps-mode-automation-grammar.el b/phps-mode-automation-grammar.el index 04e55fc..991a632 100644 --- a/phps-mode-automation-grammar.el +++ b/phps-mode-automation-grammar.el @@ -477,1020 +477,6 @@ "The look-ahead number of grammar.") (defvar - phps-mode-automation-grammar--productions - '( - - (start - top_statement_list - ) - - (reserved_non_modifiers - T_INCLUDE - T_INCLUDE_ONCE - T_EVAL - T_REQUIRE - T_REQUIRE_ONCE - T_LOGICAL_OR - T_LOGICAL_XOR - T_LOGICAL_AND - T_INSTANCEOF - T_NEW - T_CLONE - T_EXIT - T_IF - T_ELSEIF - T_ELSE - T_ENDIF - T_ECHO - T_DO - T_WHILE - T_ENDWHILE - T_FOR - T_ENDFOR - T_FOREACH - T_ENDFOREACH - T_DECLARE - T_ENDDECLARE - T_AS - T_TRY - T_CATCH - T_FINALLY - T_THROW - T_USE - T_INSTEADOF - T_GLOBAL - T_VAR - T_UNSET - T_ISSET - T_EMPTY - T_CONTINUE - T_GOTO - T_FUNCTION - T_CONST - T_RETURN - T_PRINT - T_YIELD - T_LIST - T_SWITCH - T_ENDSWITCH - T_CASE - T_DEFAULT - T_BREAK - T_ARRAY - T_CALLABLE - T_EXTENDS - T_IMPLEMENTS - T_NAMESPACE - T_TRAIT - T_INTERFACE - T_CLASS - T_CLASS_C - T_TRAIT_C - T_FUNC_C - T_METHOD_C - T_LINE - T_FILE - T_DIR - T_NS_C - T_FN - T_MATCH - ) - - (semi_reserved - reserved_non_modifiers - T_STATIC - T_ABSTRACT - T_FINAL - T_PRIVATE - T_PROTECTED - T_PUBLIC - ) - - (identifier - T_STRING - semi_reserved - ) - - (top_statement_list - (top_statement_list top_statement) - %empty - ) - - (namespace_declaration_name - identifier - T_NAME_QUALIFIED - ) - - (namespace_name - T_STRING - T_NAME_QUALIFIED - ) - - (legacy_namespace_name - namespace_name - T_NAME_FULLY_QUALIFIED - ) - - (name - T_STRING - T_NAME_QUALIFIED - T_NAME_FULLY_QUALIFIED - T_NAME_RELATIVE - ) - - (attribute_decl - class_name - (class_name argument_list) - ) - - (attribute_group - attribute_decl - (attribute_group "," attribute_decl) - ) - - (attribute - (T_ATTRIBUTE attribute_group possible_comma "]") - ) - - (attributes - attribute - (attributes attribute) - ) - - (attributed_statement - function_declaration_statement - class_declaration_statement - trait_declaration_statement - interface_declaration_statement - ) - - (top_statement - statement - attributed_statement - (attributes attributed_statement) - (T_HALT_COMPILER "(" ")" ";") - (T_NAMESPACE namespace_declaration_name ";") - (T_NAMESPACE namespace_declaration_name "{" top_statement_list "}") - (T_NAMESPACE "{" top_statement_list "}") - (T_USE mixed_group_use_declaration ";") - (T_USE use_type group_use_declaration ";") - (T_USE use_declarations ";") - (T_USE use_type use_declarations ";") - (T_CONST const_list ";") - ) - - (use_type - T_FUNCTION - T_CONST - ) - - (group_use_declaration - (legacy_namespace_name T_NS_SEPARATOR "{" unprefixed_use_declarations possible_comma "}") - ) - - (mixed_group_use_declaration - (legacy_namespace_name T_NS_SEPARATOR "{" inline_use_declarations possible_comma "}") - ) - - (possible_comma - %empty - "," - ) - - (inline_use_declarations - (inline_use_declarations "," inline_use_declaration) - inline_use_declaration - ) - - (unprefixed_use_declarations - (unprefixed_use_declarations "," unprefixed_use_declaration) - unprefixed_use_declaration - ) - - (use_declarations - (use_declarations "," use_declaration) - use_declaration - ) - - (inline_use_declaration - unprefixed_use_declaration - (use_type unprefixed_use_declaration) - ) - - (unprefixed_use_declaration - namespace_name - (namespace_name T_AS T_STRING) - ) - - (use_declaration - legacy_namespace_name - (legacy_namespace_name T_AS T_STRING) - ) - - (const_list - (const_list "," const_decl) - const_decl - ) - - (inner_statement_list - (inner_statement_list inner_statement) - %empty - ) - - (inner_statement - statement - attributed_statement - (attributes attributed_statement) - (T_HALT_COMPILER "(" ")" ";") - ) - - (statement - ("{" inner_statement_list "}") - if_stmt - alt_if_stmt - (T_WHILE "(" expr ")" while_statement) - (T_DO statement T_WHILE "(" expr ")" ";") - (T_FOR "(" for_exprs ";" for_exprs ";" for_exprs ")" for_statement) - (T_SWITCH "(" expr ")" switch_case_list) - (T_BREAK optional_expr ";") - (T_CONTINUE optional_expr ";") - (T_RETURN optional_expr ";") - (T_GLOBAL global_var_list ";") - (T_STATIC static_var_list ";") - (T_ECHO echo_expr_list ";") - T_INLINE_HTML - (expr ";") - (T_UNSET "(" unset_variables possible_comma ")" ";") - (T_FOREACH "(" expr T_AS foreach_variable ")" foreach_statement) - (T_FOREACH "(" expr T_AS foreach_variable T_DOUBLE_ARROW foreach_variable ")" foreach_statement) - (T_DECLARE "(" const_list ")" declare_statement) - ";" - (T_TRY "{" inner_statement_list "}" catch_list finally_statement) - (T_GOTO T_STRING ";") - (T_STRING ":") - ) - - (catch_list - %empty - (catch_list T_CATCH "(" catch_name_list optional_variable ")" "{" inner_statement_list "}") - ) - - (catch_name_list - class_name - (catch_name_list "|" class_name) - ) - - (optional_variable - %empty - T_VARIABLE - ) - - (finally_statement - %empty - (T_FINALLY "{" inner_statement_list "}") - ) - - (unset_variables - unset_variable - (unset_variables "," unset_variable) - ) - - (unset_variable - variable - ) - - (function_declaration_statement - (function returns_ref T_STRING backup_doc_comment "(" parameter_list ")" return_type backup_fn_flags "{" inner_statement_list "}" backup_fn_flags) - ) - - (is_reference - %empty - "&" - ) - - (is_variadic - %empty - T_ELLIPSIS - ) - - (class_declaration_statement - (class_modifiers T_CLASS T_STRING extends_from implements_list backup_doc_comment "{" class_statement_list "}") - (T_CLASS T_STRING extends_from implements_list backup_doc_comment "{" class_statement_list "}") - ) - - (class_modifiers - class_modifier - (class_modifiers class_modifier) - ) - - (class_modifier - T_ABSTRACT - T_FINAL - ) - - (trait_declaration_statement - (T_TRAIT T_STRING backup_doc_comment "{" class_statement_list "}") - ) - - (interface_declaration_statement - (T_INTERFACE T_STRING interface_extends_list backup_doc_comment "{" class_statement_list "}") - ) - - (extends_from - %empty - (T_EXTENDS class_name) - ) - - (interface_extends_list - %empty - (T_EXTENDS class_name_list) - ) - - (implements_list - %empty - (T_IMPLEMENTS class_name_list) - ) - - (foreach_variable - variable - ("&" variable) - (T_LIST "(" array_pair_list ")") - ("[" array_pair_list "]") - ) - - (for_statement - statement - (":" inner_statement_list T_ENDFOR ";") - ) - - (foreach_statement - statement - (":" inner_statement_list T_ENDFOREACH ";") - ) - - (declare_statement - statement - (":" inner_statement_list T_ENDDECLARE ";") - ) - - (switch_case_list - ("{" case_list "}") - ("{" ";" case_list "}") - (":" case_list T_ENDSWITCH ";") - (":" ";" case_list T_ENDSWITCH ";") - ) - - (case_list - %empty - (case_list T_CASE expr case_separator inner_statement_list) - (case_list T_DEFAULT case_separator inner_statement_list) - ) - - (case_separator - ":" - ";" - ) - - (match - (T_MATCH "(" expr ")" "{" match_arm_list "}") - ) - - (match_arm_list - %empty - (non_empty_match_arm_list possible_comma) - ) - - (non_empty_match_arm_list - match_arm - (non_empty_match_arm_list "," match_arm) - ) - - (match_arm - (match_arm_cond_list possible_comma T_DOUBLE_ARROW expr) - (T_DEFAULT possible_comma T_DOUBLE_ARROW expr) - ) - - (match_arm_cond_list - expr - (match_arm_cond_list "," expr) - ) - - (while_statement - statement - (":" inner_statement_list T_ENDWHILE ";") - ) - - (if_stmt_without_else - (T_IF "(" expr ")" statement) - (if_stmt_without_else T_ELSEIF "(" expr ")" statement) - ) - - (if_stmt - (if_stmt_without_else %prec T_NOELSE) - (if_stmt_without_else T_ELSE statement) - ) - - (alt_if_stmt_without_else - (T_IF "(" expr ")" ":" inner_statement_list) - (alt_if_stmt_without_else T_ELSEIF "(" expr ")" ":" inner_statement_list) - ) - - (alt_if_stmt - (alt_if_stmt_without_else T_ENDIF ";") - (alt_if_stmt_without_else T_ELSE ":" inner_statement_list T_ENDIF ";") - ) - - (parameter_list - (non_empty_parameter_list possible_comma) - %empty - ) - - (non_empty_parameter_list - attributed_parameter - (non_empty_parameter_list "," attributed_parameter) - ) - - (attributed_parameter - (attributes parameter) - parameter - ) - - (optional_visibility_modifier - %empty - T_PUBLIC - T_PROTECTED - T_PRIVATE - ) - - (parameter - (optional_visibility_modifier optional_type_without_static is_reference is_variadic T_VARIABLE backup_doc_comment) - (optional_visibility_modifier optional_type_without_static is_reference is_variadic T_VARIABLE backup_doc_comment "=" expr) - ) - - (optional_type_without_static - %empty - type_expr_without_static - ) - - (type_expr - type - ("?" type) - union_type - ) - - (type - type_without_static - T_STATIC - ) - - (union_type - (type "|" type) - (union_type "|" type) - ) - - (type_expr_without_static - type_without_static - ("?" type_without_static) - union_type_without_static - ) - - (type_without_static - T_ARRAY - T_CALLABLE - name - ) - - (union_type_without_static - (type_without_static "|" type_without_static) - (union_type_without_static "|" type_without_static) - ) - - (return_type - %empty - (":" type_expr) - ) - - (argument_list - ("(" ")") - ("(" non_empty_argument_list possible_comma ")") - ) - - (non_empty_argument_list - argument - (non_empty_argument_list "," argument) - ) - - (argument - expr - (identifier ":" expr) - (T_ELLIPSIS expr) - ) - - (global_var_list - (global_var_list "," global_var) - global_var - ) - - (global_var - simple_variable - ) - - (static_var_list - (static_var_list "," static_var) - static_var - ) - - (static_var - T_VARIABLE - (T_VARIABLE "=" expr) - ) - - (class_statement_list - (class_statement_list class_statement) - %empty - ) - - (attributed_class_statement - (variable_modifiers optional_type_without_static property_list ";") - (method_modifiers T_CONST class_const_list ";") - (method_modifiers function returns_ref identifier backup_doc_comment "(" parameter_list ")" return_type backup_fn_flags method_body backup_fn_flags) - ) - - (class_statement - attributed_class_statement - (attributes attributed_class_statement) - (T_USE class_name_list trait_adaptations) - ) - - (class_name_list - class_name - (class_name_list "," class_name) - ) - - (trait_adaptations - ";" - ("{" "}") - ("{" trait_adaptation_list "}") - ) - - (trait_adaptation_list - trait_adaptation - (trait_adaptation_list trait_adaptation) - ) - - (trait_adaptation - (trait_precedence ";") - (trait_alias ";") - ) - - (trait_precedence - (absolute_trait_method_reference T_INSTEADOF class_name_list) - ) - - (trait_alias - (trait_method_reference T_AS T_STRING) - (trait_method_reference T_AS reserved_non_modifiers) - (trait_method_reference T_AS member_modifier identifier) - (trait_method_reference T_AS member_modifier) - ) - - (trait_method_reference - identifier - absolute_trait_method_reference - ) - - (absolute_trait_method_reference - (class_name T_PAAMAYIM_NEKUDOTAYIM identifier) - ) - - (method_body - ";" - ("{" inner_statement_list "}") - ) - - (variable_modifiers - non_empty_member_modifiers - T_VAR - ) - - (method_modifiers - %empty - non_empty_member_modifiers - ) - - (non_empty_member_modifiers - member_modifier - (non_empty_member_modifiers member_modifier) - ) - - (member_modifier - T_PUBLIC - T_PROTECTED - T_PRIVATE - T_STATIC - T_ABSTRACT - T_FINAL - ) - - (property_list - (property_list "," property) - property - ) - - (property - (T_VARIABLE backup_doc_comment) - (T_VARIABLE "=" expr backup_doc_comment) - ) - - (class_const_list - (class_const_list "," class_const_decl) - class_const_decl - ) - - (class_const_decl - (identifier "=" expr backup_doc_comment) - ) - - (const_decl - (T_STRING "=" expr backup_doc_comment) - ) - - (echo_expr_list - (echo_expr_list "," echo_expr) - echo_expr - ) - - (echo_expr - expr - ) - - (for_exprs - %empty - non_empty_for_exprs - ) - - (non_empty_for_exprs - (non_empty_for_exprs "," expr) - expr - ) - - (anonymous_class - (T_CLASS ctor_arguments extends_from implements_list backup_doc_comment "{" class_statement_list "}") - ) - - (new_expr - (T_NEW class_name_reference ctor_arguments) - (T_NEW anonymous_class) - (T_NEW attributes anonymous_class) - ) - - (expr - variable - (T_LIST "(" array_pair_list ")" "=" expr) - ("[" array_pair_list "]" "=" expr) - (variable "=" expr) - (variable "=" "&" variable) - (T_CLONE expr) - (variable T_PLUS_EQUAL expr) - (variable T_MINUS_EQUAL expr) - (variable T_MUL_EQUAL expr) - (variable T_POW_EQUAL expr) - (variable T_DIV_EQUAL expr) - (variable T_CONCAT_EQUAL expr) - (variable T_MOD_EQUAL expr) - (variable T_AND_EQUAL expr) - (variable T_OR_EQUAL expr) - (variable T_XOR_EQUAL expr) - (variable T_SL_EQUAL expr) - (variable T_SR_EQUAL expr) - (variable T_COALESCE_EQUAL expr) - (variable T_INC) - (T_INC variable) - (variable T_DEC) - (T_DEC variable) - (expr T_BOOLEAN_OR expr) - (expr T_BOOLEAN_AND expr) - (expr T_LOGICAL_OR expr) - (expr T_LOGICAL_AND expr) - (expr T_LOGICAL_XOR expr) - (expr "|" expr) - (expr "&" expr) - (expr "^" expr) - (expr "." expr) - (expr "+" expr) - (expr "-" expr) - (expr "*" expr) - (expr T_POW expr) - (expr "/" expr) - (expr "%" expr) - (expr T_SL expr) - (expr T_SR expr) - ("+" expr %prec "~") - ("-" expr %prec "~") - ("!" expr) - ("~" expr) - (expr T_IS_IDENTICAL expr) - (expr T_IS_NOT_IDENTICAL expr) - (expr T_IS_EQUAL expr) - (expr T_IS_NOT_EQUAL expr) - (expr "<" expr) - (expr T_IS_SMALLER_OR_EQUAL expr) - (expr ">" expr) - (expr T_IS_GREATER_OR_EQUAL expr) - (expr T_SPACESHIP expr) - (expr T_INSTANCEOF class_name_reference) - ("(" expr ")") - new_expr - (expr "?" expr ":" expr) - (expr "?" ":" expr) - (expr T_COALESCE expr) - internal_functions_in_yacc - (T_INT_CAST expr) - (T_DOUBLE_CAST expr) - (T_STRING_CAST expr) - (T_ARRAY_CAST expr) - (T_OBJECT_CAST expr) - (T_BOOL_CAST expr) - (T_UNSET_CAST expr) - (T_EXIT exit_expr) - ("@" expr) - scalar - ("`" backticks_expr "`") - (T_PRINT expr) - T_YIELD - (T_YIELD expr) - (T_YIELD expr T_DOUBLE_ARROW expr) - (T_YIELD_FROM expr) - (T_THROW expr) - inline_function - (attributes inline_function) - (T_STATIC inline_function) - (attributes T_STATIC inline_function) - match - ) - - (inline_function - (function returns_ref backup_doc_comment "(" parameter_list ")" lexical_vars return_type backup_fn_flags "{" inner_statement_list "}" backup_fn_flags) - (fn returns_ref backup_doc_comment "(" parameter_list ")" return_type T_DOUBLE_ARROW backup_fn_flags backup_lex_pos expr backup_fn_flags) - ) - - (fn - T_FN - ) - - (function - T_FUNCTION - ) - - (backup_doc_comment - %empty - ) - - (backup_fn_flags - (%prec PREC_ARROW_FUNCTION %empty) - ) - - (backup_lex_pos - %empty - ) - - (returns_ref - %empty - "&" - ) - - (lexical_vars - %empty - (T_USE "(" lexical_var_list possible_comma ")") - ) - - (lexical_var_list - (lexical_var_list "," lexical_var) - lexical_var - ) - - (lexical_var - T_VARIABLE - ("&" T_VARIABLE) - ) - - (function_call - (name argument_list) - (class_name T_PAAMAYIM_NEKUDOTAYIM member_name argument_list) - (variable_class_name T_PAAMAYIM_NEKUDOTAYIM member_name argument_list) - (callable_expr argument_list) - ) - - (class_name - T_STATIC - name - ) - - (class_name_reference - class_name - new_variable - ("(" expr ")") - ) - - (exit_expr - %empty - ("(" optional_expr ")") - ) - - (backticks_expr - %empty - T_ENCAPSED_AND_WHITESPACE - encaps_list - ) - - (ctor_arguments - %empty - argument_list - ) - - (dereferencable_scalar - (T_ARRAY "(" array_pair_list ")") - ("[" array_pair_list "]") - T_CONSTANT_ENCAPSED_STRING - ("\"" encaps_list "\"") - ) - - (scalar - T_LNUMBER - T_DNUMBER - (T_START_HEREDOC T_ENCAPSED_AND_WHITESPACE T_END_HEREDOC) - (T_START_HEREDOC T_END_HEREDOC) - (T_START_HEREDOC encaps_list T_END_HEREDOC) - dereferencable_scalar - constant - class_constant - ) - - (constant - name - T_LINE - T_FILE - T_DIR - T_TRAIT_C - T_METHOD_C - T_FUNC_C - T_NS_C - T_CLASS_C - ) - - (class_constant - (class_name T_PAAMAYIM_NEKUDOTAYIM identifier) - (variable_class_name T_PAAMAYIM_NEKUDOTAYIM identifier) - ) - - (optional_expr - %empty - expr - ) - - (variable_class_name - fully_dereferencable - ) - - (fully_dereferencable - variable - ("(" expr ")") - dereferencable_scalar - class_constant - ) - - (array_object_dereferencable - fully_dereferencable - constant - ) - - (callable_expr - callable_variable - ("(" expr ")") - dereferencable_scalar - ) - - (callable_variable - simple_variable - (array_object_dereferencable "[" optional_expr "]") - (array_object_dereferencable "{" expr "}") - (array_object_dereferencable T_OBJECT_OPERATOR property_name argument_list) - (array_object_dereferencable T_NULLSAFE_OBJECT_OPERATOR property_name argument_list) - function_call - ) - - (variable - callable_variable - static_member - (array_object_dereferencable T_OBJECT_OPERATOR property_name) - (array_object_dereferencable T_NULLSAFE_OBJECT_OPERATOR property_name) - ) - - (simple_variable - T_VARIABLE - ("$" "{" expr "}") - ("$" simple_variable) - ) - - (static_member - (class_name T_PAAMAYIM_NEKUDOTAYIM simple_variable) - (variable_class_name T_PAAMAYIM_NEKUDOTAYIM simple_variable) - ) - - (new_variable - simple_variable - (new_variable "[" optional_expr "]") - (new_variable "{" expr "}") - (new_variable T_OBJECT_OPERATOR property_name) - (new_variable T_NULLSAFE_OBJECT_OPERATOR property_name) - (class_name T_PAAMAYIM_NEKUDOTAYIM simple_variable) - (new_variable T_PAAMAYIM_NEKUDOTAYIM simple_variable) - ) - - (member_name - identifier - ("{" expr "}") - simple_variable - ) - - (property_name - T_STRING - ("{" expr "}") - simple_variable - ) - - (array_pair_list - non_empty_array_pair_list - ) - - (possible_array_pair - %empty - array_pair - ) - - (non_empty_array_pair_list - (non_empty_array_pair_list "," possible_array_pair) - possible_array_pair - ) - - (array_pair - (expr T_DOUBLE_ARROW expr) - expr - (expr T_DOUBLE_ARROW "&" variable) - ("&" variable) - (T_ELLIPSIS expr) - (expr T_DOUBLE_ARROW T_LIST "(" array_pair_list ")") - (T_LIST "(" array_pair_list ")") - ) - - (encaps_list - (encaps_list encaps_var) - (encaps_list T_ENCAPSED_AND_WHITESPACE) - encaps_var - (T_ENCAPSED_AND_WHITESPACE encaps_var) - ) - - (encaps_var - T_VARIABLE - (T_VARIABLE "[" encaps_var_offset "]") - (T_VARIABLE T_OBJECT_OPERATOR T_STRING) - (T_VARIABLE T_NULLSAFE_OBJECT_OPERATOR T_STRING) - (T_DOLLAR_OPEN_CURLY_BRACES expr "}") - (T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME "}") - (T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME "[" expr "]" "}") - (T_CURLY_OPEN variable "}") - ) - - (encaps_var_offset - T_STRING - T_NUM_STRING - ("-" T_NUM_STRING) - T_VARIABLE - ) - - (internal_functions_in_yacc - (T_ISSET "(" isset_variables possible_comma ")") - (T_EMPTY "(" expr ")") - (T_INCLUDE expr) - (T_INCLUDE_ONCE expr) - (T_EVAL "(" expr ")") - (T_REQUIRE expr) - (T_REQUIRE_ONCE expr) - ) - - (isset_variables - isset_variable - (isset_variables "," isset_variable) - ) - - (isset_variable - expr - ) - - ) - "The productions of grammar.") - -(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.")