7

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 do), although I would not be opposed to translating it either manually or automatically.

I am aware of SMIE, are there any other options available to me in Emacs lisp that allow me to define the grammar of the language and have as much automatically generated as possible, e.g. faces, sexp commands, imenu population.

I am concerned primarily with simplicity and correctness of the mode, rather than its raw performance, but I'd certainly like to have a rough idea of what the trade-offs are (obviously if the performance is too low it'd be unusable and therefore not appropriate to use).

This is somewhat related to Writing a Major Mode although further advanced, as I am already aware of everything under "Major Modes" in the Emacs Lisp manual.

UPDATE: I have studied and spoken with the author of Semantic and it isn't able to generate the font-locks, it's more aiming to provide higher level tools and it's not something I am looking for.

7
  • 1
    I'd go for CEDET/Wisent, but I haven't done it myself. See cedet.sourceforge.net/addlang.shtml Oct 25, 2018 at 10:54
  • CEDET looked fairly unmaintained to me, but the parser sounded cool.
    – fommil
    Oct 25, 2018 at 11:23
  • 1
    It seem like at least the parser part of CEDET is now part of Emacs. See gnu.org/software/emacs/manual/html_node/semantic/index.html#Top Oct 25, 2018 at 12:28
  • 2
    CEDET is part of Emacs, but that does not mean it's maintained, see Bug#23792.
    – npostavs
    Oct 25, 2018 at 13:16
  • I've now read the semantic / wisent manual(s) cover to cover and I don't think it helps me avoid writing a font-locking or indenting engine. The lexer still depends on syntax tables. It has a lot of high level features that I'm not interested in (I don't believe they will work or scale satisfactorily for my language), but there seems to be a gap in the low level stuff. Am I missing something? @StefanKamphausen
    – fommil
    Oct 27, 2018 at 17:04

1 Answer 1

4

Besides the SMIE package (which can indeed use a BNF grammar, but will usually not work well with a BNF grammar that was designed for the usual LALR-style parser), there's the wisi package available from GNU ELPA (http://elpa.gnu.org/packages/wisi.html):

The wisi package provides utilities for using generalized LALR parsers to do indentation, fontification, and navigation. See ada-mode for an example of its use.

I have no experience with it and don't know of any package other than ada-mode using it, but ada-mode is quite featureful, so it's worth taking a look. Also I'd expect its author would be happy to help you make use of it.

1
  • this looks kinda cool, although it is very tied up with ada-mode and I'm not sure how generalisable it is. One concern I'd voice is that the underlying parser, wisent, from Semantic, often does full file parsing rather than localised, and is not particularly robust to syntax errors, so it may introduce a huge perf regression. I guess one would need a proof of concept to see, as there are no definite answers.
    – fommil
    Oct 27, 2018 at 21:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.