[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/parseclj 7794d9ee59 101/185: Add docstrings for `parseclj-
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/parseclj 7794d9ee59 101/185: Add docstrings for `parseclj-lex` module |
Date: |
Tue, 28 Dec 2021 14:05:24 -0500 (EST) |
branch: elpa/parseclj
commit 7794d9ee593a7fad869d8fe599f2e937ea09ed16
Author: Daniel Barreto <daniel.barreto.n@gmail.com>
Commit: Daniel Barreto <daniel.barreto.n@gmail.com>
Add docstrings for `parseclj-lex` module
---
parseclj-lex.el | 66 ++++++++++++++++++++++++++++++++++++++++-----------------
1 file changed, 47 insertions(+), 19 deletions(-)
diff --git a/parseclj-lex.el b/parseclj-lex.el
index 5831933e7b..0eff257ddb 100644
--- a/parseclj-lex.el
+++ b/parseclj-lex.el
@@ -59,7 +59,7 @@ Other ATTRIBUTES can be given as a flat list of key-value
pairs."
(defun parseclj-lex-token? (token)
"Is the given TOKEN a parseclj-lex TOKEN.
-A token is an association list with :token-type as its first key. "
+A token is an association list with :token-type as its first key."
(and (consp token)
(consp (car token))
(eq :token-type (caar token))))
@@ -70,14 +70,15 @@ A token is an association list with :token-type as its
first key. "
(cdr (assq :token-type token))))
(defun parseclj-lex-leaf-token? (token)
- "Return `t' if the given ast TOKEN is a leaf node."
+ "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)
- "Return `t' if the given ast TOKEN is a closing toking."
+ "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? ()
+ "Return t if char at point is white space."
(let ((char (char-after (point))))
(or (equal char ?\ )
(equal char ?\t)
@@ -86,23 +87,27 @@ A token is an association list with :token-type as its
first key. "
(equal char ?,))))
(defun parseclj-lex-at-eof? ()
+ "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?)
(right-char))
(parseclj-lex-token :whitespace
- (buffer-substring-no-properties pos (point))
- pos)))
+ (buffer-substring-no-properties pos (point))
+ pos)))
(defun parseclj-lex-skip-digits ()
+ "Skip all consecutive digits after point."
(while (and (char-after (point))
(<= ?0 (char-after (point)))
(<= (char-after (point)) ?9))
(right-char)))
(defun parseclj-lex-skip-number ()
+ "Skip a number at point."
;; [\+\-]?\d+\.\d+
(when (member (char-after (point)) '(?+ ?-))
(right-char))
@@ -115,6 +120,7 @@ A token is an association list with :token-type as its
first key. "
(parseclj-lex-skip-digits))
(defun parseclj-lex-number ()
+ "Consume a number and return a :number token."
(let ((pos (point)))
(parseclj-lex-skip-number)
@@ -135,51 +141,59 @@ A token is an association list with :token-type as its
first key. "
(progn
(right-char)
(parseclj-lex-token :lex-error
- (buffer-substring-no-properties pos (point))
- pos
- :error-type :invalid-number-format))
+ (buffer-substring-no-properties pos (point))
+ pos
+ :error-type :invalid-number-format))
(parseclj-lex-token :number
- (buffer-substring-no-properties pos (point))
- pos)))))
+ (buffer-substring-no-properties pos (point))
+ pos)))))
(defun parseclj-lex-digit? (char)
+ "Return t if CHAR is a digit."
(and char (<= ?0 char) (<= char ?9)))
(defun parseclj-lex-at-number? ()
+ "Return t if point is at a number."
(let ((char (char-after (point))))
(or (parseclj-lex-digit? char)
(and (member char '(?- ?+ ?.))
(parseclj-lex-digit? (char-after (1+ (point))))))))
(defun parseclj-lex-symbol-start? (char &optional alpha-only)
- "Symbols begin with a non-numeric character and can contain
-alphanumeric characters and . * + ! - _ ? $ % & = < >. If -, + or
-. are the first character, the second character (if any) must be
-non-numeric.
-
-In some cases, like in tagged elements, symbols are required to
-start with alphabetic characters only. ALPHA-ONLY ensures this
-behavior."
+ "Return t if CHAR is a valid start for a symbol.
+
+Symbols begin with a non-numeric character and can contain alphanumeric
+characters and . * + ! - _ ? $ % & = < >. If - + or . are the first
+character, the second character (if any) must be non-numeric.
+
+In some cases, like in tagged elements, symbols are required to start with
+alphabetic characters only. ALPHA-ONLY ensures this behavior."
(not (not (and char
(or (and (<= ?a char) (<= char ?z))
(and (<= ?A char) (<= char ?Z))
(and (not alpha-only) (member char '(?. ?* ?+ ?! ?- ?_ ??
?$ ?% ?& ?= ?< ?> ?/))))))))
(defun parseclj-lex-symbol-rest? (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)
(eq ?: char)
(eq ?# char)))
(defun parseclj-lex-get-symbol-at-point (pos)
- "Return the symbol at point."
+ "Return a string containing the symbol at POS."
(while (parseclj-lex-symbol-rest? (char-after (point)))
(right-char))
(buffer-substring-no-properties pos (point)))
(defun parseclj-lex-symbol ()
+ "Return a lex token representing a symbol.
+Because of their special meaning, symbols \"nil\", \"true\", and \"false\"
+are returned as their own lex tokens."
(let ((pos (point)))
(right-char)
(let ((sym (parseclj-lex-get-symbol-at-point pos)))
@@ -190,6 +204,9 @@ behavior."
(t (parseclj-lex-token :symbol sym pos))))))
(defun parseclj-lex-string ()
+ "Return a lex token representing a string.
+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?)))
@@ -203,9 +220,11 @@ behavior."
(parseclj-lex-token :lex-error (buffer-substring-no-properties pos
(point)) pos))))
(defun parseclj-lex-lookahead (n)
+ "Return a lookahead string of N characters after point."
(buffer-substring-no-properties (point) (min (+ (point) n) (point-max))))
(defun parseclj-lex-character ()
+ "Return a lex token representing a character."
(let ((pos (point)))
(right-char)
(cond
@@ -238,6 +257,11 @@ behavior."
(parseclj-lex-token :character (buffer-substring-no-properties pos
(point)) pos)))))
(defun parseclj-lex-keyword ()
+ "Return a lex token representing a keyword.
+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?'."
(let ((pos (point)))
(right-char)
(when (equal (char-after (point)) ?:) ;; same-namespace keyword
@@ -253,6 +277,7 @@ behavior."
(parseclj-lex-token :keyword (buffer-substring-no-properties pos
(point)) pos)))))
(defun parseclj-lex-comment ()
+ "Return a lex token representing a comment."
(let ((pos (point)))
(goto-char (line-end-position))
(when (equal (char-after (point)) ?\n)
@@ -260,6 +285,9 @@ behavior."
(parseclj-lex-token :comment (buffer-substring-no-properties pos (point))
pos)))
(defun parseclj-lex-next ()
+ "Consume characters at point and return the next lexical token.
+
+See `parseclj-lex-token'."
(if (parseclj-lex-at-eof?)
(parseclj-lex-token :eof nil (point))
(let ((char (char-after (point)))
- [nongnu] elpa/parseclj 7d70ee4c38 059/185: Add support for tagged literals, (continued)
- [nongnu] elpa/parseclj 7d70ee4c38 059/185: Add support for tagged literals, ELPA Syncer, 2021/12/28
- [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 <=
- [nongnu] elpa/parseclj 296a093132 102/185: Remove `parseclj-unparse`, ELPA Syncer, 2021/12/28
- [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