Documentation
¶
Index ¶
- Constants
- Variables
- func AppendHistoryEntries(path string, entries []string) error
- func ApplyReplConfig(env *object.Environment, cfg *ReplConfig)
- func ApplyReplProfile(cfg *ReplConfig, profile string) error
- func ColorEnabled() bool
- func ColorizeInputLine(line string) string
- func CurrentToken(buf []rune, cursor int) (prefix string, start int, end int, ok bool)
- func EvalReplInput(input string, env *object.Environment)
- func FindCompletions(prefix string, candidates []string) []string
- func FormatObjectForDisplay(obj object.Object) string
- func FormatObjectForDisplayWithEnv(obj object.Object, env *object.Environment) string
- func FormatObjectPlain(obj object.Object) string
- func FormatRuntimeErrorForDisplay(obj object.Object, source string) string
- func HandleReplMetaCommand(line string, editor *ReplEditor, env *object.Environment) bool
- func HistoryEntriesToPersist(history []string, from int) []string
- func IsTerminal(f *os.File) bool
- func LoadHistoryEntries(path string) ([]string, error)
- func LongestCommonPrefix(items []string) string
- func LooksLikeDateString(s string) bool
- func Paint(s, code string) string
- func ParseHistoryData(data []byte) []string
- func PrintWelcome(env *object.Environment)
- func ReplActiveCall(line string, cursor int) (name string, argIndex int, ok bool)
- func ReplBuiltinArgHint(detail string, argIndex int) string
- func ReplBuiltinCallTip(name string, argIndex int) string
- func ReplBuiltinDetail(name string) string
- func ReplCallTip(line string, cursor int, env *object.Environment) string
- func ReplCandidates() []string
- func ReplCandidatesForEnv(env *object.Environment) []string
- func ReplCommandDetail(name string) string
- func ReplCommandNames() []string
- func ReplCommandsTable(query string) string
- func ReplCompactHint(text string, maxRunes int) string
- func ReplConfigTable(env *object.Environment) string
- func ReplDocText(name string, env *object.Environment) string
- func ReplEvalSource(input string, env *object.Environment, sourcePath string, printResult bool)
- func ReplExamplesText() string
- func ReplFunctionCallTip(name string, fn *object.Function, argIndex int) string
- func ReplFunctionParamTip(fn *object.Function, argIndex int) string
- func ReplFunctionSignature(name string, fn *object.Function) string
- func ReplHintLines(text string, width int) []string
- func ReplInstallDependency(alias, source string, env *object.Environment) error
- func ReplMemoryUsage() string
- func ReplNeedsContinuation(input string) bool
- func ReplObjectFields(obj object.Object) []string
- func ReplObjectMethods(obj object.Object) []string
- func ReplPalette(query string, editor *ReplEditor, env *object.Environment) string
- func ReplParseProgram(input string) (any, []string)
- func ReplPrintLine(s string)
- func ReplResolvedPath(path string, env *object.Environment) (string, error)
- func ReplTipsText() string
- func ReplToolsText() string
- func RunReplBasic(env *object.Environment)
- func RunReplInteractive(env *object.Environment) error
- func StyleContinuationPrompt(p string) string
- func StylePrompt(p string) string
- type NativeCommandResult
- type ReplCompletionContext
- type ReplConfig
- type ReplEditor
- func (e *ReplEditor) CompletionsForContext(ctx ReplCompletionContext) []string
- func (e *ReplEditor) InlineHint(line string, cursor int) string
- func (e *ReplEditor) RecordInput(input string)
- func (e *ReplEditor) ReverseHistorySearch(current []rune) ([]rune, int)
- func (e *ReplEditor) SuggestionLines(ctx ReplCompletionContext, candidates []string, width int) []string
Constants ¶
const ( ColorReset = "\033[0m" ColorBold = "\033[1m" ColorDim = "\033[2m" ColorRed = "\033[31m" ColorGreen = "\033[32m" ColorYellow = "\033[33m" ColorBlue = "\033[34m" ColorMagenta = "\033[35m" ColorCyan = "\033[36m" ColorGray = "\033[90m" )
Variables ¶
var ( TOKEN_EOF int TOKEN_LPAREN int TOKEN_RPAREN int TOKEN_LBRACE int TOKEN_RBRACE int TOKEN_LBRACKET int TOKEN_RBRACKET int TOKEN_ASSIGN int TOKEN_PLUS int TOKEN_MINUS int TOKEN_MULTIPLY int TOKEN_DIVIDE int TOKEN_MODULO int TOKEN_EQ int TOKEN_NEQ int TOKEN_LT int TOKEN_GT int TOKEN_LTE int TOKEN_GTE int TOKEN_AND int TOKEN_OR int TOKEN_BITAND int TOKEN_BITOR int TOKEN_BITXOR int TOKEN_COMMA int TOKEN_COLON int TOKEN_DOT int TOKEN_LET int TOKEN_CONST int TOKEN_RETURN int TOKEN_IF int TOKEN_ELSE int TOKEN_FOR int TOKEN_WHILE int TOKEN_FUNCTION int TOKEN_TRY int TOKEN_CATCH int TOKEN_SWITCH int TOKEN_CASE int TOKEN_THROW int TOKEN_IMPORT int TOKEN_EXPORT int )
var BuiltinHelpTextFn func(name string) string
BuiltinHelpTextFn returns help text for a builtin.
var BuiltinNames func() map[string]struct{}
BuiltinNames returns all registered builtin names.
var DispatchHotReloadHooksFn func(path string)
DispatchHotReloadHooksFn fires hot-reload hooks for a path.
var EvalFn func(node any, env *object.Environment) object.Object
EvalFn evaluates an AST node in the given environment.
var FormatCallStackFn func(stack []object.CallFrame) string
FormatCallStackFn formats call-stack frames.
var HasBuiltinFn func(name string) bool
HasBuiltinFn returns true if a builtin with the given name exists.
var IsErrorFn func(obj object.Object) bool
IsErrorFn returns true if the object is an Error.
var LexerNextTokenFn func(lexer any) (tokenType int, literal string)
LexerNextTokenFn returns the next token from a lexer. Token is returned as (tokenType int, literal string).
var LineContextFn func(source string, line, column int) string
LineContextFn extracts a source-line context snippet.
var LoadConfigObjectFromPathFn func(path, format string) (object.Object, error)
LoadConfigObjectFromPathFn loads a config file.
var NewLexerFn func(input string) any
NewLexerFn creates a new lexer from source input.
var NewParserFn func(lexer any) any
NewParserFn creates a new parser from a lexer.
var ObjectErrorStringFn func(obj object.Object) string
ObjectErrorStringFn formats an error object as a string.
var ParseProgramFn func(parser any) (program any, errors []string)
ParseProgramFn parses and returns (program, errors).
var ResolveImportPathFn func(path string, env *object.Environment) (string, error)
ResolveImportPathFn resolves an import path to a file system path.
var RunNativeCommandLineFn func(env *object.Environment, command string, args []string) NativeCommandResult
var RunProgramSandboxedFn func(program any, env *object.Environment, policy *object.SecurityPolicy) object.Object
RunProgramSandboxedFn evaluates a program in the sandbox.
Functions ¶
func AppendHistoryEntries ¶
func ApplyReplConfig ¶
func ApplyReplConfig(env *object.Environment, cfg *ReplConfig)
func ApplyReplProfile ¶
func ApplyReplProfile(cfg *ReplConfig, profile string) error
func ColorEnabled ¶
func ColorEnabled() bool
ColorEnabled checks whether the terminal supports colours.
func ColorizeInputLine ¶
ColorizeInputLine applies syntax highlighting to a single input line.
func CurrentToken ¶
func EvalReplInput ¶
func EvalReplInput(input string, env *object.Environment)
EvalReplInput evaluates a complete REPL input string.
func FindCompletions ¶
func FormatObjectForDisplay ¶
FormatObjectForDisplay returns a colourised representation of an object for interactive REPL display.
func FormatObjectForDisplayWithEnv ¶
func FormatObjectForDisplayWithEnv(obj object.Object, env *object.Environment) string
func FormatObjectPlain ¶
FormatObjectPlain produces a plain-text representation of an object, suitable for REPL output.
func FormatRuntimeErrorForDisplay ¶
FormatRuntimeErrorForDisplay formats an error object with context for REPL display.
func HandleReplMetaCommand ¶
func HandleReplMetaCommand(line string, editor *ReplEditor, env *object.Environment) bool
HandleReplMetaCommand processes REPL meta-commands (lines starting with ':' or '!'). Returns true if the line was handled.
func HistoryEntriesToPersist ¶
func IsTerminal ¶
IsTerminal returns true if the given file is connected to a terminal.
func LoadHistoryEntries ¶
func LongestCommonPrefix ¶
func LooksLikeDateString ¶
LooksLikeDateString checks if a string looks like a date literal.
func ParseHistoryData ¶
func PrintWelcome ¶
func PrintWelcome(env *object.Environment)
func ReplActiveCall ¶
ReplActiveCall returns the function call enclosing cursor and the current zero-based argument index. It is intentionally lightweight so it can run on every keypress in the REPL.
func ReplBuiltinArgHint ¶
func ReplBuiltinCallTip ¶
func ReplBuiltinDetail ¶
func ReplCallTip ¶
func ReplCallTip(line string, cursor int, env *object.Environment) string
func ReplCandidates ¶
func ReplCandidates() []string
ReplCandidates returns completion candidates without an environment.
func ReplCandidatesForEnv ¶
func ReplCandidatesForEnv(env *object.Environment) []string
ReplCandidatesForEnv returns completion candidates from builtins, keywords, and environment variables.
func ReplCommandDetail ¶
func ReplCommandNames ¶
func ReplCommandNames() []string
func ReplCommandsTable ¶
func ReplCompactHint ¶
func ReplConfigTable ¶
func ReplConfigTable(env *object.Environment) string
func ReplDocText ¶
func ReplDocText(name string, env *object.Environment) string
func ReplEvalSource ¶
func ReplEvalSource(input string, env *object.Environment, sourcePath string, printResult bool)
ReplEvalSource evaluates source code and optionally prints the result.
func ReplExamplesText ¶
func ReplExamplesText() string
func ReplFunctionCallTip ¶
func ReplHintLines ¶
func ReplInstallDependency ¶
func ReplInstallDependency(alias, source string, env *object.Environment) error
func ReplMemoryUsage ¶
func ReplMemoryUsage() string
func ReplNeedsContinuation ¶
ReplNeedsContinuation returns true when the input looks incomplete and requires additional lines.
func ReplObjectFields ¶
ReplObjectFields returns known fields for common object types.
func ReplObjectMethods ¶
ReplObjectMethods returns known methods for common object types.
func ReplPalette ¶
func ReplPalette(query string, editor *ReplEditor, env *object.Environment) string
func ReplParseProgram ¶
ReplParseProgram parses input and returns (program, errors).
func ReplPrintLine ¶
func ReplPrintLine(s string)
func ReplResolvedPath ¶
func ReplResolvedPath(path string, env *object.Environment) (string, error)
func ReplTipsText ¶
func ReplTipsText() string
func ReplToolsText ¶
func ReplToolsText() string
func RunReplBasic ¶
func RunReplBasic(env *object.Environment)
RunReplBasic starts a simple line-based REPL without raw terminal input.
func RunReplInteractive ¶
func RunReplInteractive(env *object.Environment) error
RunReplInteractive starts the interactive REPL with line editing.
func StyleContinuationPrompt ¶
StyleContinuationPrompt styles the continuation prompt.
Types ¶
type NativeCommandResult ¶
type ReplCompletionContext ¶
func CompletionContext ¶
func CompletionContext(buf []rune, cursor int) ReplCompletionContext
type ReplConfig ¶
type ReplConfig struct {
ExecutionProfile string
ModuleDir string
StrictMode bool
ProtectHost bool
AllowEnvWrite bool
AllowedCapabilities []string
DeniedCapabilities []string
AllowedExecCommands []string
AllowedNativeModules []string
DeniedNativeModules []string
AllowedNetworkHosts []string
AllowedDBDrivers []string
AllowedDBDSNPatterns []string
AllowedFileReadPaths []string
AllowedFileWritePaths []string
MaxDepth int
MaxSteps int64
MaxHeapMB int64
TimeoutMS int64
MaxOutputBytes int64
MaxHTTPBodyBytes int64
MaxExecOutputBytes int64
RenderMode string
RenderTerminalProtocol string
RenderMaxBytes int64
RenderAllowURLs bool
RenderAllowURLHosts []string
}
func ReplConfigForEnv ¶
func ReplConfigForEnv(env *object.Environment) *ReplConfig
type ReplEditor ¶
type ReplEditor struct {
In *os.File
Out *os.File
Fd int
Env *object.Environment
History []string
HistoryPos int
HistoryFile string
HistoryBase int
Candidates []string
Index *tooling.WorkspaceIndex
SourcePath string
Source string
}
func (*ReplEditor) CompletionsForContext ¶
func (e *ReplEditor) CompletionsForContext(ctx ReplCompletionContext) []string
func (*ReplEditor) InlineHint ¶
func (e *ReplEditor) InlineHint(line string, cursor int) string
func (*ReplEditor) RecordInput ¶
func (e *ReplEditor) RecordInput(input string)
func (*ReplEditor) ReverseHistorySearch ¶
func (e *ReplEditor) ReverseHistorySearch(current []rune) ([]rune, int)
func (*ReplEditor) SuggestionLines ¶
func (e *ReplEditor) SuggestionLines(ctx ReplCompletionContext, candidates []string, width int) []string