public void RunRepl (NetworkStream s)
{
string input = null;
while (!InteractiveBase.QuitRequested) {
try {
string error_string;
StringWriter error_output = new StringWriter ();
// Report.Stderr = error_output;
string line = s.GetString ();
bool result_set;
object result;
if (input == null)
input = line;
else
input = input + "\n" + line;
try {
input = Evaluator.Evaluate (input, out result, out result_set);
} catch (Exception e) {
s.WriteByte ((byte) AgentStatus.ERROR);
s.WriteString (e.ToString ());
s.WriteByte ((byte) AgentStatus.RESULT_NOT_SET);
continue;
}
if (input != null){
s.WriteByte ((byte) AgentStatus.PARTIAL_INPUT);
continue;
}
// Send warnings and errors back
error_string = error_output.ToString ();
if (error_string.Length != 0){
s.WriteByte ((byte) AgentStatus.ERROR);
s.WriteString (error_output.ToString ());
}
if (result_set){
s.WriteByte ((byte) AgentStatus.RESULT_SET);
StringWriter sr = new StringWriter ();
CSharpShell.PrettyPrint (sr, result);
s.WriteString (sr.ToString ());
} else {
s.WriteByte ((byte) AgentStatus.RESULT_NOT_SET);
}
} catch (IOException) {
break;
} catch (Exception e){
Console.WriteLine (e);
}
}
}
}