A GNU Emacs major mode for editing BNF grammars.
“Precise language is not the problem. Clear language is the problem.”
Richard Feynman
Currently provides basic syntax and font-locking for BNF files. BNF notation is supported exactly form as it was first announced in the ALGOL 60 report. EBNF and ABNF are not supported but in my plans for the near future.
When developing this mode, the following documents were taken into account:
- Revised Report on the Algorithmic Language Algol 60
- RFC822: Standard for ARPA Internet Text Messages
- RFC5234: Augmented BNF for Syntax Specifications: ABNF
- RFC7405: Case-Sensitive String Support in ABNF
- Basic syntax definition
- Syntax highlighting
Known to work with GNU Emacs 24.3 and later. BNF Mode may work with older versions of Emacs, or with other flavors of Emacs (e.g. XEmacs) but this is not guaranteed. Bug reports for problems related to using BNF Mode with older versions of Emacs will most like not be addressed.
The master of all the material is the Git repository at https://github.com/sergeyklay/bnf-mode .
NOTE: The master
branch will always contain the latest unstable version.
If you wish to check older versions or formal, tagged release, please switch
to the relevant tag.
The best way of installing this major mode, at least for GNU Emacs 24, is to use the packaging system. Add MELPA or MELPA Stable to the list of repositories to access this mode. For those who want only formal, tagged releases use MELPA Stable:
(require 'package)
(add-to-list 'package-archives
'("melpa-stable" . "https://stable.melpa.org/packages/") t)
(package-initialize)
For those who want rolling releases as they happen use MELPA:
(require 'package)
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/") t)
(package-initialize)
and then use M-x package-refresh-contents
and M-x package-list-packages
to get to
the package listing and install bnf-mode
from there. MELPA tracks this Git repository
and updates relatively soon after each commit or formal release. For more detail on
setting up see MELPA Getting Started.
You can install bnf-mode
manually by adding following to your init file:
(unless (package-installed-p 'bnf-mode)
(package-refresh-contents)
(package-install 'bnf-mode))
Add following to your Cask file:
(source melpa)
(depends-on "bnf-mode")
Add following to your init file:
(use-package bnf-mode
:ensure t
:mode "\\.bnf\\'")
If you use el-get, just create a recipe file bnf.rcp
:
(:name bnf-mode
:website "https://github.com/sergeyklay/bnf-mode"
:description "BNF Mode: A major mode for editing BNF grammars"
:type github
:pkgname "sergeyklay/bnf-mode")
and add it to a directory present in el-get-recipe-path
.
Then, use M-x el-get-install <RET> bnf-mode
or add:
(el-get-bundle bnf-mode)
to your init file.
- Download
bnf-mode.el
- Put the file in your Elisp common folder like
$HOME/.emacs.d/lisp/
- Then you can include like this:
(add-to-list 'load-path (expand-file-name "lisp" user-emacs-directory))
- Add either of the two following lines to your initialization file.
The first only loads BNF Mode when necessary, the 2nd always during startup
of GNU Emacs.
(autoload 'bnf-mode "bnf-mode" nil t) ;; OR (require 'bnf-mode)
- Optionally byte compile
bnf-mode.el
for faster startup:M-x byte-compile
Command (For the M-x prompt.) | Description |
---|---|
bnf-mode | Switches to BNF Mode. |
Any file that matches the glob *.bnf
is automatically opened in bnf-mode
.
Feel free to ask question or make suggestions in our issue tracker .
To see what has changed in recent versions of BNF Mode, see the CHANGELOG.org .
- Wikipedia: Backus–Naur form
- Wikipedia: Extended Backus–Naur form
- Wikipedia: Augmented Backus–Naur form
- ISO/IEC 14977: EBNF
- EBNF: A Notation to Describe Syntax
BNF Mode is open source software licensed under the GNU General Public Licence version 3 .