From a8b2798322d6be6a063c0fe26209131731c97971 Mon Sep 17 00:00:00 2001 From: FabricSoul Date: Sun, 20 Apr 2025 23:36:06 -0400 Subject: [PATCH] feat(cobweb): add support for cobweb --- README.md | 1 + lua/nvim-treesitter/parsers.lua | 9 ++++ queries/cobweb/highlights.scm | 76 +++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 queries/cobweb/highlights.scm diff --git a/README.md b/README.md index 2cb5f033b..ee6376e37 100644 --- a/README.md +++ b/README.md @@ -201,6 +201,7 @@ We are looking for maintainers to add more parsers and to write query files for - [x] [circom](https://github.com/Decurity/tree-sitter-circom) (maintained by @alexandr-martirosyan) - [x] [clojure](https://github.com/sogaiu/tree-sitter-clojure) (maintained by @NoahTheDuke) - [x] [cmake](https://github.com/uyha/tree-sitter-cmake) (maintained by @uyha) +- [x] [cobweb](https://github.com/FabricSoul/tree-sitter-cobweb) (maintained by @FabricSoul) - [x] [comment](https://github.com/stsewd/tree-sitter-comment) (maintained by @stsewd) - [x] [commonlisp](https://github.com/theHamsta/tree-sitter-commonlisp) (maintained by @theHamsta) - [x] [cooklang](https://github.com/addcninblue/tree-sitter-cooklang) (maintained by @addcninblue) diff --git a/lua/nvim-treesitter/parsers.lua b/lua/nvim-treesitter/parsers.lua index 31b691209..e78f46f6a 100644 --- a/lua/nvim-treesitter/parsers.lua +++ b/lua/nvim-treesitter/parsers.lua @@ -297,6 +297,15 @@ list.cmake = { maintainers = { "@uyha" }, } +list.cobweb = { + install_info = { + url = "https://github.com/FabricSoul/tree-sitter-cobweb", + files = { "src/parser.c" }, + }, + maintainers = { "@FabricSoul" }, +} + + list.comment = { install_info = { url = "https://github.com/stsewd/tree-sitter-comment", diff --git a/queries/cobweb/highlights.scm b/queries/cobweb/highlights.scm new file mode 100644 index 000000000..cc80f812d --- /dev/null +++ b/queries/cobweb/highlights.scm @@ -0,0 +1,76 @@ +; tree-sitter-cobweb/queries/highlights.scm + +; === Comments === +(line_comment) @comment +(block_comment) @comment + +; === Sections === +(section_header) @keyword.control.import ; #manifest, #import, #defs, #commands, #scenes + +; === Keywords === +(keyword) @keyword ; 'as' + +; === Literals === +(string_literal) @string +(escape_sequence) @string.escape +(line_continuation) @string.escape +(number_literal) @constant.numeric +(hex_literal) @constant.numeric ; Often highlighted like numbers or colors + +; === Builtin Constants === +(language_constant) @constant.builtin ; auto, inf, nan + +; === Definitions (#defs section) === +(definition name: (constant_identifier) @variable.constant) +(definition "=" @operator) + +; === Constants Usage === +(constant_usage "$" @constant) ; Highlight the '$' itself +; Highlight all identifiers within the path field of a constant usage +(constant_usage path: (identifier) @constant) +; The PATH_SEPARATOR is captured globally below + +; === Manifest & Import Sections === +(manifest_entry path: (string_literal) @string.special.path) ; Highlight file paths +(manifest_entry alias: (identifier) @variable.alias) +(import_entry source: (identifier) @variable.module) ; Imported manifest key +(import_entry alias: (identifier) @variable.alias) + +; === Scenes Section === +(scene_definition name: (string_literal) @label) ; Scene names +(named_element name: (string_literal) @label) ; Nested element names like "cell" + +; === Loadables & Types === +; General Types +(type_identifier) @type ; Default for uppercase identifiers + +; Specific Loadable Types +(struct_loadable type: (type_identifier) @type) +(tuple_loadable type: (type_identifier) @type) +(simple_loadable type: (type_identifier) @type) ; e.g., MainInterface +(generic_loadable type: (type_identifier) @type) ; e.g., Animated +(generic_loadable generic_type: (type_identifier) @type.generic) ; e.g., BackgroundColor inside <> + +; Type Identifiers used as Values (Enum Variants) +((field value: (type_identifier)) @constant.builtin.enum) ; e.g., Column in flex_direction:Column + +; === Fields === +(field name: (identifier) @property) ; Field names like 'color', 'text' +(field ":" @punctuation.delimiter) + +; === Punctuation === +"{" @punctuation.bracket +"}" @punctuation.bracket +"(" @punctuation.bracket +")" @punctuation.bracket +"<" @punctuation.bracket +">" @punctuation.bracket +":" @punctuation.delimiter ; Already captured in field, but maybe useful standalone if it occurs elsewhere +"=" @operator ; Already captured in definition +(PATH_SEPARATOR) @punctuation.delimiter ; Highlight '::' globally using the aliased node name + +; === Fallback (Optional) === +; (identifier) @variable ; Generic lowercase identifiers (might catch aliases/module names if not specifically captured) + +; === Errors (Optional but Recommended) === +; (ERROR) @error