|
| 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