[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode 339e39b 37/96: Started on YACC grammar parser
From: |
Christian Johansson |
Subject: |
[elpa] externals/phps-mode 339e39b 37/96: Started on YACC grammar parser generator |
Date: |
Fri, 29 Oct 2021 11:14:42 -0400 (EDT) |
branch: externals/phps-mode
commit 339e39ba821445e9b3284cc597aaea2e801547fd
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
Started on YACC grammar parser generator
---
admin/phps-mode-grammar-parser-generator.el | 142 ++++++++++++++++++++++++++++
1 file changed, 142 insertions(+)
diff --git a/admin/phps-mode-grammar-parser-generator.el
b/admin/phps-mode-grammar-parser-generator.el
new file mode 100644
index 0000000..fa024e1
--- /dev/null
+++ b/admin/phps-mode-grammar-parser-generator.el
@@ -0,0 +1,142 @@
+;;; 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-mod-grammar-parser-generator()
+ "Generate parser here."
+
+ (parser-generator-set-look-ahead-number
+ 1)
+ (setq
+ parser-generator--e-identifier
+ '%empty)
+ (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 Start-Delimiter Productions End-Delimiter
Productions Production LHS RHSS RHS RHS-Symbol Comment Logic Symbol)
+ (start-delimiter end-delimiter ":" "|" ";" comment logic symbol)
+ (
+ (Start Productions-Block)
+ (Productions-Block (Start-Delimiter Productions End-Delimiter))
+ (Start-Delimiter start-delimiter)
+ (End-Delimiter end-delimiter)
+ (Productions Production (Productions Production))
+ (Production (LHS ":" RHSS ";"))
+ (LHS Symbol)
+ (RHSS RHS (RHSS "|" RHS))
+ (RHS RHS-Symbol (RHS RHS-Symbol))
+ (RHS-Symbol Comment Logic Symbol)
+ (Comment comment)
+ (Logic logic)
+ (Symbol symbol)
+ )
+ 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 ]+")
+ (when
+ (search-forward-regexp "[^\t ]" nil t)
+ (forward-char -1)
+ (setq-local
+ parser-generator-lex-analyzer--move-to-index-flag
+ (point))))
+
+ (cond
+
+ ((looking-at "\\(/\\*.+\\*/\\)")
+ (setq
+ token
+ `(comment ,(match-beginning 0) . ,(match-end 0))))
+
+ ((looking-at "\\({.+}\\)")
+ (setq
+ token
+ `(logic ,(match-beginning 0) . ,(match-end 0))))
+
+ ((looking-at "\\(:\\|;\\||\\)")
+ (setq
+ token
+ `(
+ ,(buffer-substring-no-properties
+ (match-beginning 0)
+ (match-end 0))
+ ,(match-beginning 0)
+ . ,(match-end 0)
+ )))
+
+ (t (error "Unexpected input at %d!" index))))
+ 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)
+
+ ))
+
+(provide 'phps-mode-grammar-parser-generator)
+;;; phps-mode-grammar-parser-generator.el ends here
- [elpa] externals/phps-mode f56ba64 49/96: Terminals, non-terminals and start is automatically generated from YACC, (continued)
- [elpa] externals/phps-mode f56ba64 49/96: Terminals, non-terminals and start is automatically generated from YACC, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode 7323416 31/96: Added failing test for parser, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode 7c66145 30/96: Refactor of parsers lex-analyzer complete, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode 0e89b6e 35/96: Fixed bug in automation grammar, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode 65152f4 36/96: Added TODO item, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode add17a7 24/96: T_COMMENT and T_DOC_COMMENT are excluded from parser, Christian Johansson, 2021/10/29
- [elpa] externals/phps-mode f46b98f 25/96: More work on integrating parser, Christian Johansson, 2021/10/29
- [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 <=
- [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, 2021/10/29
- [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