repl

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package repl provides the read-eval-print loop for interactive M28 sessions.

Index

Constants

View Source
const (
	ColorReset     = "\033[0m"
	ColorBold      = "\033[1m"
	ColorDim       = "\033[2m"
	ColorUnderline = "\033[4m"

	// Regular colors
	ColorBlack   = "\033[30m"
	ColorRed     = "\033[31m"
	ColorGreen   = "\033[32m"
	ColorYellow  = "\033[33m"
	ColorBlue    = "\033[34m"
	ColorMagenta = "\033[35m"
	ColorCyan    = "\033[36m"
	ColorWhite   = "\033[37m"

	// Bright colors
	ColorBrightBlack   = "\033[90m"
	ColorBrightRed     = "\033[91m"
	ColorBrightGreen   = "\033[92m"
	ColorBrightYellow  = "\033[93m"
	ColorBrightBlue    = "\033[94m"
	ColorBrightMagenta = "\033[95m"
	ColorBrightCyan    = "\033[96m"
	ColorBrightWhite   = "\033[97m"
)

ANSI color codes

Variables

This section is empty.

Functions

func CompleteFilename

func CompleteFilename(prefix string) []string

CompleteFilename returns filename completions for the given prefix

Types

type ColorManager

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

ColorManager manages syntax highlighting

func NewColorManager

func NewColorManager(enabled bool) *ColorManager

NewColorManager creates a new color manager

func (*ColorManager) Colorize

func (cm *ColorManager) Colorize(text, color string) string

Colorize applies color to text if colors are enabled

func (*ColorManager) ColorizeError

func (cm *ColorManager) ColorizeError(text string) string

ColorizeError colors error messages

func (*ColorManager) ColorizeOutputPrompt

func (cm *ColorManager) ColorizeOutputPrompt(prompt string) string

ColorizeOutputPrompt colors the output prompt

func (*ColorManager) ColorizePrompt

func (cm *ColorManager) ColorizePrompt(prompt string) string

ColorizePrompt colors the input prompt

func (*ColorManager) ColorizeSyntax

func (cm *ColorManager) ColorizeSyntax(code string) string

ColorizeSyntax applies syntax highlighting to M28 code

func (*ColorManager) IsEnabled

func (cm *ColorManager) IsEnabled() bool

IsEnabled returns whether colors are enabled

func (*ColorManager) SetEnabled

func (cm *ColorManager) SetEnabled(enabled bool)

SetEnabled enables or disables colors

type ColorTheme

type ColorTheme struct {
	Keyword      string
	String       string
	Number       string
	Comment      string
	Function     string
	Variable     string
	Operator     string
	Parenthesis  string
	Error        string
	Prompt       string
	Output       string
	OutputPrompt string
}

ColorTheme defines colors for different syntax elements

func DefaultTheme

func DefaultTheme() *ColorTheme

DefaultTheme returns the default color theme

type CommandFlags

type CommandFlags struct {
	ShowHelp      bool
	EvalCode      string
	Command       string
	Filenames     []string
	Interactive   bool
	HistorySize   int
	NoHistoryFile bool
	Debug         bool
}

CommandFlags holds the parsed command line arguments

func ParseFlags

func ParseFlags() *CommandFlags

ParseFlags parses command line arguments and returns the configuration

type CommandHandler

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

CommandHandler handles REPL-specific commands

func NewCommandHandler

func NewCommandHandler(repl *REPL) *CommandHandler

NewCommandHandler creates a new command handler

func (*CommandHandler) GetCommandToExecute

func (ch *CommandHandler) GetCommandToExecute() string

GetCommandToExecute returns the command to execute after handling

func (*CommandHandler) HandleCommand

func (ch *CommandHandler) HandleCommand(input string) (bool, error)

HandleCommand processes a REPL command and returns whether it was handled

func (*CommandHandler) IsCommand

func (ch *CommandHandler) IsCommand(input string) bool

IsCommand checks if the input is a REPL command

type Completer

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

Completer provides tab completion for the REPL

func NewCompleter

func NewCompleter(ctx *core.Context) *Completer

NewCompleter creates a new completer

func (*Completer) Complete

func (c *Completer) Complete(prefix string) []string

Complete returns completions for the given prefix

type ErrorReporter

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

ErrorReporter provides enhanced error reporting

func NewErrorReporter

