Run clang-format and add more error messages
MODIFY
src/vcpkg/parse.cpp
src/vcpkg/parse.cpp
#include <vcpkg/parse.h>
-#include <vcpkg/base/util.h>
#include <vcpkg/base/system.print.h>
+#include <vcpkg/base/util.h>
namespace vcpkg::Parse
{
@@ -45,10 +45,7 @@ namespace vcpkg::Parse
return nullptr;
}
- static bool is_whitespace(char c)
- {
- return c == ' ' || c == '\t' || c == '\n' || c == '\r';
- }
+ static bool is_whitespace(char c) { return c == ' ' || c == '\t' || c == '\n' || c == '\r'; }
std::vector<std::string> parse_comma_list(const std::string& str)
{
@@ -61,7 +58,8 @@ namespace vcpkg::Parse
auto iter = str.cbegin();
- do {
+ do
+ {
// Trim leading whitespace of each element
while (iter != str.cend() && is_whitespace(*iter))
{
@@ -80,10 +78,24 @@ namespace vcpkg::Parse
// do not support nested []
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;
}
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;
}
@@ -97,32 +109,30 @@ namespace vcpkg::Parse
}
}
- if (element_begin == element_end)
- {
- System::print2( System::Color::warning,
- "Warning: empty element in list\n"
- "> '", str, "'\n"
- "> ", std::string(static_cast<int>(element_begin - str.cbegin()), ' '), "^\n"
- );
- }
- else
- {
+ Checks::check_exit(VCPKG_LINE_INFO,
+ element_begin != element_end,
+ "Empty element in list\n"
+ "> '%s'\n"
+ "> %s^\n",
+ str,
+ std::string(static_cast<int>(element_begin - str.cbegin()), ' '));
+
out.push_back({element_begin, element_end});
- }
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
++iter;
- if (iter == str.end())
- {
- System::print2(System::Color::warning,
- "Warning: empty element in list\n"
- "> '", str, "'\n"
- "> ", std::string(str.length(), ' '), "^\n"
- );
- }
+ Checks::check_exit(VCPKG_LINE_INFO,
+ iter != str.end(),
+ "Empty element in list\n"
+ "> '%s'\n"
+ "> %s^\n",
+ str,
+ std::string(str.length(), ' '));
}
} while (iter != str.cend());

Run clang-format and add more error messages