How expr-lang/expr works
Expr is a Go expression language for safely compiling and evaluating expressions against Go-provided environments. The main workflow is expression input through parsing, static checking and optimization to bytecode, then VM evaluation and a result. Separate capabilities include built-ins, environment/type modeling, AST tools, context/operator patching, documentation generation, debugging and an interactive REPL. The workflow links are grounded in the README and SOURCE INDEX references; unsampled implementation details are not expanded into additional call edges.
Main entry points: expr.go Expr API · parser.go Parser · checker.go Type Checker · vm.go Virtual Machine
Components 19
Language Front End
- Expr API
expr.go - Parser
parser/parser.go - Lexer
parser/lexer/lexer.go - Expression AST
ast/node.go - Type Checker
checker/checker.go - Type Model
checker/nature/nature.go
Compilation and Runtime
- Optimizer
optimizer/fold.go - Bytecode Compiler
compiler/compiler.go - Bytecode Program
vm/program.go - Virtual Machine
vm/vm.go - Runtime Helpers
vm/runtime/runtime.go
Language Extensions
- Built-in Functions
builtin/builtin.go - Environment Config
conf/env.go - Expression Patching
patcher/with_context.go
Developer Tools
- Type Documentation
docgen/docgen.go - VM Debugger
debug/debugger.go - Interactive REPL
repl/repl.go
Other components
- Go Caller
- Evaluation Result
Connections 21
- Go Caller → Expr API: supplies expression
README.md - Expr API → Parser: parses input
expr.go - Parser → Lexer: reads tokens
parser/parser.go - Parser → Expression AST: builds tree
- Expr API → Type Checker: type-checks
expr.go - Type Checker → Type Model: uses type model
checker/checker.go - Expr API → Optimizer: optimizes tree
expr.go - Expr API → Bytecode Compiler: compiles expression
expr.go - Bytecode Compiler → Bytecode Program: emits bytecode
compiler/compiler.go - Expr API → Virtual Machine: runs program
expr.go - Virtual Machine → Runtime Helpers: uses helpers
vm/vm.go - Built-in Functions → Runtime Helpers: uses helpers
builtin/builtin.go - Environment Config → Type Checker: provides environment types
- Expr API → Evaluation Result: returns evaluation
README.md - Go Caller → Type Documentation: requests type docs
- Go Caller → VM Debugger: starts debugging
- VM Debugger → Virtual Machine: inspects program
debug/debugger.go - Go Caller → Interactive REPL: enters expressions
repl/repl.go - Interactive REPL → Expr API: compiles and runs
repl/repl.go - Go Caller → Expression Patching: configures patches
- Expression Patching → Expression AST: rewrites calls
patcher/with_context.go