tree-sitter-language-pack-parsing-source
Use when the user wants a tree-sitter syntax tree for a source file — an s-expression dump or JSON tree. Covers `ts-pack parse`, language auto-detection vs `--language`, stdin input, and reading `has_errors`.
- License 许可
- MIT
- 最近更新
- 2026-11-07
- Stars
- ★ 485
- Forks
- 71
01 前言 Front Matter
- name
- tree-sitter-language-pack-parsing-source
- description
- Use when the user wants a tree-sitter syntax tree for a source file — an s-expression dump or JSON tree. Covers `ts-pack parse`, language auto-detection vs `--language`, stdin input, and reading `has_errors`.
02 资源文件 1
- 参考文档index.md523 B
03 SKILL.md 正文
<!-- AI-RULEZ :: GENERATED FILE — DO NOT EDIT Content-Hash: blake3:211a994b629d9e5e530945c00db243d6f0e4a8f78e054dc7c52db4527c90c35f Source-Hash: blake3:b8687cf31ac8c66a5ecc15c4f11520ff201d8db14467b7528d5120124e9753a4 Schema-Version: v1 -->
Parsing source into a syntax tree
ts-pack parse <file> parses one source file with the matching
tree-sitter grammar and prints the resulting concrete syntax tree. Use it
when the user wants the tree itself — to inspect node structure, debug a
grammar, or feed an s-expression to another tool.
Quick recipe
# S-expression (default) — auto-detects language from the file extension
ts-pack parse src/main.rs
# JSON form: { "language", "sexp", "has_errors" }
ts-pack parse src/main.rs --format json
Flag surface
| Flag | Short | Default | Purpose |
|---|---|---|---|
--language <name> |
-l |
auto | Override the language (skip extension detection). |
--format <fmt> |
-f |
sexp |
sexp or json. |
The parser library for the language downloads on first use and is cached.
Language detection
The language is auto-detected from the file extension. Override it when the extension is missing, misleading, or you are reading from stdin:
# Misleading extension or no extension:
ts-pack parse script --language bash
# stdin (use "-" as the file):
cat snippet.py | ts-pack parse - --language python
stdin cannot be auto-detected by path; always pass --language with -.
For content-based detection without a path, use the SDK
(detect_language_from_content) — see the tree-sitter-language-pack-detecting-languages skill.
Output shapes
S-expression
A nested (node_type child ...) tree. Compact, good for eyeballing
structure or piping to a grammar tool.
JSON
{
"language": "rust",
"sexp": "(source_file (function_item ...))",
"has_errors": false
}
Read has_errors to know whether the parse produced any error nodes — a
fast syntax check. For positioned, per-error detail use
ts-pack process <file> --diagnostics (see tree-sitter-language-pack-extracting-code-structure).
Examples
# Inspect a TypeScript file's tree
ts-pack parse src/app.ts
# Machine-readable, then check for syntax errors with jq
ts-pack parse src/app.ts --format json | jq '.has_errors'
# Parse a heredoc as Python
printf 'def f():\n return 1\n' | ts-pack parse - -l python
When to reach for process instead
parse gives you the raw tree. If the user wants structured metadata
(functions, imports, exports, symbols, docstrings) rather than the tree,
use ts-pack process — see the tree-sitter-language-pack-extracting-code-structure skill.
04 同仓库更多 Skills
tree-sitter-language-pack
Parse and extract code intelligence from 371 programming languages using tree-sitter grammars. Use when writing code that parses source, extracts structure/imports/exports/symbols/docstrings/comments, detects a language, runs syntax diagnostics, or produces syntax-aware chunks for LLMs — in Rust, Python, Node.js/TypeScript, or the ts-pack CLI. Covers installation, the CLI surface, the SDK surface, and parser-cache management.
tree-sitter-language-pack-using-the-mcp-server
Use when parsing source, extracting code structure, or detecting a language through the tree-sitter-language-pack MCP server's tools, rather than shelling out to the ts-pack CLI. Covers the tool surface, the auto-installing launcher, and when MCP beats the CLI or SDK.
tree-sitter-language-pack-parsing-source
Use when the user wants a tree-sitter syntax tree for a source file — an s-expression dump or JSON tree. Covers `ts-pack parse`, language auto-detection vs `--language`, stdin input, and reading `has_errors`.
tree-sitter-language-pack-managing-parsers
Use when the user needs to manage the tree-sitter parser cache — prefetch parsers for offline or CI runs, list what is downloaded, inspect a language, find the cache directory, or clean it. Covers `ts-pack download`, `list`, `info`, `cache-dir`, `clean`, and `init`.
tree-sitter-language-pack-extracting-code-structure
Use when the user wants structured code metadata from a source file — functions, classes, imports, exports, symbols, docstrings, comments, or syntax diagnostics. Covers `ts-pack process` feature flags, the JSON result shape, and the default feature set.
tree-sitter-language-pack-detecting-languages
Use when the user wants to know which programming language a file or snippet is. Covers implicit detection in `ts-pack parse`/`process`, confirming support with `ts-pack list`/`info`, and the SDK detection functions for path, extension, and raw content.