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

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

[nongnu] elpa/parseclj ece9648128 179/185: Merge pull request #33 from c


From: ELPA Syncer
Subject: [nongnu] elpa/parseclj ece9648128 179/185: Merge pull request #33 from clojure-emacs/arne/remove-a-from-tests
Date: Tue, 28 Dec 2021 14:05:34 -0500 (EST)

branch: elpa/parseclj
commit ece96481286d3284a309e688ce2d98dadbf1fbfc
Merge: 1c8f833b4c c7f50e3414
Author: Arne Brasseur <arne.brasseur@gmail.com>
Commit: GitHub <noreply@github.com>

    Merge pull request #33 from clojure-emacs/arne/remove-a-from-tests
    
    Remove the last remains of a.el, restructure requires
---
 CHANGELOG.md                     |   2 +-
 Cask                             |   1 -
 parseclj.el => parseclj-alist.el | 108 ++++++++-------------------------------
 parseclj-ast.el                  |   1 +
 parseclj-lex.el                  |   2 +
 parseclj-parser.el               |   4 +-
 parseclj.el                      |  53 +------------------
 test/parseclj-ast-test.el        |   8 +--
 test/parseclj-test-data.el       |  15 +++++-
 9 files changed, 48 insertions(+), 146 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index e814682d7e..db9490b7fb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,6 @@
 # Unreleased
 
-## 1.0.2 (2021-09-28)
+## 1.0.3 (2021-09-29)
 
 - Remove remaining a.el usage (this time for real)
 
diff --git a/Cask b/Cask
index d2e52aae75..197ccc59b7 100644
--- a/Cask
+++ b/Cask
@@ -8,5 +8,4 @@
        "parseclj-parser.el")
 
 (development
- (depends-on "a")
  (depends-on "ert-runner"))
diff --git a/parseclj.el b/parseclj-alist.el
similarity index 53%
copy from parseclj.el
copy to parseclj-alist.el
index 4ba69b5082..1537293284 100644
--- a/parseclj.el
+++ b/parseclj-alist.el
@@ -1,11 +1,8 @@
-;;; parseclj.el --- Clojure/EDN parser              -*- lexical-binding: t; -*-
+;;; parseclj-alist.el --- Clojure/EDN parser              -*- lexical-binding: 
t; -*-
 
 ;; Copyright (C) 2017-2021  Arne Brasseur
 
 ;; Author: Arne Brasseur <arne@arnebrasseur.net>
-;; Keywords: lisp clojure edn parser
-;; Package-Requires: ((emacs "25"))
-;; Version: 1.0.2
 
 ;; This file is not part of GNU Emacs.
 
@@ -26,13 +23,10 @@
 
 ;;; Commentary:
 
-;; Top level API for the Clojure parser.
+;; A shift/reduce parser for Clojure source.
 
 ;;; Code:
 
