{"id":48550071,"url":"https://github.com/wharflab/tree-sitter-batch","last_synced_at":"2026-04-21T13:05:21.337Z","repository":{"id":343585259,"uuid":"1178145873","full_name":"wharflab/tree-sitter-batch","owner":"wharflab","description":"Tree-sitter grammar for Windows Batch / CMD scripts (.bat, .cmd).","archived":false,"fork":false,"pushed_at":"2026-04-02T01:07:18.000Z","size":227,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-02T09:05:48.360Z","etag":null,"topics":["batch","batch-script","cmd","grammar","parser","tree-sitter","windows"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wharflab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-03-10T18:26:30.000Z","updated_at":"2026-04-02T01:06:53.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/wharflab/tree-sitter-batch","commit_stats":null,"previous_names":["wharflab/tree-sitter-batch"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/wharflab/tree-sitter-batch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wharflab%2Ftree-sitter-batch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wharflab%2Ftree-sitter-batch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wharflab%2Ftree-sitter-batch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wharflab%2Ftree-sitter-batch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wharflab","download_url":"https://codeload.github.com/wharflab/tree-sitter-batch/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wharflab%2Ftree-sitter-batch/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31545909,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-07T16:28:08.000Z","status":"online","status_checked_at":"2026-04-08T02:00:06.127Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["batch","batch-script","cmd","grammar","parser","tree-sitter","windows"],"created_at":"2026-04-08T08:03:49.231Z","updated_at":"2026-04-21T13:05:21.321Z","avatar_url":"https://github.com/wharflab.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tree-sitter-batch\n\nWindows Batch/CMD grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter).\n\nParses `.bat` and `.cmd` files into a concrete syntax tree for syntax highlighting, code navigation, and analysis.\n\n## Features\n\n- **Control flow** \u0026mdash; `IF`/`ELSE` (EXIST, DEFINED, ERRORLEVEL, comparison with NOT), `FOR` (/D /R /L /F), `GOTO`, `CALL`, `EXIT /B`\n- **Variables** \u0026mdash; `SET` (plain, `/A` arithmetic, `/P` prompt, display-only without `=`), `%VAR%`, `!VAR!`, `%%i`, `%~dp0`, `%VAR:old=new%`, subscripted delayed expansion `!ARR[%%i]!`, for-variable modifiers `%%~dpnxf` `%%~zS` `%%~$PATH:F`, escaped forms `%%VAR%%` `%%%%i`\n- **Echo** \u0026mdash; free-form text with literal `(` `)` `!` `%`, inline strings, and variable references\n- **Operators** \u0026mdash; pipes `|`, redirects `\u003e` `\u003e\u003e` `\u003c` `2\u003e` `2\u003e\u00261` (fds 0-9, including variable handles `\u003e\u0026%FD%` / `\u003c\u0026%FD%`), conditional `\u0026\u0026` `||`, separator `\u0026`\n- **Line continuation** \u0026mdash; trailing caret `^` joins the current line with the next (e.g. `\"%JAVACMD%\" ^` followed by indented arguments)\n- **Commands** \u0026mdash; bare names, variable references as command, and quoted paths (`\"C:\\path\\app.exe\" args`, `call \"%SCRIPT%\" %*`)\n- **Structure** \u0026mdash; labels `:name`, comments `REM` `::`, parenthesized blocks (including `@(...)`), `@ECHO OFF`, macro invocations, DosTips idioms `(call,)` / `(call;)` / `(call)` for ERRORLEVEL manipulation\n- **Scope** \u0026mdash; `SETLOCAL`/`ENDLOCAL` with `ENABLEDELAYEDEXPANSION`\n- **Polyglot headers** \u0026mdash; tolerates batch/PowerShell `\u003c# ... #\u003e` header lines and batch/VBScript lines marked with a trailing `'VBS` so SysToolsLib-style dual-language scripts parse cleanly\n- **Case-insensitive** \u0026mdash; all keywords match regardless of casing\n\n## Example\n\n```batch\n@echo off\nREM Build script\nsetlocal enabledelayedexpansion\n\nset \"PROJECT=MyApp\"\nset /a VERSION=1\n\nif not exist \"dist\" (\n  mkdir dist\n)\n\nfor %%f in (src\\*.txt) do (\n  copy \"%%f\" \"dist\\\"\n)\n\nif %ERRORLEVEL% == 0 (\n  echo Build successful\n) else (\n  echo Build failed\n  exit /b 1\n)\n\nexit /b 0\n```\n\nParsed tree:\n\n```\n(program\n  (echo_off)\n  (comment)\n  (setlocal_stmt)\n  (variable_assignment\n    (set_keyword) (variable_name) (assignment_value))\n  (variable_assignment\n    (set_keyword) (arithmetic_assignment (set_option) (arithmetic_expression)))\n  (if_stmt\n    (string)\n    (parenthesized\n      (cmd (command_name) (argument_list (argument_value)))))\n  (for_stmt\n    (for_variable)\n    (for_set (for_set_literal))\n    (parenthesized\n      (cmd (command_name) (argument_list (string) (string)))))\n  (if_stmt\n    (variable_reference)\n    (comparison_op)\n    (argument_value)\n    (parenthesized\n      (cmd (command_name) (argument_list (argument_value) (argument_value))))\n    (else_clause\n      (parenthesized\n        (cmd (command_name) (argument_list (argument_value) (argument_value)))\n        (exit_stmt (integer)))))\n  (exit_stmt (integer)))\n```\n\n## Installation\n\n### npm\n\n```sh\nnpm install tree-sitter-batch\n```\n\n### Cargo\n\n```sh\ncargo add tree-sitter-batch\n```\n\n### PyPI\n\n```sh\npip install tree-sitter-batch\n```\n\n### Go\n\n```go\nimport tree_sitter_batch \"github.com/wharflab/tree-sitter-batch/bindings/go\"\n```\n\nThe root package also exports the bundled `queries/highlights.scm` via `go:embed`:\n\n```go\nimport batch \"github.com/wharflab/tree-sitter-batch\"\n\nlang := batch.GetLanguage()\nquery, _ := batch.GetHighlightsQuery()\n// or access the raw .scm source:\n// raw := batch.HighlightsQuery\n```\n\n## Usage\n\n### Node.js\n\n```javascript\nimport Parser from \"tree-sitter\";\nimport Batch from \"tree-sitter-batch\";\n\nconst parser = new Parser();\nparser.setLanguage(Batch);\n\nconst tree = parser.parse(`@echo off\\necho Hello World\\n`);\nconsole.log(tree.rootNode.toString());\n```\n\n### Rust\n\n```rust\nlet mut parser = tree_sitter::Parser::new();\nlet language = tree_sitter_batch::LANGUAGE;\nparser.set_language(\u0026language.into()).unwrap();\n\nlet tree = parser.parse(\"@echo off\\necho Hello\\n\", None).unwrap();\nprintln!(\"{}\", tree.root_node().to_sexp());\n```\n\n### Python\n\n```python\nfrom tree_sitter import Language, Parser\nimport tree_sitter_batch\n\nparser = Parser(Language(tree_sitter_batch.language()))\ntree = parser.parse(b\"@echo off\\necho Hello\\n\")\nprint(tree.root_node.sexp())\n```\n\n## Syntax Highlighting\n\nThe grammar ships with a `queries/highlights.scm` file for use in editors that support tree-sitter highlighting (Neovim, Helix, Zed, etc.).\n\n## References\n\n- Grammar informed by [Blinter](https://github.com/tboy1337/Blinter) batch file linter (159 rules)\n- [SS64 CMD reference](https://ss64.com/nt/)\n- [Microsoft CMD documentation](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/windows-commands)\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwharflab%2Ftree-sitter-batch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwharflab%2Ftree-sitter-batch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwharflab%2Ftree-sitter-batch/lists"}