A tree-sitter grammar for NATS server configuration files.
Provides syntax highlighting, code folding, indentation, and structural navigation for .conf files used by nats-server.
The grammar handles the full NATS server configuration format:
- Comments:
#and//line comments - Key-value pairs: with
=or:separators - Blocks:
cluster { },jetstream { },tls { }, etc. - Nested blocks: arbitrary nesting depth
- Arrays:
[value1, value2]with commas or newlines - Strings: quoted
"..."with escape sequences, and unquoted bare strings (URLs, paths, IP addresses) - Numbers: integers, floats, with size suffixes (
KB,MB,GB,TB) and duration suffixes (ns,us,ms,s,m,h,d) - Booleans:
true/false,yes/no,on/off(case insensitive) - Variables:
$VARNAMEreferences - Include directives:
include ./path/to/file.conf
# Install dependencies
npm install
# This is more reliable than the npm approach, so we've split it out.
# Assumes that you have rust/cargo installed and ~/.cargo/bin in $PATH already.
command -v tree-sitter || cargo install tree-sitter-cli
# Generate the parser
tree-sitter generate
# Run tests
tree-sitter test
# Parse a file
tree-sitter parse examples/basic.conf# Build the shared library
make
# Install system-wide
sudo make install- Neovim — nvim-treesitter setup with highlighting, folding, and indentation
- Helix — languages.toml configuration and query installation
- VS Code — Extension setup with TextMate grammar fallback
- Emacs — Built-in treesit (29+) and emacs-tree-sitter setup
- Zed — Extension with tree-sitter grammar and query files
- Nova — Panic Nova extension with syntax definition
source_file
├── comment # or // line comments
├── include_directive include <path>
├── pair key = value or key: value
│ ├── key identifier
│ └── value
│ ├── string "quoted" or bare/unquoted
│ ├── number 42, 3.14, 1GB, 30s
│ ├── boolean true/false/yes/no/on/off
│ ├── variable_reference $VARNAME
│ └── array [...]
└── block_definition name { ... }
└── block { statements... }
Bindings are available for:
- C —
bindings/c/ - Go —
bindings/go/+go.mod - Node.js —
bindings/node/ - Python —
bindings/python/+pyproject.toml - Rust —
bindings/rust/+Cargo.toml - Swift —
bindings/swift/+Package.swift
See the examples/ directory for sample configuration files:
basic.conf— Simple server setupcluster.conf— Cluster with routes and TLSjetstream.conf— JetStream with accountsfull.conf— Comprehensive configuration
MIT — see LICENSE.