[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/parseclj 62c9bf9126 177/185: Remove the last remains of a.
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/parseclj 62c9bf9126 177/185: Remove the last remains of a.el, restructure requires |
Date: |
Tue, 28 Dec 2021 14:05:34 -0500 (EST) |
branch: elpa/parseclj
commit 62c9bf912628b32375fdf0bd2a4115421f6be038
Author: Arne Brasseur <arne@arnebrasseur.net>
Commit: Arne Brasseur <arne@arnebrasseur.net>
Remove the last remains of a.el, restructure requires
Remove the last calls of a-equals from the tests, so we can truly drop this.
Extract the alist/hash-map helpers in a separate file so we can require them
everywhere we need them.
---
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 +++++-
8 files changed, 47 insertions(+), 145 deletions(-)
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"
- [nongnu] elpa/parseclj 168027fed5 094/185: Merge pull request #7 from lambdaisland/reorganize-package, (continued)
- [nongnu] elpa/parseclj 168027fed5 094/185: Merge pull request #7 from lambdaisland/reorganize-package, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 45bd6a7431 109/185: Clean up tests, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 1f8e449897 105/185: Simplify error messages, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj f362018ff1 112/185: Silence the byte-compiler about some unused vars., ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 70804992ee 122/185: Merge pull request #14 from lambdaisland/parseclj-lex-symbol-fix, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 19ca5f5bd0 121/185: Stick to the previous Travis Trusty image, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj b2550e6456 133/185: Add docstring for `parseclj-lex--string-value`, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 13059d8529 138/185: Minor checkdoc fixes, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 49c715ed22 148/185: For prefix-2 elements: pass children to reduce in right order, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj dc0d165b0a 152/185: Merge pull request #23 from clojure-emacs/read-one, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 62c9bf9126 177/185: Remove the last remains of a.el, restructure requires,
ELPA Syncer <=
- [nongnu] elpa/parseclj 517a371616 166/185: Use map-elt instead of parseclj-alist-get, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj ba04dbe334 171/185: Remove remaining a-list call, move a.el to be test-only, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 48abe456c6 155/185: Update the installation instructions, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj b234692020 157/185: error on unmatched closing paren/brace, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 1bb3800f8f 162/185: Update CHANGELOG, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj fcebf65075 180/185: Provide parseclj-alist-merge for older Emacsen, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj eff9411268 161/185: Merge pull request #26 from ikappaki/master, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 689ebddbdd 158/185: Add support for shebang and symbolic values, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 1e46607912 015/185: Split files into packages, More test setup, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj a9dba19760 086/185: Clean up node and token types, ELPA Syncer, 2021/12/28