Documentation
¶
Overview ¶
Package repl provides composable components for building interactive Scheme REPLs on top of the Wile engine.
Components can be used independently or composed into a full REPL:
- REPL: Full read-eval-print loop with readline support
- MetaCommandHandler: Comma-prefixed commands (,doc, ,apropos, etc.)
- Completer: Tab completion for bindings and commands
- github.com/aalpar/wile/pkg/debug.DebugContext: breakpoints, stepping, backtrace
- DocProvider: Documentation lookup interface
- RegistryDocProvider: Registry-backed documentation
All components that need engine access take *wile.Engine at construction time. The REPL composes the other components with sensible defaults; embedders can construct and configure individual components for custom use.
Index ¶
- func StripExamples(doc string) string
- type Completer
- type DocInfo
- type DocProvider
- type DocSearchProvider
- type MetaCommandHandler
- func (p *MetaCommandHandler) Commands() []string
- func (p *MetaCommandHandler) DisassembleBinding(name string) (string, error)
- func (p *MetaCommandHandler) Handle(ctx context.Context, line string, out io.Writer) bool
- func (p *MetaCommandHandler) SetDebugContext(dc *debug.DebugContext)
- func (p *MetaCommandHandler) SetPager(pager string)
- type MetaOption
- type Option
- func WithCompleter(c *Completer) Option
- func WithContinuationPrompt(prompt string) Option
- func WithDebugContext(dc *debug.DebugContext) Option
- func WithDocProvider(dp DocProvider) Option
- func WithErrorOutput(w io.Writer) Option
- func WithHistoryFile(path string) Option
- func WithInput(in io.Reader) Option
- func WithOutput(w io.Writer) Option
- func WithPrompt(prompt string) Option
- func WithVersion(version string) Option
- type REPL
- type RegistryDocProvider
- func (p *RegistryDocProvider) ByCategory(category string) []registry.DocSearchResult
- func (p *RegistryDocProvider) Categories() []string
- func (p *RegistryDocProvider) LookupDoc(name string) (DocInfo, bool)
- func (p *RegistryDocProvider) Search(ctx context.Context, pattern string) []registry.DocSearchResult
- func (p *RegistryDocProvider) UnloadedLibraries(ctx context.Context) []*wile.LibraryInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func StripExamples ¶
StripExamples removes the Examples: section from a docstring. Returns the description portion only. If no Examples: section exists, returns the original string unchanged.
Types ¶
type Completer ¶
type Completer struct {
// contains filtered or unexported fields
}
Completer implements readline.AutoCompleter for a Wile REPL. It completes Scheme bindings, meta-command names, and filenames.
func NewCompleter ¶
NewCompleter creates a completer. eng may be nil if only meta-command completion is needed.
func (*Completer) BindingNames ¶
BindingNames returns all binding names visible in the environment.
type DocInfo ¶
type DocInfo struct {
Doc string
Syntax string // e.g. "(if <test> <consequent> <alternate>)"
TypeLabel string // e.g. "special form", "syntax"
ParamNames []string
Category string
ParamCount int
IsVariadic bool
ParamTypes []values.TypeConstraint
ReturnType values.TypeConstraint
Keywords []string
// Origin is the binding's import-provenance root: the library that DEFINES
// it and the name it is defined under, invariant to any export/import
// renaming along the way. Nil for anything not reached by import (a
// top-level define, a primitive read straight off the registry), which is
// why it is rendered only when present.
Origin *environment.OriginRef
}
DocInfo holds documentation for a primitive binding.
type DocProvider ¶
type DocProvider interface {
// LookupDoc returns documentation for the named primitive.
// Returns found=false if no documentation exists.
LookupDoc(name string) (info DocInfo, found bool)
}
DocProvider looks up documentation for named bindings.
type DocSearchProvider ¶
type DocSearchProvider interface {
DocProvider
// Search returns entries whose name, doc, category, or keywords contain
// pattern (case-insensitive substring match). Results are sorted by name.
Search(ctx context.Context, pattern string) []registry.DocSearchResult
// Categories returns sorted category names.
Categories() []string
// ByCategory returns entries in the named category, sorted by name.
ByCategory(category string) []registry.DocSearchResult
}
DocSearchProvider extends DocProvider with search and category browsing.
type MetaCommandHandler ¶
type MetaCommandHandler struct {
// contains filtered or unexported fields
}
MetaCommandHandler dispatches comma-prefixed meta-commands. Session commands (help, doc, edit) are handled directly; debug commands are delegated to DebugContext.
func NewMetaCommandHandler ¶
func NewMetaCommandHandler(eng *wile.Engine, opts ...MetaOption) *MetaCommandHandler
NewMetaCommandHandler creates a new meta-command handler.
func (*MetaCommandHandler) Commands ¶
func (p *MetaCommandHandler) Commands() []string
Commands returns all meta-command names and aliases (session + debug) for autocomplete.
func (*MetaCommandHandler) DisassembleBinding ¶
func (p *MetaCommandHandler) DisassembleBinding(name string) (string, error)
DisassembleBinding looks up a named binding and returns its formatted disassembly. Returns an error if the name is unbound, nil, or not a procedure. Exported for use by the MCP handler.
func (*MetaCommandHandler) Handle ¶
Handle processes a line starting with ",". Returns true if the line was a meta-command (even if unrecognized), false if it's not a meta-command.
func (*MetaCommandHandler) SetDebugContext ¶
func (p *MetaCommandHandler) SetDebugContext(dc *debug.DebugContext)
SetDebugContext attaches a debug context for debug command delegation.
func (*MetaCommandHandler) SetPager ¶
func (p *MetaCommandHandler) SetPager(pager string)
SetPager overrides the pager command used for long output. Pass "" to disable paging (e.g., for non-TTY contexts like MCP).
type MetaOption ¶
type MetaOption func(*MetaCommandHandler)
MetaOption configures a MetaCommandHandler.
func WithMetaDocProvider ¶
func WithMetaDocProvider(dp DocProvider) MetaOption
WithMetaDocProvider sets the documentation provider for the meta handler.
func WithMetaVersion ¶
func WithMetaVersion(version string) MetaOption
WithMetaVersion sets the version string shown by the ,version command.
type Option ¶
type Option func(*REPL)
Option configures a REPL.
func WithCompleter ¶
WithCompleter sets an externally-created completer.
func WithContinuationPrompt ¶
WithContinuationPrompt sets the continuation prompt for multi-line input.
func WithDebugContext ¶
func WithDebugContext(dc *debug.DebugContext) Option
WithDebugContext sets an externally-created debug context.
func WithDocProvider ¶
func WithDocProvider(dp DocProvider) Option
WithDocProvider sets the documentation provider for the ,doc command.
func WithErrorOutput ¶
WithErrorOutput sets the error output writer.
func WithHistoryFile ¶
WithHistoryFile sets the history file path.
func WithInput ¶
WithInput sets the input reader used by the simple (non-readline) loop. Defaults to os.Stdin. The readline loop reads from the terminal directly and is unaffected by this option.
func WithVersion ¶
WithVersion sets the version string shown by the ,version meta-command.
type REPL ¶
type REPL struct {
// contains filtered or unexported fields
}
REPL is an interactive Read-Eval-Print Loop.
type RegistryDocProvider ¶
type RegistryDocProvider struct {
// contains filtered or unexported fields
}
RegistryDocProvider adapts a registry.PrimitiveRegistry to the DocProvider interface.
func NewRegistryDocProvider ¶
func NewRegistryDocProvider(reg *registry.PrimitiveRegistry, eng *wile.Engine) *RegistryDocProvider
NewRegistryDocProvider creates a DocProvider backed by the given registry. eng may be nil; when non-nil, Search includes loaded and unloaded libraries.
func (*RegistryDocProvider) ByCategory ¶
func (p *RegistryDocProvider) ByCategory(category string) []registry.DocSearchResult
ByCategory returns entries in the named category, sorted by name.
func (*RegistryDocProvider) Categories ¶
func (p *RegistryDocProvider) Categories() []string
Categories returns sorted category names, excluding the empty-string category.
func (*RegistryDocProvider) LookupDoc ¶
func (p *RegistryDocProvider) LookupDoc(name string) (DocInfo, bool)
LookupDoc returns documentation for the named binding from the registry. It checks primitives first, then falls back to binding specs and doc entries.
func (*RegistryDocProvider) Search ¶
func (p *RegistryDocProvider) Search(ctx context.Context, pattern string) []registry.DocSearchResult
Search returns entries whose name, doc, category, or keywords contain pattern (case-insensitive substring match). Results are sorted by name. Delegates to registry.SearchDoc for non-library results, then appends library results from the Engine's loaded and unloaded library methods.
The library matching logic here mirrors registry.SearchDoc's searchLibraries/searchUnloadedExports functions but operates on wile.LibraryInfo instead of compilation.* types. This duplication is a structural consequence of decoupling repl/ from machine/compilation/.
func (*RegistryDocProvider) UnloadedLibraries ¶
func (p *RegistryDocProvider) UnloadedLibraries(ctx context.Context) []*wile.LibraryInfo
UnloadedLibraries returns info for libraries that are discoverable via the file resolver but not yet imported. Returns nil if no engine is available.