Files
storybook/.serena/memories/tree-sitter-commands.md

89 lines
2.1 KiB
Markdown
Raw Normal View History

# Tree-sitter Grammar Commands
## Location
Tree-sitter grammar is at: `/Users/sienna/Development/storybook/tree-sitter-storybook/`
## Running Tests
**Use Serena's execute_shell_command when Bash tool fails:**
```bash
cd /Users/sienna/Development/storybook/tree-sitter-storybook && npm run test
```
This runs the tree-sitter test suite against all corpus files in `test/corpus/`.
## Test Corpus Structure
Test files are in `test/corpus/*.txt` format:
```
==================
Test Name
==================
[input code]
---
[expected parse tree]
```
### Key Parse Tree Patterns for Behaviors:
1. **All declarations wrap in `(declaration ...)`**
2. **Behavior nodes wrap children in `(behavior_node ...)`**
3. **Paths have internal structure:**
```
(path
(path_segments
(identifier)
(identifier)))
```
Not just `(path)`
### Example Behavior Test Structure:
```
behavior SimpleBehavior {
walk_around
}
---
(source_file
(declaration
(behavior
name: (identifier)
root: (behavior_node
(action_node (identifier))))))
```
## Regenerating Parser
If grammar.js changes:
```bash
cd /Users/sienna/Development/storybook/tree-sitter-storybook && npm run build
```
This runs `tree-sitter generate` and compiles the parser.
## Test Results (as of 2026-02-09)
✅ All 27 tests passing:
- 17 declaration tests
- 7 behavior tree tests (selector, sequence, repeat, nested, subtree, etc.)
- 3 basic tests
## Behavior Tree Node Types Tested
- `action_node` - Simple action identifiers
- `selector_node` - `? { ... }` - Try options in order
- `sequence_node` - `> { ... }` - Execute in sequence
- `repeat_node` - `* { ... }` - Repeat forever
- `subtree_node` - `@path::to::tree` - Reference external behavior
## Common Issues
1. **Bash tool failing with exit code 1** - Use Serena's execute_shell_command instead
2. **Path structure mismatch** - Remember paths include path_segments wrapper
3. **Missing declaration wrapper** - All top-level items wrap in `(declaration ...)`
4. **Missing behavior_node wrapper** - Behavior children wrap in `(behavior_node ...)`