From 41a59591a534d3b901e6a1039f04d91bf83a356a Mon Sep 17 00:00:00 2001 From: RubixDev Date: Sun, 2 Oct 2022 18:12:30 +0200 Subject: [PATCH] Add ebnf parser --- lua/nvim-treesitter/parsers.lua | 11 +++++++++ queries/ebnf/highlights.scm | 43 +++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 queries/ebnf/highlights.scm diff --git a/lua/nvim-treesitter/parsers.lua b/lua/nvim-treesitter/parsers.lua index 2844e8e38..fff6540e2 100644 --- a/lua/nvim-treesitter/parsers.lua +++ b/lua/nvim-treesitter/parsers.lua @@ -1331,6 +1331,17 @@ list.mermaid = { experimental = true, } +list.ebnf = { + install_info = { + url = "https://github.com/RubixDev/ebnf.git", + files = { "src/parser.c" }, + location = "crates/tree-sitter-ebnf", + branch = "main", + }, + maintainers = { "@RubixDev" }, + experimental = true, +} + local M = { list = list, filetype_to_parsername = filetype_to_parsername, diff --git a/queries/ebnf/highlights.scm b/queries/ebnf/highlights.scm new file mode 100644 index 000000000..416aaab68 --- /dev/null +++ b/queries/ebnf/highlights.scm @@ -0,0 +1,43 @@ +;;;; Simple tokens ;;;; +(terminal) @string.grammar + +(special_sequence) @string.special.grammar + +(integer) @number + +(comment) @comment + +;;;; Identifiers ;;;; + +; Allow different highlighting for specific casings +((identifier) @type + (#match? @type "^[A-Z]")) + +((identifier) @symbol + (#match? @symbol "^[a-z]")) + +((identifier) @constant + (#match? @constant "^[A-Z][A-Z0-9_]+$")) + +;;; Punctuation ;;;; +[ + ";" + "," +] @punctuation.delimiter + +[ + "|" + "*" + "-" +] @operator + +"=" @keyword.operator + +[ + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket