japl-lang / japl

Official repository of the JAPL language
Apache License 2.0
35 stars 1 forks source link

REPL Multi-line support #12

Open nocturn9x opened 3 years ago

nocturn9x commented 3 years ago

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

ghost commented 3 years ago

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.

nocturn9x commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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)

ghost commented 3 years ago

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.