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

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

[nongnu] elpa/parseclj d3cb78544d 106/185: Use Emacs Lisp predicate styl


From: ELPA Syncer
Subject: [nongnu] elpa/parseclj d3cb78544d 106/185: Use Emacs Lisp predicate style convention
Date: Tue, 28 Dec 2021 14:05:25 -0500 (EST)

branch: elpa/parseclj
commit d3cb78544d440a94ca156d79a9a043e25a86966e
Author: Daniel Barreto <daniel.barreto.n@gmail.com>
Commit: Daniel Barreto <daniel.barreto.n@gmail.com>

    Use Emacs Lisp predicate style convention
---
 parseclj-ast.el           |  6 +++---
 parseclj-lex.el           | 52 +++++++++++++++++++++++------------------------
 parseclj.el               | 18 ++++++++--------
 test/parseclj-lex-test.el | 52 +++++++++++++++++++++++------------------------
 test/parseclj-test.el     |  8 ++++----
 5 files changed, 68 insertions(+), 68 deletions(-)

diff --git a/parseclj-ast.el b/parseclj-ast.el
index e0ae5d90f4..a5ef6667be 100644
--- a/parseclj-ast.el
+++ b/parseclj-ast.el
@@ -38,7 +38,7 @@
 Other ATTRIBUTES can be given as a flat list of key-value pairs."
   (apply 'a-list :node-type type :position position attributes))
 
-(defun parseclj-ast-node? (node)
+(defun parseclj-ast-node-p (node)
   "Return t if the given NODE is a Clojure AST node."
   (and (consp node)
        (consp (car node))
@@ -48,7 +48,7 @@ Other ATTRIBUTES can be given as a flat list of key-value 
pairs."
   "Return the type of the AST node NODE."
   (a-get node :node-type))
 
-(defun parseclj-ast-leaf-node? (node)
+(defun parseclj-ast-leaf-node-p (node)
   "Return t if the given ast NODE is a leaf node."
   (member (parseclj-ast-node-type node) parseclj-lex--leaf-tokens))
 
@@ -134,7 +134,7 @@ on available options."
       (cons (parseclj-ast-node :discard (a-get opening-token :pos) :children 
children) stack)
     (let* ((stack (funcall #'parseclj-ast--reduce-branch stack opening-token 
children options))
            (top (car stack)))
-      (if (parseclj-ast-node? top)
+      (if (parseclj-ast-node-p top)
           (cons (cl-list* (car top) ;; make sure :node-type remains the first 
element in the list
                           '(:lexical-preservation . t)
                           (cdr top))
diff --git a/parseclj-lex.el b/parseclj-lex.el
index 0eff257ddb..0d89a10e85 100644
--- a/parseclj-lex.el
+++ b/parseclj-lex.el
@@ -56,7 +56,7 @@ Tokens at a mimimum have these attributes
 Other ATTRIBUTES can be given as a flat list of key-value pairs."
   (apply 'a-list :token-type type :form form :pos pos attributes))
 
-(defun parseclj-lex-token? (token)
+(defun parseclj-lex-token-p (token)
   "Is the given TOKEN a parseclj-lex TOKEN.
 
 A token is an association list with :token-type as its first key."
@@ -69,15 +69,15 @@ A token is an association list with :token-type as its 
first key."
   (and (consp token)
        (cdr (assq :token-type token))))
 
-(defun parseclj-lex-leaf-token? (token)
+(defun parseclj-lex-leaf-token-p (token)
   "Return t if the given AST TOKEN is a leaf node."
   (member (parseclj-lex-token-type token) parseclj-lex--leaf-tokens))
 
-(defun parseclj-lex-closing-token? (token)
+(defun parseclj-lex-closing-token-p (token)
   "Return t if the given ast TOKEN is a closing toking."
   (member (parseclj-lex-token-type token) parseclj-lex--closing-tokens))
 
-(defun parseclj-lex-at-whitespace? ()
+(defun parseclj-lex-at-whitespace-p ()
   "Return t if char at point is white space."
   (let ((char (char-after (point))))
     (or (equal char ?\ )
@@ -86,14 +86,14 @@ A token is an association list with :token-type as its 
first key."
         (equal char ?\r)
         (equal char ?,))))
 
-(defun parseclj-lex-at-eof? ()
+(defun parseclj-lex-at-eof-p ()
   "Return t if point is at the end of file."
   (eq (point) (point-max)))
 
 (defun parseclj-lex-whitespace ()
   "Consume all consecutive white space as possible and return an :whitespace 
token."
   (let ((pos (point)))
-    (while (parseclj-lex-at-whitespace?)
+    (while (parseclj-lex-at-whitespace-p)
       (right-char))
     (parseclj-lex-token :whitespace
                         (buffer-substring-no-properties pos (point))
@@ -150,18 +150,18 @@ A token is an association list with :token-type as its 
first key."
                             pos)))))
 
 
-(defun parseclj-lex-digit? (char)
+(defun parseclj-lex-digit-p (char)
   "Return t if CHAR is a digit."
   (and char (<= ?0 char) (<= char ?9)))
 
-(defun parseclj-lex-at-number? ()
+(defun parseclj-lex-at-number-p ()
   "Return t if point is at a number."
   (let ((char (char-after (point))))
-    (or (parseclj-lex-digit? char)
+    (or (parseclj-lex-digit-p char)
         (and (member char '(?- ?+ ?.))
-             (parseclj-lex-digit? (char-after (1+ (point))))))))
+             (parseclj-lex-digit-p (char-after (1+ (point))))))))
 
-(defun parseclj-lex-symbol-start? (char &optional alpha-only)
+(defun parseclj-lex-symbol-start-p (char &optional alpha-only)
   "Return t if CHAR is a valid start for a symbol.
 
 Symbols begin with a non-numeric character and can contain alphanumeric
@@ -175,18 +175,18 @@ alphabetic characters only.  ALPHA-ONLY ensures this 
behavior."
                      (and (<= ?A char) (<= char ?Z))
                      (and (not alpha-only) (member char '(?. ?* ?+ ?! ?- ?_ ?? 
?$ ?% ?& ?= ?< ?> ?/))))))))
 
-(defun parseclj-lex-symbol-rest? (char)
+(defun parseclj-lex-symbol-rest-p (char)
   "Return t if CHAR is a valid character in a symbol.
 For more information on what determines a valid symbol, see
-`parseclj-lex-symbol-start?'"
-  (or (parseclj-lex-symbol-start? char)
-      (parseclj-lex-digit? char)
+`parseclj-lex-symbol-start-p'"
+  (or (parseclj-lex-symbol-start-p char)
+      (parseclj-lex-digit-p char)
       (eq ?: char)
       (eq ?# char)))
 
 (defun parseclj-lex-get-symbol-at-point (pos)
   "Return a string containing the symbol at POS."
-  (while (parseclj-lex-symbol-rest? (char-after (point)))
+  (while (parseclj-lex-symbol-rest-p (char-after (point)))
     (right-char))
   (buffer-substring-no-properties pos (point)))
 
@@ -209,7 +209,7 @@ If EOF is reached without finding a closing double quote, a 
:lex-error
 token is returned."
   (let ((pos (point)))
     (right-char)
-    (while (not (or (equal (char-after (point)) ?\") (parseclj-lex-at-eof?)))
+    (while (not (or (equal (char-after (point)) ?\") (parseclj-lex-at-eof-p)))
       (if (equal (char-after (point)) ?\\)
           (right-char 2)
         (right-char)))
@@ -261,7 +261,7 @@ token is returned."
 Keywords follow the same rules as symbols, except they might start with one
 or two colon characters.
 
-See `parseclj-lex-symbol', `parseclj-lex-symbol-start?'."
+See `parseclj-lex-symbol', `parseclj-lex-symbol-start-p'."
   (let ((pos (point)))
     (right-char)
     (when (equal (char-after (point)) ?:) ;; same-namespace keyword
@@ -271,7 +271,7 @@ See `parseclj-lex-symbol', `parseclj-lex-symbol-start?'."
           (right-char)
           (parseclj-lex-token :lex-error (buffer-substring-no-properties pos 
(point)) pos :error-type :invalid-keyword))
       (progn
-        (while (or (parseclj-lex-symbol-rest? (char-after (point)))
+        (while (or (parseclj-lex-symbol-rest-p (char-after (point)))
                    (equal (char-after (point)) ?#))
           (right-char))
         (parseclj-lex-token :keyword (buffer-substring-no-properties pos 
(point)) pos)))))
@@ -288,12 +288,12 @@ See `parseclj-lex-symbol', `parseclj-lex-symbol-start?'."
   "Consume characters at point and return the next lexical token.
 
 See `parseclj-lex-token'."
-  (if (parseclj-lex-at-eof?)
+  (if (parseclj-lex-at-eof-p)
       (parseclj-lex-token :eof nil (point))
     (let ((char (char-after (point)))
           (pos  (point)))
       (cond
-       ((parseclj-lex-at-whitespace?)
+       ((parseclj-lex-at-whitespace-p)
         (parseclj-lex-whitespace))
 
        ((equal char ?\()
@@ -320,10 +320,10 @@ See `parseclj-lex-token'."
         (right-char)
         (parseclj-lex-token :rbrace "}" pos))
 
-       ((parseclj-lex-at-number?)
+       ((parseclj-lex-at-number-p)
         (parseclj-lex-number))
 
-       ((parseclj-lex-symbol-start? char)
+       ((parseclj-lex-symbol-start-p char)
         (parseclj-lex-symbol))
 
        ((equal char ?\")
@@ -348,12 +348,12 @@ See `parseclj-lex-token'."
            ((equal char ?_)
             (right-char)
             (parseclj-lex-token :discard "#_" pos))
-           ((parseclj-lex-symbol-start? char t)
+           ((parseclj-lex-symbol-start-p char t)
             (right-char)
             (parseclj-lex-token :tag (concat "#" 
(parseclj-lex-get-symbol-at-point (1+ pos))) pos))
            (t
-            (while (not (or (parseclj-lex-at-whitespace?)
-                            (parseclj-lex-at-eof?)))
+            (while (not (or (parseclj-lex-at-whitespace-p)
+                            (parseclj-lex-at-eof-p)))
               (right-char))
             (parseclj-lex-token :lex-error (buffer-substring-no-properties pos 
(point)) pos :error-type :invalid-hashtag-dispatcher)))))
 
diff --git a/parseclj.el b/parseclj.el
index 7a565bd31f..7d9a189753 100644
--- a/parseclj.el
+++ b/parseclj.el
@@ -82,7 +82,7 @@ available options."
         (progn
           (when fail-fast
             ;; any unreduced tokens left: bail early
-            (when-let ((token (seq-find #'parseclj-lex-token? collection)))
+            (when-let ((token (seq-find #'parseclj-lex-token-p collection)))
               (parseclj--error "At position %s, unmatched %S"
                                (a-get token :pos)
                                (parseclj-lex-token-type token))))
@@ -114,7 +114,7 @@ and whitespace)."
     (cl-block nil
       (while stack
         (cond
-         ((parseclj-lex-token? (car stack))
+         ((parseclj-lex-token-p (car stack))
           (cl-return nil))
 
          ((funcall value-p (car stack))
@@ -143,7 +143,7 @@ TOKEN-TYPES are the token types to look for."
           (cl-return (cons (car stack) result)))
          ((funcall value-p (car stack))
           (cl-return nil))
-         ((parseclj-lex-token? (car stack))
+         ((parseclj-lex-token-p (car stack))
           (cl-return nil))
          (t
           (push (pop stack) result)))))))
@@ -187,7 +187,7 @@ functions. Additionally the following options are recognized
   tag.  This options in only available in `parseedn-read', for more
   information, please refer to its documentation."
   (let ((fail-fast (a-get options :fail-fast t))
-        (value-p (a-get options :value-p (lambda (e) (not (parseclj-lex-token? 
e)))))
+        (value-p (a-get options :value-p (lambda (e) (not 
(parseclj-lex-token-p e)))))
         (stack nil)
         (token (parseclj-lex-next)))
 
@@ -197,10 +197,10 @@ functions. Additionally the following options are 
recognized
 
       ;; Reduce based on the top item on the stack (collections)
       (cond
-       ((parseclj-lex-leaf-token? token)
+       ((parseclj-lex-leaf-token-p token)
         (setf stack (funcall reduce-leaf stack token options)))
 
-       ((parseclj-lex-closing-token? token)
+       ((parseclj-lex-closing-token-p token)
         (setf stack (parseclj--reduce-coll stack token reduce-branch options)))
 
        (t (push token stack)))
@@ -220,7 +220,7 @@ functions. Additionally the following options are recognized
 
     ;; reduce root
     (when fail-fast
-      (when-let ((token (seq-find #'parseclj-lex-token? stack)))
+      (when-let ((token (seq-find #'parseclj-lex-token-p stack)))
         (parseclj--error "At position %s, unmatched %S"
                          (a-get token :pos)
                          (parseclj-lex-token-type token))))
@@ -251,7 +251,7 @@ key-value pairs to specify parsing options.
         (goto-char 1)
         (apply 'parseclj-parse-clojure (cdr string-and-options)))
     (let* ((value-p (lambda (e)
-                      (and (parseclj-ast-node? e)
+                      (and (parseclj-ast-node-p e)
                            (not (member (parseclj-ast-node-type e) 
'(:whitespace :comment :discard))))))
            (options (apply 'a-list :value-p value-p string-and-options))
            (lexical? (a-get options :lexical-preservation)))
@@ -269,7 +269,7 @@ key-value pairs to specify parsing options.
 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? ast)
+  (if (parseclj-ast-leaf-node-p ast)
       (insert (a-get ast :form))
     (if (eql (parseclj-ast-node-type ast) :tag)
         (parseclj-ast--unparse-tag ast)
diff --git a/test/parseclj-lex-test.el b/test/parseclj-lex-test.el
index 6e96522fbc..6589809c48 100644
--- a/test/parseclj-lex-test.el
+++ b/test/parseclj-lex-test.el
@@ -197,18 +197,18 @@
     (should (equal (parseclj-lex-next) (parseclj-lex-token :number "14" 21)))
     (should (equal (parseclj-lex-next) (parseclj-lex-token :rparen ")" 23)))))
 
-(ert-deftest parseclj-lex-test-at-number? ()
+(ert-deftest parseclj-lex-test-at-number-p ()
   (dolist (str '("123" ".9" "+1" "0" "-456"))
     (with-temp-buffer
       (insert str)
       (goto-char 1)
-      (should (equal (parseclj-lex-at-number?) t))))
+      (should (equal (parseclj-lex-at-number-p) t))))
 
   (dolist (str '("a123" "$.9" "+/1" "++0" "-"))
     (with-temp-buffer
       (insert str)
       (goto-char 1)
-      (should (equal (parseclj-lex-at-number?) nil)))))
+      (should (equal (parseclj-lex-at-number-p) nil)))))
 
 (ert-deftest parseclj-lex-test-token ()
   (should (equal (parseclj-lex-token :whitespace ",,," 10)
@@ -216,29 +216,29 @@
                    (:form . ",,,")
                    (:pos . 10)))))
 
-(ert-deftest parseclj-lex-test-digit? ()
-  (should (equal (parseclj-lex-digit? ?0) t))
-  (should (equal (parseclj-lex-digit? ?5) t))
-  (should (equal (parseclj-lex-digit? ?9) t))
-  (should (equal (parseclj-lex-digit? ?a) nil))
-  (should (equal (parseclj-lex-digit? ?-) nil)))
-
-(ert-deftest parseclj-lex-test-symbol-start? ()
-  (should (equal (parseclj-lex-symbol-start? ?0) nil))
-  (should (equal (parseclj-lex-symbol-start? ?a) t))
-  (should (equal (parseclj-lex-symbol-start? ?A) t))
-  (should (equal (parseclj-lex-symbol-start? ?.) t))
-  (should (equal (parseclj-lex-symbol-start? ?. t) nil))
-  (should (equal (parseclj-lex-symbol-start? ?~) nil))
-  (should (equal (parseclj-lex-symbol-start? ? ) nil)))
-
-(ert-deftest parseclj-lex-test-symbol-rest? ()
-  (should (equal (parseclj-lex-symbol-rest? ?0) t))
-  (should (equal (parseclj-lex-symbol-rest? ?a) t))
-  (should (equal (parseclj-lex-symbol-rest? ?A) t))
-  (should (equal (parseclj-lex-symbol-rest? ?.) t))
-  (should (equal (parseclj-lex-symbol-rest? ?~) nil))
-  (should (equal (parseclj-lex-symbol-rest? ? ) nil)))
+(ert-deftest parseclj-lex-test-digit-p ()
+  (should (equal (parseclj-lex-digit-p ?0) t))
+  (should (equal (parseclj-lex-digit-p ?5) t))
+  (should (equal (parseclj-lex-digit-p ?9) t))
+  (should (equal (parseclj-lex-digit-p ?a) nil))
+  (should (equal (parseclj-lex-digit-p ?-) nil)))
+
+(ert-deftest parseclj-lex-test-symbol-start-p ()
+  (should (equal (parseclj-lex-symbol-start-p ?0) nil))
+  (should (equal (parseclj-lex-symbol-start-p ?a) t))
+  (should (equal (parseclj-lex-symbol-start-p ?A) t))
+  (should (equal (parseclj-lex-symbol-start-p ?.) t))
+  (should (equal (parseclj-lex-symbol-start-p ?. t) nil))
+  (should (equal (parseclj-lex-symbol-start-p ?~) nil))
+  (should (equal (parseclj-lex-symbol-start-p ? ) nil)))
+
+(ert-deftest parseclj-lex-test-symbol-rest-p ()
+  (should (equal (parseclj-lex-symbol-rest-p ?0) t))
+  (should (equal (parseclj-lex-symbol-rest-p ?a) t))
+  (should (equal (parseclj-lex-symbol-rest-p ?A) t))
+  (should (equal (parseclj-lex-symbol-rest-p ?.) t))
+  (should (equal (parseclj-lex-symbol-rest-p ?~) nil))
+  (should (equal (parseclj-lex-symbol-rest-p ? ) nil)))
 
 (ert-deftest parseclj-lex-test-get-symbol-at-point ()
   (with-temp-buffer
diff --git a/test/parseclj-test.el b/test/parseclj-test.el
index 3d6fbb1641..ec439b3d5f 100644
--- a/test/parseclj-test.el
+++ b/test/parseclj-test.el
@@ -217,7 +217,7 @@
                   (parseclj-lex-token :discard "#_" 30)
                   (parseclj-ast-node :comment 20))
             (lambda (e)
-              (and (parseclj-ast-node? e)
+              (and (parseclj-ast-node-p e)
                    (not (member (parseclj-ast-node-type e) '(:whitespace 
:comment :discard)))))
             '(:discard))
            '(((:token-type . :discard) (:form . "#_") (:pos . 30))
@@ -231,7 +231,7 @@
                   (parseclj-lex-token :discard "#_" 30)
                   (parseclj-ast-node :comment 20))
             (lambda (e)
-              (and (parseclj-ast-node? e)
+              (and (parseclj-ast-node-p e)
                    (not (member (parseclj-ast-node-type e) '(:whitespace 
:comment :discard)))))
             '(:discard))
            nil)))
@@ -240,7 +240,7 @@
   (let ((stack '(((:node-type . :number) (:position . 3) (:form . "4") (:value 
. 4))
                  ((:token-type . :discard) (:form . "#_") (:pos . 1))))
         (value-p (lambda (e)
-                   (and (parseclj-ast-node? e)
+                   (and (parseclj-ast-node-p e)
                         (not (member (parseclj-ast-node-type e) '(:whitespace 
:comment :discard)))))))
     (should (equal (parseclj--take-value stack value-p)
                    '(((:node-type . :number) (:position . 3) (:form . "4") 
(:value . 4)))))
@@ -256,7 +256,7 @@
   (let ((stack '(((:node-type . :whitespace) (:position . 3) (:form . " "))
                  ((:token-type . :discard) (:form . "#_") (:pos . 1))))
         (value-p (lambda (e)
-                   (and (parseclj-ast-node? e)
+                   (and (parseclj-ast-node-p e)
                         (not (member (parseclj-ast-node-type e) '(:whitespace 
:comment :discard)))))))
 
     (let* ((top-value (parseclj--take-value stack value-p))



reply via email to

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