From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tom Tromey Newsgroups: gmane.emacs.bugs Subject: bug#25529: diagnosis and one approach to a fix Date: Sun, 05 Feb 2017 11:43:04 -0700 Message-ID: <87k2948onb.fsf@tromey.com> References: <87wpd58ag6.fsf@tromey.com> <87shnt89be.fsf@tromey.com> <87o9yg8qdi.fsf@tromey.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1486320254 11087 195.159.176.226 (5 Feb 2017 18:44:14 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 5 Feb 2017 18:44:14 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.91 (gnu/linux) Cc: 25529@debbugs.gnu.org, Dmitry Gutov To: Tom Tromey Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Feb 05 19:44:08 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1caRnD-0002ca-Jh for geb-bug-gnu-emacs@m.gmane.org; Sun, 05 Feb 2017 19:44:08 +0100 Original-Received: from localhost ([::1]:44123 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1caRnJ-00023Z-46 for geb-bug-gnu-emacs@m.gmane.org; Sun, 05 Feb 2017 13:44:13 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55364) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1caRnD-00023S-HW for bug-gnu-emacs@gnu.org; Sun, 05 Feb 2017 13:44:08 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1caRn9-0008Am-JF for bug-gnu-emacs@gnu.org; Sun, 05 Feb 2017 13:44:07 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:58673) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1caRn9-0008Ae-8l for bug-gnu-emacs@gnu.org; Sun, 05 Feb 2017 13:44:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1caRn7-0000QQ-Qr for bug-gnu-emacs@gnu.org; Sun, 05 Feb 2017 13:44:03 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Tom Tromey Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 05 Feb 2017 18:44:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 25529 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 25529-submit@debbugs.gnu.org id=B25529.14863202091590 (code B ref 25529); Sun, 05 Feb 2017 18:44:01 +0000 Original-Received: (at 25529) by debbugs.gnu.org; 5 Feb 2017 18:43:29 +0000 Original-Received: from localhost ([127.0.0.1]:56872 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1caRmb-0000PZ-JF for submit@debbugs.gnu.org; Sun, 05 Feb 2017 13:43:29 -0500 Original-Received: from gproxy3-pub.mail.unifiedlayer.com ([69.89.30.42]:59258) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1caRmZ-0000PH-Kn for 25529@debbugs.gnu.org; Sun, 05 Feb 2017 13:43:28 -0500 Original-Received: (qmail 14007 invoked by uid 0); 5 Feb 2017 18:43:11 -0000 Original-Received: from unknown (HELO CMOut01) (10.0.90.82) by gproxy3.mail.unifiedlayer.com with SMTP; 5 Feb 2017 18:43:11 -0000 Original-Received: from box522.bluehost.com ([74.220.219.122]) by CMOut01 with id h6j61u00M2f2jeq016j9LQ; Sun, 05 Feb 2017 11:43:11 -0700 X-Authority-Analysis: v=2.1 cv=NJxGpSKg c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=n2v9WMKugxEA:10 a=zstS-IiYAAAA:8 a=k0DwgZvpFiRD_Sh1wb0A:9 a=4G6NA9xxw8l3yy4pmD5M:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=rMAGzlW3axTdAe9v4bKBOdr2GKzzS78AiGINLWs6Mi8=; b=bWBximhwWUDOiiFt6FFbiKocge ENjpD8JppJqiU/U6Hf8q2YyWS2Sin0jRHCyd81lcFShX6R4S/TMv1uCLpwoi3lJTDY+K8axJSR8Z+ 229WE9VRL+NRtkL7KnfxklY0U; Original-Received: from 174-16-146-181.hlrn.qwest.net ([174.16.146.181]:58020 helo=bapiya) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1caRmE-0000xf-4U; Sun, 05 Feb 2017 11:43:06 -0700 X-Attribution: Tom In-Reply-To: <87o9yg8qdi.fsf@tromey.com> (Tom Tromey's message of "Sun, 05 Feb 2017 11:05:45 -0700") X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box522.bluehost.com X-AntiAbuse: Original Domain - debbugs.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 174.16.146.181 X-Exim-ID: 1caRmE-0000xf-4U X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 174-16-146-181.hlrn.qwest.net (bapiya) [174.16.146.181]:58020 X-Source-Auth: tom+tromey.com X-Email-Count: 2 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:128994 Archived-At: Tom> Another way is to use a regexp, see appended. Tom> I'll try to write a test for this soon. Now with a test. Dmitry, I'd appreciate your comments on this. Tom commit 0841c586b5a933773e770579b4a9cd6f86b2dcf7 Author: Tom Tromey Date: Sun Feb 5 11:40:18 2017 -0700 Recognize JS regexp literals more correctly * lisp/progmodes/js.el (js--syntax-propertize-regexp-regexp): New constant. (js-syntax-propertize-regexp): Use it. * test/lisp/progmodes/js-tests.el (js-mode-regexp-syntax-bug-25529): New test. diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el index e42e014..145aa6f 100644 --- a/lisp/progmodes/js.el +++ b/lisp/progmodes/js.el @@ -1694,22 +1694,33 @@ js--syntax-propertize-regexp-syntax-table (modify-syntax-entry ?\\ "\\" st) st)) +(defconst js--syntax-propertize-regexp-regexp + (rx + ;; Start of regexp. + "/" + (0+ (or + ;; Match characters outside of a character class. + (not (any ?\[ ?/ ?\\)) + ;; Match backslash quoted characters. + (and "\\" not-newline) + ;; Match character class. + (and + "[" + (0+ (or + (not (any ?\] ?\\)) + (and "\\" not-newline))) + "]"))) + (group "/")) + "Regular expression matching the body of a JavaScript regexp literal.") + (defun js-syntax-propertize-regexp (end) (let ((ppss (syntax-ppss))) (when (eq (nth 3 ppss) ?/) ;; A /.../ regexp. - (while - (when (re-search-forward "\\(?:\\=\\|[^\\]\\)\\(?:\\\\\\\\\\)*/" - end 'move) - (if (nth 1 (with-syntax-table - js--syntax-propertize-regexp-syntax-table - (let ((parse-sexp-lookup-properties nil)) - (parse-partial-sexp (nth 8 ppss) (point))))) - ;; A / within a character class is not the end of a regexp. - t - (put-text-property (1- (point)) (point) - 'syntax-table (string-to-syntax "\"/")) - nil)))))) + (goto-char (nth 8 ppss)) + (when (looking-at js--syntax-propertize-regexp-regexp) + (put-text-property (match-beginning 1) (match-end 1) + 'syntax-table (string-to-syntax "\"/")))))) (defun js-syntax-propertize (start end) ;; JavaScript allows immediate regular expression objects, written /.../. diff --git a/test/lisp/progmodes/js-tests.el b/test/lisp/progmodes/js-tests.el index 7cb737c..d1a8db0 100644 --- a/test/lisp/progmodes/js-tests.el +++ b/test/lisp/progmodes/js-tests.el @@ -99,6 +99,15 @@ (forward-line) (should (looking-at " \\* test")))) +(ert-deftest js-mode-regexp-syntax-bug-25529 () + (with-temp-buffer + (js-mode) + (insert "let x = /[^[]/;\n") + (save-excursion (insert "something();\n")) + ;; The failure mode was that the regexp literal was not + ;; recognized, causing the next line to be given string syntax. + (should-not (nth 3 (syntax-ppss))))) + (provide 'js-tests) ;;; js-tests.el ends here