From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Toshi Umehara Newsgroups: gmane.emacs.devel Subject: Re: Scheme Mode and Regular Expression Literals Date: Tue, 19 Mar 2024 12:06:24 +0900 Message-ID: <87edc6kjin.fsf@niceume.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="9592"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , jcubic@onet.pl, emacs-devel@gnu.org To: monnier@iro.umontreal.ca Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Mar 19 04:07:38 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rmPpB-0002LD-7Z for ged-emacs-devel@m.gmane-mx.org; Tue, 19 Mar 2024 04:07:38 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rmPoP-0003tV-M7; Mon, 18 Mar 2024 23:06:49 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rmPoN-0003t2-BU for emacs-devel@gnu.org; Mon, 18 Mar 2024 23:06:47 -0400 Original-Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rmPoJ-0006nh-Ue; Mon, 18 Mar 2024 23:06:47 -0400 Original-Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id AF8395C0088; Mon, 18 Mar 2024 23:06:38 -0400 (EDT) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Mon, 18 Mar 2024 23:06:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=niceume.com; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:reply-to:subject:subject:to :to; s=mesmtp; t=1710817598; x=1710903998; bh=I75P9/ZU49Zkp4axcN Tlukw52tOVQchXE5mxgskscqk=; b=t7K6TQP65Epadazc5cUJZnFKzNnzDmje4U siOJXfGAmAutJ6kbPEBr7lz8IcnHBLErPw+CUYcJqhmG01lhwHnGcIKgSJqsECG3 IgwWjGsAVRU5ulaYiusUWKpn7QFQXOun3i2KrEnJH8kZaAJJK8di1PXWUB+UX0XB bJyw9anHA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:reply-to:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1710817598; x=1710903998; bh=I75P9/ZU49Zkp4axcNTlukw52tOV QchXE5mxgskscqk=; b=pftdr0EwUgvwqmQz5D8duPuXib0BYfTDWr1Ko8WYo2d6 QIKFu1FMp1yyaIWyVEbfis40TZyD/npuEYAOj3atlbAckmv/+8jJEjMLq9unEx/W UwIwVGXxVfSlOtl1CaRT9kjVS9gq2zORmjfqQmOI1sVJQn2eStppZ/PG+v6KZep2 BV/27yraKONKba8glSvFYQqwG1hQwe0T50VGZz/RdoEpcU2EGIFhXhe/tOJs4RT0 QZh5T/Cb/QKawx9RO184MgFGKQWXg/ya45RPTS6ggui7Ocp+PfIougOI4vkBgKGf Ok/zr2Tq8NySZL20kbL4fh6QWXRDuPUHi1qnswMn7A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrkeekgdehhecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffujgevfffkgggtsehmtderredttddtnecuhfhrohhmpefvohhshhhiucgf mhgvhhgrrhgruceothhoshhhihesnhhitggvuhhmvgdrtghomheqnecuggftrfgrthhtvg hrnhepffejhedttedutdevvdduheejgeeluefhkeevveehkeeiheevgedvteelhfeiteei necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepthhosh hhihesnhhitggvuhhmvgdrtghomh X-ME-Proxy: Feedback-ID: iaf1147ca:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 18 Mar 2024 23:06:32 -0400 (EDT) In-Reply-To: jwv1q89fwmx.fsf-monnier+emacs@gnu.org Received-SPF: pass client-ip=66.111.4.28; envelope-from=toshi@niceume.com; helo=out4-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:317175 Archived-At: --=-=-= Content-Type: text/plain Thank you very much for your comments, Stefan. As you point out, the previous code is found to fail when regular expressions and sexp comments exist in the same line. Now I put the logic to scan the beginning of sexp comments and regular expressions in syntax-propertize-rules macro. I use different functions to be invoked by them, because the beginning of regular expressions need to be canceled when they are already in normal strings or comments. (This kind of logic might be required also for sexp comment, but the current implementation does not do that and does not seem to cause any harms.) Therefore, if I use the same function, it requires an extra conditional code only for regular expressions, which is a repetition of what is done in syntax-propertize-rules level. (At syntax-propertize-rules leve, we already know it's a beginning of a sexp comment or a possible beginning of regular expression). The following explains the functions implemented. - scheme-syntax-propertize-sexp-comment No change from the current built-in implementation - scheme-syntax-propertize-regexp-end If the posistion is already in regular expressions and not in comments, it searches regular expression end (/) ignoring backslash slash (\/). - scheme-syntax-propertize-regexp This is invoked in syntax-propertize-rules. It cancels syntax class assignment to # of #/ if the # part is already in strings or comments. (Precisely, it assigns @ syntax class to # .) Otherwise it continues to scan the end of regular expression by calling scheme-syntax-propertize-regexp-end. Thanks. #+BEGIN_SRC (add-hook 'scheme-mode-hook (lambda () (setq-local syntax-propertize-function (lambda (beg end) (goto-char beg) (scheme-syntax-propertize-sexp-comment (point) end) (scheme-syntax-propertize-regexp-end (point) end) (funcall (syntax-propertize-rules ("\\(#\\);" (1 (prog1 "< cn" (scheme-syntax-propertize-sexp-comment (point) end)))) ("\\(#\\)/" (1 (prog1 "|" (scheme-syntax-propertize-regexp (point) end)))) ) (point) end) )))) (defun scheme-syntax-propertize-sexp-comment (_ end) (let ((state (syntax-ppss))) (when (eq 2 (nth 7 state)) ;; It's a sexp-comment. Tell parse-partial-sexp where it ends. (condition-case nil (progn (goto-char (+ 2 (nth 8 state))) ;; FIXME: this doesn't handle the case where the sexp ;; itself contains a #; comment. (forward-sexp 1) (put-text-property (1- (point)) (point) 'syntax-table (string-to-syntax "> cn"))) (scan-error (goto-char end)))))) (defun scheme-syntax-propertize-regexp-end (_ end) (let* ((state (syntax-ppss)) (within-str (nth 3 state)) (within-comm (nth 4 state)) (start-delim-pos (nth 8 state))) (if (and (not within-comm) (and within-str (string= (buffer-substring-no-properties start-delim-pos (1+ start-delim-pos)) "#"))) (let ((end-found nil)) (while (and (not end-found) (re-search-forward "\\(/\\)" end t)) (progn (if (not (char-equal (char-before (match-beginning 1)) ?\\ )) (progn (put-text-property (match-beginning 1) (1+ (match-beginning 1)) 'syntax-table (string-to-syntax "|")) (setq end-found t) ))))) ))) (defun scheme-syntax-propertize-regexp (_ end) (let* ((match-start-state (save-excursion (syntax-ppss (match-beginning 1)))) (within-str (nth 3 match-start-state)) (within-comm (nth 4 match-start-state))) (if (or within-str within-comm) (put-text-property ;; Cancel regular expression start (match-beginning 1) (1+ (match-beginning 1)) 'syntax-table (string-to-syntax "@")) (scheme-syntax-propertize-regexp-end _ end) ))) #+END_SRC --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=scheme-regexp.v2.patch Content-Description: deals with scheme regular expression syntax diff --git a/lisp/progmodes/scheme.el b/lisp/progmodes/scheme.el index 67abab6913d..98405513099 100644 --- a/lisp/progmodes/scheme.el +++ b/lisp/progmodes/scheme.el @@ -410,11 +410,18 @@ scheme-sexp-comment-syntax-table (defun scheme-syntax-propertize (beg end) (goto-char beg) (scheme-syntax-propertize-sexp-comment (point) end) + (scheme-syntax-propertize-regexp-end (point) end) (funcall (syntax-propertize-rules ("\\(#\\);" (1 (prog1 "< cn" - (scheme-syntax-propertize-sexp-comment (point) end))))) - (point) end)) + (scheme-syntax-propertize-sexp-comment + (point) end)))) + ("\\(#\\)/" (1 (prog1 "|" + (scheme-syntax-propertize-regexp + (point) end)))) + ) + (point) end) + ) (defun scheme-syntax-propertize-sexp-comment (_ end) (let ((state (syntax-ppss))) @@ -430,6 +437,49 @@ scheme-syntax-propertize-sexp-comment 'syntax-table (string-to-syntax "> cn"))) (scan-error (goto-char end)))))) +(defun scheme-syntax-propertize-regexp-end (_ end) + (let* ((state (syntax-ppss)) + (within-str (nth 3 state)) + (within-comm (nth 4 state)) + (start-delim-pos (nth 8 state))) + (if (and (not within-comm) + (and within-str + (string= + (buffer-substring-no-properties + start-delim-pos + (1+ start-delim-pos)) + "#"))) + (let ((end-found nil)) + (while (and + (not end-found) + (re-search-forward "\\(/\\)" end t)) + (progn + (if + (not (char-equal + (char-before (match-beginning 1)) + ?\\ )) + (progn + (put-text-property + (match-beginning 1) + (1+ (match-beginning 1)) + 'syntax-table (string-to-syntax "|")) + (setq end-found t) + ))))) + ))) + +(defun scheme-syntax-propertize-regexp (_ end) + (let* ((match-start-state (save-excursion + (syntax-ppss (match-beginning 1)))) + (within-str (nth 3 match-start-state)) + (within-comm (nth 4 match-start-state))) + (if (or within-str within-comm) + (put-text-property ;; Cancel regular expression start + (match-beginning 1) + (1+ (match-beginning 1)) + 'syntax-table (string-to-syntax "@")) + (scheme-syntax-propertize-regexp-end _ end) + ))) + ;;;###autoload (define-derived-mode dsssl-mode scheme-mode "DSSSL" "Major mode for editing DSSSL code. --=-=-= Content-Type: text/plain -- Toshi (Toshihiro Umehara) --=-=-=--