func NewErrorReporter(colorManager *ColorManager) *ErrorReporter

NewErrorReporter creates a new error reporter

func (*ErrorReporter) AddSource

func (er *ErrorReporter) AddSource(filename, source string)

AddSource adds source code for error reporting

func (*ErrorReporter) ReportError

func (er *ErrorReporter) ReportError(err error, ctx *core.Context, w io.Writer)

ReportError reports an error with context

type ExecutionState

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

ExecutionState tracks the state of REPL execution including counters and output history

func NewExecutionState

func NewExecutionState(ctx *core.Context) *ExecutionState

NewExecutionState creates a new execution state manager

func (*ExecutionState) ClearLastPrintOutput

func (es *ExecutionState) ClearLastPrintOutput()

ClearLastPrintOutput clears the last print output

func (*ExecutionState) FormatContinuationPrompt

func (es *ExecutionState) FormatContinuationPrompt() string

FormatContinuationPrompt formats the continuation prompt with proper indentation

func (*ExecutionState) FormatInputPrompt

func (es *ExecutionState) FormatInputPrompt() string

FormatInputPrompt formats the input prompt with execution number

func (*ExecutionState) FormatOutputPrompt

func (es *ExecutionState) FormatOutputPrompt(num int) string

FormatOutputPrompt formats the output prompt with execution number

func (*ExecutionState) GetExecutionNumber

func (es *ExecutionState) GetExecutionNumber() int

GetExecutionNumber returns the current execution number

func (*ExecutionState) GetLastOutput

func (es *ExecutionState) GetLastOutput() core.Value

GetLastOutput returns the last output value

func (*ExecutionState) GetLastPrintOutput

func (es *ExecutionState) GetLastPrintOutput() string

GetLastPrintOutput returns the last print output

func (*ExecutionState) IsOutputDuplicate

func (es *ExecutionState) IsOutputDuplicate(output string) bool

IsOutputDuplicate checks if the output is a duplicate of the last print

func (*ExecutionState) NextExecutionNumber

func (es *ExecutionState) NextExecutionNumber() int

NextExecutionNumber increments and returns the next execution number

func (*ExecutionState) SetLastPrintOutput

func (es *ExecutionState) SetLastPrintOutput(output string)

SetLastPrintOutput sets the last print output to track duplicates

func (*ExecutionState) StoreOutput

func (es *ExecutionState) StoreOutput(num int, value core.Value) error

StoreOutput stores the output value in history and updates context variables

type HelpSystem

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

HelpSystem provides help and documentation for the REPL

func NewHelpSystem

func NewHelpSystem(ctx *core.Context) *HelpSystem

NewHelpSystem creates a new help system

func (*HelpSystem) ShowHelp

func (h *HelpSystem) ShowHelp(topic string, w io.Writer)

ShowHelp displays help for a specific topic or general help

type History

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

History manages REPL command history

func NewHistory

func NewHistory(maxSize int) *History

NewHistory creates a new history manager

func (*History) Add

func (h *History) Add(cmd string)

Add adds a command to history

func (*History) FindByPrefix

func (h *History) FindByPrefix(prefix string) string

FindByPrefix finds the most recent command starting with the given prefix

func (*History) GetCommand

func (h *History) GetCommand(position int) string

GetCommand returns the command at the given position (1-based)

func (*History) GetLastN

func (h *History) GetLastN(n int) []string

GetLastN returns the last n commands from history

func (*History) GetTotalCount

func (h *History) GetTotalCount() int

GetTotalCount returns the total number of commands ever entered

func (*History) Next

func (h *History) Next() (string, bool)

Next returns the next command in history

func (*History) Previous

func (h *History) Previous() (string, bool)

Previous returns the previous command in history

func (*History) Reset

func (h *History) Reset()

Reset resets the history position

type IndentationTracker

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

IndentationTracker tracks and manages indentation for multi-line input

func NewIndentationTracker

func NewIndentationTracker() *IndentationTracker

NewIndentationTracker creates a new indentation tracker

func (*IndentationTracker) AnalyzeLine

func (it *IndentationTracker) AnalyzeLine(line string) (indentChange int)

AnalyzeLine analyzes a line and returns the appropriate indentation change

func (*IndentationTracker) DetectDedent

func (it *IndentationTracker) DetectDedent(line string) bool

DetectDedent checks if a line represents a dedent

