Skip to content

Repository files navigation

tree-sitter-sudolang

A Tree-sitter grammar for SudoLang, the pseudolanguage for instructing LLMs.

Status

Version 0.3.2 targets SudoLang v2.2, a strict superset of v2.1. The grammar needs strict block structure and rejects bare prose lines. Write prose as a string literal or as a comment. Identifiers and property names are single words. The grammar reads # Section heading markers at the top level and inside blocks, which drives outline navigation.

Version 2.2 adds:

  • qualified capability names: mcp::linear.getIssue(id)
  • named arguments: f(branch = x)
  • guard statements: cond -> stmt
  • decorators: @retry(3)
  • optional chaining ?. and nullish default ??
  • spread and rest ...
  • the pipe placeholder _

Read examples/issue-to-pr.sudo for a program that uses all of them.

File types

Write SudoLang in markdown with sudo code fences. Use a plain .md file, or use .sudo.md to mark the file as SudoLang content. Markdown documents need tree-sitter-markdown. A ```sudo or ```SudoLang fence injects this grammar into the fence body. A pure .sudo file holds one whole program and no prose, and the parser reads it as one unit.

For the literate form, read examples/showcase-2.2.sudo.md. To validate fences from a script, read scripts/parse-examples.sh.

Install

From npm, with the Node bindings, the queries, and the wasm build:

npm install tree-sitter-sudolang

From crates.io, with the Rust binding. The parser is ABI 15, so pair it with tree-sitter >= 0.25:

[dependencies]
tree-sitter = "0.25"
tree-sitter-sudolang = "0.3.2"

Build

npm install
npx tree-sitter generate
npx tree-sitter test
npx tree-sitter parse examples/ai-rpg.sudo
npx tree-sitter build --wasm

Queries

Default queries ship under queries/:

  • highlights.scm for syntax highlighting
  • injections.scm is empty by design. Injection into sudo fences is the job of the host grammar.
  • locals.scm for scope tracking
  • tags.scm for ctags and GitHub linguist

An editor integration can shadow these files. See zed-sudolang for the Zed extension that pins this grammar.

License

MIT. See LICENSE.

About

Tree-sitter grammar for SudoLang

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages