Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions include/vcpkg-test/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ namespace vcpkg::Test

inline auto test_parse_control_file(const std::vector<std::unordered_map<std::string, std::string>>& v)
{
std::vector<vcpkg::Parse::Paragraph> pghs;
std::vector<vcpkg::Paragraph> pghs;
for (auto&& p : v)
{
pghs.emplace_back();
for (auto&& kv : p)
pghs.back().emplace(kv.first, std::make_pair(kv.second, vcpkg::Parse::TextRowCol{}));
pghs.back().emplace(kv.first, std::make_pair(kv.second, vcpkg::TextRowCol{}));
}
return vcpkg::SourceControlFile::parse_control_file("", std::move(pghs));
}
Expand Down Expand Up @@ -135,7 +135,7 @@ namespace vcpkg::Test
inline std::vector<FullPackageSpec> parse_test_fspecs(StringView sv, Triplet t = X86_WINDOWS)
{
std::vector<FullPackageSpec> ret;
Parse::ParserBase parser(sv, "test");
ParserBase parser(sv, "test");
while (!parser.at_eof())
{
auto opt = parse_qualified_specifier(parser);
Expand Down
17 changes: 17 additions & 0 deletions include/vcpkg/base/fwd/parse.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

namespace vcpkg
{
struct ParseError;
struct SourceLoc;

enum class MessageKind
{
Warning,
Error,
};

struct ParseMessage;
struct ParseMessages;
struct ParserBase;
}
9 changes: 5 additions & 4 deletions include/vcpkg/base/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,11 @@ namespace vcpkg::Json
underlying_t underlying_;
};

ExpectedT<std::pair<Value, JsonStyle>, std::unique_ptr<Parse::IParseError>> parse_file(
const Filesystem&, const Path&, std::error_code& ec) noexcept;
ExpectedT<std::pair<Value, JsonStyle>, std::unique_ptr<Parse::IParseError>> parse(StringView text,
StringView origin = {}) noexcept;
ExpectedT<std::pair<Value, JsonStyle>, std::unique_ptr<ParseError>> parse_file(const Filesystem&,
const Path&,
std::error_code& ec) noexcept;
ExpectedT<std::pair<Value, JsonStyle>, std::unique_ptr<ParseError>> parse(StringView text,
StringView origin = {}) noexcept;
std::pair<Value, JsonStyle> parse_file(vcpkg::LineInfo li, const Filesystem&, const Path&) noexcept;

std::string stringify(const Value&, JsonStyle style);
Expand Down
27 changes: 8 additions & 19 deletions include/vcpkg/base/parse.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <vcpkg/base/fwd/parse.h>

#include <vcpkg/base/messages.h>
#include <vcpkg/base/optional.h>
#include <vcpkg/base/stringview.h>
Expand All @@ -11,16 +13,9 @@
#include <memory>
#include <string>

namespace vcpkg::Parse
namespace vcpkg
{
struct IParseError
{
virtual ~IParseError() = default;
virtual std::string format() const = 0;
virtual const std::string& get_message() const = 0;
};

struct ParseError : IParseError
struct ParseError
{
ParseError(std::string origin, int row, int column, int caret_col, std::string line, std::string message)
: origin(std::move(origin))
Expand All @@ -39,8 +34,8 @@ namespace vcpkg::Parse
const std::string line;
const std::string message;

virtual std::string format() const override;
virtual const std::string& get_message() const override;
std::string format() const;
const std::string& get_message() const;
};

struct SourceLoc
Expand All @@ -51,12 +46,6 @@ namespace vcpkg::Parse
int column;
};

enum class MessageKind
{
Warning,
Error,
};

struct ParseMessage
{
SourceLoc location = {};
Expand Down Expand Up @@ -147,8 +136,8 @@ namespace vcpkg::Parse
void add_warning(LocalizedString&& message) { add_warning(std::move(message), cur_loc()); }
void add_warning(LocalizedString&& message, const SourceLoc& loc);

const IParseError* get_error() const { return m_messages.error.get(); }
std::unique_ptr<IParseError> extract_error() { return std::move(m_messages.error); }
const ParseError* get_error() const { return m_messages.error.get(); }
std::unique_ptr<ParseError> extract_error() { return std::move(m_messages.error); }

const ParseMessages& messages() const { return m_messages; }
ParseMessages extract_messages() { return std::move(m_messages); }
Expand Down
2 changes: 1 addition & 1 deletion include/vcpkg/binaryparagraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace vcpkg
struct BinaryParagraph
{
BinaryParagraph();
explicit BinaryParagraph(Parse::Paragraph fields);
explicit BinaryParagraph(Paragraph fields);
BinaryParagraph(const SourceParagraph& spgh,
Triplet triplet,
const std::string& abi_tag,
Expand Down
7 changes: 7 additions & 0 deletions include/vcpkg/fwd/paragraphparser.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

namespace vcpkg
{
struct ParseControlErrorInfo;
struct ParagraphParser;
}
13 changes: 5 additions & 8 deletions include/vcpkg/packagespec.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <vcpkg/base/fwd/parse.h>

#include <vcpkg/base/expected.h>
#include <vcpkg/base/format.h>
#include <vcpkg/base/json.h>
Expand All @@ -10,11 +12,6 @@
#include <vcpkg/triplet.h>
#include <vcpkg/versions.h>

namespace vcpkg::Parse
{
struct ParserBase;
}

namespace vcpkg
{
///
Expand Down Expand Up @@ -190,10 +187,10 @@ namespace vcpkg
ExpectedS<PackageSpec> to_package_spec(Triplet default_triplet) const;
};

Optional<std::string> parse_feature_name(Parse::ParserBase& parser);
Optional<std::string> parse_package_name(Parse::ParserBase& parser);
Optional<std::string> parse_feature_name(ParserBase& parser);
Optional<std::string> parse_package_name(ParserBase& parser);
ExpectedS<ParsedQualifiedSpecifier> parse_qualified_specifier(StringView input);
Optional<ParsedQualifiedSpecifier> parse_qualified_specifier(Parse::ParserBase& parser);
Optional<ParsedQualifiedSpecifier> parse_qualified_specifier(ParserBase& parser);
}

template<class Char>
Expand Down
4 changes: 3 additions & 1 deletion include/vcpkg/paragraphparser.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <vcpkg/fwd/paragraphparser.h>

#include <vcpkg/base/expected.h>

#include <vcpkg/packagespec.h>
Expand All @@ -11,7 +13,7 @@
#include <unordered_map>
#include <vector>

namespace vcpkg::Parse
namespace vcpkg
{
struct ParseControlErrorInfo
{
Expand Down
16 changes: 4 additions & 12 deletions include/vcpkg/paragraphs.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
#pragma once

#include <vcpkg/fwd/paragraphparser.h>
#include <vcpkg/fwd/registries.h>

#include <vcpkg/base/expected.h>

#include <vcpkg/binaryparagraph.h>

namespace vckpg::Parse
{
struct ParseControlErrorInfo;
}

namespace vcpkg::Paragraphs
{
using Paragraph = Parse::Paragraph;

uint64_t get_load_ports_stats();

ExpectedS<Paragraph> parse_single_paragraph(StringView str, StringView origin);
Expand All @@ -26,10 +20,8 @@ namespace vcpkg::Paragraphs

bool is_port_directory(const Filesystem& fs, const Path& maybe_directory);

Parse::ParseExpected<SourceControlFile> try_load_port(const Filesystem& fs, const Path& port_directory);
Parse::ParseExpected<SourceControlFile> try_load_port_text(const std::string& text,
StringView origin,
bool is_manifest);
ParseExpected<SourceControlFile> try_load_port(const Filesystem& fs, const Path& port_directory);
ParseExpected<SourceControlFile> try_load_port_text(const std::string& text, StringView origin, bool is_manifest);

ExpectedS<BinaryControlFile> try_load_cached_package(const Filesystem& fs,
const Path& package_dir,
Expand All @@ -38,7 +30,7 @@ namespace vcpkg::Paragraphs
struct LoadResults
{
std::vector<SourceControlFileAndLocation> paragraphs;
std::vector<std::unique_ptr<Parse::ParseControlErrorInfo>> errors;
std::vector<std::unique_ptr<ParseControlErrorInfo>> errors;
};

// this allows one to pass this around as an overload set to stuff like `Util::fmap`,
Expand Down
13 changes: 6 additions & 7 deletions include/vcpkg/sourceparagraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,10 @@ namespace vcpkg
{
SourceControlFile clone() const;

static Parse::ParseExpected<SourceControlFile> parse_manifest_object(StringView origin,
const Json::Object& object);
static ParseExpected<SourceControlFile> parse_manifest_object(StringView origin, const Json::Object& object);

static Parse::ParseExpected<SourceControlFile> parse_control_file(
StringView origin, std::vector<Parse::Paragraph>&& control_paragraphs);
static ParseExpected<SourceControlFile> parse_control_file(StringView origin,
std::vector<Paragraph>&& control_paragraphs);

// Always non-null in non-error cases
std::unique_ptr<SourceParagraph> core_paragraph;
Expand Down Expand Up @@ -147,11 +146,11 @@ namespace vcpkg
Path source_location;
};

void print_error_message(Span<const std::unique_ptr<Parse::ParseControlErrorInfo>> error_info_list);
inline void print_error_message(const std::unique_ptr<Parse::ParseControlErrorInfo>& error_info_list)
void print_error_message(Span<const std::unique_ptr<ParseControlErrorInfo>> error_info_list);
inline void print_error_message(const std::unique_ptr<ParseControlErrorInfo>& error_info_list)
{
return print_error_message({&error_info_list, 1});
}

std::string parse_spdx_license_expression(StringView sv, Parse::ParseMessages& messages);
std::string parse_spdx_license_expression(StringView sv, ParseMessages& messages);
}
2 changes: 1 addition & 1 deletion include/vcpkg/statusparagraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace vcpkg
struct StatusParagraph
{
StatusParagraph() noexcept;
explicit StatusParagraph(Parse::Paragraph&& fields);
explicit StatusParagraph(Paragraph&& fields);

bool is_installed() const { return want == Want::INSTALL && state == InstallState::INSTALLED; }

Expand Down
2 changes: 1 addition & 1 deletion include/vcpkg/textrowcol.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

namespace vcpkg::Parse
namespace vcpkg
{
struct TextRowCol
{
Expand Down
16 changes: 8 additions & 8 deletions src/vcpkg-test/manifests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ enum class PrintErrors : bool
Yes,
};

static Parse::ParseExpected<SourceControlFile> test_parse_manifest(const Json::Object& obj,
PrintErrors print = PrintErrors::Yes)
static ParseExpected<SourceControlFile> test_parse_manifest(const Json::Object& obj,
PrintErrors print = PrintErrors::Yes)
{
auto res = SourceControlFile::parse_manifest_object("<test manifest>", obj);
if (!res.has_value() && print == PrintErrors::Yes)
Expand All @@ -46,7 +46,7 @@ static Parse::ParseExpected<SourceControlFile> test_parse_manifest(const Json::O
}
return res;
}
static Parse::ParseExpected<SourceControlFile> test_parse_manifest(StringView obj, PrintErrors print = PrintErrors::Yes)
static ParseExpected<SourceControlFile> test_parse_manifest(StringView obj, PrintErrors print = PrintErrors::Yes)
{
return test_parse_manifest(parse_json_object(obj), print);
}
Expand Down Expand Up @@ -983,20 +983,20 @@ static std::string test_serialized_license(StringView license)

static bool license_is_parseable(StringView license)
{
Parse::ParseMessages messages;
ParseMessages messages;
parse_spdx_license_expression(license, messages);
return messages.error == nullptr;
}
static bool license_is_strict(StringView license)
{
Parse::ParseMessages messages;
ParseMessages messages;
parse_spdx_license_expression(license, messages);
return messages.error == nullptr && messages.warnings.empty();
}

static std::string test_format_parse_warning(const Parse::ParseMessage& msg)
static std::string test_format_parse_warning(const ParseMessage& msg)
{
return msg.format("<license string>", Parse::MessageKind::Warning).extract_data();
return msg.format("<license string>", MessageKind::Warning).extract_data();
}

TEST_CASE ("simple license in manifest", "[manifests][license]")
Expand Down Expand Up @@ -1046,7 +1046,7 @@ TEST_CASE ("license serialization", "[manifests][license]")

TEST_CASE ("license error messages", "[manifests][license]")
{
Parse::ParseMessages messages;
ParseMessages messages;
parse_spdx_license_expression("", messages);
REQUIRE(messages.error);
CHECK(messages.error->format() == R"(<license string>:1:1: error: SPDX license expression was empty.
Expand Down
6 changes: 3 additions & 3 deletions src/vcpkg-test/paragraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <vcpkg-test/util.h>

namespace Strings = vcpkg::Strings;
using vcpkg::Parse::Paragraph;
using vcpkg::Paragraph;

namespace
{
Expand All @@ -18,7 +18,7 @@ namespace
{
pghs.emplace_back();
for (auto&& kv : p)
pghs.back().emplace(kv.first, std::make_pair(kv.second, vcpkg::Parse::TextRowCol{}));
pghs.back().emplace(kv.first, std::make_pair(kv.second, vcpkg::TextRowCol{}));
}
return vcpkg::SourceControlFile::parse_control_file("", std::move(pghs));
}
Expand All @@ -27,7 +27,7 @@ namespace
{
Paragraph pgh;
for (auto&& kv : v)
pgh.emplace(kv.first, std::make_pair(kv.second, vcpkg::Parse::TextRowCol{}));
pgh.emplace(kv.first, std::make_pair(kv.second, vcpkg::TextRowCol{}));

return vcpkg::BinaryParagraph(std::move(pgh));
}
Expand Down
26 changes: 13 additions & 13 deletions src/vcpkg-test/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,26 +53,26 @@ namespace vcpkg::Test
const char* default_features,
const char* triplet)
{
return std::make_unique<StatusParagraph>(Parse::Paragraph{{"Package", {name, {}}},
{"Version", {"1", {}}},
{"Architecture", {triplet, {}}},
{"Multi-Arch", {"same", {}}},
{"Depends", {depends, {}}},
{"Default-Features", {default_features, {}}},
{"Status", {"install ok installed", {}}}});
return std::make_unique<StatusParagraph>(Paragraph{{"Package", {name, {}}},
{"Version", {"1", {}}},
{"Architecture", {triplet, {}}},
{"Multi-Arch", {"same", {}}},
{"Depends", {depends, {}}},
{"Default-Features", {default_features, {}}},
{"Status", {"install ok installed", {}}}});
}

std::unique_ptr<StatusParagraph> make_status_feature_pgh(const char* name,
const char* feature,
const char* depends,
const char* triplet)
{
return std::make_unique<StatusParagraph>(Parse::Paragraph{{"Package", {name, {}}},
{"Feature", {feature, {}}},
{"Architecture", {triplet, {}}},
{"Multi-Arch", {"same", {}}},
{"Depends", {depends, {}}},
{"Status", {"install ok installed", {}}}});
return std::make_unique<StatusParagraph>(Paragraph{{"Package", {name, {}}},
{"Feature", {feature, {}}},
{"Architecture", {triplet, {}}},
{"Multi-Arch", {"same", {}}},
{"Depends", {depends, {}}},
{"Status", {"install ok installed", {}}}});
}

PackageSpec PackageSpecMap::emplace(const char* name,
Expand Down
Loading