feat: implement storybook DSL with template composition and validation
Add complete domain-specific language for authoring narrative content for agent simulations. Features: - Complete parser using LALRPOP + logos lexer - Template composition (includes + multiple inheritance) - Strict mode validation for templates - Reserved keyword protection - Semantic validators (trait ranges, schedule overlaps, life arcs, behaviors) - Name resolution and cross-reference tracking - CLI tool (validate, inspect, query commands) - Query API with filtering - 260 comprehensive tests (unit, integration, property-based) Implementation phases: - Phase 1 (Parser): Complete - Phase 2 (Resolution + Validation): Complete - Phase 3 (Public API + CLI): Complete BREAKING CHANGE: Initial implementation
This commit is contained in:
113
tests/examples/field_access.sb
Normal file
113
tests/examples/field_access.sb
Normal file
@@ -0,0 +1,113 @@
|
||||
// Test field access in relationship contexts
|
||||
|
||||
relationship Marriage {
|
||||
PersonA as spouse
|
||||
PersonB as spouse
|
||||
|
||||
self {
|
||||
bond: 0.8
|
||||
}
|
||||
other {
|
||||
bond: 0.8
|
||||
}
|
||||
}
|
||||
|
||||
life_arc RelationshipDynamics {
|
||||
state stable {
|
||||
// Field access with comparisons
|
||||
on self.bond < 0.3 -> troubled
|
||||
on other.bond < 0.3 -> troubled
|
||||
on self.bond > 0.9 and other.bond > 0.9 -> thriving
|
||||
}
|
||||
|
||||
state troubled {
|
||||
on self.bond > 0.7 and other.bond > 0.7 -> stable
|
||||
on self.bond < 0.1 or other.bond < 0.1 -> broken
|
||||
}
|
||||
|
||||
state thriving {
|
||||
on self.bond < 0.8 or other.bond < 0.8 -> stable
|
||||
}
|
||||
|
||||
state broken {
|
||||
on self.bond > 0.5 and other.bond > 0.5 -> troubled
|
||||
}
|
||||
}
|
||||
|
||||
life_arc CharacterStates {
|
||||
state monitoring {
|
||||
// Field access with self
|
||||
on self.age > 18 -> adult
|
||||
on self.energy < 0.2 -> exhausted
|
||||
on self.health < 30 -> sick
|
||||
|
||||
// Field access with equality
|
||||
on self.status is active -> active_state
|
||||
on self.ready is true -> ready_state
|
||||
}
|
||||
|
||||
state adult {
|
||||
on self.age < 18 -> monitoring
|
||||
}
|
||||
|
||||
state exhausted {
|
||||
on self.energy > 0.7 -> monitoring
|
||||
}
|
||||
|
||||
state sick {
|
||||
on self.health > 80 -> monitoring
|
||||
}
|
||||
|
||||
state active_state {
|
||||
on self.status is inactive -> monitoring
|
||||
}
|
||||
|
||||
state ready_state {
|
||||
on self.ready is false -> monitoring
|
||||
}
|
||||
}
|
||||
|
||||
life_arc ComplexFieldAccess {
|
||||
state checking {
|
||||
// Nested field access patterns
|
||||
on self.stats.health > 50 -> healthy
|
||||
on other.profile.age < 18 -> young_other
|
||||
|
||||
// Field access with logical operators
|
||||
on self.energy > 0.5 and self.health > 70 -> strong
|
||||
on not self.ready -> waiting
|
||||
on self.completed is true or other.completed is true -> done
|
||||
|
||||
// Mixed field access and regular identifiers
|
||||
on self.score > threshold -> passed
|
||||
on other.level is beginner and difficulty > 5 -> too_hard
|
||||
}
|
||||
|
||||
state healthy {
|
||||
on self.stats.health < 30 -> checking
|
||||
}
|
||||
|
||||
state young_other {
|
||||
on other.profile.age >= 18 -> checking
|
||||
}
|
||||
|
||||
state strong {
|
||||
on self.energy < 0.3 or self.health < 50 -> checking
|
||||
}
|
||||
|
||||
state waiting {
|
||||
on self.ready -> checking
|
||||
}
|
||||
|
||||
state done {
|
||||
on self.completed is false and other.completed is false -> checking
|
||||
}
|
||||
|
||||
state passed {
|
||||
on self.score < threshold -> checking
|
||||
}
|
||||
|
||||
state too_hard {
|
||||
on other.level is advanced or difficulty < 3 -> checking
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user