unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Working around the limitations of SMIE
@ 2022-11-09 21:25 Philip Kaludercic
  2022-11-10  5:00 ` Stefan Monnier via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 5+ messages in thread
From: Philip Kaludercic @ 2022-11-09 21:25 UTC (permalink / raw)
  To: help-gnu-emacs


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.



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-11-13  0:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2022-11-13  0:12       ` Philip Kaludercic

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