Main loop: bugs with prompts and error handling



I have been trying to fix some bugs related to prompts and error
handling in the main loop. The basic problem is that a prompt should be
displayed if and only if input is expected. It sounds like a simple
policy, but I am finding it surprisingly difficult to implement in the
current system. As CY's "inner workings" diagram shows, the read part of
the main loop is surprisingly complicated. The way exceptions are thrown
and caught makes it particularly confusing.

Producing prompts at the right time is crucial for programs like texmacs
and wxmaxima that need to interact with maxima.

Here are four related input cases:

Case 1: Incorrect syntax.
------------------------------------------------------
(%i1) integrate(,x);
Incorrect syntax: , is not a prefix operator
integrate(,
         ^
(%i1) Incorrect syntax: Too many )'s
x)
^
(%i1) Incorrect syntax: Premature termination of input at ;.
;
^
(%i1)
------------------------------------------------------
The problem here is that two spurious input prompts are displayed. The
second error message is also confusing.

Case 2: Incorrect syntax followed by a syntactically correct expression.
------------------------------------------------------
(%i1) integrate(,x)1+1;
Incorrect syntax: , is not a prefix operator
integrate(,
         ^
(%i1) Incorrect syntax: Too many )'s
x)
^
(%i1)
(%o1)                                  2
(%i2) %i1;

(%o2)                                  2
------------------------------------------------------
Again, we get a spurious input prompt. We also get the following
confusing behavior: the "integrate(,x)" part of the expression is simply
ignored. Maxima considers the input to be the syntactically correct
expression "1+1".

Case 3: Two inputs separated by a ";".
------------------------------------------------------
(%i3) a+b;c+d;

(%o3)                                b + a
(%i4)
(%o4)                                d + c
------------------------------------------------------
Here we get a prompt, even though no further input is expected.

Case 4: Two inputs separated by a ";", but the second input is not
complete.
------------------------------------------------------
(%i5) a+b;c+d

(%o5)                                b + a
(%i6) ;

(%o6)                                d + c
(%i7)
------------------------------------------------------
This time input is expected when the prompt appears. I guess this case
is OK.

If anyone has any bright ideas about how to fix cases 1-3, I'd be glad
to hear them.

--Jim