[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/parseclj f395b9cbcc 097/185: Move `parseclj--leaf-token-va
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/parseclj f395b9cbcc 097/185: Move `parseclj--leaf-token-value` to `parseedn` module |
Date: |
Tue, 28 Dec 2021 14:05:24 -0500 (EST) |
branch: elpa/parseclj
commit f395b9cbcccd7b5652f38a0bcbb773130aade81e
Author: Daniel Barreto <daniel.barreto.n@gmail.com>
Commit: Daniel Barreto <daniel.barreto.n@gmail.com>
Move `parseclj--leaf-token-value` to `parseedn` module
Also moves string/char parsing functions to `parseedn`.
---
parseclj-ast.el | 4 +++-
parseclj.el | 50 --------------------------------------------------
parseedn.el | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 55 insertions(+), 52 deletions(-)
diff --git a/parseclj-ast.el b/parseclj-ast.el
index 7326471af1..95958a662d 100644
--- a/parseclj-ast.el
+++ b/parseclj-ast.el
@@ -27,6 +27,8 @@
;;; Code:
+(require 'parseedn)
+
;; AST helper functions
(defun parseclj-ast-node (type position &rest attributes)
@@ -58,7 +60,7 @@ Other ATTRIBUTES can be given as a flat list of key-value
pairs. "
(parseclj-ast-node (parseclj-lex-token-type token)
(a-get token :pos)
:form (a-get token :form)
- :value (parseclj--leaf-token-value token))
+ :value (parseedn--leaf-token-value token))
stack)))
(defun parseclj-ast--reduce-leaf-with-lexical-preservation (stack token
options)
diff --git a/parseclj.el b/parseclj.el
index 259606c303..8d5698300a 100644
--- a/parseclj.el
+++ b/parseclj.el
@@ -56,56 +56,6 @@
:rbrace)
"Types of tokens that mark the end of a non-atomic form.")
-;; The EDN spec is not clear about wether \u0123 and \o012 are supported in
-;; strings. They are described as character literals, but not as string escape
-;; codes. In practice all implementations support them (mostly with broken
-;; surrogate pair support), so we do the same. Sorry, emoji 🙁.
-;;
-;; Note that this is kind of broken, we don't correctly detect if \u or \o
forms
-;; don't have the right forms.
-(defun parseclj--string (s)
- (replace-regexp-in-string
- "\\\\o[0-8]\\{3\\}"
- (lambda (x)
- (make-string 1 (string-to-number (substring x 2) 8) ))
- (replace-regexp-in-string
- "\\\\u[0-9a-fA-F]\\{4\\}"
- (lambda (x)
- (make-string 1 (string-to-number (substring x 2) 16)))
- (replace-regexp-in-string "\\\\[tbnrf'\"\\]"
- (lambda (x)
- (cl-case (elt x 1)
- (?t "\t")
- (?f "\f")
- (?\" "\"")
- (?r "\r")
- (?n "\n")
- (?\\ "\\\\")
- (t (substring x 1))))
- (substring s 1 -1)))))
-
-(defun parseclj--character (c)
- (let ((first-char (elt c 1)))
- (cond
- ((equal c "\\newline") ?\n)
- ((equal c "\\return") ?\r)
- ((equal c "\\space") ?\ )
- ((equal c "\\tab") ?\t)
- ((eq first-char ?u) (string-to-number (substring c 2) 16))
- ((eq first-char ?o) (string-to-number (substring c 2) 8))
- (t first-char))))
-
-(defun parseclj--leaf-token-value (token)
- (cl-case (parseclj-lex-token-type token)
- (:number (string-to-number (alist-get :form token)))
- (:nil nil)
- (:true t)
- (:false nil)
- (:symbol (intern (alist-get :form token)))
- (:keyword (intern (alist-get :form token)))
- (:string (parseclj--string (alist-get :form token)))
- (:character (parseclj--character (alist-get :form token)))))
-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Shift-Reduce Parser
diff --git a/parseedn.el b/parseedn.el
index 9eaa9fd38e..633cf4a714 100644
--- a/parseedn.el
+++ b/parseedn.el
@@ -27,6 +27,57 @@
;;; Code:
+;; The EDN spec is not clear about wether \u0123 and \o012 are supported in
+;; strings. They are described as character literals, but not as string escape
+;; codes. In practice all implementations support them (mostly with broken
+;; surrogate pair support), so we do the same. Sorry, emoji 🙁.
+;;
+;; Note that this is kind of broken, we don't correctly detect if \u or \o
forms
+;; don't have the right forms.
+(defun parseedn--string (s)
+ (replace-regexp-in-string
+ "\\\\o[0-8]\\{3\\}"
+ (lambda (x)
+ (make-string 1 (string-to-number (substring x 2) 8) ))
+ (replace-regexp-in-string
+ "\\\\u[0-9a-fA-F]\\{4\\}"
+ (lambda (x)
+ (make-string 1 (string-to-number (substring x 2) 16)))
+ (replace-regexp-in-string "\\\\[tbnrf'\"\\]"
+ (lambda (x)
+ (cl-case (elt x 1)
+ (?t "\t")
+ (?f "\f")
+ (?\" "\"")
+ (?r "\r")
+ (?n "\n")
+ (?\\ "\\\\")
+ (t (substring x 1))))
+ (substring s 1 -1)))))
+
+(defun parseedn--character (c)
+ (let ((first-char (elt c 1)))
+ (cond
+ ((equal c "\\newline") ?\n)
+ ((equal c "\\return") ?\r)
+ ((equal c "\\space") ?\ )
+ ((equal c "\\tab") ?\t)
+ ((eq first-char ?u) (string-to-number (substring c 2) 16))
+ ((eq first-char ?o) (string-to-number (substring c 2) 8))
+ (t first-char))))
+
+(defun parseedn--leaf-token-value (token)
+ "Parse the given leaf TOKEN to an Emacs Lisp value."
+ (cl-case (parseclj-lex-token-type token)
+ (:number (string-to-number (alist-get :form token)))
+ (:nil nil)
+ (:true t)
+ (:false nil)
+ (:symbol (intern (alist-get :form token)))
+ (:keyword (intern (alist-get :form token)))
+ (:string (parseedn--string (alist-get :form token)))
+ (:character (parseedn--character (alist-get :form token)))))
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Reader
@@ -44,7 +95,7 @@ handlers as an optional argument to the reader functions.")
(defun parseedn-reduce-leaf (stack token options)
(if (member (parseclj-lex-token-type token) (list :whitespace :comment))
stack
- (cons (parseclj--leaf-token-value token) stack)))
+ (cons (parseedn--leaf-token-value token) stack)))
(defun parseedn-reduce-branch (stack opening-token children options)
(let ((tag-readers (a-merge parseedn-default-tag-readers (a-get options
:tag-readers)))
- [nongnu] elpa/parseclj ba04dbe334 171/185: Remove remaining a-list call, move a.el to be test-only, (continued)
- [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
- [nongnu] elpa/parseclj 9480ae09b3 068/185: push is destructive, in this case cons will do, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj f395b9cbcc 097/185: Move `parseclj--leaf-token-value` to `parseedn` module,
ELPA Syncer <=
- [nongnu] elpa/parseclj 91dd43667c 110/185: Fix `parseclj-ast--reduce-branch` for tags., ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 9a586f267d 103/185: Remove `parseedn` requirement from `parseclj`, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj e65eb085ad 114/185: Remove duplicated test, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 811f35e05a 117/185: Loops reduction over the first 2 elements of the stack, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 5b4b222b4f 124/185: Return error token when there's invalid input in `parseclj-lex-next`, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj b26fadbc05 128/185: Get rid of `parseclj-lex-error-token` side-effect, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 2ffadc6239 134/185: Mark OPTIONS as unused in `parseedn-reduce-leaf`, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 45cd754c32 140/185: Remove parseedn files, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj 3e48aa7b40 141/185: Remove mentions to parseedn in README.md, ELPA Syncer, 2021/12/28
- [nongnu] elpa/parseclj c62a11884d 165/185: First pass in inlining the necessary bits from a.el, ELPA Syncer, 2021/12/28