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

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

[nongnu] elpa/parseclj 96b8180987 087/185: Unparse ASTs that have lexica


From: ELPA Syncer
Subject: [nongnu] elpa/parseclj 96b8180987 087/185: Unparse ASTs that have lexical preservation.
Date: Tue, 28 Dec 2021 14:05:21 -0500 (EST)

branch: elpa/parseclj
commit 96b818098722a18486a59df47812001a6deda140
Author: Arne Brasseur <arne@arnebrasseur.net>
Commit: Arne Brasseur <arne@arnebrasseur.net>

    Unparse ASTs that have lexical preservation.
    
    This also includes a change where a reduction of :root returns a stack, 
rather
    than a single reduced result. This makes the interface of the reduce-branch
    functions consistent (they always return a stack).
---
 parseclj-ast.el                   |  61 +++----------
 parseclj-unparse.el               |  53 +++++++++++
 parseclj.el                       |  28 +++++-
 parseedn.el                       |   7 +-
 test/parseclj-ast-test.el         |   2 +-
 test/parseclj-ast-unparse-test.el | 166 ----------------------------------
 test/parseclj-unparse-test.el     | 184 ++++++++++++++++++++++++++++++++++++++
 7 files changed, 283 insertions(+), 218 deletions(-)

diff --git a/parseclj-ast.el b/parseclj-ast.el
index a56cfd8c00..afa91f8fc2 100644
--- a/parseclj-ast.el
+++ b/parseclj-ast.el
@@ -84,58 +84,25 @@ Other ATTRIBUTES can be given as a flat list of key-value 
pairs. "
                  (:lbrace :map)
                  (t type))))
     (cl-case type
-      (:root (parseclj-ast--node :root 0 :children children))
+      (:root (cons (parseclj-ast-node :root 0 :children children) stack))
       (:discard stack)
-      (:tag (list (parseclj-ast--node :tag
-                                      pos
-                                      :tag (intern (substring (a-get 
opener-token 'form) 1))
-                                      :children children)))
+      (:tag (list (parseclj-ast-node :tag
+                                     pos
+                                     :tag (intern (substring (a-get 
opener-token :form) 1))
+                                     :children children)))
       (t (cons
-          (parseclj-ast--node type pos :children children)
+          (parseclj-ast-node type pos :children children)
           stack)))))
 
 (defun parseclj-ast--reduce-branch-with-lexical-preservation (&rest args)
-  (let ((node (apply #'parseclj-ast--reduce-branch args)))
-    (cl-list*
-     (car node) ;; make sure :node-type remains the first element in the list
-     '(:lexical-preservation . t)
-     (cdr node))))
-
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Unparser
-
-(defun parseclj-ast-unparse-collection (nodes ld rd)
-  (insert ld)
-  (when-let (node (car nodes))
-    (parseclj-ast-unparse node))
-  (seq-doseq (node (cdr nodes))
-    (insert " ")
-    (parseclj-ast-unparse node))
-  (insert rd))
-
-(defun parseclj-ast-unparse-tag (node)
-  (progn
-    (insert "#")
-    (insert (symbol-name (a-get node :tag)))
-    (insert " ")
-    (parseclj-ast-unparse (car (a-get node :children)))))
-
-(defun parseclj-ast-unparse (node)
-  (if (parseclj--leaf? node)
-      (insert (alist-get ':form node))
-    (let ((subnodes (alist-get ':children node)))
-      (cl-case (a-get node ':node-type)
-        (:root (parseclj-ast-unparse-collection subnodes "" ""))
-        (:list (parseclj-ast-unparse-collection subnodes "(" ")"))
-        (:vector (parseclj-ast-unparse-collection subnodes "[" "]"))
-        (:set (parseclj-ast-unparse-collection subnodes "#{" "}"))
-        (:map (parseclj-ast-unparse-collection subnodes "{" "}"))
-        (:tag (parseclj-ast-unparse-tag node))))))
-
-(defun parseclj-ast-unparse-str (data)
-  (with-temp-buffer
-    (parseclj-ast-unparse data)
-    (buffer-substring-no-properties (point-min) (point-max))))
+  (let* ((stack (apply #'parseclj-ast--reduce-branch args))
+         (top (car stack)))
+    (if (parseclj-ast-node? top)
+        (cons (cl-list* (car top) ;; make sure :node-type remains the first 
element in the list
+                        '(:lexical-preservation . t)
+                        (cdr top))
+              (cdr stack))
+      stack)))
 
 (provide 'parseclj-ast)
 
diff --git a/parseclj-unparse.el b/parseclj-unparse.el
new file mode 100644
index 0000000000..8f2495c2b6
--- /dev/null
+++ b/parseclj-unparse.el
@@ -0,0 +1,53 @@
+;;; 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 1d98452502..1720f32fdf 100644
--- a/parseclj.el
+++ b/parseclj.el
@@ -205,7 +205,8 @@ functions.
                          (a-get token :pos)
                          (parseclj-lex-token-type token))))
 
-    (funcall reduce-branch stack '((type . :root) (pos . 1)) (reverse stack))))
+    (car (funcall reduce-branch nil (parseclj-lex-token :root "" 1)
+                  (reverse stack)))))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Top level API
@@ -238,6 +239,31 @@ key-value pairs to specify parsing options.
                         #'parseclj-ast--reduce-branch)
                       options))))
 
+(defun parseclj-unparse-clojure (ast)
+  "Parse Clojure AST to source code.
+
+Given an abstract syntax tree AST (as returned by
+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)))))
+
+(defun parseclj-unparse-clojure-to-string (ast)
+  "Parse Clojure AST to a source code string.
+
+Given an abstract syntax tree AST (as returned by
+parseclj-parse-clojure), turn it back into source code, and
+return it as a string"
+  (with-temp-buffer
+    (parseclj-unparse-clojure ast)
+    (buffer-substring-no-properties (point-min) (point-max))))
 
 (provide 'parseclj)
 
diff --git a/parseedn.el b/parseedn.el
index be15573824..863671d35a 100644
--- a/parseedn.el
+++ b/parseedn.el
@@ -47,12 +47,13 @@ handlers as an optional argument to the reader functions.")
     (cons (parseclj--leaf-token-value token) stack)))
 
 (defun parseedn-reduce-branch (tag-readers)
-  (lambda (stack opener-token children)
-    (let ((token-type (parseclj-lex-token-type opener-token)))
-      (if (member token-type '(:root :discard))
+  (lambda (stack opening-token children)
+    (let ((token-type (parseclj-lex-token-type opening-token)))
+      (if (eq token-type :discard)
           stack
         (cons
          (cl-case token-type
+           (:root children)
            (:lparen children)
            (:lbracket (apply #'vector children))
            (:set (list 'edn-set children))
diff --git a/test/parseclj-ast-test.el b/test/parseclj-ast-test.el
index 7283b8de68..0245dda8cd 100644
--- a/test/parseclj-ast-test.el
+++ b/test/parseclj-ast-test.el
@@ -58,7 +58,7 @@
                 (let ((test-name (intern (concat "parseclj-ast-rountrip:" 
name))))
                   `(ert-deftest ,test-name ()
                      :tags '(parseclj-ast-rountrip)
-                     (should (a-equal (parseclj-parse-clojure 
(parseclj-ast-unparse-str ',(a-get data :ast))) ',(a-get data :ast))))))))
+                     (should (a-equal (parseclj-parse-clojure 
(parseclj-unparse-clojure-to-string ',(a-get data :ast))) ',(a-get data 
:ast))))))))
         parseclj-test-data)))
 
 
diff --git a/test/parseclj-ast-unparse-test.el 
b/test/parseclj-ast-unparse-test.el
deleted file mode 100644
index 3851fd073e..0000000000
--- a/test/parseclj-ast-unparse-test.el
+++ /dev/null
@@ -1,166 +0,0 @@
-;;; parseclj-ast-unparse-test.el --- Print Clojure AST back to code - tests
-
-;; 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:
-
-;; Print Clojure AST back to code - tests
-
-;;; Code:
-
-(require 'ert)
-(require 'parseclj-ast)
-
-;;; Printer modes
-;; ----------------------------------------------------------------------------
-
-(ert-deftest parseclj-ast-unparse-list ()
-  (should (equal "(0 1 2)"
-                 (parseclj-ast-unparse-str '((:node-type . :root)
-                                        (:position . 0)
-                                        (:children . (((:node-type . :list)
-                                                       (:position . 1)
-                                                       (:children . 
(((:node-type . :number)
-                                                                      
(:position . 2)
-                                                                      (:form . 
"0")
-                                                                      (:value 
. 0))
-                                                                     
((:node-type . :number)
-                                                                      
(:position . 4)
-                                                                      (:form . 
"1")
-                                                                      (:value 
. 1))
-                                                                     
((:node-type . :number)
-                                                                      
(:position . 6)
-                                                                      (:form . 
"2")
-                                                                      (:value 
. 2))))))))))))
-
-(ert-deftest parseclj-ast-unparse-empty-list ()
-  (should (equal "()"
-                 (parseclj-ast-unparse-str '((:node-type . :root)
-                                        (:position . 0)
-                                        (:children . (((:node-type . :list)
-                                                       (:position . 1)
-                                                       (:children . 
nil)))))))))
-
-(ert-deftest parseclj-ast-unparse-nested-list ()
-  (should (equal "((.9 abc (true) (hello)))"
-                 (parseclj-ast-unparse-str '((:node-type . :root)
-                                        (:position . 0)
-                                        (:children . (((:node-type . :list)
-                                                       (:position . 1)
-                                                       (:children . 
(((:node-type . :list)
-                                                                      
(:position . 2)
-                                                                      
(:children ((:node-type . :number)
-                                                                               
   (:position . 3)
-                                                                               
   (:form . ".9")
-                                                                               
   (:value . 0.9))
-                                                                               
  ((:node-type . :symbol)
-                                                                               
   (:position . 6)
-                                                                               
   (:form . "abc")
-                                                                               
   (:value . abc))
-                                                                               
  ((:node-type . :list)
-                                                                               
   (:position . 10)
-                                                                               
   (:children ((:node-type . :true)
-                                                                               
               (:position . 11)
-                                                                               
               (:form . "true")
-                                                                               
               (:value . t))))
-                                                                               
  ((:node-type . :list)
-                                                                               
   (:position . 17)
-                                                                               
   (:children ((:node-type . :symbol)
-                                                                               
               (:position . 18)
-                                                                               
               (:form . "hello")
-                                                                               
               (:value . hello))))))))))))))))
-
-(ert-deftest parseclj-ast-unparse-string ()
-  (should (equal "\"abc hello \\t\\\"x\""
-                 (parseclj-ast-unparse-str '((:node-type . :root)
-                                        (:position . 0)
-                                        (:children . (((:node-type . :string)
-                                                       (:position . 1)
-                                                       (:form . "\"abc hello 
\\t\\\"x\"")
-                                                       (:value . "abc hello 
\t\"x")))))))))
-
-(ert-deftest parseclj-ast-unparse-chars ()
-  (should (equal "(\\newline \\return \\space \\tab \\a \\b \\c \\u0078 
\\o171)"
-                 (parseclj-ast-unparse-str '((:node-type . :root)
-                                        (:position . 0)
-                                        (:children . (((:node-type . :list)
-                                                       (:position . 1)
-                                                       (:children . 
(((:node-type . :character) (:position . 2) (:form . "\\newline") (:value . 
?\n))
-                                                                     
((:node-type . :character) (:position . 11) (:form . "\\return") (:value . ?\r))
-                                                                     
((:node-type . :character) (:position . 19) (:form . "\\space") (:value . 32))
-                                                                     
((:node-type . :character) (:position . 26) (:form . "\\tab") (:value . ?\t))
-                                                                     
((:node-type . :character) (:position . 31) (:form . "\\a") (:value . ?a))
-                                                                     
((:node-type . :character) (:position . 34) (:form . "\\b") (:value . ?b))
-                                                                     
((:node-type . :character) (:position . 37) (:form . "\\c") (:value . ?c))
-                                                                     
((:node-type . :character) (:position . 40) (:form . "\\u0078") (:value . ?x))
-                                                                     
((:node-type . :character) (:position . 47) (:form . "\\o171") (:value . 
?y)))))))))
-                 )))
-
-(ert-deftest parseclj-ast-unparse-keyword ()
-  (should (equal ":foo-bar"
-                 (parseclj-ast-unparse-str '((:node-type . :root)
-                                        (:position . 0)
-                                        (:children . (((:node-type . :keyword)
-                                                       (:position . 1)
-                                                       (:form . ":foo-bar")
-                                                       (:value . 
:foo-bar)))))))))
-
-(ert-deftest parseclj-ast-unparse-vector ()
-  (should (equal "[123]"
-                 (parseclj-ast-unparse-str '((:node-type . :root)
-                                        (:position . 0)
-                                        (:children . (((:node-type . :vector)
-                                                       (:position . 1)
-                                                       (:children . 
(((:node-type . :number)
-                                                                      
(:position . 2)
-                                                                      (:form . 
"123")
-                                                                      (:value 
. 123))))))))))))
-
-(ert-deftest parseclj-ast-unparse-map ()
-  (should (equal "{:count 123}"
-                 (parseclj-ast-unparse-str '((:node-type . :root)
-                                        (:position . 0)
-                                        (:children . (((:node-type . :map)
-                                                       (:position . 1)
-                                                       (:children . 
(((:node-type . :keyword)
-                                                                      
(:position . 2)
-                                                                      (:form . 
":count")
-                                                                      (:value 
. :count))
-                                                                     
((:node-type . :number)
-                                                                      
(:position . 9)
-                                                                      (:form . 
"123")
-                                                                      (:value 
. 123))))))))))))
-
-(ert-deftest parseclj-ast-unparse-set ()
-  (should (equal "#{:x}"
-                 (parseclj-ast-unparse-str '((:node-type . :root)
-                                        (:position . 0)
-                                        (:children . (((:node-type . :set)
-                                                       (:position . 1)
-                                                       (:children . 
(((:node-type . :keyword)
-                                                                      
(:position . 3)
-                                                                      (:form . 
":x")
-                                                                      (:value 
. :x))))))))))))
-
-(provide 'clj-unparse-test)
-
-;;; parseclj-ast-unparse-test.el ends here
diff --git a/test/parseclj-unparse-test.el b/test/parseclj-unparse-test.el
new file mode 100644
index 0000000000..37be1631dd
--- /dev/null
+++ b/test/parseclj-unparse-test.el
@@ -0,0 +1,184 @@
+;;; parseclj-unparse-test.el --- Print Clojure AST back to code - tests
+
+;; 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:
+
+;; Print Clojure AST back to code - tests
+
+;;; Code:
+
+(require 'ert)
+(require 'parseclj-ast)
+
+;;; Printer modes
+;; ----------------------------------------------------------------------------
+
+(ert-deftest parseclj-unparse-clojure-list ()
+  (should (equal "(0 1 2)"
+                 (parseclj-unparse-clojure-to-string
+                  '((:node-type . :root)
+                    (:position . 0)
+                    (:children . (((:node-type . :list)
+                                   (:position . 1)
+                                   (:children . (((:node-type . :number)
+                                                  (:position . 2)
+                                                  (:form . "0")
+                                                  (:value . 0))
+                                                 ((:node-type . :number)
+                                                  (:position . 4)
+                                                  (:form . "1")
+                                                  (:value . 1))
+                                                 ((:node-type . :number)
+                                                  (:position . 6)
+                                                  (:form . "2")
+                                                  (:value . 2))))))))))))
+
+(ert-deftest parseclj-unparse-clojure-empty-list ()
+  (should (equal "()"
+                 (parseclj-unparse-clojure-to-string
+                  '((:node-type . :root)
+                    (:position . 0)
+                    (:children . (((:node-type . :list)
+                                   (:position . 1)
+                                   (:children . nil)))))))))
+
+(ert-deftest parseclj-unparse-clojure-nested-list ()
+  (should (equal "((.9 abc (true) (hello)))"
+                 (parseclj-unparse-clojure-to-string
+                  '((:node-type . :root)
+                    (:position . 0)
+                    (:children . (((:node-type . :list)
+                                   (:position . 1)
+                                   (:children . (((:node-type . :list)
+                                                  (:position . 2)
+                                                  (:children ((:node-type . 
:number)
+                                                              (:position . 3)
+                                                              (:form . ".9")
+                                                              (:value . 0.9))
+                                                             ((:node-type . 
:symbol)
+                                                              (:position . 6)
+                                                              (:form . "abc")
+                                                              (:value . abc))
+                                                             ((:node-type . 
:list)
+                                                              (:position . 10)
+                                                              (:children 
((:node-type . :true)
+                                                                          
(:position . 11)
+                                                                          
(:form . "true")
+                                                                          
(:value . t))))
+                                                             ((:node-type . 
:list)
+                                                              (:position . 17)
+                                                              (:children 
((:node-type . :symbol)
+                                                                          
(:position . 18)
+                                                                          
(:form . "hello")
+                                                                          
(:value . hello))))))))))))))))
+
+(ert-deftest parseclj-unparse-clojure-to-stringing ()
+  (should (equal "\"abc hello \\t\\\"x\""
+                 (parseclj-unparse-clojure-to-string
+                  '((:node-type . :root)
+                    (:position . 0)
+                    (:children . (((:node-type . :string)
+                                   (:position . 1)
+                                   (:form . "\"abc hello \\t\\\"x\"")
+                                   (:value . "abc hello \t\"x")))))))))
+
+(ert-deftest parseclj-unparse-clojure-chars ()
+  (should (equal "(\\newline \\return \\space \\tab \\a \\b \\c \\u0078 
\\o171)"
+                 (parseclj-unparse-clojure-to-string
+                  '((:node-type . :root)
+                    (:position . 0)
+                    (:children . (((:node-type . :list)
+                                   (:position . 1)
+                                   (:children . (((:node-type . :character) 
(:position . 2) (:form . "\\newline") (:value . ?\n))
+                                                 ((:node-type . :character) 
(:position . 11) (:form . "\\return") (:value . ?\r))
+                                                 ((:node-type . :character) 
(:position . 19) (:form . "\\space") (:value . 32))
+                                                 ((:node-type . :character) 
(:position . 26) (:form . "\\tab") (:value . ?\t))
+                                                 ((:node-type . :character) 
(:position . 31) (:form . "\\a") (:value . ?a))
+                                                 ((:node-type . :character) 
(:position . 34) (:form . "\\b") (:value . ?b))
+                                                 ((:node-type . :character) 
(:position . 37) (:form . "\\c") (:value . ?c))
+                                                 ((:node-type . :character) 
(:position . 40) (:form . "\\u0078") (:value . ?x))
+                                                 ((:node-type . :character) 
(:position . 47) (:form . "\\o171") (:value . ?y)))))))))
+                 )))
+
+(ert-deftest parseclj-unparse-clojure-keyword ()
+  (should (equal ":foo-bar"
+                 (parseclj-unparse-clojure-to-string
+                  '((:node-type . :root)
+                    (:position . 0)
+                    (:children . (((:node-type . :keyword)
+                                   (:position . 1)
+                                   (:form . ":foo-bar")
+                                   (:value . :foo-bar)))))))))
+
+(ert-deftest parseclj-unparse-clojure-vector ()
+  (should (equal "[123]"
+                 (parseclj-unparse-clojure-to-string
+                  '((:node-type . :root)
+                    (:position . 0)
+                    (:children . (((:node-type . :vector)
+                                   (:position . 1)
+                                   (:children . (((:node-type . :number)
+                                                  (:position . 2)
+                                                  (:form . "123")
+                                                  (:value . 123))))))))))))
+
+(ert-deftest parseclj-unparse-clojure-map ()
+  (should (equal "{:count 123}"
+                 (parseclj-unparse-clojure-to-string
+                  '((:node-type . :root)
+                    (:position . 0)
+                    (:children . (((:node-type . :map)
+                                   (:position . 1)
+                                   (:children . (((:node-type . :keyword)
+                                                  (:position . 2)
+                                                  (:form . ":count")
+                                                  (:value . :count))
+                                                 ((:node-type . :number)
+                                                  (:position . 9)
+                                                  (:form . "123")
+                                                  (:value . 123))))))))))))
+
+(ert-deftest parseclj-unparse-clojure-set ()
+  (should (equal "#{:x}"
+                 (parseclj-unparse-clojure-to-string
+                  '((:node-type . :root)
+                    (:position . 0)
+                    (:children . (((:node-type . :set)
+                                   (:position . 1)
+                                   (:children . (((:node-type . :keyword)
+                                                  (:position . 3)
+                                                  (:form . ":x")
+                                                  (:value . :x))))))))))))
+
+(ert-deftest parseclj-unparse-clojure-lexical ()
+  (let ((src ";; hello world
+              (+ 1  2
+                      ;;good stuff
+          3)"))
+    (should (equal src (thread-first src
+                         (parseclj-parse-clojure :lexical-preservation t)
+                         (parseclj-unparse-clojure-to-string))))))
+
+(provide 'parseclj-unparse-test)
+
+;;; parseclj-unparse-test.el ends here



reply via email to

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