From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#24870: 26.0.50; parse-partial-sexp ignores comment-end Date: Wed, 14 Dec 2016 21:58:34 +0000 Message-ID: <20161214215834.GB3881@acm.fritz.box> References: <7cb86247-1e30-f029-0b9b-c53cc096ec4b@easy-emacs.de> <87mvggh2hu.fsf@users.sourceforge.net> <87h967cj0f.fsf@users.sourceforge.net> <87eg1bcg0y.fsf@users.sourceforge.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1481752764 29202 195.159.176.226 (14 Dec 2016 21:59:24 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 14 Dec 2016 21:59:24 +0000 (UTC) User-Agent: Mutt/1.5.24 (2015-08-30) Cc: 24870@debbugs.gnu.org, Matt Armstrong To: npostavs@users.sourceforge.net Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Dec 14 22:59:15 2016 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 1cHHZw-0005D1-4q for geb-bug-gnu-emacs@m.gmane.org; Wed, 14 Dec 2016 22:59:12 +0100 Original-Received: from localhost ([::1]:50488 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cHHZx-0006MZ-4u for geb-bug-gnu-emacs@m.gmane.org; Wed, 14 Dec 2016 16:59:13 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38254) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cHHZq-0006Cf-Hv for bug-gnu-emacs@gnu.org; Wed, 14 Dec 2016 16:59:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cHHZm-0004wh-KY for bug-gnu-emacs@gnu.org; Wed, 14 Dec 2016 16:59:06 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:54983) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cHHZm-0004wT-H3 for bug-gnu-emacs@gnu.org; Wed, 14 Dec 2016 16:59:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cHHZm-0002vc-AN for bug-gnu-emacs@gnu.org; Wed, 14 Dec 2016 16:59:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 14 Dec 2016 21:59:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 24870 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: confirmed Original-Received: via spool by 24870-submit@debbugs.gnu.org id=B24870.148175273711245 (code B ref 24870); Wed, 14 Dec 2016 21:59:02 +0000 Original-Received: (at 24870) by debbugs.gnu.org; 14 Dec 2016 21:58:57 +0000 Original-Received: from localhost ([127.0.0.1]:42149 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cHHZh-0002vJ-JB for submit@debbugs.gnu.org; Wed, 14 Dec 2016 16:58:57 -0500 Original-Received: from ocolin.muc.de ([193.149.48.4]:49720 helo=mail.muc.de) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1cHHZf-0002vA-Q7 for 24870@debbugs.gnu.org; Wed, 14 Dec 2016 16:58:56 -0500 Original-Received: (qmail 79997 invoked by uid 3782); 14 Dec 2016 21:58:54 -0000 Original-Received: from acm.muc.de (p548C778A.dip0.t-ipconnect.de [84.140.119.138]) by colin.muc.de (tmda-ofmipd) with ESMTP; Wed, 14 Dec 2016 22:58:53 +0100 Original-Received: (qmail 19286 invoked by uid 1000); 14 Dec 2016 21:58:34 -0000 Content-Disposition: inline In-Reply-To: <87eg1bcg0y.fsf@users.sourceforge.net> X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de 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:127042 Archived-At: Hello again, Noam. On Tue, Dec 13, 2016 at 11:04:45PM -0500, npostavs@users.sourceforge.net wrote: > npostavs@users.sourceforge.net writes: > > I have tracked the issue down to scan_sexps_forward in syntax.c > Applying this change which reverts part of [1] seems to fix the issue: > --- i/src/syntax.c > +++ w/src/syntax.c > @@ -3192,7 +3192,11 @@ scan_sexps_forward (struct lisp_parse_state *state, > while (from < end) > { > - if (SYNTAX_FLAGS_COMSTART_FIRST (prev_from_syntax) > + INC_FROM; > + code = prev_from_syntax & 0xff; > + > + if (from < end > + && SYNTAX_FLAGS_COMSTART_FIRST (prev_from_syntax) > && (c1 = FETCH_CHAR (from_byte), > syntax = SYNTAX_WITH_FLAGS (c1), > SYNTAX_FLAGS_COMSTART_SECOND (syntax))) > @@ -3213,8 +3217,6 @@ scan_sexps_forward (struct lisp_parse_state *state, > } > else > { > - INC_FROM; > - code = prev_from_syntax & 0xff; > if (code == Scomment_fence) > { > /* Record the comment style we have entered so that only Alas, that patch won't do. The very first thing that must be done in the loop is to check for a two-character comment delimiter, of which the first character might have been recorded in OLDSTATE element 9 rather than having been scanned by scan_sexps_forward on the previous loop iteration. My analysis of what's happening in the bug recipe you posted one or two posts previously, here in scan_sexps_forward is as follows. (In that recipe, "{-C-}\nX" was parse-partial-sexp'd over, and the syntax table had been set to recognise "{-" and "-}" as matching comment delimiters.) (i) On the first iteration of the main loop, the "{" is read. It is recognised as an opening paren, and causes the "current paren depth" to be incremented. (ii) On the second iteration of the loop, the "-" is read. The function now recognises the two-character comment opener, and proceeds to read the innards of the comment together with its closing delimiter (the "-}"). (iii) On the third and fourth iterations, the function reads "\n" and "X". It then terminates, having reached point-max. (iv) The paren depth counter remains at 1. What is new here is characters with paren syntax also being components of 2-char comment delimiters. I recently fixed a similar problem when characters with word syntax were also flagged as 2-char comment delimiter parts. I think a similar patch at case label Sopen: (Line ~3322), which would peek ahead at the next character to check for "{-" before recognising the "{" as an open paren would be the best fix. Do you want to make this fix, or should I do it? If you want to do it, I'm willing (indeed, eager) to review it for you. [ .... ] -- Alan Mackenzie (Nuremberg, Germany).