func (*IndentationTracker) GetIndentation

func (it *IndentationTracker) GetIndentation() string

GetIndentation returns the current indentation string

func (*IndentationTracker) Reset

func (it *IndentationTracker) Reset()

Reset resets the indentation level

func (*IndentationTracker) SetLevelFromLine

func (it *IndentationTracker) SetLevelFromLine(line string)

SetLevelFromLine sets the indentation level based on leading spaces

func (*IndentationTracker) UpdateLevel

func (it *IndentationTracker) UpdateLevel(line string)

UpdateLevel updates the indentation level based on the line

type OutputTracker

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

OutputTracker wraps an io.Writer and tracks what was printed

func NewOutputTracker

func NewOutputTracker(writer io.Writer) *OutputTracker

NewOutputTracker creates a new output tracker

func (*OutputTracker) ClearLastOutput

func (ot *OutputTracker) ClearLastOutput()

ClearLastOutput clears the last tracked output

func (*OutputTracker) GetLastOutput

func (ot *OutputTracker) GetLastOutput() string

GetLastOutput returns the last tracked output

func (*OutputTracker) StartTracking

func (ot *OutputTracker) StartTracking()

StartTracking starts tracking output

func (*OutputTracker) StopTracking

func (ot *OutputTracker) StopTracking() string

StopTracking stops tracking and returns the tracked output

func (*OutputTracker) Write

func (ot *OutputTracker) Write(p []byte) (n int, err error)

Write implements io.Writer

type REPL

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

REPL represents a read-eval-print loop

func NewREPL

func NewREPL(globalCtx *core.Context) *REPL

NewREPL creates a new REPL with the given context

func (*REPL) IsReadlineEnabled added in v0.2.0

func (r *REPL) IsReadlineEnabled() bool

IsReadlineEnabled returns whether readline is enabled

func (*REPL) SetInput

func (r *REPL) SetInput(reader io.Reader)

SetInput sets the input reader for the REPL

func (*REPL) SetKeyBindingMode added in v0.2.0

func (r *REPL) SetKeyBindingMode(mode string) error

SetKeyBindingMode sets the key binding mode (vi or emacs)

func (*REPL) SetOutput

func (r *REPL) SetOutput(writer io.Writer)

SetOutput sets the output writer for the REPL

func (*REPL) SetPythonMode added in v0.3.0

func (r *REPL) SetPythonMode(enabled bool)

SetPythonMode enables or disables Python syntax parsing mode

func (*REPL) Start

func (r *REPL) Start()

Start starts the REPL

type REPLSettings

type REPLSettings struct {
	KeybindingMode string // "emacs" or "vi"
	ColorsEnabled  bool
	HistorySize    int
}

REPLSettings stores configurable REPL settings

type ReadlineInput added in v0.2.0

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

ReadlineInput provides readline-based input handling for the REPL

func NewReadlineInput added in v0.2.0

func NewReadlineInput(completer *Completer, history *History, colorManager *ColorManager, indentTracker *IndentationTracker) (*ReadlineInput, error)

NewReadlineInput creates a new readline input handler

func (*ReadlineInput) Close added in v0.2.0

func (ri *ReadlineInput) Close() error

Close closes the readline instance

func (*ReadlineInput) ReadLine added in v0.2.0

func (ri *ReadlineInput) ReadLine(prompt string) (string, error)

ReadLine reads a line of input with all readline features

func (*ReadlineInput) ReadMultiLine added in v0.2.0

func (ri *ReadlineInput) ReadMultiLine(firstLine string) (string, error)

ReadMultiLine reads multiple lines for incomplete expressions

func (*ReadlineInput) SetPrompt added in v0.2.0

func (ri *ReadlineInput) SetPrompt(prompt string)

SetPrompt updates the prompt

func (*ReadlineInput) SetPythonMode added in v0.3.0

func (ri *ReadlineInput) SetPythonMode(enabled bool)

SetPythonMode enables or disables Python syntax parsing mode

func (*ReadlineInput) SetViMode added in v0.2.0

func (ri *ReadlineInput) SetViMode(enabled bool) error

SetViMode switches between vi and emacs modes

func (*ReadlineInput) Terminal added in v0.2.0

func (ri *ReadlineInput) Terminal() *readline.Terminal

Terminal returns the underlying terminal

Jump to

Keyboard shortcuts

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