PeaBox Lab › PeaLang › Learn › Chapter 1 › Lesson 3

Part I — Foundations · Chapter 1 · Lesson 3 of 5 · 8 min read

Lesson 3: The Command-Line Workflow—Run, REPL, Format, Check, Docs, Debug, and DAP

Lesson level: Foundation

Purpose: Build a disciplined edit–check–run–inspect workflow and understand when each PeaLang command belongs in development or automation.

Learning objectives

By the end of this lesson, you should be able to:

3.1 One command, several feedback loops

The pea command is the main entry point for language development. Each subcommand answers a different question. run asks whether the program executes. repl supports quick experiments. fmt normalizes layout. check finds source diagnostics without running the program. docs extracts documentation. debug opens an interactive inspection path. dap exposes debugger operations to compatible tools.

A reliable workflow uses the cheapest, safest feedback first. Format and check before execution; run focused examples before larger tests; use debugging when output and diagnostics no longer explain behavior.

3.2 Run a source file

The standard execution form is:

pea run FILE

For example:

pea run hello.pea

The runtime resolves the source path, reads UTF-8 text, associates execution with the file’s directory, and reports language or operating-system failures as errors. A successful run returns a success status; a failure returns a nonzero status suitable for scripts and automation.

Process execution is denied by default. The run command accepts an explicit --allow-process option, but it should be used only for trusted code with a justified requirement. It is not a general remedy for a failing script. Ordinary course examples do not require it.

Convenience form. When one source path is supplied without a recognized subcommand, the CLI can run that file directly. This book nevertheless uses pea run FILE because the intent remains obvious in notes, scripts, and CI logs.

3.3 Use the REPL for focused experiments

Start the interactive environment with:

pea repl

Calling pea with no arguments also opens the REPL. The prompt preserves variables and definitions between entries, making it useful for testing expressions, standard-library calls, and short language constructs before placing them in a source file.

The REPL recognizes these control commands:

For a multi-line block, the REPL continues collecting input while opening braces outnumber closing braces. A language error is displayed, and the interactive process remains available for the next attempt.

Choose the right surface. Use the REPL to answer a small question quickly. Move code into a .pea file when it must be repeatable, reviewable, testable, documented, or shared.

3.4 Format source consistently

Format one or more files or directories with:

pea fmt PATH [PATH ...]

The formatter discovers .pea files beneath the supplied paths, rewrites them into canonical form, and prints the files it formatted. Use it before review so changes in spacing and layout do not distract from changes in behavior.

To verify formatting without rewriting files, use:

pea fmt --check PATH [PATH ...]

Check mode identifies files that differ from canonical formatting and returns a failure status when changes are required. This makes it appropriate for continuous integration and pre-commit validation.

Safe habit: During active editing, format locally and review the diff. In automation, use --check so the pipeline reports drift rather than mutating the workspace.

3.5 Check source without running it

Run static source checks with:

pea check PATH [PATH ...]

The checker discovers .pea files, analyzes their source, and renders diagnostics with file context. It returns a failure status when error-level diagnostics are found. Because it does not execute the program, it is safer and faster than using execution as the first syntax check.

The check command is distinct from later analysis tools. Basic checking focuses on source diagnostics. Optional typing and flow-aware semantic analysis use dedicated commands covered in the type-system chapter.

3.6 A minimal edit loop

This ordering shortens feedback and separates formatting, static diagnostics, runtime behavior, and interactive investigation into distinct signals.

3.7 Generate source documentation

Generate documentation from one source file with:

pea docs FILE

Without an output option, generated content is printed to standard output. To write it to a file, use:

pea docs FILE -o OUTPUT

For example:

pea docs rules.pea -o rules.md

Documentation generation reads the named source file and produces documentation from its supported declarations and comments. Treat the output as derived material: update the source, regenerate the document, and avoid manually maintaining divergent copies.

3.8 Start a debugging session

Inspect a source file with:

pea debug FILE

To register a source-line breakpoint at startup, add one or more breakpoint options:

pea debug FILE --break=LINE

The command constructs a debug session for the file, registers requested line breakpoints, starts execution, and prints the resulting debugger state in structured form. A breakpoint is meaningful only when it corresponds to executable source.

Use debugging to inspect control flow, variables, stack frames, and evaluation state. Before debugging, confirm that the file passes basic checking and that you can reproduce the unexpected behavior with a focused input.

3.9 Debug Adapter Protocol

Start the source-level Debug Adapter Protocol service with:

pea dap

The adapter communicates through Content-Length framed JSON over standard input and output. It supports initialization, launch, breakpoint configuration, continue, next, step in, step out, thread and stack inspection, scopes, variables, expression evaluation, disconnect, and termination.

DAP is primarily an integration surface for editors and IDEs. A compatible client sends protocol requests and renders the results as familiar debugging controls. Because protocol traffic uses standard input and output, do not mix unrelated console output into the adapter channel.

PeaLang also includes a VM-oriented adapter started with pea vm-dap. The source-level dap command is the appropriate starting point for this lesson; VM-specific debugging is covered with bytecode and VM internals.

3.10 Command selection guide

NeedCommandKey behavior
Execute a source filepea run FILERuns with process execution denied unless explicitly enabled.
Try a short experimentpea replPreserves interactive state until cleared or exited.
Normalize source layoutpea fmt PATHRewrites discovered .pea files.
Verify formatting in automationpea fmt --check PATHReports drift and returns failure without rewriting.
Find source diagnosticspea check PATHChecks without executing the program.
Generate documentationpea docs FILE -o OUTPUTProduces derived documentation from source.
Inspect executionpea debug FILE --break=LINEStarts a debug session with an optional breakpoint.
Connect an editor debuggerpea dapRuns the source-level protocol adapter over standard streams.

3.11 Exit status and automation

Command-line workflows depend on more than printed messages. A zero exit status indicates success; a nonzero status lets shell scripts, pre-commit hooks, and CI pipelines stop when a required condition fails. Formatting check, source check, and execution failures can therefore act as quality gates.

A simple validation sequence is:

pea fmt --check .
pea check .
pea run hello.pea

In a real project, native tests would follow. Keep diagnostic stages separate so a failure clearly identifies formatting, static analysis, runtime, or test behavior.

3.12 Common mistakes

3.13 Troubleshooting

3.14 Hands-on lab: Build a repeatable CLI workflow

Goal: Practice every command in this lesson against a small learning file.

Deliverable: A short workflow report containing each command, its purpose, whether it modifies files, whether it executes PeaLang code, its observed result, and any nonzero exit status. Do not enable process execution for this lab.

3.15 Review questions

3.16 Applied challenge

Design a local pre-review routine for a PeaLang project. Include formatting, static checking, one focused run, documentation regeneration when public declarations change, and criteria for opening a debugger. Then design the corresponding non-mutating CI routine and explain every difference.

Lesson summary

The PeaLang CLI supports a progression from fast feedback to deep inspection. Use the REPL for disposable experiments, source files for repeatability, formatting and checking for early feedback, run for behavior, docs for derived reference material, debug for focused investigation, and DAP for editor integration. Preserve secure defaults and use exit statuses to build reliable automation.

Lesson status: Approved.

← Previous Next →