repline icon indicating copy to clipboard operation
repline copied to clipboard

Add the ability to manually toggle multi-line mode

Open sofia-m-a opened this issue 3 years ago • 0 comments

Currently, there's a way to toggle multiline mode based on matching a specific commmand:

>>> :multi
... continuation

However, it would be nice to provide a way to toggle this mode based on parsing information, to make something like the following work

>>> incomplete expression (
... so REPL enters multiline mode )

A possible API for this would be:

beginMultiline :: HaskelineT m ()
endMultiline :: HaskelineT m ()
 -- returns a list of lines since the enclosing beginMultiline
 -- alternatively, this could be managed by the caller
multilineContext :: HaskelineT m [String]

allowing something like

cmd :: Command (HaskelineT IO)
cmd s = do
  context <- multilineContext
  if Parser.isIncomplete (context ++ [s])
    then beginMultiline
    else do
      endMultiline
      -- process (context ++ [s]) as a multi-line chunk

sofia-m-a avatar Apr 24 '22 14:04 sofia-m-a