From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Reliable after-change-functions (via: Using incremental parsing in Emacs) Date: Thu, 02 Apr 2020 15:39:05 -0400 Message-ID: References: <83tv22x9lx.fsf@gnu.org> <9F3099CD-EAA4-4995-92B4-764A2E5815F3@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="43446"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: Emacs-devel@gnu.org, =?utf-8?B?7KGw7ISx67mI?= , Dmitry Gutov , acm@muc.de, Eli Zaretskii , akrl@sdf.org To: Yuan Fu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Apr 02 21:40:01 2020 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 1jK5h1-000B8J-Ti for ged-emacs-devel@m.gmane-mx.org; Thu, 02 Apr 2020 21:39:59 +0200 Original-Received: from localhost ([::1]:46650 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jK5h1-00059s-0l for ged-emacs-devel@m.gmane-mx.org; Thu, 02 Apr 2020 15:39:59 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37787) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jK5gF-0004RF-6L for Emacs-devel@gnu.org; Thu, 02 Apr 2020 15:39:12 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jK5gD-0007s7-I1 for Emacs-devel@gnu.org; Thu, 02 Apr 2020 15:39:10 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:9473) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jK5gD-0007ro-By; Thu, 02 Apr 2020 15:39:09 -0400 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 4313582853; Thu, 2 Apr 2020 15:39:08 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 8AC4C801AC; Thu, 2 Apr 2020 15:39:06 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1585856346; bh=tMwUGyYhaL07jqHx1Ui8zWGvgnWdSyAA2TSTq+z7N1s=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=N7JpRuCCgHcgC6fc2j5TfUzulKSiDD2uhr1PD5IAqaJ1qtKY/z6rYlGYjU1DO4xFT FytWF5DV8pwwKHJdgJYQXXO29A2MsaSdJkMTnr+YSz0H4wKz1+MhgScpqv+HB9+LA1 yXgfOwVLvvG4fLeMQ1Op+4Wvoi+srO6eMkxeRqOtSqxcXZMEl8G50RNzuC5pm+NZtG F6UxPcbYE0OgWLhyzD48wbTkKyr4mazETfZvJh4UgZGxf3lri0br7qsnnPFPx6t4hy qEI/hfcUVsDsHzabSIM4JKbRTmpW2Sk/GNV3t1lPnP935QtXDueoYY0FVY6tOFWe2L 3/7ppr3OeqG4g== Original-Received: from alfajor (unknown [104.247.241.114]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 331D31206E3; Thu, 2 Apr 2020 15:39:06 -0400 (EDT) In-Reply-To: <9F3099CD-EAA4-4995-92B4-764A2E5815F3@gmail.com> (Yuan Fu's message of "Thu, 2 Apr 2020 14:27:30 -0400") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 132.204.25.50 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 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" Xref: news.gmane.io gmane.emacs.devel:246289 Archived-At: > Some modes doesn=E2=80=99t require a font-up parsing. IIRC, an example fr= om an > earlier message is javascript-mode. Yet, in order to decide whether position P in a javascript buffer is inside a comment or not, you will either have to look at everything between point-min and P, or think hard about all the various possibilities to try and see if you can argue that in this particular case it's not necessary. E.g. if you see foo /* bar */ then you might be able to say that "bar" is within a comment without looking much further. But for "foo" you first have to look back because there might have been an earlier unmatched `/*`. BTW, for "bar" you still have to look a bit further: it might be that the previous line was: tmp =3D "hello\ in which case "bar" is not inside a comment but inside a string. Well, unless there's ... an earlier unmatched `/*`. Etc... For the case of Javascript I believe that you can come up with an algorithm which will reliably give the right answer while almost never having to go back all the way to `point-min`. I even believe it's possible to write a tool that will automatically find that algorithm given a suitable input grammar. But for some languages like Elisp, Python, and OCaml I believe it's simply impossible (for Elisp/Python it's because of the existence of multiline strings (with no "trailing \" to indicate their possible presence) and for OCaml it's because of the nested comments). Stefan