Skip to content

Latest commit

 

History

History
100 lines (75 loc) · 3.23 KB

File metadata and controls

100 lines (75 loc) · 3.23 KB

tree-sitter-nats-server-conf

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.

Features

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: $VARNAME references
  • Include directives: include ./path/to/file.conf

Quick Start

# 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

Building

# Build the shared library
make

# Install system-wide
sudo make install

Editor Integration

  • 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

Grammar Structure

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... }

Language Bindings

Bindings are available for:

  • Cbindings/c/
  • Gobindings/go/ + go.mod
  • Node.jsbindings/node/
  • Pythonbindings/python/ + pyproject.toml
  • Rustbindings/rust/ + Cargo.toml
  • Swiftbindings/swift/ + Package.swift

Examples

See the examples/ directory for sample configuration files:

  • basic.conf — Simple server setup
  • cluster.conf — Cluster with routes and TLS
  • jetstream.conf — JetStream with accounts
  • full.conf — Comprehensive configuration

License

MIT — see LICENSE.