repl

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package repl provides a Python-inspired Read-Eval-Print Loop for the English programming language.

The REPL reads one statement at a time from an io.Reader, evaluates it using the AST VM, and writes output to an io.Writer. Because all I/O is injected the loop is trivially testable without a real terminal.

Primary prompt: ">>> " Continuation prompt: "... "

Multi-line blocks are detected by counting block-openers ("following:", "if …, then") and the corresponding block-closer ("thats it."). When the depth is greater than zero the continuation prompt is shown until the block is complete.

Index

Constants

View Source
const (
	// PrimaryPrompt is displayed when the REPL is ready for a new statement.
	PrimaryPrompt = ">>> "
	// ContinuationPrompt is displayed when more input is needed to complete a
	// multi-line block.
	ContinuationPrompt = "... "
)

Variables

View Source
var Version = "1.2.25"

Version is the language version string shown in the REPL banner. cmd/repl.go overrides this with the value of version.Version at startup.

Functions

This section is empty.

Types

type REPL

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

REPL is an interactive Read-Eval-Print Loop for the English language.

func New

func New(in io.Reader, out io.Writer, useColor bool) *REPL

New creates a REPL that reads from in and writes all output (prompts, program output, and error messages) to out.

When useColor is true, error messages are rendered with ANSI colour codes. Pass stacktraces.HasColor() for automatic TTY detection.

func (*REPL) Loop

func (r *REPL) Loop()

Loop runs the REPL input loop without printing the startup banner. This is useful for testing or for embedding the REPL in a larger program.

func (*REPL) Run

func (r *REPL) Run()

Run prints the startup banner and then enters the interactive loop. It returns when the user types "exit" / "quit" or when the input reader reaches EOF.

Jump to

Keyboard shortcuts

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