From fead45db00f9503e7b3b0dbb1a797f7f88041b5f Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Sat, 4 Jul 2026 16:20:40 -0400 Subject: [PATCH] Add language support for Batch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Kristoffer Plagborg Bak Sørensen <57013304+kpbaks@users.noreply.github.com> --- book/src/generated/lang-support.md | 1 + languages.toml | 13 +++++++ runtime/queries/batch/highlights.scm | 53 +++++++++++++++++++++++++++ runtime/queries/batch/indents.scm | 8 ++++ runtime/queries/batch/injections.scm | 11 ++++++ runtime/queries/batch/rainbows.scm | 9 +++++ runtime/queries/batch/tags.scm | 6 +++ runtime/queries/batch/textobjects.scm | 4 ++ 8 files changed, 105 insertions(+) create mode 100644 runtime/queries/batch/highlights.scm create mode 100644 runtime/queries/batch/indents.scm create mode 100644 runtime/queries/batch/injections.scm create mode 100644 runtime/queries/batch/rainbows.scm create mode 100644 runtime/queries/batch/tags.scm create mode 100644 runtime/queries/batch/textobjects.scm diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index 9c478cc0..2969ec8b 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -10,6 +10,7 @@ | bash | ✓ | ✓ | ✓ | ✓ | ✓ | `bash-language-server` | | basic | ✓ | ✓ | ✓ | ✓ | | | | bass | ✓ | | | | | `bass` | +| batch | ✓ | ✓ | ✓ | ✓ | ✓ | | | beancount | ✓ | | | | | `beancount-language-server` | | bibtex | ✓ | | | | | `texlab` | | bicep | ✓ | | | | | `bicep-langserver` | diff --git a/languages.toml b/languages.toml index d8b54f33..d0e6d589 100644 --- a/languages.toml +++ b/languages.toml @@ -5635,3 +5635,16 @@ language-servers = [ "mm-lsp-server" ] [[grammar]] name = "metamath" source = { git = "https://git.sr.ht/~m4dh0rs3/tree-sitter-metamath", rev = "d6a57b0ddb4feba4a88f8cbb2f497b718e0c5c1d" } + +[[language]] +name = "batch" +scope = "source.batch" +injection-regex = "(cmd|bat(ch)?)" +file-types = ["bat", "cmd", "btm"] +indent = { tab-width = 2, unit = " " } +comment-tokens = ["REM", "::"] + +[[grammar]] +name = "batch" +source = { git = "https://github.com/wharflab/tree-sitter-batch", rev = "5fc5f54267ef9a78e7a5319b80e092194252aabf" } + diff --git a/runtime/queries/batch/highlights.scm b/runtime/queries/batch/highlights.scm new file mode 100644 index 00000000..57b521da --- /dev/null +++ b/runtime/queries/batch/highlights.scm @@ -0,0 +1,53 @@ +(echo_off) @keyword +(comment) @comment +(label) @label + +(set_keyword) @keyword +(variable_name) @variable +(set_option) @constant +(assignment_literal) @string +(arithmetic_expression) @string + +; IF/FOR/GOTO/CALL statements +(if_stmt) @keyword.control.conditional +(for_stmt) @keyword.control.repeat +(goto_stmt) @keyword +(call_stmt) @keyword.function +(setlocal_stmt) @keyword +(endlocal_stmt) @keyword +(exit_stmt) @keyword + +(comparison_op) @operator +(redirect_op) @operator +(fd_redirect) @operator + +(command_name) @function + +; CMD pseudo/dynamic environment variables +((variable_reference) @variable.builtin + (#match? @variable.builtin "(?i)^[%!](CD|ERRORLEVEL|DATE|TIME|RANDOM|CMDCMDLINE|CMDEXTVERSION|HIGHESTNUMANODENUMBER|__APPDIR__|__CD__)[%!]$")) + +(variable_reference) @variable + +(for_set_literal) @string +(for_variable) @variable.parameter +(for_options) @constant + +(string) @string +(integer) @constant.numeric +(command_option) @constant +(argument_value) @string +(redirect_target) @string.special + +; e.g. `set INSTALL_AS_SERVICE=true` +(variable_assignment + (assignment_value + (assignment_literal) @constant.builtin.boolean) + (#any-of? @constant.builtin.boolean "true" "false" "TRUE" "FALSE" "yes" "no")) + +; e.g. `set PORT_MSGROUTER=10100` +(variable_assignment + (assignment_value + (assignment_literal) @constant.numeric) + (#match? @constant.numeric "^\\d+$")) + diff --git a/runtime/queries/batch/indents.scm b/runtime/queries/batch/indents.scm new file mode 100644 index 00000000..ef7cf75e --- /dev/null +++ b/runtime/queries/batch/indents.scm @@ -0,0 +1,8 @@ +[ + (parenthesized) +] @indent + +[ + ")" +] @outdent + diff --git a/runtime/queries/batch/injections.scm b/runtime/queries/batch/injections.scm new file mode 100644 index 00000000..fd052d60 --- /dev/null +++ b/runtime/queries/batch/injections.scm @@ -0,0 +1,11 @@ +((comment) @injection.content + (#set! injection.language "comment")) + +; e.g. `echo hello123 | findstr /R "[a-z]*[0-9][0-9][0-9]"` +(cmd + (command_name) @_command + (argument_list + (string) @injection.content) + (#eq? @_command "findstr") + (#set! injection.language "regex")) + diff --git a/runtime/queries/batch/rainbows.scm b/runtime/queries/batch/rainbows.scm new file mode 100644 index 00000000..0f8a2d3b --- /dev/null +++ b/runtime/queries/batch/rainbows.scm @@ -0,0 +1,9 @@ +[ + (parenthesized) + (for_stmt) +] @rainbow.scope + +[ + "(" ")" +] @rainbow.bracket + diff --git a/runtime/queries/batch/tags.scm b/runtime/queries/batch/tags.scm new file mode 100644 index 00000000..5659fb6b --- /dev/null +++ b/runtime/queries/batch/tags.scm @@ -0,0 +1,6 @@ +(label) @definition.function + +(variable_assignment + (set_keyword) + (variable_name) @definition.constant) + diff --git a/runtime/queries/batch/textobjects.scm b/runtime/queries/batch/textobjects.scm new file mode 100644 index 00000000..975fd4c5 --- /dev/null +++ b/runtime/queries/batch/textobjects.scm @@ -0,0 +1,4 @@ +(comment) @comment.inside + +(comment)+ @comment.around + -- 2.51.2