help-gnu-emacs
[Top][All Lists]
Advanced

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

Working around the limitations of SMIE


From: Philip Kaludercic
Subject: Working around the limitations of SMIE
Date: Wed, 09 Nov 2022 21:25:15 +0000

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.



reply via email to

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