feat(tree-sitter): add Tree-sitter grammar for Storybook DSL
This commit is contained in:
88
tree-sitter-storybook/README.md
Normal file
88
tree-sitter-storybook/README.md
Normal file
@@ -0,0 +1,88 @@
|
||||
# tree-sitter-storybook
|
||||
|
||||
Tree-sitter grammar for the Storybook narrative DSL.
|
||||
|
||||
## Overview
|
||||
|
||||
This is a Tree-sitter grammar for Storybook, a domain-specific language for narrative design and character development. The grammar provides syntax highlighting, code navigation, and other editor features through Tree-sitter.
|
||||
|
||||
## Features
|
||||
|
||||
- **Syntax highlighting** for all Storybook constructs
|
||||
- **Symbol outline** for navigating characters, templates, relationships, etc.
|
||||
- **Bracket matching** including special handling for prose blocks
|
||||
- **Auto-indentation** support
|
||||
|
||||
## Installation
|
||||
|
||||
### For development
|
||||
|
||||
```bash
|
||||
# Install dependencies
|
||||
npm install
|
||||
|
||||
# Generate parser
|
||||
npm run build
|
||||
|
||||
# Run tests
|
||||
npm run test
|
||||
```
|
||||
|
||||
### For Zed editor
|
||||
|
||||
This grammar is integrated into the Zed Storybook extension. See the `zed-storybook` directory for the extension.
|
||||
|
||||
## Grammar Structure
|
||||
|
||||
The grammar supports the following top-level declarations:
|
||||
|
||||
- `use` - Import statements
|
||||
- `character` - Character definitions
|
||||
- `template` - Reusable field templates
|
||||
- `life_arc` - State machines for character development
|
||||
- `schedule` - Daily schedules and routines
|
||||
- `behavior` - Behavior trees for AI
|
||||
- `institution` - Organizations and groups
|
||||
- `relationship` - Multi-party relationships
|
||||
- `location` - Places and settings
|
||||
- `species` - Species definitions with templates
|
||||
- `enum` - Enumeration types
|
||||
|
||||
## Special Features
|
||||
|
||||
### Prose Blocks
|
||||
|
||||
The grammar includes an external scanner (written in C) to handle prose blocks:
|
||||
|
||||
```storybook
|
||||
---backstory
|
||||
This is a prose block that can contain
|
||||
multiple lines of narrative text.
|
||||
---
|
||||
```
|
||||
|
||||
### Expression Support
|
||||
|
||||
Full support for expressions in life arc transitions:
|
||||
|
||||
```storybook
|
||||
on self.age >= 18 and self.location is wonderland -> adult_state
|
||||
```
|
||||
|
||||
## Testing
|
||||
|
||||
The grammar includes comprehensive tests. Run them with:
|
||||
|
||||
```bash
|
||||
tree-sitter test
|
||||
```
|
||||
|
||||
To test parsing a specific file:
|
||||
|
||||
```bash
|
||||
tree-sitter parse path/to/file.sb
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
Reference in New Issue
Block a user