japl icon indicating copy to clipboard operation
japl copied to clipboard

REPL Multi-line support

Open nocturn9x opened this issue 4 years ago • 5 comments

The JAPL repl is quite friendly already (surely friendlier than its previous python versions). All expressions evaluated in the top level code are printed to stdout once they're returned, but to make the REPL more usable multi-line support is a must have.

It should be quite easy and should not require big changes in the parser, other than maybe the addition of a method to know if the parser reached an EOF, and a check inside the parser to not report EOF errors under specific conditions. If we are at EOF, then maybe the user might want to type something more and instead of erroring out we store the previous code and ask for more input, until the code parses succesfully or causes other syntactical errors

nocturn9x avatar Oct 22 '20 12:10 nocturn9x

Another comment about the REPL: perhaps not every expression statement should be modified to print the result. It might get cluttered with code like this:

if (x == 5) {
  x = x + 1; //var assignments are expressions so they would also print the result
}

The python REPL seems to not let you finish the expression when it's a single line, such as x =, while inim seems to allow you to continue working when var x =.

I think it could be reasonable to allow multiline inputs when there are braces (or maybe parentheses) open.

ghost avatar Oct 22 '20 12:10 ghost

Sure, I immediately thought that as soon as I clicked "open issue". probably if you type a bare if and nothing else that should be an error

nocturn9x avatar Oct 22 '20 12:10 nocturn9x

Small update that I forgot to mention. Now only the top level code expressions' output is actually printed to stdout (recursive calls were a mess otherwise). The next step is differentiate which kind of expression actually must produce an output

nocturn9x avatar Oct 25 '20 08:10 nocturn9x

For performance reasons we've moved the code that prints the last non-nil expression from the VM to the REPL. @Productive2 is also working on a much friendlier version of our REPL (with multiline support and history)

nocturn9x avatar Jan 17 '21 15:01 nocturn9x

PR #42 adds multiline REPLs, but pressing the enter does not do any checks whether to open a new line or submit yet. Perhaps some of the heuristics can be implemented from this thread, so not closing yet. Multiline right now is manual.

ghost avatar Feb 26 '21 14:02 ghost