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

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

[elpa] externals/parser-generator f2791c1 022/434: Passed unit test 3 in


From: ELPA Syncer
Subject: [elpa] externals/parser-generator f2791c1 022/434: Passed unit test 3 intermediate grammar
Date: Mon, 29 Nov 2021 15:59:00 -0500 (EST)

branch: externals/parser-generator
commit f2791c19f732d43796f3045dc46ac00fc0335eac
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>

    Passed unit test 3 intermediate grammar
---
 parser.el           |  9 ++++--
 test/parser-test.el | 92 ++++++++++++++++-------------------------------------
 2 files changed, 34 insertions(+), 67 deletions(-)

diff --git a/parser.el b/parser.el
index 2ac43be..053720b 100644
--- a/parser.el
+++ b/parser.el
@@ -506,7 +506,11 @@
                     (push symbol first)
                     (setq first-length (1+ first-length)))
                    ((parser--valid-non-terminal-p symbol)
-                    (let ((symbol-f-set (sort (gethash symbol (gethash (1- 
i-max) parser--f-sets)) 'string<)))
+                    (parser--debug
+                     (message "non-terminal symbol: %s" symbol))
+                    (let ((symbol-f-set (gethash symbol (gethash (1- i-max) 
parser--f-sets))))
+                      (parser--debug
+                       (message "symbol-f-set: %s" symbol-f-set))
                       (when (> (length symbol-f-set) 1)
                         ;; Handle this scenario here were a non-terminal can 
result in different FIRST sets
                         (let ((symbol-f-set-index 1)
@@ -516,7 +520,8 @@
                               (let ((alternative-first-length (+ first-length 
(length symbol-f-set-element)))
                                     (alternative-first (append first 
symbol-f-set-element))
                                     (alternative-tape-index (1+ 
input-tape-index)))
-                                (push `(,alternative-tape-index 
,alternative-first-length ,alternative-first) stack))))))
+                                (push `(,alternative-tape-index 
,alternative-first-length ,alternative-first) stack)))
+                            (setq symbol-f-set-index (1+ 
symbol-f-set-index)))))
                       (setq first-length (+ first-length (length (car 
symbol-f-set))))
                       (setq first (append first (car symbol-f-set)))))))
                 (setq input-tape-index (1+ input-tape-index)))
diff --git a/test/parser-test.el b/test/parser-test.el
index 9916fea..1c7ef74 100644
--- a/test/parser-test.el
+++ b/test/parser-test.el
@@ -42,113 +42,75 @@
     (parser--first 'S)))
   (message "Passed first 2 with rudimentary grammar")
 
+  (parser--set-grammar '((S) ("a" b "c") ((S ("a" b "c"))) S) 3)
   (should
    (equal
-    '("a" b "c")
-    (parser--first
-     3
-     'S
-     '((S "a" b "c")))))
+    '(("a" b "c"))
+    (parser--first 'S)))
   (message "Passed first 3 with rudimentary grammar")
 
+  (parser--set-grammar '((S A) (b) ((S A) (A b)) S) 2)
   (should
    (equal
-    '(b)
-    (parser--first
-     1
-     'S
-     '((S A)
-       (A b)))))
+    '((b))
+    (parser--first 'S)))
   (message "Passed first 1 with intermediate grammar")
 
+  (parser--set-grammar '((S A) ("a" "b") ((S A) (A ("b" "a"))) S) 2)
   (should
    (equal
-    '("b" "a")
-    (parser--first
-     2
-     'S
-     '((S A)
-       (A ("b" "a"))))))
+    '(("b" "a"))
+    (parser--first 'S)))
   (message "Passed first 2 with intermediate grammar")
 
+  (parser--set-grammar '((S A) ("a" "b" "c" "d") ((S A) (A ("b" "a" "c" "d"))) 
S) 3)
   (should
    (equal
-    '("b" "a" "c")
-    (parser--first
-     3
-     'S
-     '((S A)
-       (A ("b" "a" "c" e))))))
+    '(("b" "a" "c"))
+    (parser--first 'S)))
   (message "Passed first 3 with intermediate grammar")
 
+  (parser--set-grammar '((S A B) ("c" "d") ((S A) (A B) (B c d)) S) 1)
   (should
    (equal
-    '(c d)
-    (parser--first
-     1
-     'S
-     '((S A)
-       (A B)
-       (B (c d))))))
+    '((c) (d))
+    (parser--first 'S)))
   (message "Passed first 1 with semi-complex grammar")
 
+  (parser--set-grammar '((S A B) (a c d f) ((S A a) (A B) (B (c f) d)) S) 2)
   (should
    (equal
-    '((c f) (da))
-    (parser--first
-     2
-     'S
-     '((S (A a))
-       (A B)
-       (B (c f) d)))))
+    '((c f) (d a))
+    (parser--first 'S)))
   (message "Passed first 2 with semi-complex grammar")
 
+  (parser--set-grammar '((S A B) ("a" "c" "d" "m") ((S A) (A (B "a" "m")) (B 
"c" "d")) S) 3)
   (should
    (equal
     '(("c" "a" "m") ("d" "a" "m"))
-    (parser--first
-     3
-     'S
-     '((S A)
-       (A (B "a" "m"))
-       (B "c" "d")))))
+    (parser--first 'S)))
   (message "Passed first 3 with semi-complex grammar")
 
+  (parser--set-grammar '((S A B C) (a b c) ((S A B) (A (B a) e) (B (C b) C) (C 
c e)) S) 1)
   (should
    (equal
     '((a) (b) (c) (e))
-    (parser--first
-     1
-     'S
-     '((S (A B))
-       (A (B a) e)
-       (B (C b) C)
-       (C c e)))))
+    (parser--first 'S)))
   (message "Passed first 1 with complex grammar")
 
   ;; Example 5.28 p 402
+  (parser--set-grammar '((S A B C) ("a" "b" "c") ((S A B) (A (B "a") e) (B (C 
"b") C) (C "c" e)) S) 2)
   (should
    (equal
     '(("a") ("a" "b") ("a" "c") ("b") ("b" "a") ("c") ("c" "a") ("c" "b") (e))
-    (parser--first
-     2
-     'S
-     '((S (AB))
-       (A (B "a") e)
-       (B (C "b") C)
-       (C "c" e)))))
+    (parser--first 'S)))
   (message "Passed first 2 with complex grammar")
 
+  (parser--set-grammar '((S A B C) ("a" "b" "c") ((S A B) (A (B "a") e) (B (C 
"b") C) (C "c" e)) S) 3)
   (should
    (equal
-    '(("a") ("a" "b") ("a" "c") ("a" "c" "b") "b" ("b" "a") ("b" "a" "b") ("b" 
"a" "c") "c" ("c" "a") ("c" "a" "b") ("c" "a" "c") ("c" "b") ("c" "b" "a") e)
-    (parser--first
-     3
-     'S
-     '((S (A B))
-       (A (B "a") e)
-       (B (C "b") C)
-       (C "c" e)))))
+    '(("a") ("a" "b") ("a" "c") ("a" "c" "b") ("b") ("b" "a") ("b" "a" "b") 
("b" "a" "c") "c" ("c" "a") ("c" "a" "b") ("c" "a" "c") ("c" "b") ("c" "b" "a") 
(e))
+    (parser--first 'S)))
   (message "Passed first 3 with complex grammar")
 
   (message "Passed tests for (parser--first)"))



reply via email to

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