Crates.io | tree-sitter-ebnf |
lib.rs | tree-sitter-ebnf |
version | 0.1.0 |
source | src |
created_at | 2022-10-21 14:38:53.948281 |
updated_at | 2022-10-21 14:38:53.948281 |
description | EBNF grammar for the tree-sitter parsing library |
homepage | |
repository | https://github.com/RubixDev/ebnf |
max_upload_size | |
id | 693662 |
size | 49,334 |
EBNF grammar for tree-sitter
This parser implements the EBNF syntax as described by the ISO/IEC 14977:1996 standard with two notable differences:
_
in meta-identifiersThe nvim-treesitter plugin
does not include this parser
currently. To
use it you must instead manually add it to your tree-sitter config and then
install it with :TSInstall ebnf
or by adding it to your ensure_installed
list:
require('nvim-treesitter.parsers').get_parser_configs().ebnf = {
install_info = {
url = 'https://github.com/RubixDev/ebnf.git',
files = { 'src/parser.c' },
location = 'crates/tree-sitter-ebnf',
branch = 'main',
},
}
You will likely also have to add the ebnf
file type:
vim.filetype.add { extension = { ebnf = 'ebnf' } }
If you want to use this parser for highlighting, you will also have to add the
contents of queries/highlights.scm
to a file
called queries/ebnf/highlights.scm
in your Neovim runtime path (see
:help rtp
). I also recommend customizing these highlights:
@string.grammar
: terminal symbols enclosed with '
or "
, falls back to
@string
@string.special.grammar
: special sequences enclosed with ?
, falls back to
@string.special
@variable.grammar
: non-terminal symbols, i.e., identifiers, falls back to
@variable
@variable.grammar.pascal
: non-terminal symbols in PascalCase@variable.grammar.camel
: non-terminal symbols in camelCase@variable.grammar.upper
: non-terminal symbols in UPPERCASE@variable.grammar.lower
: non-terminal symbols in lowercaseAs an example, here is my personal configuration:
vim.api.nvim_set_hl(0, '@string.special.grammar', { link = '@string.regex' })
vim.api.nvim_set_hl(0, '@variable.grammar.pascal', { link = '@type' })
vim.api.nvim_set_hl(0, '@variable.grammar.camel', { link = '@property' })
vim.api.nvim_set_hl(0, '@variable.grammar.upper', { link = '@constant' })
vim.api.nvim_set_hl(0, '@variable.grammar.lower', { link = '@parameter' })