all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Philip Kaludercic <philipk@posteo.net>
Cc: Stefan Monnier via Users list for the GNU Emacs text editor
	<help-gnu-emacs@gnu.org>
Subject: Re: Working around the limitations of SMIE
Date: Sat, 12 Nov 2022 14:06:14 -0500	[thread overview]
Message-ID: <jwvy1sgm23d.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87zgcx1mzw.fsf@posteo.net> (Philip Kaludercic's message of "Fri,  11 Nov 2022 16:20:35 +0000")

>>> 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 ' ;

Hmm... so the only "reliable" separator token is the close parenthesis, huh?
I think I'd go with a hack in the lexer which checks if this is "the
close paren of a function definition" and make it include the subsequent
type annotation (if present).  I.e. that new token would cover the whole of

    ')' ( ':' typeName ) ?

Then again, that wouldn't work with the usual handling of parens in SMIE
(IOW, you couldn't rely on syntax tables for them any more) :-(

Maybe instead you can try and make the lexer recognize just ": typeName"
(treating it as a special token) and then tweak the indentation rules so
as to align the subsequent instruction with it.

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

IIRC it's easier to get it not to work than to get it to work, the
"messed up" doesn't carry the right connotation.


        Stefan




  reply	other threads:[~2022-11-12 19:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-09 21:25 Working around the limitations of SMIE Philip Kaludercic
2022-11-10  5:00 ` Stefan Monnier via Users list for the GNU Emacs text editor
2022-11-11 16:20   ` Philip Kaludercic
2022-11-12 19:06     ` Stefan Monnier [this message]
2022-11-13  0:12       ` Philip Kaludercic

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvy1sgm23d.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=help-gnu-emacs@gnu.org \
    --cc=philipk@posteo.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.