Run clang-format and add more error messages

This commit is contained in:
Phil Christensen 2019-08-26 16:21:57 -07:00
parent bd4678610b
commit 6d8e66ff4f

View File

@ -2,8 +2,8 @@
#include <vcpkg/parse.h> #include <vcpkg/parse.h>
#include <vcpkg/base/util.h>
#include <vcpkg/base/system.print.h> #include <vcpkg/base/system.print.h>
#include <vcpkg/base/util.h>
namespace vcpkg::Parse namespace vcpkg::Parse
{ {
@ -45,10 +45,7 @@ namespace vcpkg::Parse
return nullptr; return nullptr;
} }
static bool is_whitespace(char c) static bool is_whitespace(char c) { return c == ' ' || c == '\t' || c == '\n' || c == '\r'; }
{
return c == ' ' || c == '\t' || c == '\n' || c == '\r';
}
std::vector<std::string> parse_comma_list(const std::string& str) std::vector<std::string> parse_comma_list(const std::string& str)
{ {
@ -61,7 +58,8 @@ namespace vcpkg::Parse
auto iter = str.cbegin(); auto iter = str.cbegin();
do { do
{
// Trim leading whitespace of each element // Trim leading whitespace of each element
while (iter != str.cend() && is_whitespace(*iter)) while (iter != str.cend() && is_whitespace(*iter))
{ {
@ -80,10 +78,24 @@ namespace vcpkg::Parse
// do not support nested [] // do not support nested []
if (value == '[') if (value == '[')
{ {
Checks::check_exit(VCPKG_LINE_INFO,
!bracket_nesting,
"Lists do not support nested brackets, Did you forget a ']'?\n"
"> '%s'\n"
"> %s^\n",
str,
std::string(static_cast<int>(iter - str.cbegin()), ' '));
bracket_nesting = true; bracket_nesting = true;
} }
else if (value == ']') else if (value == ']')
{ {
Checks::check_exit(VCPKG_LINE_INFO,
bracket_nesting,
"Found unmatched ']'. Did you forget a '['?\n"
"> '%s'\n"
"> %s^\n",
str,
std::string(static_cast<int>(iter - str.cbegin()), ' '));
bracket_nesting = false; bracket_nesting = false;
} }
@ -97,32 +109,30 @@ namespace vcpkg::Parse
} }
} }
if (element_begin == element_end) Checks::check_exit(VCPKG_LINE_INFO,
{ element_begin != element_end,
System::print2( System::Color::warning, "Empty element in list\n"
"Warning: empty element in list\n" "> '%s'\n"
"> '", str, "'\n" "> %s^\n",
"> ", std::string(static_cast<int>(element_begin - str.cbegin()), ' '), "^\n" str,
); std::string(static_cast<int>(element_begin - str.cbegin()), ' '));
}
else
{
out.push_back({element_begin, element_end}); out.push_back({element_begin, element_end});
}
if (iter != str.cend()) if (iter != str.cend())
{ {
Checks::check_exit(VCPKG_LINE_INFO, *iter == ',', "Internal parsing error - expected comma");
// Not at the end, must be at a comma that needs to be stepped over // Not at the end, must be at a comma that needs to be stepped over
++iter; ++iter;
if (iter == str.end()) Checks::check_exit(VCPKG_LINE_INFO,
{ iter != str.end(),
System::print2(System::Color::warning, "Empty element in list\n"
"Warning: empty element in list\n" "> '%s'\n"
"> '", str, "'\n" "> %s^\n",
"> ", std::string(str.length(), ' '), "^\n" str,
); std::string(str.length(), ' '));
}
} }
} while (iter != str.cend()); } while (iter != str.cend());