Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Increase Input Length #72

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

RexWzh
Copy link

@RexWzh RexWzh commented Feb 5, 2025

Hi,

Issue report: When parsing sketch theorems using REPL, one could get stuck if the input is too long. Investigation revealed this is related to the TTY buffer limitation (e.g. 1024 characters on MacOS), as discussed here.

The current implementation handle longer inputs by concatenating multiple lines, there's a bug where the newline characters (\n) at line endings cause JSON syntax errors.

Current Implementation:

partial def getLines : IO String := do
  let line ← (← IO.getStdin).getLine
  if line.trim.isEmpty then
    return line
  else
    return line ++ (← getLines)

Proposed Fix:

    return line.trimRight ++ (← getLines)

This change allows users to break long inputs into multiple lines using line continuation.

Moveover, the File mode has no input length limitation, but ignores the env field and runs code in a fresh environment. I've updated the env field handling as well.

/-- Process a Lean file in a fresh environment if `env` is not provided. -/
structure File extends CommandOptions where
  env: Option Nat
  path : System.FilePath
deriving FromJson

def processFile (s : File) : M IO (CommandResponse ⊕ Error) := do
  try
    let cmd ← IO.FS.readFile s.path
    -- runCommand { s with env := none, cmd }
    runCommand { s with env := s.env, cmd }

All these proposed changes are backward compatible. Thanks in advance for considering these improvements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant