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

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

[nongnu] elpa/parseclj 296a093132 102/185: Remove `parseclj-unparse`


From: ELPA Syncer
Subject: [nongnu] elpa/parseclj 296a093132 102/185: Remove `parseclj-unparse`
Date: Tue, 28 Dec 2021 14:05:24 -0500 (EST)

branch: elpa/parseclj
commit 296a0931325b1e5c1395b7613fef3a3d001c0193
Author: Daniel Barreto <daniel.barreto.n@gmail.com>
Commit: Daniel Barreto <daniel.barreto.n@gmail.com>

    Remove `parseclj-unparse`
    
    Place unparse logic in `parseclj-ast`.
---
 parseclj-ast.el     | 35 +++++++++++++++++++++++++++++++++++
 parseclj-unparse.el | 53 -----------------------------------------------------
 parseclj.el         | 11 +++--------
 3 files changed, 38 insertions(+), 61 deletions(-)

diff --git a/parseclj-ast.el b/parseclj-ast.el
index 190c3e6a75..e0ae5d90f4 100644
--- a/parseclj-ast.el
+++ b/parseclj-ast.el
@@ -27,6 +27,7 @@
 
 ;;; Code:
 
+(require 'subr-x)
 (require 'parseclj-lex)
 (require 'parseedn)
 
@@ -51,6 +52,7 @@ Other ATTRIBUTES can be given as a flat list of key-value 
pairs."
   "Return t if the given ast NODE is a leaf node."
   (member (parseclj-ast-node-type node) parseclj-lex--leaf-tokens))
 
+
 ;; Parse/reduce strategy functions
 
 (defun parseclj-ast--reduce-leaf (stack token &optional options)
@@ -139,6 +141,39 @@ on available options."
                 (cdr stack))
         stack))))
 
+
+
+;; Unparse functions
+
+(declare-function parseclj-unparse-clojure "parseclj")
+
+(defun parseclj-ast--unparse-collection (node)
+  "Insert the given AST branch NODE into buffer as a string."
+  (let* ((token-type (parseclj-ast-node-type node))
+         (delimiters (cl-case token-type
+                       (:root (cons "" ""))
+                       (:list (cons "(" ")"))
+                       (:vector (cons "[" "]"))
+                       (:set (cons "#{" "}"))
+                       (:map (cons "{" "}")))))
+    (insert (car delimiters))
+    (let ((nodes (alist-get ':children node)))
+      (when-let (node (car nodes))
+        (parseclj-unparse-clojure node))
+      (seq-doseq (child (cdr nodes))
+        (when (not (a-get node :lexical-preservation))
+          (insert " "))
+        (parseclj-unparse-clojure child)))
+    (insert (cdr delimiters))))
+
+(defun parseclj-ast--unparse-tag (node)
+  "Insert the given AST tag NODE into buffer as a string."
+  (progn
+    (insert "#")
+    (insert (symbol-name (a-get node :tag)))
+    (insert " ")
+    (parseclj-unparse-clojure (car (a-get node :children)))))
+
 (provide 'parseclj-ast)
 
 ;;; parseclj-ast.el ends here
diff --git a/parseclj-unparse.el b/parseclj-unparse.el
deleted file mode 100644
index 8f2495c2b6..0000000000
--- a/parseclj-unparse.el
+++ /dev/null
@@ -1,53 +0,0 @@
-;;; parseclj-unparser.el --- Clojure unparser   -*- lexical-binding: t; -*-
-
-;; Copyright (C) 2017  Arne Brasseur
-
-;; Author: Arne Brasseur <arne@arnebrasseur.net>
-
-;; This file is not part of GNU Emacs.
-
-;; This file is free software; you can redistribute it and/or modify
-;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 3, or (at your option)
-;; any later version.
-
-;; This file is distributed in the hope that it will be useful,
-;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-;; GNU General Public License for more details.
-
-;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to
-;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
-
-;;; Commentary:
-
-;; Unparse an AST to Clojure code
-
-;;; Code:
-
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Unparser helpers
-
-(defun parseclj-unparse--collection (node ld rd)
-  (insert ld)
-  (let ((nodes (alist-get ':children node)))
-    (when-let (node (car nodes))
-      (parseclj-unparse-clojure node))
-    (seq-doseq (child (cdr nodes))
-      (when (not (a-get node :lexical-preservation))
-        (insert " "))
-      (parseclj-unparse-clojure child)))
-  (insert rd))
-
-(defun parseclj-unparse--tag (node)
-  (progn
-    (insert "#")
-    (insert (symbol-name (a-get node :tag)))
-    (insert " ")
-    (parseclj-unparse-clojure (car (a-get node :children)))))
-
-(provide 'parseclj-unparse)
-
-;;; parseclj-unparse.el ends here
diff --git a/parseclj.el b/parseclj.el
index 8d60df3b89..0d3450c86f 100644
--- a/parseclj.el
+++ b/parseclj.el
@@ -36,7 +36,6 @@
 (require 'parseclj-lex)
 (require 'parseedn)
 (require 'parseclj-ast)
-(require 'parseclj-unparse)
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;; Shift-Reduce Parser
@@ -273,13 +272,9 @@ parseclj-parse-clojure), turn it back into source code, and
 insert it into the current buffer."
   (if (parseclj-ast-leaf-node? ast)
       (insert (a-get ast :form))
-    (cl-case (parseclj-ast-node-type ast)
-      (:root (parseclj-unparse--collection ast "" ""))
-      (:list (parseclj-unparse--collection ast "(" ")"))
-      (:vector (parseclj-unparse--collection ast "[" "]"))
-      (:set (parseclj-unparse--collection ast "#{" "}"))
-      (:map (parseclj-unparse--collection ast "{" "}"))
-      (:tag (parseclj-unparse--tag ast)))))
+    (if (eql (parseclj-ast-node-type ast) :tag)
+        (parseclj-ast--unparse-tag ast)
+      (parseclj-ast--unparse-collection ast))))
 
 (defun parseclj-unparse-clojure-to-string (ast)
   "Parse Clojure AST to a source code string.



reply via email to

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