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

[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)))



reply via email to

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