-(require 'map)
-(require 'seq)
-
 (defun parseclj-alist (&rest kvs)
   "Create an association list from the given keys and values KVS.
 Arguments are simply provided in sequence, rather than as lists or cons cells.
@@ -41,26 +35,6 @@ For example: (parseclj-alist :foo 123 :bar 456)"
   ;; (map-into kvs 'alist)
   (mapcar (lambda (kv) (cons (car kv) (cadr kv))) (seq-partition kvs 2)))
 
-(require 'parseclj-parser)
-(require 'parseclj-ast)
-
-(defun parseclj-hash-table (&rest kvs)
-  "Create a hash table from the given keys and values KVS.
-Arguments are simply provided in sequence, rather than as lists
-or cons cells. As \"test\" for the hash table, equal is used. The
-hash table is created without extra storage space, so with a size
-equal to amount of key-value pairs, since it is assumed to be
-treated as immutable.
-For example: (parseclj-hash-table :foo 123 :bar 456)"
-  ;; Emacs 27:
-  ;; (map-into kvs 'hash-table)
-  (let* ((kv-pairs (seq-partition kvs 2))
-         (hash-map (make-hash-table :test 'equal :size (length kv-pairs))))
-    (seq-do (lambda (pair)
-              (puthash (car pair) (cadr pair) hash-map))
-            kv-pairs)
-    hash-map))
-
 (defun parseclj-alist-assoc (coll k v)
   "Associate a key K with a value V in the association list COLL
 
@@ -86,61 +60,23 @@ value."
                         key
                         (apply #'funcall fn (map-elt coll key) args)))
 
-(defun parseclj-parse-clojure (&rest string-and-options)
-  "Parse Clojure source to AST.
-
-Reads either from the current buffer, starting from point, until
-`point-max', or reads from the optional string argument.
-
-STRING-AND-OPTIONS can be an optional string, followed by
-key-value pairs to specify parsing options.
-
-- `:lexical-preservation' Retain whitespace, comments, and
-  discards.  Defaults to nil.
-- `:fail-fast' Raise an error when encountering invalid syntax.
-  Defaults to t.
-- `:read-one'
-  Read a single form.  Defaults to false: parse the complete input."
-  (if (stringp (car string-and-options))
-      (with-temp-buffer
-        (insert (car string-and-options))
-        (goto-char 1)
-        (apply 'parseclj-parse-clojure (cdr string-and-options)))
-    (let* ((value-p (lambda (e)
-                      (and (parseclj-ast-node-p e)
-                           (not (member (parseclj-ast-node-type e) 
'(:whitespace :comment :discard))))))
-           (options (apply 'parseclj-alist :value-p value-p 
string-and-options))
-           (lexical? (map-elt options :lexical-preservation)))
-      (parseclj-parser (if lexical?
-                           
#'parseclj-ast--reduce-leaf-with-lexical-preservation
-                         #'parseclj-ast--reduce-leaf)
-                       (if lexical?
-                           
#'parseclj-ast--reduce-branch-with-lexical-preservation
-                         #'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-p ast)
-      (insert (map-elt ast :form))
-    (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.
-
-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)
-
-;;; parseclj.el ends here
+(defun parseclj-hash-table (&rest kvs)
+  "Create a hash table from the given keys and values KVS.
+Arguments are simply provided in sequence, rather than as lists
+or cons cells. As \"test\" for the hash table, equal is used. The
+hash table is created without extra storage space, so with a size
+equal to amount of key-value pairs, since it is assumed to be
+treated as immutable.
+For example: (parseclj-hash-table :foo 123 :bar 456)"
+  ;; Emacs 27:
+  ;; (map-into kvs 'hash-table)
+  (let* ((kv-pairs (seq-partition kvs 2))
+         (hash-map (make-hash-table :test 'equal :size (length kv-pairs))))
+    (seq-do (lambda (pair)
+              (puthash (car pair) (cadr pair) hash-map))
+            kv-pairs)
+    hash-map))
+
+(provide 'parseclj-alist)
+
+;;; parseclj-alist.el ends here
diff --git a/parseclj-ast.el b/parseclj-ast.el
index 2470b06ed7..63b25612ae 100644
--- a/parseclj-ast.el
+++ b/parseclj-ast.el
@@ -30,6 +30,7 @@
 (require 'seq)
 (require 'subr-x)
 (require 'parseclj-lex)
+(require 'parseclj-alist)
 
 ;; AST helper functions
 
diff --git a/parseclj-lex.el b/parseclj-lex.el
index 8752f5dbd1..8b30393251 100644
--- a/parseclj-lex.el
+++ b/parseclj-lex.el
@@ -27,6 +27,8 @@
 
 ;;; Code:
 
+(require 'parseclj-alist)
+
 (defvar parseclj-lex--leaf-tokens '(:whitespace
                                     :comment
                                     :symbolic-value
diff --git a/parseclj-parser.el b/parseclj-parser.el
index 5ff210df45..aaad607d39 100644
--- a/parseclj-parser.el
+++ b/parseclj-parser.el
@@ -3,9 +3,6 @@
 ;; Copyright (C) 2017-2021  Arne Brasseur
 
 ;; Author: Arne Brasseur <arne@arnebrasseur.net>
-;; Keywords: lisp
-;; Package-Requires: ((emacs "25"))
-;; Version: 0.2.0
 
 ;; This file is not part of GNU Emacs.
 
@@ -33,6 +30,7 @@
 (require 'cl-lib)
 (require 'subr-x)
 (require 'parseclj-lex)
+(require 'parseclj-alist)
 
 (define-error 'parseclj-parser-error "parseclj: Syntax error")
 
diff --git a/parseclj.el b/parseclj.el
index 4ba69b5082..f2aecb8ac3 100644
--- a/parseclj.el
+++ b/parseclj.el
@@ -5,7 +5,7 @@
 ;; Author: Arne Brasseur <arne@arnebrasseur.net>
 ;; Keywords: lisp clojure edn parser
 ;; Package-Requires: ((emacs "25"))
-;; Version: 1.0.2
+;; Version: 1.0.3
 
 ;; This file is not part of GNU Emacs.
 
@@ -33,58 +33,9 @@
 (require 'map)
 (require 'seq)
 
-(defun parseclj-alist (&rest kvs)
-  "Create an association list from the given keys and values KVS.
-Arguments are simply provided in sequence, rather than as lists or cons cells.
-For example: (parseclj-alist :foo 123 :bar 456)"
-  ;; Emacs 27:
-  ;; (map-into kvs 'alist)
-  (mapcar (lambda (kv) (cons (car kv) (cadr kv))) (seq-partition kvs 2)))
-
 (require 'parseclj-parser)
 (require 'parseclj-ast)
-
-(defun parseclj-hash-table (&rest kvs)
-  "Create a hash table from the given keys and values KVS.
-Arguments are simply provided in sequence, rather than as lists
-or cons cells. As \"test\" for the hash table, equal is used. The
-hash table is created without extra storage space, so with a size
-equal to amount of key-value pairs, since it is assumed to be
-treated as immutable.
-For example: (parseclj-hash-table :foo 123 :bar 456)"
-  ;; Emacs 27:
-  ;; (map-into kvs 'hash-table)
-  (let* ((kv-pairs (seq-partition kvs 2))
-         (hash-map (make-hash-table :test 'equal :size (length kv-pairs))))
-    (seq-do (lambda (pair)
-              (puthash (car pair) (cadr pair) hash-map))
-            kv-pairs)
-    hash-map))
-
-(defun parseclj-alist-assoc (coll k v)
-  "Associate a key K with a value V in the association list COLL
-
-Returns a new alist (does not mutate its argument). If an entry
-with the same key is present it will be replaced, otherwise the
-new kv-pair is added to the head of the list."
-  (if (map-contains-key coll k)
-      (mapcar (lambda (entry)
-                (if (equal (car entry) k)
-                    (cons k v)
-                  entry))
-              coll)
-    (cons (cons k v) coll)))
-
-(defun parseclj-alist-update (coll key fn &rest args)
-  "In collection COLL, at location KEY, apply FN with extra args ARGS.
-'Updates' a value in an associative collection COLL, where KEY is
-a key and FN is a function that will take the old value and any
-supplied args and return the new value, and returns a new
-structure. If the key does not exist, nil is passed as the old
-value."
-  (parseclj-alist-assoc coll
-                        key
-                        (apply #'funcall fn (map-elt coll key) args)))
+(require 'parseclj-alist)
 
 (defun parseclj-parse-clojure (&rest string-and-options)
   "Parse Clojure source to AST.
diff --git a/test/parseclj-ast-test.el b/test/parseclj-ast-test.el
index 4ac9355c2c..d039548628 100644
--- a/test/parseclj-ast-test.el
+++ b/test/parseclj-ast-test.el
@@ -27,7 +27,6 @@
 
 ;;; Code
 
-(require 'a)
 (require 'ert)
 (require 'parseclj-ast)
 
@@ -46,7 +45,7 @@
                      (with-temp-buffer
                        (insert ,(map-elt data :source))
                        (goto-char 1)
-                       (should (a-equal (parseclj-parse-clojure) ',(map-elt 
data :ast)))))))))
+                       (should (equal (parseclj-parse-clojure) ',(map-elt data 
:ast)))))))))
         parseclj-test-data)))
 
 (defmacro define-parseclj-ast-roundtrip-tests ()
@@ -59,7 +58,10 @@
                 (let ((test-name (intern (concat "parseclj-ast-rountrip:" 
name))))
                   `(ert-deftest ,test-name ()
                      :tags '(parseclj-ast-rountrip)
-                     (should (a-equal (parseclj-parse-clojure 
(parseclj-unparse-clojure-to-string ',(map-elt data :ast))) ',(map-elt data 
:ast))))))))
+                     (should (equal (parseclj-parse-clojure 
(parseclj-unparse-clojure-to-string
+                                                             ',(map-elt data 
:ast)))
+                                    ',(or (map-elt data :roundtrip-ast)
+                                          (map-elt data :ast)))))))))
         parseclj-test-data)))
 
 (define-parseclj-ast-roundtrip-tests)
diff --git a/test/parseclj-test-data.el b/test/parseclj-test-data.el
index cc7a8ba490..053fe126a4 100644
--- a/test/parseclj-test-data.el
+++ b/test/parseclj-test-data.el
@@ -272,7 +272,20 @@
                                             ((:node-type . :number)
                                              (:position . 10)
                                              (:form . "12")
-                                             (:value . 12)))))))))
+                                             (:value . 12))))))))
+        ;; After round-tripping the position of the "12" is no longer the same
+        :roundtrip-ast '((:node-type . :root)
+                         (:position . 1)
+                         (:children . (((:node-type . :list)
+                                        (:position . 1)
+                                        (:children . (((:node-type . :number)
+                                                       (:position . 2)
+                                                       (:form . "10")
+                                                       (:value . 10))
+                                                      ((:node-type . :number)
+                                                       (:position . 5)
+                                                       (:form . "12")
+                                                       (:value . 12)))))))))
 
 
        "tag-1"



reply via email to

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