00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifdef MMX_SUPPORTS_READLINE
00014 #include <readline/readline.h>
00015 #include <readline/history.h>
00016 #endif // MMX_SUPPORTS_READLINE
00017 #include <mmxlight/environment.hpp>
00018 #include <mmxlight/shell.hpp>
00019 #include <basix/syntactic.hpp>
00020 #include <basix/list.hpp>
00021 #include <basix/string.hpp>
00022 #include <basix/evaluator.hpp>
00023 #include <basix/math_syntax.hpp>
00024 #include <basix/parse_tools.hpp>
00025 #include <basix/literal.hpp>
00026
00027 namespace mmx {
00028
00029
00030
00031
00032
00033 void
00034 itf_terminal_output (const generic& g, const generic& t) {
00035 if (math_mode) mmout << flatten_as_texmacs_scheme (g);
00036 else mmout << g;
00037 if (exact_neq (t, "None") &&
00038 exact_neq (t, "Document") &&
00039 exact_neq (t, "Graphics"))
00040 mmout << ": " << t;
00041 mmout << "\n";
00042 }
00043
00044
00045
00046
00047
00048 bool
00049 itf_terminal_print_parse_errors (const list<generic>& errors) {
00050 bool raise_error= false;
00051 iterator<generic> it = iterate (reverse (errors));
00052 for (; busy(it); ++it) {
00053 generic err= *it;
00054 string msg= literal_to_string ((*as<exception> (err)) [1]);
00055 if (!starts (msg, "warning")) raise_error = true;
00056 itf_terminal_print_exception (err);
00057 }
00058 return raise_error;
00059 }
00060
00061 bool
00062 itf_terminal_print_exception (const generic& g) {
00063 nat i;
00064 string s;
00065 generic err;
00066 source_location l;
00067
00068 ASSERT (is <exception> (g), "invalid exception");
00069 if (has_trace (g)) {
00070 itf_terminal_print_exception (trace_pull (g));
00071 itf_terminal_print_exception (trace_top (g));
00072 return true;
00073 }
00074 err = *as <exception> (g);
00075 ASSERT (is <compound> (err), "invalid error message");
00076 ASSERT (N(err) > 2, "invalid error message");
00077 source_locate (err[N(err)-1], l);
00078 if (is_nil (l)) mmerr << "Inside " << err[N(err)-1] << ": ";
00079 else {
00080 if (l.file_name != "")
00081 mmerr << l.file_name << ":";
00082 mmerr << l.begin.line+1 << ":"
00083 << l.begin.column+1 << ": ";
00084 }
00085 if (err[1] == "error") mmerr << err[0] << ", ";
00086 else if (err[1] == "warning") mmerr << "warning, ";
00087 else {
00088 mmerr << err[0] << ", ";
00089 mmerr << err[1] << " ";
00090 }
00091 for (i = 2; i+1 < N(err); i++)
00092 mmerr << err[i] << " ";
00093 mmerr << "\n";
00094 mmerr << source_underlined (err[N(err)-1]);
00095 return true;
00096 }
00097
00098 }