psy/grammar-tree-sitter
0 forks
id: 75
10,055 Lines
  • C 70.2%
  • JSON 25.8%
  • JavaScript 2.3%
  • Scheme 0.9%
  • Markdown 0.7%
README.md

tree-sitter

Tree-sitter grammar for the Psy specification language.

Psy is indentation-oriented and its strings are usually unquoted, so most lexical decisions live in the external scanner (src/scanner.c), which mirrors the reference lexer in core:

  • layout tokens from indentation, with blank and comment-only lines never affecting layout;
  • block kind inference, so a multiline string block's contents are text rather than assignments or list items;
  • the identifier-resolution rule that decides whether the text after : is a structured value or an unquoted string.
npm install
npm run generate     # regenerate src/parser.c from grammar.js
npm test             # run the corpus suite

Both need a C toolchain. No other checkout does.

src/parser.c, src/grammar.json, src/node-types.json and src/tree_sitter/ are committed on purpose: consumers compile the C directly rather than running tree-sitter generate.

Queries

queries/highlights.scm is canonical. Editors that need their own copy — Zed, for one — pull it in; see zed.

Checking it against real Psy

Every .psy file across the sibling checkouts parses with zero error nodes:

npx tree-sitter parse --quiet --stat \
  '../spec/**/*.psy' '../build/**/*.psy' \
  '../examples/**/*.psy' '../core/fixtures/valid/**/*.psy'

The repository

Psy lives in one repository. The packages inside it stay separate npm packages, depending on each other through file:../<dir>.

psy/                   the root: bootstrap, verify-all, tests that span packages
  compiler/            lexer, parser, AST, binder, resolver, checker, IR,
                       provenance, formatter, linter — and its own specification
  framework/           the types a framework or adapter consumes
  config/              psy.config.ts loading and typing
  morphic/             the skill / agent / command vocabulary
  adapter-claude/      Claude Code agents, skills, commands, plugins
  adapter-data/        JSON, YAML and TOML
  cli/                 the psy command line
  spec/                the language specification, written in Psy
  builders/            the Morphic agents and skills that build Psy
  plugin-fluency/      a Claude Code plugin: fluency in Psy, for an agent
  examples/            runnable example projects
  docs/                the documentation site
  grammar-tree-sitter/ the tree-sitter grammar
  zed/                 the Zed extension

file:../<dir> resolves to a real symlink, so a change in one package is visible to the next immediately, with no publish and no version bump. They do have to be built in dependency order, which is what bootstrap.mjs is for.

node bootstrap.mjs             # install and build everything, in order
node verify-all.mjs            # every package, then the tests that span them
node verify-all.mjs compiler   # just one
Please wait...
Connection lost or session expired, reload to recover
Page is in error, reload to recover