tree-sitter-grammars

Define Tree-sitter grammars using grammar.js DSL and rule helpers.

1|Updated Mar 15, 2026
One-click install
npx skills add https://github.com/hafley66/claude-research --skill tree-sitter-grammars
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: tree-sitter-grammars
Source: https://github.com/hafley66/claude-research/tree/main/skills/tree-sitter-grammars
Command: npx skills add https://github.com/hafley66/claude-research --skill tree-sitter-grammars

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Tree-sitter grammar authoring is intricate; this Skill provides a concise DSL, helper functions, and testing guidance to streamline grammar creation and debugging.

Core Features & Use Cases

  • Grammar.js DSL for defining grammars with rules, extras, conflicts, and externals
  • Rule helpers: seq, choice, repeat, prec, field, alias
  • Testing and validation workflow using tree-sitter CLI
  • Guidance for setting up grammar structure, tokens, and aliases to produce clean parse trees
  • Use cases include creating or extending language grammars and debugging parsing issues

Quick Start

Initialize a new grammar project and begin defining rules in grammar.js

Frequently Asked Questions about tree-sitter-grammars

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I define a Tree-sitter grammar using a DSL?

Tree-sitter grammar definition uses a DSL in grammar.js to specify rules, extras, conflicts, and externals. This approach provides helper functions like seq, choice, repeat, prec, field, and alias to structure tokens and produce clean parse trees.

How do I debug Tree-sitter parse issues in my grammar?

Debugging Tree-sitter parse issues involves running a testing and validation workflow using the tree-sitter CLI. This process helps identify rule conflicts and structural errors in grammar.js to ensure accurate syntax tree generation.

What is the best way to structure Tree-sitter rules for clean parse trees?

Structuring Tree-sitter rules for clean parse trees requires using rule helpers like field and alias to define grammar.js tokens. Properly configuring extras and resolving conflicts ensures the parser generates the intended syntax tree hierarchy.

Can I use Tree-sitter rule helpers like prec and alias to resolve parsing conflicts?

Tree-sitter rule helpers like prec and alias are designed to resolve parsing conflicts and structure grammar.js rules. They allow language developers to enforce operator precedence and rename nodes to produce clean, unambiguous parse trees.

Does Tree-sitter grammar testing require the tree-sitter CLI?

Tree-sitter grammar testing utilizes the tree-sitter CLI to validate grammar.js rules and parse outputs. This workflow allows language developers to run test suites and verify that syntax parsing matches expected structural results.

Why does my Tree-sitter grammar have conflicts when using choice and repeat?

Tree-sitter grammar conflicts often arise when combining choice and repeat rules without proper precedence. Defining explicit conflict resolutions and using prec helpers in grammar.js ensures the parser handles ambiguous syntax correctly.