This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Bobbin is a narrative scripting language for branching dialogue and interactive stories in video games. It consists of:
- Runtime (
runtime/): Core Rust library implementing the language - Godot Bindings (
bindings/godot/): GDExtension exposing the runtime to Godot 4.5+
cargo test -p bobbin-runtime # Run all tests
cargo test -p bobbin-runtime --test choices # Run specific test filedocker compose run --rm --build godot windows # Fast local build (release)
docker compose run --rm --build godot windows debug # Fast local build (debug)
docker compose run --rm --build godot all # All platforms × all types
docker compose run --rm --build godot all --ci # CI builds (optimized, small binaries)Binaries output to bindings/godot/addons/bobbin/bin/.
Source → Scanner → Parser → AST → Resolver → Compiler → Bytecode → VM
See docs/adr/0001-compiler-architecture.md for the rationale. Key points:
- AST enables tooling (LSP, linter, formatter) without separate parsing
- Bytecode VM supports pause/resume for save games and hot reloading
- Symbol table from semantic analysis enables go-to-definition, autocomplete
| File | Responsibility |
|---|---|
scanner.rs |
Tokenizes source, handles indentation (INDENT/DEDENT tokens) |
parser.rs |
Recursive descent parser producing AST |
resolver.rs |
Semantic analysis: symbol resolution, type checking |
compiler.rs |
Tree-walks AST to emit bytecode |
vm.rs |
Stack-based bytecode interpreter |
storage.rs |
VariableStorage and HostState traits for game integration |
commands.rs |
CommandHandler trait for game effect invocations |
- save: Persistent variables (survive save/load)
- temp: Session-scoped variables (cleared on restart)
- extern: Read-only variables provided by host game at runtime
Storage uses Arc<dyn VariableStorage> with interior mutability (RwLock) for thread-safe shared ownership between game and runtime.
BobbinLanguage: ScriptLanguageExtension for.bobbinfile support in editorBobbinScript: Holds source code for script resourcesBobbinLoader/BobbinSaver: Resource format loaders for.bobbinfilesBobbinRuntime: Main API for games -from_string(),advance(),select_choice(), etc.
Tests live in runtime/tests/ with test data in runtime/tests/cases/. Test runners use sidecar files:
.out- Expected output lines.trace- Interactive execution traces (choices, assertions).err- Expected error substrings
See CONTRIBUTING.md for the trace file format specification.
save gold = 100
temp greeted = false
extern player_name
extern give_item(name, count)
extern play_sound(name)
Welcome, {player_name}!
- Buy sword (50 gold)
set gold = gold - 50
give_item("sword", 1)
play_sound("purchase")
You bought a sword.
- Leave
Goodbye!
See docs/language/grammar.md for the complete EBNF specification.