]> git.eshelyaron.com Git - emacs.git/commitdiff
Enhance syntax-tests.el to test nestable comments (Lisp style)
authorAlan Mackenzie <acm@muc.de>
Tue, 17 Nov 2020 16:51:49 +0000 (16:51 +0000)
committerAlan Mackenzie <acm@muc.de>
Tue, 17 Nov 2020 16:51:49 +0000 (16:51 +0000)
Also add some tests for braces and parse-partial-sexp amongst Lisp style
comments.

* test/src/syntax-tests.el (\;-in, \;-out): Add syntax for { and }.
(top-level): Add new tests for Lisp style comments.
(\#|-in, \#|-out): New functions.
(top-level): Add new tests for nested Lisp style comments, and mixtures of
nested comments with "ordinary" comments.

* test/src/syntax-resources/syntax-comments.txt (top-level): Add new test
fragments for #|...|#, etc.

test/src/syntax-resources/syntax-comments.txt
test/src/syntax-tests.el

index 6f595e4d8dc55a40de1220c78242cbe9034445a6..a292d816b9dc7eed4a33a75f6928d053101b5784 100644 (file)
 33;        \
 33
 
+/* Lisp comments within lists */
+40)40
+41(;90 comment
+91)41
+42(;92\
+93)42
+43( ;94
+95
+
+/* Nested Lisp comments */
+100|#100
+101#|#
+102#||#102
+103#| Comment |#103
+104#| Comment
+|#104
+105#|#|#105
+106#| #| Comment |# |#106
+107#|#|#|#|#|#|#|#|#| Comment |#|#|#|#|#|#|#|#|#107
+
+/* Mixed Lisp comments */
+110; #|
+110
+111#| ; |#111
+
 Local Variables:
 mode: fundamental
 eval: (set-syntax-table (make-syntax-table))
 End:
+999
\ No newline at end of file
index 4b9c3f277aa6e78eeab55c048337d8094328a6f2..edee01ec5850bb0c9366fe858b4cafae5ede9708 100644 (file)
@@ -220,7 +220,7 @@ missing or nil, the value of -START- is assumed for it."
          (cond
           ((eq -dir- 'forward) t)
           ((eq -dir- 'backward) nil)
-          (t (error "Invalid -dir- argument \"%s\" to `syntax-comments'" -dir-))))
+          (t (error "Invalid -dir- argument \"%s\" to `syntax-br-comments'" -dir-))))
          (start -start-)
         (start-str (format "%d" (abs start)))
         (type -type-))
@@ -338,10 +338,14 @@ the `parse-partial-sexp's are expected to stop.  See
   (setq parse-sexp-ignore-comments t)
   (setq comment-end-can-be-escaped nil)
   (modify-syntax-entry ?\n ">")
-  (modify-syntax-entry ?\; "<"))
+  (modify-syntax-entry ?\; "<")
+  (modify-syntax-entry ?{ ".")
+  (modify-syntax-entry ?} "."))
 (defun \;-out ()
   (modify-syntax-entry ?\n " ")
-  (modify-syntax-entry ?\; "."))
+  (modify-syntax-entry ?\; ".")
+  (modify-syntax-entry ?{ "(}")
+  (modify-syntax-entry ?} "){"))
 (eval-and-compile
   (setq syntax-comments-section "lisp"))
 
@@ -353,6 +357,62 @@ the `parse-partial-sexp's are expected to stop.  See
 (syntax-comments \; forward t 33)
 (syntax-comments \; backward t 33)
 
+;; "Lisp" style comments inside lists.
+(syntax-br-comments \; backward nil 40)
+(syntax-br-comments \; forward t 41)
+(syntax-br-comments \; backward t 41)
+(syntax-br-comments \; forward t 42)
+(syntax-br-comments \; backward t 42)
+(syntax-br-comments \; forward nil 43)
+
+;; "Lisp" style comments parsed by `parse-partial-sexp'.
+(syntax-pps-comments \; 41 90 91)
+(syntax-pps-comments \; 42 92 93)
+(syntax-pps-comments \; 43 94 95 -999)
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; "Lisp" style nested comments: between delimiters #|  |#.
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+(defun \#|-in ()
+  (setq parse-sexp-ignore-comments t)
+  (modify-syntax-entry ?# ". 14")
+  (modify-syntax-entry ?| ". 23n")
+  (modify-syntax-entry ?\; "< b")
+  (modify-syntax-entry ?\n "> b"))
+(defun \#|-out ()
+  (modify-syntax-entry ?# ".")
+  (modify-syntax-entry ?| ".")
+  (modify-syntax-entry ?\; ".")
+  (modify-syntax-entry ?\n " "))
+(eval-and-compile
+  (setq syntax-comments-section "lisp-n"))
+
+(syntax-comments \#| forward nil 100 0)
+(syntax-comments \#| backward nil 100 0)
+(syntax-comments \#| forward nil 101 -999)
+(syntax-comments \#| forward t 102)
+(syntax-comments \#| backward t 102)
+
+(syntax-comments \#| forward t 103)
+(syntax-comments \#| backward t 103)
+(syntax-comments \#| forward t 104)
+(syntax-comments \#| backward t 104)
+
+(syntax-comments \#| forward nil 105 -999)
+(syntax-comments \#| backward t 105)
+(syntax-comments \#| forward t 106)
+(syntax-comments \#| backward t 106)
+(syntax-comments \#| forward t 107)
+(syntax-comments \#| backward t 107)
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Mixed "Lisp" style (nested and unnested) comments.
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+(syntax-comments \#| forward t 110)
+(syntax-comments \#| backward t 110)
+(syntax-comments \#| forward t 111)
+(syntax-comments \#| backward t 111)
+
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Emacs 27 "C" style comments - `comment-end-can-be-escaped' is non-nil.
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;