diff --git a/include/chaiscript/language/chaiscript_common.hpp b/include/chaiscript/language/chaiscript_common.hpp index 6c71cc8..f45d9f0 100644 --- a/include/chaiscript/language/chaiscript_common.hpp +++ b/include/chaiscript/language/chaiscript_common.hpp @@ -71,13 +71,10 @@ namespace chaiscript std::string filename; std::vector call_stack; - eval_error(const std::string &t_why, const File_Position &t_where, const std::string &t_fname) throw() : - std::runtime_error("Error: \"" + t_why + "\" " + - (t_fname != "__EVAL__" ? ("in '" + t_fname + "' ") : "during evaluation ") + - + "at (" + boost::lexical_cast(t_where.line) + ", " + - boost::lexical_cast(t_where.column) + ")"), - reason(t_why), start_position(t_where), end_position(t_where), filename(t_fname) - { } + eval_error(const std::string &t_why, const File_Position &t_where, const std::string &t_fname) throw() + : std::runtime_error(format(t_why, t_where, t_fname)), + reason(t_why), start_position(t_where), end_position(t_where), filename(t_fname) + {} eval_error(const std::string &t_why) throw() : std::runtime_error("Error: \"" + t_why + "\" "), @@ -85,6 +82,42 @@ namespace chaiscript {} virtual ~eval_error() throw() {} + + private: + static std::string format_why(const std::string &t_why) + { + return "Error: \"" + t_why + "\""; + } + + static std::string format_filename(const std::string &t_fname) + { + std::stringstream ss; + if (t_fname != "__EVAL__") + { + ss << "in '" << t_fname << "' "; + } else { + ss << "during evaluation "; + } + return ss.str(); + } + + static std::string format_location(const File_Position &t_where) + { + std::stringstream ss; + ss << "at (" << t_where.line << ", " << t_where.column << ")"; + return ss.str(); + } + + static std::string format(const std::string &t_why, const File_Position &t_where, const std::string &t_fname) + { + std::stringstream ss; + ss << format_why(t_why); + ss << " "; + ss << format_filename(t_fname); + ss << " "; + ss << format_location(t_where); + return ss.str(); + } }; /** diff --git a/src/main.cpp b/src/main.cpp index ea9a8f5..3cdb09e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -80,7 +80,18 @@ std::string get_next_command() { char *input_raw = readline("eval> "); if ( input_raw ) { add_history(input_raw); - retval = boost::trim_copy_if(std::string(input_raw),boost::is_any_of(" \t")); + std::string val(input_raw); + size_t pos = val.find_first_not_of("\t \n"); + if (pos != std::string::npos) + { + val.erase(0, pos); + } + pos = val.find_last_not_of("\t \n"); + if (pos != std::string::npos) + { + val.erase(pos+1, std::string::npos); + } + retval = val; ::free(input_raw); } }