Documentation
¶
Overview ¶
Package repl provides the read-eval-print loop for interactive M28 sessions.
Index ¶
- Constants
- func CompleteFilename(prefix string) []string
- type ColorManager
- func (cm *ColorManager) Colorize(text, color string) string
- func (cm *ColorManager) ColorizeError(text string) string
- func (cm *ColorManager) ColorizeOutputPrompt(prompt string) string
- func (cm *ColorManager) ColorizePrompt(prompt string) string
- func (cm *ColorManager) ColorizeSyntax(code string) string
- func (cm *ColorManager) IsEnabled() bool
- func (cm *ColorManager) SetEnabled(enabled bool)
- type ColorTheme
- type CommandFlags
- type CommandHandler
- type Completer
- type ErrorReporter
- type ExecutionState
- func (es *ExecutionState) ClearLastPrintOutput()
- func (es *ExecutionState) FormatContinuationPrompt() string
- func (es *ExecutionState) FormatInputPrompt() string
- func (es *ExecutionState) FormatOutputPrompt(num int) string
- func (es *ExecutionState) GetExecutionNumber() int
- func (es *ExecutionState) GetLastOutput() core.Value
- func (es *ExecutionState) GetLastPrintOutput() string
- func (es *ExecutionState) IsOutputDuplicate(output string) bool
- func (es *ExecutionState) NextExecutionNumber() int
- func (es *ExecutionState) SetLastPrintOutput(output string)
- func (es *ExecutionState) StoreOutput(num int, value core.Value) error
- type HelpSystem
- type History
- func (h *History) Add(cmd string)
- func (h *History) FindByPrefix(prefix string) string
- func (h *History) GetCommand(position int) string
- func (h *History) GetLastN(n int) []string
- func (h *History) GetTotalCount() int
- func (h *History) Next() (string, bool)
- func (h *History) Previous() (string, bool)
- func (h *History) Reset()
- type IndentationTracker
- func (it *IndentationTracker) AnalyzeLine(line string) (indentChange int)
- func (it *IndentationTracker) DetectDedent(line string) bool
- func (it *IndentationTracker) GetIndentation() string
- func (it *IndentationTracker) Reset()
- func (it *IndentationTracker) SetLevelFromLine(line string)
- func (it *IndentationTracker) UpdateLevel(line string)
- type OutputTracker
- type REPL
- type REPLSettings
- type ReadlineInput
- func (ri *ReadlineInput) Close() error
- func (ri *ReadlineInput) ReadLine(prompt string) (string, error)
- func (ri *ReadlineInput) ReadMultiLine(firstLine string) (string, error)
- func (ri *ReadlineInput) SetPrompt(prompt string)
- func (ri *ReadlineInput) SetPythonMode(enabled bool)
- func (ri *ReadlineInput) SetViMode(enabled bool) error
- func (ri *ReadlineInput) Terminal() *readline.Terminal
Constants ¶
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 ¶
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
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 ¶
NewCompleter creates a new completer
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 ¶
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
type History ¶
type History struct {
// contains filtered or unexported fields
}
History manages REPL command history
func (*History) FindByPrefix ¶
FindByPrefix finds the most recent command starting with the given prefix
func (*History) GetCommand ¶
GetCommand returns the command at the given position (1-based)
func (*History) GetTotalCount ¶
GetTotalCount returns the total number of commands ever entered
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
type REPL ¶
type REPL struct {
// contains filtered or unexported fields
}
REPL represents a read-eval-print loop
func (*REPL) IsReadlineEnabled ¶ added in v0.2.0
IsReadlineEnabled returns whether readline is enabled
func (*REPL) SetKeyBindingMode ¶ added in v0.2.0
SetKeyBindingMode sets the key binding mode (vi or emacs)
func (*REPL) SetPythonMode ¶ added in v0.3.0
SetPythonMode enables or disables Python syntax parsing mode
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