From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stephen Leake Newsgroups: gmane.emacs.devel Subject: Re: access to parser stack in SMIE Date: Mon, 08 Oct 2012 18:58:49 -0400 Message-ID: <85vcek1sgm.fsf@member.fsf.org> References: <85pq4wgrho.fsf@member.fsf.org> <85lifjfn10.fsf@member.fsf.org> <85wqz1dg7k.fsf@member.fsf.org> <857gr1da6d.fsf@member.fsf.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1349737434 8679 80.91.229.3 (8 Oct 2012 23:03:54 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 8 Oct 2012 23:03:54 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Oct 09 01:04:01 2012 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1TLMMi-0004VH-BD for ged-emacs-devel@m.gmane.org; Tue, 09 Oct 2012 01:04:00 +0200 Original-Received: from localhost ([::1]:33435 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TLMMc-00077M-36 for ged-emacs-devel@m.gmane.org; Mon, 08 Oct 2012 19:03:54 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:34402) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TLMMZ-00076Q-Gp for emacs-devel@gnu.org; Mon, 08 Oct 2012 19:03:52 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TLMMY-0005lv-CC for emacs-devel@gnu.org; Mon, 08 Oct 2012 19:03:51 -0400 Original-Received: from qmta11.westchester.pa.mail.comcast.net ([76.96.59.211]:47822) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TLMMY-0005lm-8z for emacs-devel@gnu.org; Mon, 08 Oct 2012 19:03:50 -0400 Original-Received: from omta10.westchester.pa.mail.comcast.net ([76.96.62.28]) by QMTA11.westchester.pa.mail.comcast.net with comcast id 8msL1k0080cZkys5Bn3uta; Mon, 08 Oct 2012 23:03:54 +0000 Original-Received: from TAKVER ([69.140.67.196]) by omta10.westchester.pa.mail.comcast.net with comcast id 8myo1k0044E4Fsd3WmyorL; Mon, 08 Oct 2012 22:58:48 +0000 In-Reply-To: <857gr1da6d.fsf@member.fsf.org> (Stephen Leake's message of "Sun, 07 Oct 2012 21:28:26 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (windows-nt) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 76.96.59.211 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 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.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:154248 Archived-At: Stephen Leake writes: > Stefan Monnier writes: > >> I get the impression that a >> >> (let ((begin-flavor nil)) >> (while (let ((s (smie-backward-sexp 'halfsexp))) >> (null (setq begin-flavor (ada--begin-flavor s)))))) >> >> wouldn't be that hard to write and that ada--begin-flavor would look >> similar to your current function that looks at the stack items. >> But of course, here, details matter, so we can't know without actually >> trying it out. > > Yes. I should look at this again; it might be better than what I have > now. It turns out you were right. Scanning backwards is better, because there is one additional test you can apply; as you cross each Ada statement or declaration, you can check which it was (statement or declaration), and that tells you whether you have begin-open or begin-body. So you typically only have to go back one statement, not all the way to the top. I can construct a worse case scenario that requires scanning to the top, but it's pretty pathological code. That still involves encountering unrefined "begin", but you just recurse on that, no problem. I've implemented that, and removed my local copy of smie.el. The code is quite straight-forward, not much more hairy than the code it replaces. And this technique should work for the other places I thought I needed full parse-forward. I hereby withdraw my request for smie--levels. Thanks for pushing me on this :). I've kept the cache; it's simple, and it should speed things up quite a bit. I'll try to measure how much when I'm all done. I'll still play with semantic; there are front-end tools like code completion and function call template that rely on it. But it's less urgent. -- -- Stephe