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

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

[nongnu] elpa/parseclj 81fe979450 051/185: Handle parsing of semicolon-b


From: ELPA Syncer
Subject: [nongnu] elpa/parseclj 81fe979450 051/185: Handle parsing of semicolon-based comments.
Date: Tue, 28 Dec 2021 14:05:16 -0500 (EST)

branch: elpa/parseclj
commit 81fe9794500ba9434c2078d8a00945bfc13b62ba
Author: Arne Brasseur <arne@arnebrasseur.net>
Commit: Arne Brasseur <arne@arnebrasseur.net>

    Handle parsing of semicolon-based comments.
    
    The lexer treats each comment line as a separate token, starting with the 
first
    semicolon, and up to and including the closing newline. A parser/reducer may
    choose to merge consecutive comment/whitespace tokens into a single comment 
AST
    token.
---
 clj-lex.el   | 10 ++++++++++
 clj-parse.el |  3 ++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/clj-lex.el b/clj-lex.el
index bc12a7b4bc..604f29d1e9 100644
--- a/clj-lex.el
+++ b/clj-lex.el
@@ -176,6 +176,13 @@ behavior."
         (right-char)
         (clj-lex-token :lex-error (buffer-substring-no-properties pos (point)) 
pos 'error-type :invalid-keyword)))))
 
+(defun clj-lex-comment ()
+  (let ((pos (point)))
+    (goto-char (line-end-position))
+    (when (equal (char-after (point)) ?\n)
+      (right-char))
+    (clj-lex-token :comment (buffer-substring-no-properties pos (point)) pos)))
+
 (defun clj-lex-next ()
   (if (clj-lex-at-eof?)
       (clj-lex-token :eof nil (point))
@@ -224,6 +231,9 @@ behavior."
        ((equal char ?:)
         (clj-lex-keyword))
 
+       ((equal char ?\;)
+        (clj-lex-comment))
+
        ((equal char ?#)
         (right-char)
         (let ((char (char-after (point))))
diff --git a/clj-parse.el b/clj-parse.el
index 655af83d20..a447ca8a43 100644
--- a/clj-parse.el
+++ b/clj-parse.el
@@ -34,6 +34,7 @@
 (require 'clj-lex)
 
 (defvar clj-parse--leaf-tokens '(:whitespace
+                                 :comment
                                  :number
                                  :nil
                                  :true
@@ -197,7 +198,7 @@
 ; Elisp
 
 (defun clj-parse--edn-reduce-leaf (stack token)
-  (if (eq (clj-lex-token-type token) :whitespace)
+  (if (member (clj-lex-token-type token) (list :whitespace :comment))
       stack
     (push (clj-parse--leaf-token-value token) stack)))
 



reply via email to

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