From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: access to parser stack in SMIE Date: Sun, 07 Oct 2012 21:00:11 -0400 Message-ID: References: <85pq4wgrho.fsf@member.fsf.org> <85lifjfn10.fsf@member.fsf.org> <85wqz1dg7k.fsf@member.fsf.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1349658020 31634 80.91.229.3 (8 Oct 2012 01:00:20 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 8 Oct 2012 01:00:20 +0000 (UTC) Cc: emacs-devel To: Stephen Leake Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Oct 08 03:00:26 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 1TL1hp-0001vx-U2 for ged-emacs-devel@m.gmane.org; Mon, 08 Oct 2012 03:00:26 +0200 Original-Received: from localhost ([::1]:56673 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TL1hj-0001BF-SV for ged-emacs-devel@m.gmane.org; Sun, 07 Oct 2012 21:00:19 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:45237) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TL1hh-0001Ax-Bl for emacs-devel@gnu.org; Sun, 07 Oct 2012 21:00:18 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TL1he-0003hN-Cl for emacs-devel@gnu.org; Sun, 07 Oct 2012 21:00:17 -0400 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.182]:20174) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TL1he-0003dw-7Y for emacs-devel@gnu.org; Sun, 07 Oct 2012 21:00:14 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av0EAG6Zu09FxLQG/2dsb2JhbAA7CbQRgQiCFQEBBAFWIwULCzQSFBgNJCyFeYF3BboJixiFLAOjM4FYgwWBQw X-IronPort-AV: E=Sophos;i="4.75,637,1330923600"; d="scan'208";a="200850684" Original-Received: from 69-196-180-6.dsl.teksavvy.com (HELO fmsmemgm.homelinux.net) ([69.196.180.6]) by ironport2-out.teksavvy.com with ESMTP/TLS/ADH-AES256-SHA; 07 Oct 2012 21:00:12 -0400 Original-Received: by fmsmemgm.homelinux.net (Postfix, from userid 20848) id D78C0AE2FA; Sun, 7 Oct 2012 21:00:11 -0400 (EDT) In-Reply-To: <85wqz1dg7k.fsf@member.fsf.org> (Stephen Leake's message of "Sun, 07 Oct 2012 19:18:07 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 206.248.154.182 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:154212 Archived-At: > Yes. Which is why the cache is critical. And improving the cache by > storing the stack at each keyword would be even better. That can lead to a very large cache, which can then become slow to manage. In syntax-ppss we keep the intermediate state of the parse every ~20KB. So that if we have to re-parse at most ~20KB's worth of text. >> But I wonder now: can a "begin" that comes right after a "function >> ... end;" be a begin-open? > package Package_1 is > function Function_1 return Integer > is begin > return 1; > end; > begin > That isn't "begin-open". But how can you be sure that's the case you > have? You can't just stop a the "end"; consider: No, but if you have package Package_1 is function Function_1 return Integer is begin return 1; end; function Function_2 return Integer is begin return 2; end; begin you can stop when you see the first "function". I'd expect that within a package there are usually several functions, so parsing backward a single function doesn't sound bad compared to parsing forward the whole file. > work. But it's messier and less general than the forward parse > mechanism, and the other tokens that need forward parse would need their > own variations. 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. > Too much ad-hoc code. You might be right. > (setq stack-token (nth 0 (rassoc (pop stack) ada-indent-grammar))) Hmm... indeed, by relying on the identity of the cons cells in the stack, you can recover the actual token, even if 2 tokens have the same left&right precedence. It should be the case in all real-life situations, but nothing guarantees that it's the case. Hmm... > I guess you could provide a function that scans the stack, skipping ";", > and returning the next token. That would work in this particular case, > but I'm not sure about the other cases I need. I have to think it over some more, Stefan