Questions tagged [smie]

SMIE (Simple Minded Indentation Engine) is a package that provides a generic navigation and indentation engine. Based on a very simple parser using an “operator precedence grammar”, it lets major modes extend the sexp-based navigation of Lisp to non-Lisp languages as well as provide a simple to use but reliable auto-indentation.

SMIE is a package that provides a generic navigation and indentation engine. Based on a very simple parser using an “operator precedence grammar”, it lets major modes extend the sexp-based navigation of Lisp to non-Lisp languages as well as provide a simple to use but reliable auto-indentation.


Operator precedence grammar is a very primitive technology for parsing compared to some of the more common techniques used in compilers. It has the following characteristics: its parsing power is very limited, and it is largely unable to detect syntax errors, but it has the advantage of being algorithmically efficient and able to parse forward just as well as backward. In practice that means that SMIE can use it for indentation based on backward parsing, that it can provide both forward-sexp and backward-sexp functionality, and that it will naturally work on syntactically incorrect code without any extra effort. The downside is that it also means that most programming languages cannot be parsed correctly using SMIE, at least not without resorting to some special tricks (see SMIE Tricks).

For more information, please see Simple Minded Indentation Engine on the online GNU Emacs manual.

16 questions
23
votes
3 answers

Is there any SMIE documentation that is clear?

I've spent many, many hours now trying to get any sort of SMIE indentation rule/grammar/thing working. Are there any examples of a small, toy or skeleton SMIE-based mode with documentation on how it actually works, or any discussion anywhere about…
Nagora
  • 373
  • 1
  • 9
7
votes
1 answer

what are the options to write a language grammar for a new major mode?

I am writing a major mode for a programming language that has a well-defined grammar: it has a BNF, formalised in some happy files. I don't particularly want to re-implement the BNF as a series of forward / backward regex scans (as many major modes…
fommil
  • 1,750
  • 11
  • 24
7
votes
2 answers

Do not align nested calls when using ruby-smie

When using the newly added ruby formatting functionality I face the following problem: I would really like for my rspec code to be formatted like the following: it do is_expected.to match(/\[Error\]/) .and match(/#{result}/) .and…
Renan Ranelli
  • 1,379
  • 10
  • 17
7
votes
1 answer

Parsing parentheses: smie vs syntax table

I am maintaining a mode for a programming language with... let's say "annoying" syntax constructs. For example, the angle brackets (no idea if it is the correct word) < and > are parentheses. However, the word -> is also a valid token, does not…
T. Verron
  • 4,233
  • 1
  • 22
  • 55
7
votes
0 answers

How do I parse a simple grammar and obtain a syntax tree in Emacs lisp?

How can I construct a parse tree from a string and a simple grammar? Semantic seems very tricky, and SMIE does not seem to produce a parse tree. Here's an example, assuming a language that looks like this: BLAH [ FOO "aaa"; "bbb" | BAR [ "ccc" |…
Clément
  • 3,924
  • 1
  • 22
  • 37
5
votes
1 answer

Some warnings and unexpected indentation with SMIE

I'm trying SMIE to describe the Nix language. Unfortunately when I use it, I have the following problems: There are 4 messages saying: Warning (smie): token } is both closer and neither. Which I do not understand. A message asks you for a comment…
Damien Cassou
  • 877
  • 4
  • 14
3
votes
2 answers

SMIE Basic Identation and Block Example

I've tried for a while to create a simple major mode that uses SMIE to perform navigation and indentation, but it seems like even the simple examples that I've found seems to break quite easily. The mode I'm trying to create consist of semi-colon…
Xaldew
  • 1,181
  • 9
  • 20
3
votes
0 answers

SMIE default syntax : First level of indentation

When you only do that in your major mode : (require 'smie) (smie-setup nil #'ignore) That means SMIE but no grammar, and no rules. And it's great. It makes the point stay on col0 when you TAB and there's nothing on the line, it makes indentation…
yPhil
  • 963
  • 5
  • 22
3
votes
1 answer

How to control line-continuation using SMIE?

I'm trying to implement qmake-mode using SMIE(https://www.gnu.org/software/emacs/manual/html_node/elisp/SMIE.html), but I have no idea how to control indent width in line-continuation. Block indentation works(yes, I stole block indentation from…
Chan
  • 33
  • 3
2
votes
1 answer

Using SMIE for language without comment syntax

I'm making a major mode for json (which has no comments), and using SMIE for 'free' indenting. I've currently got a half-baked grammar called json-grammar, and no rules-function. Consequently, I'm invoking smie-setup as (smie-setup json-grammar…
Squidly
  • 1,499
  • 14
  • 17
1
vote
0 answers

How does SMIE mode determine what the parent of a token is?

I'm writing indentation rules for a custom mode using SMIE. I want to use smie-rule-parent-p to have different behavior for indenting an empty line depending on context, so inside my indentation rules function, I have a case like this: (`(:elem .…
Tikhon Jelvis
  • 6,152
  • 2
  • 27
  • 40
1
vote
1 answer

How can I get SMIE to not treat keywords as parentheses?

I'm writing an SMIE-based mode for a language that has type definitions that look like this: type Foo = { foo : Int, bar : String } One problem I'm running into is that type and = are treated as parentheses. For example, if I put the cursor on…
Tikhon Jelvis
  • 6,152
  • 2
  • 27
  • 40
1
vote
3 answers

SMIE Indenting Arguments and Blocks

This is closely related to a previous question I asked here: SMIE Basic Identation and Block Example However, it is sufficiently different (and already big enough) that I might as well ask it as a separate question. Those answers may still be useful…
Xaldew
  • 1,181
  • 9
  • 20
0
votes
0 answers

SMIE: defining a build.ninja grammar

I'm trying to write a mode in SMIE, to figure out how it works and to create some documentation. build.ninja (a build system used by Meson and others) is a perfect candidate due to its very simple syntax. So despite there being a ninja-mode, I…
Hi-Angel
  • 525
  • 6
  • 18
0
votes
1 answer

SMIE precedence conflict

(defvar foo-smie-grammar (smie-prec2->grammar (smie-bnf->prec2 '((exp (exp "+" exp) (exp "*" exp) ("let" let-decls "in" exp)) (let-decls (let-decls ";" let-decls) (exp))) '((assoc ";") (assoc…
1
2