Skip to content

Add parse-only REPL input completeness check - #6543

Draft
fingolfin wants to merge 1 commit into
masterfrom
claude/gap-repl-api-design-11f227
Draft

Add parse-only REPL input completeness check#6543
fingolfin wants to merge 1 commit into
masterfrom
claude/gap-repl-api-design-11f227

Conversation

@fingolfin

Copy link
Copy Markdown
Member

Adds CHECK_ALL_COMMANDS(instream): parse input without executing or printing anything, and classify it as "complete", "incomplete" (truncated prefix of valid input) or "error". Diagnostics are returned as records with message and caret positions instead of being printed.

This is the primitive alternative frontends need for multi-line editing: a Julia REPL "GAP mode" via GAP.jl, or a Jupyter kernel's is_complete_request, can ask on every Enter whether the buffer is ready to evaluate, instead of submitting half-typed input.

Implementation: the reader runs with the interpreter in ignoring mode (cf. the experiment in #4130, but no asserts are relaxed; IntrEnd is skipped in check mode, so nothing runs, not even quit; or ?help). The scanner records whether the first syntax error was caused by the input ending; only then is input "incomplete", so a typo inside an open construct still reports "error" and cannot trap the user in an editor that never submits.

Planned follow-ups: a structured chunk evaluator (per-statement results, captured output and error text, no break loop) and libgap wrappers GAP_CheckInput / GAP_EvalStringEx.

Written with Claude Code (Claude Fable 5).

Alternative frontends (a Julia REPL mode via GAP.jl, Jupyter kernels)
need to know whether input is a complete command sequence, a truncated
prefix of valid input, or contains a syntax error -- without executing
anything. This is the primitive behind Julia's on-Enter check and
Jupyter's is_complete_request.

CHECK_ALL_COMMANDS(instream) parses the input with the interpreter in
ignoring mode and returns a record with 'status' ("complete",
"incomplete" or "error"), 'statements' and 'errors'. Diagnostics are
collected as records (message and caret positions) instead of being
printed. Input is classified as incomplete iff the first syntax error
was caused by the input ending, so an error inside an open construct
still reports "error".

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
@codecov

codecov Bot commented Aug 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.75862% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.98%. Comparing base (989cc35) to head (2331e26).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/scanner.c 76.31% 5 Missing and 4 partials ⚠️
src/streams.c 79.31% 4 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6543      +/-   ##
==========================================
- Coverage   79.00%   78.98%   -0.03%     
==========================================
  Files         684      684              
  Lines      294205   294285      +80     
  Branches     8647     8664      +17     
==========================================
- Hits       232444   232435       -9     
- Misses      59955    60036      +81     
- Partials     1806     1814       +8     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
Comment thread src/streams.c
GAP_THROW();

Obj result = NEW_PREC(3);
AssPRec(result, RNamName("status"), MakeImmString(status));

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe an integer with specific defined values (say 0, 1, 2), plus some BindGlobal("COMMAND_STATUS_ERROR", ...)etc for the values would be better: checking strings is error prone (typos...)

@fingolfin fingolfin added kind: enhancement Label for issues suggesting enhancements; and for pull requests implementing enhancements topic: library labels Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind: enhancement Label for issues suggesting enhancements; and for pull requests implementing enhancements topic: library

1 participant