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: Sat, 04 Feb 2017 23:01:57 -0700 Message-ID: <87shnt89be.fsf@tromey.com> References: <87wpd58ag6.fsf@tromey.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1486274591 19406 195.159.176.226 (5 Feb 2017 06:03:11 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 5 Feb 2017 06:03:11 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.91 (gnu/linux) Cc: 25529@debbugs.gnu.org To: Tom Tromey Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Feb 05 07:03: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 1caFuk-0004qd-UP for geb-bug-gnu-emacs@m.gmane.org; Sun, 05 Feb 2017 07:03:07 +0100 Original-Received: from localhost ([::1]:41896 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1caFuq-0006iM-IS for geb-bug-gnu-emacs@m.gmane.org; Sun, 05 Feb 2017 01:03:12 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:58270) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1caFuk-0006i9-4x for bug-gnu-emacs@gnu.org; Sun, 05 Feb 2017 01:03:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1caFuh-0002yK-26 for bug-gnu-emacs@gnu.org; Sun, 05 Feb 2017 01:03:06 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:58234) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1caFug-0002yD-Q3 for bug-gnu-emacs@gnu.org; Sun, 05 Feb 2017 01:03:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1caFug-0004v9-DB for bug-gnu-emacs@gnu.org; Sun, 05 Feb 2017 01:03:02 -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 06:03:02 +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.148627454218870 (code B ref 25529); Sun, 05 Feb 2017 06:03:02 +0000 Original-Received: (at 25529) by debbugs.gnu.org; 5 Feb 2017 06:02:22 +0000 Original-Received: from localhost ([127.0.0.1]:56433 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1caFu1-0004uI-V7 for submit@debbugs.gnu.org; Sun, 05 Feb 2017 01:02:22 -0500 Original-Received: from gproxy2-pub.mail.unifiedlayer.com ([69.89.18.3]:47133) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1caFu0-0004u4-D2 for 25529@debbugs.gnu.org; Sun, 05 Feb 2017 01:02:20 -0500 Original-Received: (qmail 9997 invoked by uid 0); 5 Feb 2017 06:02:03 -0000 Original-Received: from unknown (HELO CMOut01) (10.0.90.82) by gproxy2.mail.unifiedlayer.com with SMTP; 5 Feb 2017 06:02:03 -0000 Original-Received: from box522.bluehost.com ([74.220.219.122]) by CMOut01 with id gu1z1u00X2f2jeq01u22Hw; Sat, 04 Feb 2017 23:02:03 -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=RRKnn34OjR7MtBwWI5MA:9 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=sQN5ppcVGlkhdx1goT40sF4N6NqNybH5hQC64WZf60U=; b=QjCKaackITlof086lXyDCoN0gA YTP8f+WCV8NJz2VqzpE9lX0aBQ5WVcXZhLsblKFww3SIFnUBoMElUO42gJnB8n0ChDNcYEpL0/EGG MPEdpim08Erd8H07bknaF5lFQ; Original-Received: from 174-16-146-181.hlrn.qwest.net ([174.16.146.181]:56866 helo=bapiya) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1caFtf-0002s1-96; Sat, 04 Feb 2017 23:01:59 -0700 X-Attribution: Tom In-Reply-To: <87wpd58ag6.fsf@tromey.com> (Tom Tromey's message of "Sat, 04 Feb 2017 22:37:29 -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: 1caFtf-0002s1-96 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 174-16-146-181.hlrn.qwest.net (bapiya) [174.16.146.181]:56866 X-Source-Auth: tom+tromey.com X-Email-Count: 1 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:128977 Archived-At: Tom> I don't think there is a way to teach parse-partial-sexp that "^" is a Tom> quote only in this one specific instance. This doesn't actually make sense anyway. The "^" is a distraction, as this is valid: let x = /[[]/; Tom> One possible fix here would be to change this function to do a simple Tom> parse of the regexp literal. I think it would only really have to Tom> handle parsing bracket syntax and looking for the terminating "/". The Tom> current code also looks for balanced parens, but I don't think this is Tom> actually needed. I've appended a patch implementing this idea. Tom diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el index e42e014..083cef9 100644 --- a/lisp/progmodes/js.el +++ b/lisp/progmodes/js.el @@ -1698,18 +1698,30 @@ js-syntax-propertize-regexp (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)))))) + (let ((keep-going t) + (backslash nil) + (in-bracket nil)) + (while keep-going + (forward-char) + (let ((c (char-after))) + (cond + (backslash + (setq backslash nil)) + ((eq c ?\\) + (setq backslash t)) + ((eq c ?\[) + ;; Note that inside a bracket we can see another unescaped open + ;; bracket. + (setq in-bracket t)) + ((eq c ?\]) + (setq in-bracket nil)) + ((eq c ?/) + (unless in-bracket + ;; We're done. + (setq keep-going nil) + (put-text-property + (point) (1+ (point)) + 'syntax-table (string-to-syntax "\"/"))))))))))) (defun js-syntax-propertize (start end) ;; JavaScript allows immediate regular expression objects, written /.../.