[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/parser-generator e644708 018/434: Improved validation o
From: |
ELPA Syncer |
Subject: |
[elpa] externals/parser-generator e644708 018/434: Improved validation of grammar syntax |
Date: |
Mon, 29 Nov 2021 15:58:59 -0500 (EST) |
branch: externals/parser-generator
commit e644708c3ccb546d81cfcd2d3ab41312ee62a8e3
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
Improved validation of grammar syntax
---
parser.el | 69 ++++++++++++++++++++++++++++++++++++++++++++++++-----
test/parser-test.el | 1 +
2 files changed, 64 insertions(+), 6 deletions(-)
diff --git a/parser.el b/parser.el
index e959931..987ead7 100644
--- a/parser.el
+++ b/parser.el
@@ -164,7 +164,7 @@
(setq valid-p nil)))
(setq terminal-index (1+ terminal-index)))))
- ;; TODO Check every production
+ ;; Check every production
(let ((productions (nth 2 G)))
(let ((production-count (length productions))
(production-index 0))
@@ -172,9 +172,7 @@
valid-p
(< production-index production-count))
(let ((production (nth production-index productions)))
- (unless (or
- (symbolp production)
- (stringp production))
+ (unless (parser--valid-production-p production)
(setq valid-p nil)))
(setq production-index (1+ production-index)))))
@@ -183,8 +181,7 @@
(when (and
valid-p
(not (or (stringp start) (symbolp start))))
- (setq valid-p nil)))
- )
+ (setq valid-p nil))))
valid-p))
(defun parser--valid-look-ahead-number-p (k)
@@ -201,6 +198,66 @@
t
nil))
+(defun parser--valid-production-p (production)
+ "Return whether PRODUCTION is valid or not."
+ (let ((is-valid t))
+ (unless (listp production)
+ (setq is-valid nil))
+ (when (and is-valid
+ (not (> (length production) 1)))
+ (setq is-valid nil))
+ (when (and is-valid
+ (not (or
+ (stringp (car production))
+ (symbolp (car production))
+ (listp (car production)))))
+ (setq is-valid nil))
+
+ ;; Validate left-hand-side (LHS) of production
+ (when (and is-valid
+ (listp (car production)))
+ (let ((lhs (car production)))
+ (let ((lhs-index 0)
+ (lhs-length (length lhs)))
+ (while (and is-valid
+ (< lhs-index lhs-length))
+ (let ((p (nth lhs-index lhs)))
+ (unless (or
+ (stringp p)
+ (symbolp p))
+ (setq is-valid nil)))
+ (setq lhs-index (1+ lhs-index))))))
+
+ ;; Validate that RHS is a list or symbol or a string
+ (when (and is-valid
+ (not (or
+ (listp (car (cdr production)))
+ (symbolp (car (cdr production)))
+ (stringp (car (cdr production))))))
+ (setq is-valid nil))
+
+ ;; Validate right-hand-side (RHS) of production
+ (when is-valid
+ (let ((rhs (cdr production)))
+ (let ((rhs-index 0)
+ (rhs-length (length rhs)))
+ (while (and is-valid
+ (< rhs-index rhs-length))
+ (let ((rhs-element (nth rhs-index rhs)))
+ (cond
+ ((stringp rhs-element))
+ ((symbolp rhs-element))
+ ((listp rhs-element)
+ (dolist (rhs-sub-element rhs-element)
+ (unless (or
+ (stringp rhs-sub-element)
+ (symbolp rhs-sub-element))
+ (setq is-valid nil))))
+ (t (setq is-valid nil)))
+ (setq rhs-index (1+ rhs-index)))))))
+
+ is-valid))
+
(defun parser--valid-sentential-form-p (symbols)
"Return whether SYMBOLS is a valid sentential form in grammar or not."
(let ((is-valid t))
diff --git a/test/parser-test.el b/test/parser-test.el
index 615c0ea..ed7f1dd 100644
--- a/test/parser-test.el
+++ b/test/parser-test.el
@@ -196,6 +196,7 @@
;; (message "Passed tests for (parser-test--v-set)"))
+;; TODO Re-implement this function
(defun parser-test--valid-grammar-p ()
"Test function `parser--valid-grammar-p'."
(message "Starting tests for (parser--valid-grammar-p)")
- [elpa] externals/parser-generator f648b52 020/434: Passing first unit test for FIRST after new data-structure refactor, (continued)
- [elpa] externals/parser-generator f648b52 020/434: Passing first unit test for FIRST after new data-structure refactor, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator a4bbb2f 026/434: Using PDA algorithm for FIRST when β is above 1 symbol, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator e02d5d7 049/434: More work on calculating valid LR-items, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 0465b58 045/434: Improved commenting, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 85dde51 009/434: Added License and Travis build logos, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 7bc3b70 017/434: Updated tests to use new data structure, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator ab4b4db 021/434: Passed second FIRST test again, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 80cf73d 019/434: Passing tests for valid-grammar syntax, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator bbbdea3 034/434: More improvement of documentation, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 9d0d9e5 027/434: Various debugging, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator e644708 018/434: Improved validation of grammar syntax,
ELPA Syncer <=
- [elpa] externals/parser-generator fbb8cad 012/434: Starting a refactor, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 563cbdd 023/434: Passed FIRST tests for semi-complex grammar, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator dc78de7 025/434: Fixed page comment reference, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 3e02435 028/434: Passing complex 2 test, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 8e99d0c 035/434: Fixed typo, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator bc1ec12 036/434: Improved documentation, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator fe94691 048/434: Added hash-table for production RHS, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator afa7cb9 050/434: Added unit tests for retrieving grammar RHS, ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator 603df44 040/434: Added failing unit tests for (parser--sort-list), ELPA Syncer, 2021/11/29
- [elpa] externals/parser-generator aadb31a 042/434: Updated README.md about FOLLOW-sets, ELPA Syncer, 2021/11/29