From: Philip Kaludercic <philipk@posteo.net>
To: help-gnu-emacs@gnu.org
Subject: Working around the limitations of SMIE
Date: Wed, 09 Nov 2022 21:25:15 +0000 [thread overview]
Message-ID: <874jv795xg.fsf@posteo.net> (raw)
Hi,
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). My naive
approach at defining a grammar was as follows:
(defconst e2-grammar
(smie-prec2->grammar
(smie-bnf->prec2
'((id) (exp)
(inst ("func" insts "end") ; <--
("var" id ":" id)
("if" exp "then" insts "else" insts "end")
("if" exp "then" insts "end")
("while" exp "do" insts "end")
("return" exp)
(id ":=" exp))
(insts (inst ";" insts) (inst)))))
"SMIE grammar for e2.")
Cannot express the fact that a return type, a non-terminal is followed
by the rest of the body, another non-terminal.
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;
because it tries to parse "while ... end return 0" as an instruction.
I've been looking around the web for other major modes that use SMIE but
couldn't find anything satisfying. I wonder if it is necessary to
define a special token-function that generates whitespace tokens? I
hope there is a better way.
next reply other threads:[~2022-11-09 21:25 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-09 21:25 Philip Kaludercic [this message]
2022-11-10 5:00 ` Working around the limitations of SMIE 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
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=874jv795xg.fsf@posteo.net \
--to=philipk@posteo.net \
--cc=help-gnu-emacs@gnu.org \
/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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).