Go to the documentation of this file.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 shell_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") && exact_neq (t, "Document"))
00038 mmout << ": " << t;
00039 mmout << "\n";
00040 }
00041
00042
00043
00044
00045
00046 bool
00047 shell_terminal_print_parse_errors (const list<generic>& errors) {
00048 bool raise_error= false;
00049 iterator<generic> it = iterate (reverse (errors));
00050 for (; busy(it); ++it) {
00051 generic err= *it;
00052 string msg= literal_to_string ((*as<exception> (err)) [1]);
00053 if (!starts (msg, "warning")) raise_error = true;
00054 shell_terminal_print_exception (err);
00055 }
00056 return raise_error;
00057 }
00058
00059 bool
00060 shell_terminal_print_exception (const generic& g) {
00061 nat i;
00062 string s;
00063 generic err;
00064 source_location l;
00065
00066 ASSERT (is <exception> (g), "invalid exception");
00067 if (has_trace (g)) {
00068 shell_terminal_print_exception (trace_pull (g));
00069 shell_terminal_print_exception (trace_top (g));
00070 return true;
00071 }
00072 err = *as <exception> (g);
00073 ASSERT (is <compound> (err), "invalid error message");
00074 ASSERT (N(err) > 2, "invalid error message");
00075 source_locate (err[N(err)-1], l);
00076 if (is_nil (l)) mmerr << "Inside " << err[N(err)-1] << ": ";
00077 else {
00078 if (l.file_name != "")
00079 mmerr << l.file_name << ":";
00080 mmerr << l.begin.line+1 << ":"
00081 << l.begin.column+1 << ": ";
00082 }
00083 if (err[1] == "error") mmerr << err[0] << ", ";
00084 else if (err[1] == "warning") mmerr << "warning, ";
00085 else {
00086 mmerr << err[0] << ", ";
00087 mmerr << err[1] << " ";
00088 }
00089 for (i = 2; i+1 < N(err); i++)
00090 mmerr << err[i] << " ";
00091 mmerr << "\n";
00092 mmerr << source_underlined (err[N(err)-1]);
00093 return true;
00094 }
00095
00096 }