emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: access to parser stack in SMIE


From: Stephen Leake
Subject: Re: access to parser stack in SMIE
Date: Sun, 07 Oct 2012 21:28:26 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (windows-nt)

Stefan Monnier <address@hidden> writes:

>> 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.

That makes sense.

>> 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.

Yes. I should look at this again; it might be better than what I have now.

>>          (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...

Ah, I never even considered that it might not be unique. That makes this
technique less satisfactory; to be safe, we'd have to add the actual
token to the stack.

I did wonder why the stack didn't have the actual token; I guess you
didn't need it for anything yet.

-- 
-- Stephe



reply via email to

[Prev in Thread] Current Thread [Next in Thread]