From 79880d8d09f8d205e1e69afafb5ac16516dd115b Mon Sep 17 00:00:00 2001 From: Danyiel Colin Date: Sun, 30 Nov 2025 01:40:59 -0600 Subject: [PATCH] feat: add TOON parser support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add tree-sitter grammar for TOON (Token-Oriented Object Notation), a JSON-alternative data format with indentation-based structure. - Add parser config in parsers.lua - Add query files: highlights, folds, indents, locals Parser repository: https://github.com/DanEscher98/tree-sitter-toon TOON spec: https://github.com/toon-format/spec 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- lua/nvim-treesitter/parsers.lua | 9 ++++ queries/toon/folds.scm | 17 +++++++ queries/toon/highlights.scm | 90 +++++++++++++++++++++++++++++++++ queries/toon/indents.scm | 23 +++++++++ queries/toon/locals.scm | 15 ++++++ 5 files changed, 154 insertions(+) create mode 100644 queries/toon/folds.scm create mode 100644 queries/toon/highlights.scm create mode 100644 queries/toon/indents.scm create mode 100644 queries/toon/locals.scm diff --git a/lua/nvim-treesitter/parsers.lua b/lua/nvim-treesitter/parsers.lua index 31b691209..d4f477dc7 100644 --- a/lua/nvim-treesitter/parsers.lua +++ b/lua/nvim-treesitter/parsers.lua @@ -2434,6 +2434,15 @@ list.toml = { maintainers = { "@tk-shirasaka" }, } +list.toon = { + install_info = { + url = "https://github.com/DanEscher98/tree-sitter-toon", + files = { "src/parser.c", "src/scanner.c" }, + branch = "main", + }, + maintainers = { "@DanEscher98" }, +} + list.tsv = { install_info = { url = "https://github.com/amaanq/tree-sitter-csv", diff --git a/queries/toon/folds.scm b/queries/toon/folds.scm new file mode 100644 index 000000000..128b2ec3c --- /dev/null +++ b/queries/toon/folds.scm @@ -0,0 +1,17 @@ +; folds.scm - Folding queries for TOON +; Allows collapsing nested structures in editors +; Fold objects (nested key-value structures) +(pair + value: (object)) @fold + +; Fold array declarations with content +(array_declaration + content: (array_content)) @fold + +; Fold root arrays with content +(root_array + content: (array_content)) @fold + +; Fold list items with nested objects +(list_item + (object)) @fold diff --git a/queries/toon/highlights.scm b/queries/toon/highlights.scm new file mode 100644 index 000000000..adb30607c --- /dev/null +++ b/queries/toon/highlights.scm @@ -0,0 +1,90 @@ +; highlights.scm - Syntax highlighting queries for TOON +; Maps grammar nodes to standard Neovim highlight capture groups +; Reference: https://github.com/nvim-treesitter/nvim-treesitter/blob/master/CONTRIBUTING.md +; Literals +; -------- +(null) @constant.builtin + +(true) @boolean + +(false) @boolean + +(number) @number + +(integer) @number + +; Strings +(quoted_string) @string + +(unquoted_string) @string + +(escape_sequence) @string.escape + +; Properties/Keys +; --------------- +; Object keys +(pair + key: (key + (identifier) @property)) + +(pair + key: (key + (dotted_key + (identifier) @property))) + +(pair + key: (key + (quoted_string) @property)) + +; Array declaration keys +(array_declaration + key: (key + (identifier) @property)) + +(array_declaration + key: (key + (dotted_key + (identifier) @property))) + +; Field names in tabular arrays +(field_name + (identifier) @property) + +(field_name + (quoted_string) @property) + +; List item keys (objects as list items) +(list_item + key: (key + (identifier) @property)) + +; Punctuation +; ----------- +; Delimiters +":" @punctuation.delimiter + +"," @punctuation.delimiter + +"|" @punctuation.delimiter + +"." @punctuation.delimiter + +(delimiter) @punctuation.delimiter + +(field_delimiter) @punctuation.delimiter + +(delimiter_marker) @punctuation.delimiter + +; Brackets +"[" @punctuation.bracket + +"]" @punctuation.bracket + +"{" @punctuation.bracket + +"}" @punctuation.bracket + +; Special +"\"" @punctuation.special + +(list_marker) @punctuation.special diff --git a/queries/toon/indents.scm b/queries/toon/indents.scm new file mode 100644 index 000000000..f0005837f --- /dev/null +++ b/queries/toon/indents.scm @@ -0,0 +1,23 @@ +; indents.scm - Indentation queries for TOON +; Guides automatic indentation in editors +; Indent after opening a nested object +(pair + value: (object) @indent.begin) + +; Indent after array declaration with content +(array_declaration + content: (array_content) @indent.begin) + +; Indent after root array with content +(root_array + content: (array_content) @indent.begin) + +; Indent inside list items with nested content +(list_item + (object) @indent.begin) + +; Dedent at end of objects/arrays (handled by external scanner) +; These markers indicate where indentation should decrease +(object) @indent.end + +(array_content) @indent.end diff --git a/queries/toon/locals.scm b/queries/toon/locals.scm new file mode 100644 index 000000000..b89cd0a13 --- /dev/null +++ b/queries/toon/locals.scm @@ -0,0 +1,15 @@ +; locals.scm - Local scope and reference queries for TOON +; Used for features like go-to-definition, scope highlighting +; Each object creates a new scope +(object) @local.scope + +; Keys define local names within their scope +(pair + key: (key) @local.definition) + +; Array declarations define names +(array_declaration + key: (key) @local.definition) + +; Field names in tabular arrays are definitions +(field_name) @local.definition