[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Working around the limitations of SMIE
From: |
Philip Kaludercic |
Subject: |
Re: Working around the limitations of SMIE |
Date: |
Fri, 11 Nov 2022 16:20:35 +0000 |
Stefan Monnier via Users list for the GNU Emacs text editor
<help-gnu-emacs@gnu.org> writes:
>> I am writing a major mode for a little language I am using at
>> university, and wanted to try using SMIE for indentation and all the
>> other things. The issue I find myself confronted with is that functions
>> are defined as in the following example:
>>
>> func funktion(x : int): float
>> x := x * x;
>> return x;
>> end
>>
>> where there is no delimiter between the return type (float), and the
>> rest of the body (such as "begin" or something like that).
>
> How is the separation between the function's return type and the
> function's body defined? Is it based on the newline that follows the
> type, or is the language constrained to have types that are
> a single identifiers?
The latter. This is the grammar production:
functionDeclaration: ' func ' identifier '( ' ( parameterDeclaration ( ', '
parameterDeclaration ) * ) ? ') '
( ': ' typeName ) ? block ' end ' ;
>> Another issue I ran into with the above definition is that instructions
>> are not indented correctly, as the above grammar doesn't express that in
>> this language doesn't expect a semicolon after an end (just like C
>> doesn't expect one after a "}"). So the result is that
>>
>> instead of:
>>
>> while y >= y1 do
>> dummy := zeile(x1, x2, xstep, y);
>> y := y - ystep;
>> end
>> return 0;
>>
>> I get:
>>
>> while y >= y1 do
>> dummy := zeile(x1, x2, xstep, y);
>> y := y - ystep;
>> end
>> return 0;
>
> Based on my experience, I suspect that the simplest solution for this is
> to make "end" return 2 tokens (the "end" and then a ghost ";").
Funnily enough I had tried this out too, but I must have messed up
somewhere because the result wasn't what I had intended.
Thanks.