From 95bcf34133e84d1333301d81b640f447553f6820 Mon Sep 17 00:00:00 2001 From: "Ignacio R. Morelle" Date: Thu, 13 Feb 2014 04:50:29 -0300 Subject: [PATCH] preprocessor: Indent error location info on a separate line Messages such as: > Quoted string not terminated at ~add-ons/Foo/bar.cfg > Macro/file 'FOOBAR' is missing at ~add-ons/Baz/bat.cfg:12 included from ~add-ons/Baz/bag.cfg:2 included from ~add-ons/Baz/ban.cfg:42 Now are formatted as: > Quoted string not terminated > at ~add-ons/Foo/bar.cfg > Macro/file 'FOOBAR' is missing > at ~add-ons/Baz/bat.cfg:12 > included from ~add-ons/Baz/bag.cfg:2 > included from ~add-ons/Baz/ban.cfg:42 For messages that include the {} substitution trail, this improves readability by making the trail a sequence of lines with file locations rather than a massive opaque and unreadable text wall: > Macro/file 'FOOBAR' is missing at ~add-ons/After_the_Storm//macros/scenario-segment-implementation.cfg:61 included from ~add-ons/After_the_Storm/base-loader.cfg:6 included from ~add-ons/After_the_Storm/_main.cfg:174 included from ~add-ons/After_the_Storm/base-loader.cfg:75 included from [...] In fact, it's that particular case that motivated this report format change. Cases where there is no substitution trail but there is still a file location pointer are covered by this commit too mainly for the sake of consistency and readability -- being able to see the last (first) relevant location pointer first on a separate line should make it easier to debug most WML issues. --- src/serialization/preprocessor.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/serialization/preprocessor.cpp b/src/serialization/preprocessor.cpp index 08c2d35f313d..a46de77ddcb4 100644 --- a/src/serialization/preprocessor.cpp +++ b/src/serialization/preprocessor.cpp @@ -55,6 +55,8 @@ static t_file_number_map file_number_map; static bool encode_filename = true; +static std::string preprocessor_error_detail_prefix = "\n "; + // get filename associated to this code static std::string get_filename(const std::string& file_code){ if(!encode_filename) @@ -326,7 +328,8 @@ std::string lineno_string(const std::string &lineno) { std::vector< std::string > pos = utils::quoted_split(lineno, ' '); std::vector< std::string >::const_iterator i = pos.begin(), end = pos.end(); - std::string included_from = " included from "; + std::string included_from = + preprocessor_error_detail_prefix + "included from "; std::string res; while (i != end) { std::string const &line = *(i++); @@ -348,7 +351,7 @@ void preprocessor_streambuf::error(const std::string& error_type, int l) std::ostringstream pos; pos << l << ' ' << location_; position = lineno_string(pos.str()); - error = error_type + " at " + position; + error = error_type + preprocessor_error_detail_prefix + "at " + position; ERR_CF << error << '\n'; throw preproc_config::error(error); }