[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.
- [nongnu] elpa/parseclj 4367db07aa 061/185: Move tests to tests/, bench to benchmark/, (continued)
- [nongnu] elpa/parseclj 4367db07aa 061/185: Move tests to tests/, bench to benchmark/, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 46570ce843 060/185: A # can be part of a symbol, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj fcd1a086f6 081/185: Rename clj-ast to parseclj-ast, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 987bd16a57 089/185: Position starts at 1, not at 0 (just like (point)), ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 313fc4e630 077/185: Rename to parseclj, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 7f8bcd405e 095/185: Make checkdoc happy with parseclj.el, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 0f16fcf2fa 084/185: Implement parsing with lexical preservation (keep whitespace, comments), ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj ca854455f6 099/185: Add missing requirement to `parseedn`, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj adbc0cabf5 100/185: Move `parseclj--{leaf, closing}-tokens` to `parseclj-lex` module, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 7794d9ee59 101/185: Add docstrings for `parseclj-lex` module, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 296a093132 102/185: Remove `parseclj-unparse`,
ELPA Syncer <=
- [nongnu] elpa/parseclj d6525d30c6 111/185: Merge pull request #10 from lambdaisland/fix-ast-reduce-tag, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 0ef32ad912 120/185: Add support for having single quotes in symbols/keywords, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 0afb8c5f09 123/185: Add `parseclj-lex-error-token` helper, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj b2588ce0fb 126/185: Use EVM to setup Travis CI, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 46cfcd3120 129/185: Merge pull request #16 from lambdaisland/parseclj-lex-error-token, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 61577603f2 136/185: Update README.md with installation and usage information, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj a82f229014 139/185: Ignore *.elc files, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 7fba1624e0 142/185: Update DESIGN.md to name difference between parseclj and parseedn, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 3693dd148f 145/185: Fix Cask file, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj af6102c4a8 146/185: Minor fix to README file, ELPA Syncer, 2021/12/28