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

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

[elpa] externals/parser-generator 6a4b353 344/434: More work on translat


From: ELPA Syncer
Subject: [elpa] externals/parser-generator 6a4b353 344/434: More work on translations
Date: Mon, 29 Nov 2021 16:00:12 -0500 (EST)

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

    More work on translations
---
 parser-generator-lr.el           | 54 +++++++++++++++++++++-------------------
 parser-generator.el              |  2 +-
 test/parser-generator-lr-test.el | 35 ++++++++++++++++++--------
 3 files changed, 53 insertions(+), 38 deletions(-)

diff --git a/parser-generator-lr.el b/parser-generator-lr.el
index 79373f4..67343e1 100644
--- a/parser-generator-lr.el
+++ b/parser-generator-lr.el
@@ -1798,8 +1798,7 @@
                                 (setq popped-items (1+ popped-items)))))
                           (push production-number output)
 
-                          (let ((popped-items-meta-contents)
-                                (all-expanded t))
+                          (let ((popped-items-meta-contents))
                             ;; Collect arguments for translation
                             (dolist (popped-item popped-items-contents)
                               (parser-generator--debug
@@ -1826,15 +1825,19 @@
                                         temp-hash-key
                                         translation-symbol-table)
                                        popped-items-meta-contents)
-                                    (setq
-                                     all-expanded
-                                     nil)
                                     (push
                                      nil
                                      popped-items-meta-contents)))))
-                            (setq
-                             popped-items-meta-contents
-                             (nreverse popped-items-meta-contents))
+
+                            ;; If we just have one argument, pass it as a 
scalar
+                            (if (= (length popped-items-meta-contents) 1)
+                                (setq
+                                 popped-items-meta-contents
+                                 (car popped-items-meta-contents))
+                              (setq
+                               popped-items-meta-contents
+                               (nreverse popped-items-meta-contents)))
+
                             (parser-generator--debug
                              (message
                               "Production arguments: %s -> %s = %s"
@@ -1866,24 +1869,23 @@
                                    translation
                                    partial-translation))
 
-                              ;; When no translation is specified just use 
arguments as translation
-                              (when all-expanded
-                                (let ((partial-translation
-                                       popped-items-meta-contents))
-                                  (parser-generator--debug
-                                   (message
-                                    "translation-symbol-table: %s = %s 
(generic)"
-                                    production-lhs
-                                    partial-translation))
-                                  (puthash
-                                   (format
-                                    "%S"
-                                    production-lhs)
-                                   partial-translation
-                                   translation-symbol-table)
-                                  (setq
-                                   translation
-                                   partial-translation)))))
+                              ;; When no translation is specified just use 
partial-translation as translation
+                              (let ((partial-translation
+                                     popped-items-meta-contents))
+                                (parser-generator--debug
+                                 (message
+                                  "translation-symbol-table: %s = %s (generic)"
+                                  production-lhs
+                                  partial-translation))
+                                (puthash
+                                 (format
+                                  "%S"
+                                  production-lhs)
+                                 partial-translation
+                                 translation-symbol-table)
+                                (setq
+                                 translation
+                                 partial-translation))))
 
                           (let ((new-table-index (car pushdown-list)))
                             (let ((goto-table-distinct-index
diff --git a/parser-generator.el b/parser-generator.el
index b3520c8..72a44da 100644
--- a/parser-generator.el
+++ b/parser-generator.el
@@ -17,7 +17,7 @@
 
 (defvar
   parser-generator--debug
-  nil
+  t
   "Whether to print debug messages or not.")
 
 (defvar
diff --git a/test/parser-generator-lr-test.el b/test/parser-generator-lr-test.el
index b99a894..7da377a 100644
--- a/test/parser-generator-lr-test.el
+++ b/test/parser-generator-lr-test.el
@@ -573,7 +573,7 @@
 
   (parser-generator-process-grammar)
   ;; (should-error
-  ;;  (parser-generator-lr-generate-parser-tables))
+  ;;   (parser-generator-lr-generate-parser-tables))
   (message "Infix calculator grammar caused expected error")
 
   ;; Add precedence to resolve conflicts
@@ -641,19 +641,19 @@
       (start input)
       (input
        %empty
-       (input line))
+       (input line (lambda(args) (nth 1 args))))
       (line
        "\n"
-       (exp "\n"))
+       (exp "\n" (lambda(args) (nth 0 args))))
       (exp
        NUM
-       (exp "+" exp (lambda(args) (+ (car (nth 0 args)) (car (nth 2 args)))))
-       (exp "-" exp (lambda(args) (- (car (nth 0 args)) (car (nth 2 args)))))
-       (exp "*" exp (lambda(args) (* (car (nth 0 args)) (car (nth 2 args)))))
-       (exp "/" exp (lambda(args) (/ (car (nth 0 args)) (car (nth 2 args)))))
-       ("-" (exp (%prec NEG)) (lambda(args) (- (car (nth 1 args)))))
-       (exp "^" exp (lambda(args) (expt (car (nth 0 args)) (car (nth 2 
args)))))
-       ("(" exp ")" (lambda(args) (car (nth 1 args))))))
+       (exp "+" exp (lambda(args) (+ (nth 0 args) (nth 2 args))))
+       (exp "-" exp (lambda(args) (- (nth 0 args) (nth 2 args))))
+       (exp "*" exp (lambda(args) (* (nth 0 args) (nth 2 args))))
+       (exp "/" exp (lambda(args) (/ (nth 0 args) (nth 2 args))))
+       ("-" (exp (%prec NEG)) (lambda(args) (- (nth 1 args))))
+       (exp "^" exp (lambda(args) (expt (nth 0 args) (nth 2 args))))
+       ("(" exp ")" (lambda(args) (nth 1 args)))))
      start))
   (parser-generator-process-grammar)
 
@@ -662,21 +662,34 @@
 
   ;; TODO Test functionality here (then move to translate test)
   (let ((buffer (generate-new-buffer "*buffer*")))
+
     (switch-to-buffer buffer)
     (kill-region (point-min) (point-max))
     (insert "5+5\n")
     (should
      (equal
       10
-      (car (parser-generator-lr-translate))))
+      (parser-generator-lr-translate)))
+    (message "5+5=10\n")
+
+    (switch-to-buffer buffer)
+    (kill-region (point-min) (point-max))
+    (insert "5+4\n")
+    (should
+     (equal
+      9
+      (parser-generator-lr-translate)))
+    (message "5+4=9\n")
 
     (switch-to-buffer buffer)
     (kill-region (point-min) (point-max))
     (insert "7-3\n")
+    (message "7-3=%S" (parser-generator-lr-translate))
     (should
      (equal
       4
       (parser-generator-lr-translate)))
+    (message "7-3=4\n")
     (kill-buffer))
 
   (message "Passed tests for (parser-generator-lr--parse)"))



reply via email to

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