branch: externals/parser-generator commit 7bc3b7063c4fe78aedd296bfa6f8a6f076041c71 Author: Christian Johansson <christ...@cvj.se> Commit: Christian Johansson <christ...@cvj.se>
Updated tests to use new data structure --- parser.el | 20 +++++++++- test/parser-test.el | 108 +++++++++++++++++++++++----------------------------- 2 files changed, 67 insertions(+), 61 deletions(-) diff --git a/parser.el b/parser.el index f834667..e959931 100644 --- a/parser.el +++ b/parser.el @@ -165,7 +165,25 @@ (setq terminal-index (1+ terminal-index))))) ;; TODO Check every production - ;; TODO Check start + (let ((productions (nth 2 G))) + (let ((production-count (length productions)) + (production-index 0)) + (while (and + valid-p + (< production-index production-count)) + (let ((production (nth production-index productions))) + (unless (or + (symbolp production) + (stringp production)) + (setq valid-p nil))) + (setq production-index (1+ production-index))))) + + ;; Check start + (let ((start (nth 3 G))) + (when (and + valid-p + (not (or (stringp start) (symbolp start)))) + (setq valid-p nil))) ) valid-p)) diff --git a/test/parser-test.el b/test/parser-test.el index b7686da..615c0ea 100644 --- a/test/parser-test.el +++ b/test/parser-test.el @@ -30,162 +30,150 @@ (should (equal - '("a") + '(a) (parser--first 1 'S - '( - (S a))))) + '((S a))))) (message "Passed first 1 with rudimentary grammar") (should (equal - '("ab") + '("a" "b") (parser--first 2 'S '( - (S abc))))) + (S "a" "b" "c"))))) (message "Passed first 2 with rudimentary grammar") (should (equal - '("abc") + '("a" b "c") (parser--first 3 'S - '( - (S abc))))) + '((S "a" b "c"))))) (message "Passed first 3 with rudimentary grammar") (should (equal - '("b") + '(b) (parser--first 1 'S - '( - (S A) + '((S A) (A b))))) (message "Passed first 1 with intermediate grammar") (should (equal - '("ba") + '("b" "a") (parser--first 2 'S - '( - (S A) - (A ba))))) + '((S A) + (A ("b" "a")))))) (message "Passed first 2 with intermediate grammar") (should (equal - '("bac") + '("b" "a" "c") (parser--first 3 'S - '( - (S A) - (A bace))))) + '((S A) + (A ("b" "a" "c" e)))))) (message "Passed first 3 with intermediate grammar") (should (equal - '("c" "d") + '(c d) (parser--first 1 'S - '( - (S A) + '((S A) (A B) - (B c d))))) + (B (c d)))))) (message "Passed first 1 with semi-complex grammar") (should (equal - '("cf" "da") + '((c f) (da)) (parser--first 2 'S - '( - (S Aa) + '((S (A a)) (A B) - (B cf d))))) + (B (c f) d))))) (message "Passed first 2 with semi-complex grammar") (should (equal - '("cam" "dam") + '(("c" "a" "m") ("d" "a" "m")) (parser--first 3 'S - '( - (S A) - (A Bam) - (B c d))))) + '((S A) + (A (B "a" "m")) + (B "c" "d"))))) (message "Passed first 3 with semi-complex grammar") (should (equal - '("a" "b" "c" "e") + '((a) (b) (c) (e)) (parser--first 1 'S - '( - (S AB) - (A Ba e) - (B Cb C) + '((S (A B)) + (A (B a) e) + (B (C b) C) (C c e))))) (message "Passed first 1 with complex grammar") ;; Example 5.28 p 402 (should (equal - '("a" "ab" "ac" "b" "ba" "c" "ca" "cb" "e") + '(("a") ("a" "b") ("a" "c") ("b") ("b" "a") ("c") ("c" "a") ("c" "b") (e)) (parser--first 2 'S - '( - (S AB) - (A Ba e) - (B Cb C) - (C c e))))) + '((S (AB)) + (A (B "a") e) + (B (C "b") C) + (C "c" e))))) (message "Passed first 2 with complex grammar") (should (equal - '("a" "ab" "ac" "acb" "b" "ba" "bab" "bac" "c" "ca" "cab" "cac" "cb" "cba" "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 3 'S - '( - (S AB) - (A Ba e) - (B Cb C) - (C c e))))) + '((S (A B)) + (A (B "a") e) + (B (C "b") C) + (C "c" e))))) (message "Passed first 3 with complex grammar") (message "Passed tests for (parser--first)")) ;; Example 5.28 page 402 -(defun parser-test--empty-free-first () - "Test `parser--empty-free-first'." - (message "Starting tests for (parser--empty-free-first)") +(defun parser-test--e-free-first () + "Test `parser--e-free-first'." + (message "Starting tests for (parser--e-free-first)") ;; Example 5.28 p 402 (should (equal - '("ca" "cb") - (parser--empty-free-first + '(("c" "a") ("c" "b")) + (parser--e-free-first 2 'S - '( - (S AB) - (A Ba e) - (B Cb C) - (C c e))))) + '((S (A B)) + (A (B "a") e) + (B (C "b") C) + (C "c" e))))) (message "Passed empty-free-first 2 with complex grammar") (message "Passed tests for (parser--empty-free-first)")) @@ -283,7 +271,7 @@ (parser-test--distinct) (parser-test--valid-sentential-form-p) (parser-test--first) - (parser-test--empty-free-first) + (parser-test--e-free-first) ;; (parser-test--v-set) )