tree-sitter
2
总安装量
2
周安装量
#71887
全站排名
安装命令
npx skills add https://github.com/ssiumha/dots --skill tree-sitter
Agent 安装分布
opencode
2
gemini-cli
2
claude-code
2
github-copilot
2
codex
2
kimi-cli
2
Skill 文档
tree-sitter CLI
tree-sitter CLIë¡ AST ë¤í, S-expression 쿼리, íê·¸ ì¶ì¶ì ìíí©ëë¤.
íµì¬ ì² í:
- ast-grep ì°ì : ê²ì/ëì²´ë ast-grep, tree-sitterë ë¶ì/ì´í´ 목ì
- AST ìê°í: ì½ë 구조를 í¸ë¦¬ë¡ íì¸íì¬ ì íí ë ¸ë íì íì
- S-expression 쿼리: predicatesë¡ ì ë°í 구조ì ê²ì (neovim queryì ëì¼ ë¬¸ë²)
- íê·¸ ì¶ì¶: ì ì/참조를 구조ì ì¼ë¡ ì¶ì¶ (ctags ëì²´)
Prerequisites
tree-sitter dump-languages # ì¬ì© ê°ë¥í íì 목ë¡
“not configured” ê²½ê³ ì â ìí¬íë¡ì° 1 ì¤í.
Instructions
ìí¬íë¡ì° 1: Setup (on-demand íì ì¤ì¹)
dump-languages ì¶ë ¥ì ì¸ì´ê° ìì¼ë©´ grammarì ì¤ì¹íë¤.
# ì´ê¸° ì¤ì (1í)
tree-sitter init-config # parser-directories: ["~/.local/share/tree-sitter/grammars"]
# ì¸ì´ë³ ì¤ì¹ (íì ì)
cd ~/.local/share/tree-sitter/grammars
git clone --depth 1 https://github.com/tree-sitter/tree-sitter-<ì¸ì´>
# ì¼ë¶ ì¸ì´ë tree-sitter-grammars org: https://github.com/tree-sitter-grammars/tree-sitter-<ì¸ì´>
ìí¬íë¡ì° 2: Parse (AST ë¤í)
쿼리 ìì± ì ë ¸ë íì íì ì íì.
tree-sitter parse --no-ranges file.py # ê°ê²°í AST
tree-sitter parse --cst file.py # ì ë ¬ë í¸ë¦¬
tree-sitter parse --xml file.py # XML ì¶ë ¥
tree-sitter parse --scope source.python file.txt # ì¸ì´ ì§ì
ì¶ë ¥ ìì:
(function_definition
name: (identifier)
parameters: (parameters (identifier) (identifier))
body: (block (return_statement)))
ë
¸ë íì
(function_definition)ê³¼ íëëª
(name:, body:)ì íì¸íì¬ query í¨í´ ìì±ì ì¬ì©.
ìí¬íë¡ì° 3: Query (S-expression 쿼리)
S-expression í¨í´ì¼ë¡ ì½ë를 ê²ìíë¤. .scm íì¼ì ìì± í ì¤í.
;; queries/find-functions.scm
(function_definition
name: (identifier) @func.name)
tree-sitter query queries/find-functions.scm file.py
tree-sitter query queries/find-functions.scm src/ # ëë í 리 ì ì²´
tree-sitter query --captures queries/q.scm file.py # ìº¡ì² ìì ì¶ë ¥
tree-sitter query --row-range 10-50 queries/q.scm file.py # í ë²ì ì í
S-expression 쿼리 문ë²ì resources/01-query-syntax.md 참조.
ìí¬íë¡ì° 4: Tags (íê·¸ ì¶ì¶)
ì½ëìì ì ì(definition)ì 참조(reference)를 ì¶ì¶íë¤.
tree-sitter tags file.py
tree-sitter tags src/ # ëë í 리 ì ì²´
ì¤ì ìì¹
- Parse 먼ì : 쿼리 ìì± ì ë°ëì
parseë¡ ë ¸ë íì íì¸ - 쿼리 íì¼ ì¬ì©:
.scmíì¼ ìì± (ì¬ì¬ì©, ê°ë ì±) - ì¸ì´ë³ ë ¸ë ì°¨ì´: ê°ì ê°ë ì´ë¼ë ì¸ì´ë§ë¤ ë ¸ë íì ì´ ë¤ë¦
Examples
AST 구조 íì
User: "ì´ Python íì¼ì AST 구조 ë³´ì¬ì¤"
â tree-sitter parse --no-ranges file.py â ë
¸ë íì
ê³¼ íë 구조 ë³´ê³
ë³µì¡í 쿼리
User: "ë°ì½ë ì´í°ê° ë¶ì async í¨ìë§ ì°¾ìì¤"
â parseë¡ ë
¸ë íì
íì¸ â .scm 쿼리 ìì± â tree-sitter query query.scm src/
References
- S-expression 쿼리 문ë²:
resources/01-query-syntax.md - ê³µì 문ì: https://tree-sitter.github.io/tree-sitter/
- Grammar 목ë¡: https://github.com/tree-sitter
- ì¤ì íì¼:
~/.config/tree-sitter/config.json - Grammar ê²½ë¡:
~/.local/share/tree-sitter/grammars/