This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
make run # Build and run Ghost REPL
make build # Build for all platforms (mac/linux/windows)
make test # Run all tests with colored output
go test -v ./evaluator/... # Run tests for a specific packageGhost is a tree-walking interpreter written in Go. The execution pipeline follows this flow:
Source Code → Scanner → Parser → AST → Evaluator → Object
- scanner/ - Lexical analysis. Transforms source into tokens. Keywords defined in
scanner/scanner.go:21-48. - token/ - Token type definitions and the Token struct containing lexeme, literal, position info.
- parser/ - Recursive descent parser using Pratt parsing. Each AST node type has its own parsing function (e.g.,
parser/function.go,parser/if.go). - ast/ - Abstract syntax tree node definitions. Base interfaces in
ast/ast.go:Node,StatementNode,ExpressionNode. - evaluator/ - Tree-walking evaluation. Main entry point is
Evaluate()inevaluator/evaluator.go:15. Each AST node type has a correspondingevaluate*function. - object/ - Runtime value types (Number, String, Boolean, List, Map, Function, Class, etc.). The
Objectinterface (object/object.go:15-19) requiresType(),String(), andMethod(). - ghost/ - Main Ghost struct that orchestrates the pipeline (
ghost/ghost.go). Entry point for embedding Ghost in Go applications.
- Scope: Wraps Environment and tracks
Selffor method calls (object/scope.go). - Environment: Variable storage with parent chain for lexical scoping (
object/environment.go). - Library system: Native functions and modules registered via
library.RegisterFunction()andlibrary.RegisterModule(). Built-in modules inlibrary/modules/.
All object types implement the Method(method string, args []Object) (Object, bool) interface. Methods are defined directly on object types (e.g., string methods in object/string.go).
Ghost supports: classes with inheritance (extends), traits (trait/use), first-class functions, closures, lists, maps, for/for-in/while loops, switch statements, imports, and compound operators (+=, ++, etc.).
Update version/version.go when releasing. GoReleaser handles binary distribution.