Skip to content

Commit da294c5

Browse files
committed
feat(project): add strict native TOML parsing
2 parents 9d6928e + f5a4e7c commit da294c5

7 files changed

Lines changed: 18755 additions & 0 deletions

File tree

‎CMakeLists.txt‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ add_executable(vix::cli ALIAS vix_cli)
7474
target_include_directories(vix_cli PRIVATE
7575
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
7676
)
77+
target_include_directories(vix_cli SYSTEM PRIVATE
78+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/third_party/tomlplusplus>
79+
)
7780

7881
function(vix_add_flag_if_supported tgt flag)
7982
string(REGEX REPLACE "[^A-Za-z0-9]" "_" flag_var "${flag}")
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/** @file TomlParser.hpp
2+
* Strict TOML format-1 readers for native project/package artifacts.
3+
* This interface intentionally contains no third-party TOML types.
4+
*/
5+
#ifndef VIX_CLI_PROJECT_NATIVE_TOML_PARSER_HPP
6+
#define VIX_CLI_PROJECT_NATIVE_TOML_PARSER_HPP
7+
8+
#include <filesystem>
9+
#include <optional>
10+
#include <string>
11+
#include <string_view>
12+
#include <vector>
13+
14+
#include <vix/cli/project/native/Models.hpp>
15+
#include <vix/cli/project/native/Validation.hpp>
16+
17+
namespace vix::cli::project::native
18+
{
19+
enum class ParseErrorCode
20+
{
21+
toml_syntax_error,
22+
unsupported_format,
23+
missing_field,
24+
unknown_field,
25+
wrong_type,
26+
invalid_value,
27+
invalid_discriminated_shape,
28+
io_error
29+
};
30+
31+
struct ParseIssue
32+
{
33+
ParseErrorCode code{ParseErrorCode::invalid_value};
34+
std::string fieldPath;
35+
std::string message;
36+
std::optional<ValidationLocation> location;
37+
};
38+
39+
template <typename T>
40+
struct ParseResult
41+
{
42+
std::optional<T> value;
43+
std::vector<ParseIssue> issues;
44+
[[nodiscard]] bool valid() const noexcept { return value.has_value() && issues.empty(); }
45+
};
46+
47+
[[nodiscard]] ParseResult<NativeProject> parse_native_manifest_text(
48+
std::string_view text, std::string_view source = "<text>");
49+
[[nodiscard]] ParseResult<NativeProject> parse_native_manifest_file(const std::filesystem::path &path);
50+
51+
[[nodiscard]] ParseResult<PackageContract> parse_package_contract_text(
52+
std::string_view text, std::string_view source = "<text>");
53+
[[nodiscard]] ParseResult<PackageContract> parse_package_contract_file(const std::filesystem::path &path);
54+
55+
[[nodiscard]] ParseResult<Lockfile> parse_lockfile_text(
56+
std::string_view text, std::string_view source = "<text>");
57+
[[nodiscard]] ParseResult<Lockfile> parse_lockfile_file(const std::filesystem::path &path);
58+
59+
// Semantic validation remains explicit and is performed by the P10A APIs:
60+
// validate_native_project, validate_package_contract, and validate_lockfile.
61+
[[nodiscard]] std::string_view to_string(ParseErrorCode code) noexcept;
62+
} // namespace vix::cli::project::native
63+
64+
#endif // VIX_CLI_PROJECT_NATIVE_TOML_PARSER_HPP

0 commit comments

Comments
 (0)