# Build Reliable Tree-sitter Parsers

Tree-sitter integrations often fail on malformed code, language differences, and inefficient traversal. This skill provides reusable parsing, query, visitor, error-handling, and optimization patterns.

## Install

```bash
npx skillstore add consiliency/treesitter-patterns
```

## Metadata

- Status: approved
- Slug: consiliency-treesitter-patterns
- Skillstore revision: r1
- Version status: missing
- Tree hash: 75c9b18363586401b1787f32168d61b4426ae8df4f4e5f8828a53b7fe334cd45
- Author: Consiliency
- GitHub username: Consiliency
- License: MIT
- Repository: https://github.com/Consiliency/treesitter-chunker/tree/main/.ai-dev-kit/skills/treesitter-patterns
- Ref: 635f69fb8d2f4e6330ba47a4e5a0fb239c04d110
- Supported tools: Claude, Codex, Claude Code
- Audit status: complete
- Agent install advisory: allowed
- Manual install advisory: allowed
- Artifact signature: available
- Audit attestation: unavailable
- Human verification: not\_verified
- Risk factors: external\_commands
- Quality score: 78
- Quality tier: bronze
- Public page: https://skillstore.pages.dev/skills/consiliency-treesitter-patterns
- Manifest: https://skillstore.pages.dev/api/skills/consiliency-treesitter-patterns/manifest

## Capabilities

- Set up Python Tree-sitter parsers and access syntax tree nodes.
- Navigate named children and recursively find nodes by type.
- Write Tree-sitter queries for functions, classes, imports, and decorated definitions.
- Implement reusable AST visitor classes and function extractors.
- Detect parse errors and apply incremental parsing and query optimization.

## Use Cases

- Prototype a Parser: Set up a Python parser, inspect nodes, and extract functions from source files.
- Design Structural Queries: Create and refine Tree-sitter queries for functions, classes, imports, and decorators.
- Harden Parsing Pipelines: Add error collection, visitor abstractions, incremental parsing, and performance controls to production tooling.

## Prompt Templates

### Create a Basic Parser

```
Create a Tree-sitter Python parser for [language]. Show how to parse [sample], inspect the root, and report syntax errors.
```

### Design a Structural Query

```
Design a Tree-sitter query for [language] that captures [constructs]. Explain each capture and list grammar node types I must verify.
```

### Build an AST Visitor

```
Refactor my traversal into an AST visitor that extracts [data]. Preserve error handling, named-child traversal, and language-specific extension points.
```

### Architect a Parsing Pipeline

```
Design a production parsing pipeline for [languages] and [workload]. Include incremental parsing, query caching, version pinning, parallelism, failure handling, and tests.
```

## Limitations

- Provides reference patterns, not runnable scripts or installed parser packages.
- Cookbook files named in the instructions are not included in this skill package.
- Language node types vary by grammar and require verification against installed parser versions.
- Examples focus mainly on Python and need adaptation for other bindings.

## Best Practices

- Verify node names against each language grammar before finalizing queries.
- Test valid, incomplete, and malformed source samples for every supported language.
- Pin parser versions and benchmark large files before production rollout.

## Anti Patterns

- Do not assume one grammar uses the same node types as another.
- Do not ignore ERROR or missing nodes when extracting structure.
- Do not traverse entire trees when targeted queries or early exits are sufficient.

## Security Audit

- Audited at: 2026-07-13T17:43:44.925\+00:00
- Summary: All 24 static findings are false positives caused by Markdown backticks, fenced examples, or inline identifiers. SKILL.md contains no external command execution or intent-level security issue.

## Stats

- Views: 271
- Downloads: 7
- Favorites: 0
- Popularity score: 0
