branch: externals/parser-generator
commit 046e23911cf599e3cc9d3613b5587e67fc2867ab
Author: Christian Johansson <[email protected]>
Commit: Christian Johansson <[email protected]>
Passing first 3 complex tests for first
---
parser-generator.el | 11 ++++++++++-
test/parser-generator-test.el | 8 ++++----
2 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/parser-generator.el b/parser-generator.el
index b3fbbc4..e1eb1e6 100644
--- a/parser-generator.el
+++ b/parser-generator.el
@@ -11,7 +11,7 @@
(defvar parser-generator--debug
- t
+ nil
"Whether to print debug messages or not.")
(defvar parser-generator--e-identifier
@@ -1073,10 +1073,19 @@
(setq first (append first (car symbol-f-set))))))))
(setq input-tape-index (1+ input-tape-index)))
(when (> first-length 0)
+ ;; When length of terminals list is below K
+ ;; fill up with e-identifiers
+ (when (and
+ (< (length first) k))
+ (setq first (reverse first))
+ (while (< (length first) k)
+ (push parser-generator--e-identifier first))
+ (setq first (reverse first)))
(parser-generator--debug
(message "push to first-list: %s to %s" first first-list))
(push first first-list))))))
+ (setq first-list (parser-generator--distinct first-list))
(setq first-list (sort first-list 'parser-generator--sort-list))
first-list)))
diff --git a/test/parser-generator-test.el b/test/parser-generator-test.el
index aa42d97..c67cf95 100644
--- a/test/parser-generator-test.el
+++ b/test/parser-generator-test.el
@@ -177,7 +177,7 @@
(parser-generator-process-grammar)
(should
(equal
- '((a))
+ '((a e))
(parser-generator--first '(a))))
(message "Passed first 1d with rudimentary grammar")
@@ -204,7 +204,7 @@
(parser-generator-process-grammar)
(should
(equal
- '((b))
+ '((b e))
(parser-generator--first 'S)))
(message "Passed first 1 with intermediate grammar")
@@ -268,7 +268,7 @@
(parser-generator-process-grammar)
(should
(equal
- '((a b) (a c) (a) (b a) (b) (c a) (c) (c b) (e))
+ '((a b) (a c) (a e) (b a) (b e) (c a) (c b) (c e) (e e))
(parser-generator--first 'S)))
(message "Passed first 2 with complex grammar")
@@ -277,7 +277,7 @@
(parser-generator-process-grammar)
(should
(equal
- '((a) (a b) (a c) (a c b) (b a) (b a b) (b a c) (b) (c a) (c a b) (c a c)
(c b) (c) (c b a) (e))
+ '((a b e) (a c b) (a c e) (a e e) (b a b) (b a c) (b a e) (b e e) (c a b)
(c a c) (c a e) (c b a) (c b e) (c e e) (e e e))
(parser-generator--first 'S)))
(message "Passed first 3 with complex grammar")