From 6fffaf6a7ded9a12fb2d5715a4eb83787a5e6402 Mon Sep 17 00:00:00 2001 From: evie <50974538+mi2ebi@users.noreply.github.com> Date: Sat, 4 Oct 2025 12:22:28 -0700 Subject: [PATCH] add highlighting for nearley (#14482) --- book/src/generated/lang-support.md | 1 + languages.toml | 11 +++++++ runtime/queries/nearley/highlights.scm | 43 ++++++++++++++++++++++++++ runtime/queries/nearley/injections.scm | 2 ++ runtime/queries/nearley/rainbows.scm | 3 ++ 5 files changed, 60 insertions(+) create mode 100644 runtime/queries/nearley/highlights.scm create mode 100644 runtime/queries/nearley/injections.scm create mode 100644 runtime/queries/nearley/rainbows.scm diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index 8fa9aed27..67cd39c14 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -174,6 +174,7 @@ | move | ✓ | | | | | | | msbuild | ✓ | | ✓ | | | | | nasm | ✓ | ✓ | | | | `asm-lsp` | +| nearley | ✓ | | | | ✓ | | | nestedtext | ✓ | ✓ | ✓ | | | | | nginx | ✓ | | | | | | | nickel | ✓ | | ✓ | | | `nls` | diff --git a/languages.toml b/languages.toml index f46e8c43c..1ebd15aca 100644 --- a/languages.toml +++ b/languages.toml @@ -4876,3 +4876,14 @@ indent = { tab-width = 2, unit = " " } [[grammar]] name = "slisp" source = { git = "https://github.com/xenogenics/tree-sitter-slisp", rev = "29f9c6707ce9dfc2fc915d175ec720b207f179f3" } + +[[language]] +name = "nearley" +scope = "source.nearley" +file-types = ["ne"] +comment-token = "#" +indent = { tab-width = 2, unit = " " } + +[[grammar]] +name = "nearley" +source = { git = "https://github.com/mi2ebi/tree-sitter-nearley", rev = "12d01113e194c8e83f6341aab8c2a5f21db9cac9" } diff --git a/runtime/queries/nearley/highlights.scm b/runtime/queries/nearley/highlights.scm new file mode 100644 index 000000000..7cc0b6e42 --- /dev/null +++ b/runtime/queries/nearley/highlights.scm @@ -0,0 +1,43 @@ + +(comment) @comment.line + +(string) @string +(string "i" @keyword.modifier) + +(identifier) @variable.other +(rule_name (identifier) @function) +(rule (generic (identifier) @function)) + +(directive_name) @keyword.directive +(directive_value (identifier) @constant) +(directive_value (string) @string) + +(token) @constant + +(generic + "<" @punctuation.bracket + (identifier) @type.parameter + ">" @punctuation.bracket +) + +(group "(" @punctuation.bracket ")" @punctuation.bracket) + +(charset) @string.regexp +(wildcard) @keyword + +(quantifier) @function.builtin + +(macro_name + "[" @punctuation.bracket + (identifier) @variable.parameter + "]" @punctuation.bracket +) +(macro_arg) @variable.parameter + +(rule "->" @operator) +(rule_body "|" @operator) + +(cont_block "@{%" @keyword.directive "%}" @keyword.directive) +(cont_inline "{%" @keyword.directive "%}" @keyword.directive) + +(ifdef) @keyword.directive diff --git a/runtime/queries/nearley/injections.scm b/runtime/queries/nearley/injections.scm new file mode 100644 index 000000000..d81683049 --- /dev/null +++ b/runtime/queries/nearley/injections.scm @@ -0,0 +1,2 @@ +((cont) @injection.content + (#set! injection.language "javascript")) diff --git a/runtime/queries/nearley/rainbows.scm b/runtime/queries/nearley/rainbows.scm new file mode 100644 index 000000000..5de4f8e18 --- /dev/null +++ b/runtime/queries/nearley/rainbows.scm @@ -0,0 +1,3 @@ +((group) @rainbow.scope) + +["(" ")"] @rainbow.bracket