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: Mon, 08 Oct 2012 18:58:49 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (windows-nt)

Stephen Leake <address@hidden> writes:

> Stefan Monnier <address@hidden> 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



reply via email to

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