repl

package
v1.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 8, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

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:

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func StripExamples

func StripExamples(doc string) string

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

func NewCompleter(eng *wile.Engine, metaCommands []string) *Completer

NewCompleter creates a completer. eng may be nil if only meta-command completion is needed.

func (*Completer) BindingNames

func (p *Completer) BindingNames() []string

BindingNames returns all binding names visible in the environment.

func (*Completer) Do

func (p *Completer) Do(line []rune, pos int) ([][]rune, int)

Do implements readline.AutoCompleter.

type DebugCommandInfo

type DebugCommandInfo struct {
	Name    string
	Aliases []string
	Summary string
	Detail  string
	Handler func(args []string, out io.Writer)
}

DebugCommandInfo describes a single debug command: its canonical name, aliases, summary text, detail text, and handler function.

type DebugContext

type DebugContext struct {
	// contains filtered or unexported fields
}

DebugContext holds the state for debug commands.

func NewDebugContext

func NewDebugContext() *DebugContext

NewDebugContext creates a new debug context.

func (*DebugContext) DebugCommands

func (p *DebugContext) DebugCommands() []DebugCommandInfo

DebugCommands returns the canonical list of debug commands with bound handlers.

func (*DebugContext) Debugger

func (p *DebugContext) Debugger() *machine.Debugger

Debugger returns the debugger instance.

func (*DebugContext) HandleDebugCommand

func (p *DebugContext) HandleDebugCommand(line string, out io.Writer) bool

HandleDebugCommand processes a debug command starting with ','. Returns true if a command was handled, false otherwise.

func (*DebugContext) SetCurrentMC

func (p *DebugContext) SetCurrentMC(mc *machine.MachineContext)

SetCurrentMC sets the current machine context (for inspection commands).

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.ValueType
	ReturnType values.ValueType
}

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, or category contains pattern
	// (case-insensitive substring match). Results are sorted by name.
	Search(pattern string) []DocSearchResult
	// Categories returns sorted category names.
	Categories() []string
	// ByCategory returns entries in the named category, sorted by name.
	ByCategory(category string) []DocSearchResult
}

DocSearchProvider extends DocProvider with search and category browsing.

type DocSearchResult

type DocSearchResult struct {
	Name     string
	Doc      string
	Category string
}

DocSearchResult holds one search hit.

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

func (p *MetaCommandHandler) Handle(line string, out io.Writer) bool

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 *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.

type Option

type Option func(*REPL)

Option configures a REPL.

func WithCompleter

func WithCompleter(c *Completer) Option

WithCompleter sets an externally-created completer.

func WithContinuationPrompt

func WithContinuationPrompt(prompt string) Option

WithContinuationPrompt sets the continuation prompt for multi-line input.

func WithDebugContext

func WithDebugContext(dc *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

func WithErrorOutput(w io.Writer) Option

WithErrorOutput sets the error output writer.

func WithHistoryFile

func WithHistoryFile(path string) Option

WithHistoryFile sets the history file path.

func WithOutput

func WithOutput(w io.Writer) Option

WithOutput sets the output writer.

func WithPrompt

func WithPrompt(prompt string) Option

WithPrompt sets the primary prompt.

type REPL

type REPL struct {
	// contains filtered or unexported fields
}

REPL is an interactive Read-Eval-Print Loop.

func New

func New(eng *wile.Engine, opts ...Option) *REPL

New creates a new REPL with the given engine and options.

func (*REPL) Debugger

func (p *REPL) Debugger() *machine.Debugger

Debugger returns the REPL's debugger for external configuration.

func (*REPL) Run

func (p *REPL) Run(ctx context.Context) error

Run starts the REPL with readline support, falling back to simple mode if needed.

func (*REPL) RunSimple

func (p *REPL) RunSimple(ctx context.Context) error

RunSimple runs a basic REPL without readline support.

type RegistryDocProvider

type RegistryDocProvider struct {
	// contains filtered or unexported fields
}

RegistryDocProvider adapts a registry.Registry to the DocProvider interface.

func NewRegistryDocProvider

func NewRegistryDocProvider(reg *registry.Registry) *RegistryDocProvider

NewRegistryDocProvider creates a DocProvider backed by the given registry.

func (*RegistryDocProvider) ByCategory

func (p *RegistryDocProvider) ByCategory(category string) []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 primitive from the registry.

func (*RegistryDocProvider) Search

func (p *RegistryDocProvider) Search(pattern string) []DocSearchResult

Search returns entries whose name, doc, or category contains pattern (case-insensitive substring match). Results are sorted by name.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL