emacs-devel
[Top][All Lists]
Advanced

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

Re: ruby-mide, SMIE and token priority


From: Dmitry Gutov
Subject: Re: ruby-mide, SMIE and token priority
Date: Thu, 07 Nov 2013 15:10:59 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.0

On 07.11.2013 06:30, Stefan Monnier wrote:
bar.foo(tee) do
   bar
end

What is the AST corresponding to this code?
I mean, is it a method call on "bar" with method "foo" and 2 arguments
(tee and do...end)?  I.e. (. bar foo tee (do-end bar))?

More or less, yes. "bar" could also be a method, but the structure would be the same.

The problem seems to be that "." is considered the parent token of
"do".  Probably because the left priority of "do" is not a number.

SMIE parses it as (. bar (call foo tee (do-end bar))).
>
It would be more natural if the parent of "do" was ";" on the preceding
line, instead.

You mean parse it as (call (. bar foo tee) (do-end bar))?

Guess so. The argument in favor of doing it this way is the grammar is already a bit skewed toward indentation (for example, " @ " has higher priority than "."), but that's likely something to be fixed, too.

Is it at all possible to change the grammar this way?

You'd probably have to use a trick similar to the " @ " used on the
space between the method name and the multiple-args.

Ah, okay. Sounds not very efficient, performance-wise.

Or should we just handle this as a special case in the `ruby-smie-rules',
and in case of "do", instead of delegating to the parent, skip the parents
until we find ";"?

Depends: the rule of thumb is that if you have to choose between "make
the grammar match the AST" or "make the grammar match the indentation",
then better choose "match the AST" and then adjust the indentation via
the smie-rules.

So if the indentation you want is indeed not faithful to the AST, then
indeed it's better to fix it in smie-rules.

Let's try this way, then.



reply via email to

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