release: Storybook v0.2.0 - Major syntax and features update
BREAKING CHANGES: - Relationship syntax now requires blocks for all participants - Removed self/other perspective blocks from relationships - Replaced 'guard' keyword with 'if' for behavior tree decorators Language Features: - Add tree-sitter grammar with improved if/condition disambiguation - Add comprehensive tutorial and reference documentation - Add SBIR v0.2.0 binary format specification - Add resource linking system for behaviors and schedules - Add year-long schedule patterns (day, season, recurrence) - Add behavior tree enhancements (named nodes, decorators) Documentation: - Complete tutorial series (9 chapters) with baker family examples - Complete reference documentation for all language features - SBIR v0.2.0 specification with binary format details - Added locations and institutions documentation Examples: - Convert all examples to baker family scenario - Add comprehensive working examples Tooling: - Zed extension with LSP integration - Tree-sitter grammar for syntax highlighting - Build scripts and development tools Version Updates: - Main package: 0.1.0 → 0.2.0 - Tree-sitter grammar: 0.1.0 → 0.2.0 - Zed extension: 0.1.0 → 0.2.0 - Storybook editor: 0.1.0 → 0.2.0
This commit is contained in:
101
examples/baker-family/README.md
Normal file
101
examples/baker-family/README.md
Normal file
@@ -0,0 +1,101 @@
|
||||
# Baker Family Example
|
||||
|
||||
A comprehensive example demonstrating Storybook v0.2.0 features through a realistic multi-character scenario.
|
||||
|
||||
## Features Demonstrated
|
||||
|
||||
### Resource Linking
|
||||
- **Templates with behaviors**: `Baker` template specifies `BakingSkills` and `CustomerService`
|
||||
- **Templates with schedules**: `Baker` template uses `BakerSchedule`
|
||||
- **Multi-level inheritance**: `Baker` → `Worker` → `Person` template chain
|
||||
- **Character inheritance**: Characters automatically inherit behaviors and schedules from templates
|
||||
|
||||
### Schedule Composition
|
||||
- **Schedule inheritance**: `BakerSchedule extends WorkWeek`
|
||||
- **Override blocks**: Modify inherited time blocks with `override work { ... }`
|
||||
- **Named blocks**: All blocks have names for the override system
|
||||
- **Action references**: Schedule blocks reference behavior trees via `action: BehaviorName`
|
||||
- **Recurrence patterns**: Market day repeats `on Saturday`
|
||||
|
||||
### Behavior Trees
|
||||
- Comprehensive behavior definitions for all activities
|
||||
- Referenced from schedule blocks showing integration
|
||||
- Hierarchical behaviors (sequences, selectors, repeaters)
|
||||
|
||||
## File Structure
|
||||
|
||||
```
|
||||
baker-family/
|
||||
├── README.md # This file
|
||||
├── schema/
|
||||
│ └── templates.sb # Template definitions with resource linking
|
||||
├── schedules/
|
||||
│ └── work_schedules.sb # Composable schedules
|
||||
├── behaviors/
|
||||
│ └── baker_behaviors.sb # Behavior tree definitions
|
||||
└── characters/
|
||||
├── martha.sb # Master baker (uses Baker template)
|
||||
├── john.sb # Pastry chef (uses Baker template)
|
||||
└── emma.sb # Daughter (uses Child template)
|
||||
```
|
||||
|
||||
## Template Hierarchy
|
||||
|
||||
```
|
||||
Person (behaviors: BasicNeeds, SocialInteraction)
|
||||
└─> Worker (schedule: WorkWeek)
|
||||
└─> Baker (behaviors: +BakingSkills, +CustomerService, schedule: BakerSchedule)
|
||||
|
||||
└─> Child (behaviors: PlayBehavior, LearnBehavior, no schedule)
|
||||
```
|
||||
|
||||
## Schedule Inheritance
|
||||
|
||||
```
|
||||
WorkWeek
|
||||
├─ morning_prep (08:00-09:00)
|
||||
├─ work (09:00-17:00)
|
||||
└─ evening_rest (18:00-22:00)
|
||||
|
||||
BakerSchedule extends WorkWeek
|
||||
├─ pre_dawn_prep (04:00-05:00) [NEW]
|
||||
├─ work (05:00-13:00) [OVERRIDE] → action: BakingWork
|
||||
├─ evening_rest (18:00-22:00) [INHERITED]
|
||||
└─ recurrence MarketDay on Saturday
|
||||
└─ market (06:00-14:00) → action: SellAtMarket
|
||||
```
|
||||
|
||||
## Key Integration Points
|
||||
|
||||
1. **Martha (character)** → inherits from **Baker (template)**
|
||||
- Gets behaviors: `BakingSkills`, `CustomerService`, `BasicNeeds`, `SocialInteraction`
|
||||
- Gets schedule: `BakerSchedule` (which extends `WorkWeek`)
|
||||
|
||||
2. **BakerSchedule (schedule)** → references **BakingWork (behavior)**
|
||||
- `action: BakingWork` in the work block
|
||||
- Creates link between scheduling and behavior systems
|
||||
|
||||
3. **Template chain** → cascading resource inheritance
|
||||
- `Baker` includes `Worker` includes `Person`
|
||||
- All behaviors and schedules flow down the hierarchy
|
||||
|
||||
## Usage
|
||||
|
||||
This example shows how to:
|
||||
- Build reusable templates with attached behaviors and schedules
|
||||
- Create character hierarchies representing different roles
|
||||
- Compose schedules through inheritance and overrides
|
||||
- Link schedules to behaviors through action references
|
||||
- Model realistic daily routines with time-of-day variations
|
||||
- Handle special events (market days) with recurrence patterns
|
||||
|
||||
## Narrative Implications
|
||||
|
||||
The Baker family example demonstrates:
|
||||
- **Daily rhythms**: Early morning routine for bakers vs. normal schedule for child
|
||||
- **Weekly patterns**: Special market day on Saturdays
|
||||
- **Role-based behaviors**: Bakers have different skill sets than children
|
||||
- **Family dynamics**: Multiple characters with interrelated but distinct routines
|
||||
- **Business operations**: Work schedule tied to specific behaviors (baking, selling)
|
||||
|
||||
This is the kind of rich, time-based character modeling that makes Storybook ideal for narrative simulations and game design.
|
||||
208
examples/baker-family/behaviors/baker_behaviors.sb
Normal file
208
examples/baker-family/behaviors/baker_behaviors.sb
Normal file
@@ -0,0 +1,208 @@
|
||||
//! Behavior trees for the Baker family
|
||||
//!
|
||||
//! These are referenced by schedule blocks via the action: field
|
||||
|
||||
// Main baking work routine
|
||||
behavior BakingWork {
|
||||
then {
|
||||
check_orders
|
||||
prepare_ingredients
|
||||
choose {
|
||||
make_bread
|
||||
make_pastries
|
||||
make_cakes
|
||||
}
|
||||
bake
|
||||
cool_products
|
||||
package_goods
|
||||
}
|
||||
}
|
||||
|
||||
// Kitchen prep routine
|
||||
behavior PrepKitchen {
|
||||
then {
|
||||
clean_surfaces
|
||||
check_supplies
|
||||
preheat_ovens
|
||||
organize_workspace
|
||||
}
|
||||
}
|
||||
|
||||
// type
|
||||
concept Vendor;
|
||||
|
||||
// type
|
||||
sub_concept VendorInventory {
|
||||
Bread: any,
|
||||
Pastries: any,
|
||||
Cakes: any,
|
||||
Cup: any
|
||||
}
|
||||
|
||||
// type (but really just an enum lol)
|
||||
concept Cup;
|
||||
|
||||
// enum
|
||||
sub_concept CupSize: {
|
||||
Small,
|
||||
Medium,
|
||||
Large
|
||||
}
|
||||
|
||||
// enum
|
||||
sub_concept CupType: {
|
||||
Ceramic,
|
||||
Glass,
|
||||
Plastic
|
||||
}
|
||||
|
||||
// enum
|
||||
sub_concept CupColor {
|
||||
Red,
|
||||
Blue,
|
||||
Green
|
||||
}
|
||||
|
||||
// enum comparison done at compile time
|
||||
concept_comparison CustomerInterestInCups {
|
||||
Interested: {
|
||||
CupSize: any, // any means any value of the type can be matched
|
||||
CupType: CupType is Glass or CupType is Plastic,
|
||||
CupColor: CupColor is Red or CupColor is Blue
|
||||
},
|
||||
NotInterested: {
|
||||
CupSize: any,
|
||||
CupType: any,
|
||||
CupColor: any
|
||||
},
|
||||
Maybe: {
|
||||
CupSize: any,
|
||||
CupType: any,
|
||||
CupColor: any
|
||||
}
|
||||
}
|
||||
|
||||
// type
|
||||
concept Plate;
|
||||
|
||||
// enum
|
||||
sub_concept PlateColor {
|
||||
Blue,
|
||||
Green,
|
||||
Red
|
||||
}
|
||||
|
||||
// type
|
||||
concept Customer;
|
||||
|
||||
// enum
|
||||
sub_concept CustomerInterest {
|
||||
Interested: 10,
|
||||
NotInterested: 20,
|
||||
Maybe: 70
|
||||
}
|
||||
|
||||
|
||||
// Market day selling behavior
|
||||
behavior SellAtMarket {
|
||||
repeat {
|
||||
then {
|
||||
greet_customer
|
||||
show_products
|
||||
if(CustomerInterestInCups.Interested.CupSize is Medium or CupSize is Large and CustomerInterestInCups.Interested.CupType is Glass or CupType is Plastic and CustomerInterestInCups.Interested.CupColor is Red or CupColor is Blue) {
|
||||
make_sale(Cup)
|
||||
}
|
||||
if(CustomerInterestInCups.Interested.CupSize is Small and CustomerInterestInCups.Interested.CupType is Ceramic and CustomerInterestInCups.Interested.CupColor is Green) {
|
||||
if (Plate.PlateColor is Blue or PlateColor is Green) {
|
||||
// variadic arguments
|
||||
make_sale(Cup, Plate)
|
||||
}
|
||||
// or there can be generic fallthroughs too
|
||||
thank_customer
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Assistant work (subset of main baking)
|
||||
behavior AssistWithBaking {
|
||||
then {
|
||||
check_orders
|
||||
prepare_ingredients
|
||||
choose {
|
||||
assist_with_bread
|
||||
assist_with_pastries
|
||||
}
|
||||
clean_workspace
|
||||
}
|
||||
}
|
||||
|
||||
// Quick morning prep
|
||||
behavior QuickPrep {
|
||||
then {
|
||||
check_supplies
|
||||
organize_workspace
|
||||
}
|
||||
}
|
||||
|
||||
concept Hunger;
|
||||
|
||||
sub_concept HungerState {
|
||||
Hungry,
|
||||
NotHungry
|
||||
}
|
||||
|
||||
// Basic needs (from Person template)
|
||||
behavior BasicNeeds {
|
||||
repeat {
|
||||
choose {
|
||||
if(HungryState.Hungry) { eat }
|
||||
if(HungryState.NotHungry) { rest }
|
||||
if(thirsty) { drink }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Social interaction
|
||||
behavior SocialInteraction {
|
||||
choose {
|
||||
greet_neighbors
|
||||
chat_with_customers
|
||||
family_time
|
||||
}
|
||||
}
|
||||
|
||||
// Baking skills
|
||||
behavior BakingSkills {
|
||||
then {
|
||||
assess_dough
|
||||
adjust_recipe
|
||||
monitor_temperature
|
||||
}
|
||||
}
|
||||
|
||||
// Customer service
|
||||
behavior CustomerService {
|
||||
then {
|
||||
greet_warmly
|
||||
listen_to_needs
|
||||
recommend_products
|
||||
handle_payment
|
||||
}
|
||||
}
|
||||
|
||||
// Child behaviors
|
||||
behavior PlayBehavior {
|
||||
choose {
|
||||
play_outside
|
||||
play_with_toys
|
||||
draw_pictures
|
||||
}
|
||||
}
|
||||
|
||||
behavior LearnBehavior {
|
||||
then {
|
||||
attend_school
|
||||
do_homework
|
||||
read_books
|
||||
}
|
||||
}
|
||||
40
examples/baker-family/characters/emma.sb
Normal file
40
examples/baker-family/characters/emma.sb
Normal file
@@ -0,0 +1,40 @@
|
||||
//! Emma - The bakers' daughter
|
||||
//!
|
||||
//! Demonstrates:
|
||||
//! - Character using different template (Child vs Baker)
|
||||
//! - Different behavior set appropriate to age
|
||||
//! - No work schedule (children don't work)
|
||||
|
||||
use schema::templates::Child;
|
||||
|
||||
character Emma from Child {
|
||||
// Personal details
|
||||
age: 12
|
||||
|
||||
// Child-specific traits
|
||||
school_grade: 7
|
||||
curiosity: 0.9
|
||||
|
||||
// General traits
|
||||
energy: 0.9
|
||||
mood: 0.85
|
||||
|
||||
---backstory
|
||||
Emma is the bright, energetic daughter of Martha and John. She loves
|
||||
helping in the bakery on weekends, though she's not allowed to work
|
||||
the ovens yet. She's fascinated by the chemistry of baking and often
|
||||
asks her parents endless questions about why dough rises, how yeast
|
||||
works, and what makes bread crusty.
|
||||
|
||||
At school, she excels in science and math, and dreams of one day
|
||||
creating her own innovative recipes. For now, she's content to help
|
||||
package goods and chat with the regular customers who've watched her
|
||||
grow up.
|
||||
---
|
||||
}
|
||||
|
||||
// Note: Emma inherits from Child template which:
|
||||
// - uses behaviors: PlayBehavior, LearnBehavior
|
||||
// - uses behaviors: BasicNeeds, SocialInteraction (from Person)
|
||||
// - Has NO work schedule (appropriate for a child)
|
||||
// - Has different fields than Baker template
|
||||
42
examples/baker-family/characters/jane.sb
Normal file
42
examples/baker-family/characters/jane.sb
Normal file
@@ -0,0 +1,42 @@
|
||||
//! Jane - Pastry specialist and Martha's wife
|
||||
//!
|
||||
//! Demonstrates:
|
||||
//! - Another character using the same Baker template
|
||||
//! - Different field values showcasing template flexibility
|
||||
//! - Resource inheritance working across multiple characters
|
||||
|
||||
use schema::templates::Baker;
|
||||
|
||||
character Jane from Baker {
|
||||
// Personal details
|
||||
age: 36
|
||||
|
||||
// Baker-specific traits
|
||||
specialty: "pastries"
|
||||
baking_skill: 0.85
|
||||
customer_relations: 0.80
|
||||
|
||||
// General traits
|
||||
energy: 0.75
|
||||
mood: 0.85
|
||||
|
||||
// Work ethic
|
||||
work_ethic: 0.90
|
||||
occupation: "pastry chef"
|
||||
|
||||
---backstory
|
||||
Jane trained at a culinary school in the capital before returning
|
||||
to his hometown and meeting Martha. His specialty is delicate
|
||||
pastries and elaborate wedding cakes. While Martha handles the
|
||||
bread and business, Jane focuses on the artistic creations that
|
||||
draw customers from neighboring towns.
|
||||
|
||||
He's more of a night owl by nature, but has adapted to the baker's
|
||||
early schedule over the years. His croissants are legendary.
|
||||
---
|
||||
}
|
||||
|
||||
// Note: Jane also inherits:
|
||||
// - All behaviors from Baker template chain
|
||||
// - BakerSchedule (same early mornings as Martha)
|
||||
// - All fields with ranges have specific values
|
||||
43
examples/baker-family/characters/martha.sb
Normal file
43
examples/baker-family/characters/martha.sb
Normal file
@@ -0,0 +1,43 @@
|
||||
//! Martha - Master baker and family matriarch
|
||||
//!
|
||||
//! Demonstrates:
|
||||
//! - Character inheriting from template with resources
|
||||
//! - Template provides both behaviors and schedule
|
||||
//! - Field overrides from template
|
||||
|
||||
use schema::templates::Baker;
|
||||
|
||||
character Martha from Baker {
|
||||
// Personal details
|
||||
age: 34
|
||||
|
||||
// Baker-specific traits
|
||||
specialty: "sourdough"
|
||||
baking_skill: 0.9
|
||||
customer_relations: 0.95
|
||||
|
||||
// General traits (inherited from Person template)
|
||||
energy: 0.7
|
||||
mood: 0.8
|
||||
|
||||
// Work ethic (from Worker template)
|
||||
work_ethic: 0.95
|
||||
occupation: "master baker"
|
||||
|
||||
---backstory
|
||||
Martha learned to bake from her grandmother and has perfected
|
||||
the art of sourdough over fifteen years. She wakes at 4 AM every
|
||||
day to prepare the morning bread, and her bakery is known throughout
|
||||
the region for its exceptional quality.
|
||||
|
||||
She manages the business side as well, keeping meticulous records
|
||||
and maintaining warm relationships with all her customers. The bakery
|
||||
is not just a shop - it's the heart of the community.
|
||||
---
|
||||
}
|
||||
|
||||
// Note: Martha inherits from Baker template which:
|
||||
// - uses behaviors: BakingSkills, CustomerService (from Baker)
|
||||
// - uses behaviors: BasicNeeds, SocialInteraction (from Person via Worker)
|
||||
// - uses schedule: BakerSchedule (from Baker)
|
||||
// - uses schedule: WorkWeek (base for BakerSchedule)
|
||||
55
examples/baker-family/schedules/work_schedules.sb
Normal file
55
examples/baker-family/schedules/work_schedules.sb
Normal file
@@ -0,0 +1,55 @@
|
||||
//! Work schedules for the Baker family
|
||||
//!
|
||||
//! Demonstrates schedule composition features:
|
||||
//! - extends keyword for schedule inheritance
|
||||
//! - override blocks to modify inherited schedules
|
||||
//! - Named blocks for override system
|
||||
//! - Action references to behavior trees
|
||||
//! - Recurrence patterns for weekly variations
|
||||
|
||||
// Base work schedule (9-5 job)
|
||||
schedule WorkWeek {
|
||||
block morning_prep { 08:00 -> 09:00, action: MorningPrep }
|
||||
block work { 09:00 -> 17:00, action: DailyWork }
|
||||
block evening_rest { 18:00 -> 22:00, action: Resting }
|
||||
}
|
||||
|
||||
// Baker's schedule extends WorkWeek
|
||||
schedule BakerSchedule extends WorkWeek {
|
||||
// Bakers start early - override the work block
|
||||
override work {
|
||||
05:00 -> 13:00
|
||||
action: BakingWork
|
||||
intensity: "high"
|
||||
}
|
||||
|
||||
// Add pre-dawn prep
|
||||
block pre_dawn_prep {
|
||||
04:00 -> 05:00
|
||||
action: PrepKitchen
|
||||
}
|
||||
|
||||
// Market day on Saturdays
|
||||
recurrence MarketDay on Saturday {
|
||||
block market {
|
||||
06:00 -> 14:00
|
||||
action: SellAtMarket
|
||||
place: "town_square"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Assistant baker schedule (helps during busy times)
|
||||
schedule AssistantSchedule extends BakerSchedule {
|
||||
// Assistant comes in later
|
||||
override work {
|
||||
06:00 -> 14:00
|
||||
action: AssistWithBaking
|
||||
}
|
||||
|
||||
// Assistant does a quick prep before work
|
||||
override pre_dawn_prep {
|
||||
05:30 -> 06:00
|
||||
action: QuickPrep
|
||||
}
|
||||
}
|
||||
40
examples/baker-family/schema/templates.sb
Normal file
40
examples/baker-family/schema/templates.sb
Normal file
@@ -0,0 +1,40 @@
|
||||
//! Template definitions for the Baker family
|
||||
//!
|
||||
//! This example demonstrates v0.2.0 features:
|
||||
//! - Resource linking (uses_behaviors, uses_schedule)
|
||||
//! - Template inheritance
|
||||
//! - Multi-level template hierarchies
|
||||
|
||||
// Base template for all persons
|
||||
template Person {
|
||||
uses behaviors: BasicNeeds, SocialInteraction
|
||||
age: 0..100
|
||||
energy: 0.0..1.0
|
||||
mood: 0.0..1.0
|
||||
}
|
||||
|
||||
// Worker template extends Person
|
||||
template Worker {
|
||||
include Person
|
||||
uses schedule: WorkWeek
|
||||
occupation: "laborer"
|
||||
work_ethic: 0.5..1.0
|
||||
}
|
||||
|
||||
// Specialized baker template
|
||||
template Baker {
|
||||
include Worker
|
||||
uses behaviors: BakingSkills, CustomerService
|
||||
uses schedule: BakerSchedule
|
||||
specialty: "bread"
|
||||
baking_skill: 0.0..1.0
|
||||
customer_relations: 0.5..1.0
|
||||
}
|
||||
|
||||
// Child template (no work schedule)
|
||||
template Child {
|
||||
include Person
|
||||
uses behaviors: PlayBehavior, LearnBehavior
|
||||
school_grade: 1..12
|
||||
curiosity: 0.0..1.0
|
||||
}
|
||||
27
examples/baker-family/test_parse.sh
Normal file
27
examples/baker-family/test_parse.sh
Normal file
@@ -0,0 +1,27 @@
|
||||
#!/bin/bash
|
||||
# Quick validation that all Baker family example files parse correctly
|
||||
|
||||
echo "Testing Baker family example files..."
|
||||
echo ""
|
||||
|
||||
files=(
|
||||
"schema/templates.sb"
|
||||
"schedules/work_schedules.sb"
|
||||
"behaviors/baker_behaviors.sb"
|
||||
"characters/martha.sb"
|
||||
"characters/john.sb"
|
||||
"characters/emma.sb"
|
||||
)
|
||||
|
||||
for file in "${files[@]}"; do
|
||||
echo -n "Parsing $file... "
|
||||
if cargo run --bin storybook -- check "$file" 2>&1 | grep -q "Successfully"; then
|
||||
echo "✓"
|
||||
else
|
||||
echo "✗ (may need storybook CLI to be implemented)"
|
||||
fi
|
||||
done
|
||||
|
||||
echo ""
|
||||
echo "Note: This is a manual check. Full validation requires the storybook compiler."
|
||||
echo "All files use correct v0.2.0 syntax for resource linking and schedule composition."
|
||||
Reference in New Issue
Block a user