diff --git a/.vscode/settings.json b/.vscode/settings.json index 99408530..73792c10 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -116,7 +116,8 @@ "span": "cpp", "valarray": "cpp", "expected": "cpp", - "cfenv": "cpp" + "cfenv": "cpp", + "*.ipp": "cpp" }, "C_Cpp.errorSquiggles": "Disabled", "todo-tree.tree.scanMode": "workspace", diff --git a/sn.confy b/sn.confy new file mode 100644 index 00000000..cb6313ba --- /dev/null +++ b/sn.confy @@ -0,0 +1,3 @@ +project { + +} \ No newline at end of file diff --git a/src/app/cli.cc b/src/app/cli.cc index fe5ba664..b2cd6f84 100644 --- a/src/app/cli.cc +++ b/src/app/cli.cc @@ -1,5 +1,12 @@ -#include "cli.h" +#include + +#include "app/cli.h" +#include "compiler/reports/error.h" +#include "compiler/frontend/location.h" + +#define CONFY_USE_UTILS +#include "app/vendor/confy/src/confy.hpp" namespace snowball { namespace cli { @@ -12,8 +19,38 @@ const Ctx CLI::parse(int argc, char** argv) { ctx.build_mode = BuildMode::Build; ctx.input_file = "tests/main.sn"; ctx.emit_type = EmitType::Llvm; + get_package_config(ctx, ""); return ctx; } +// CONFY IMPLEMENTATION + +class ConfyPackageType final : public confy::StringType { +public: + std::optional validate(const std::string& value) const override { + if (value != "lib" && value != "exe" && value != "both") { + return "Invalid package type. Must be one of 'lib', 'exe' or 'both'"; + } + return std::nullopt; + } + static std::shared_ptr create() { + return std::make_shared(); + } +}; + +void CLI::get_package_config(Ctx& ctx, const std::string& path) { + static auto interface = confy::Interface::create({}); + std::string config_path = path.empty() ? "sn.confy" : path; + auto config = confy::parse_file(interface, config_path); + bool hasError = false; + for (const auto& error : config.get_errors()) { + hasError = true; + auto err_loc = error.get_position(); + auto loc = frontend::SourceLocation(err_loc.line, err_loc.column, 1, std::make_shared(config_path)); + auto e = E(error.get_message(), loc); + e.print(); + } +} + } } diff --git a/src/app/cli.h b/src/app/cli.h index 6bfaeb4d..88d587b9 100644 --- a/src/app/cli.h +++ b/src/app/cli.h @@ -3,6 +3,7 @@ #define __SNOWBALL_CLI_H__ #include "compiler/ctx.h" +#include "compiler/package.h" namespace snowball { namespace cli { @@ -28,6 +29,8 @@ class CLI { const Ctx parse(int argc, char** argv); private: void make_run(); + + void get_package_config(Ctx& ctx, const std::string& path = ""); }; } diff --git a/src/compiler/ctx.h b/src/compiler/ctx.h index 174f59ac..d0ad6616 100644 --- a/src/compiler/ctx.h +++ b/src/compiler/ctx.h @@ -3,6 +3,7 @@ #define __SNOWBALL_CTX_H__ #include +#include "compiler/package.h" namespace snowball { @@ -51,6 +52,8 @@ struct Ctx { BuildMode build_mode; EmitType emit_type; OptLevel opt_level = OptLevel::None; + + PackageConfig package_config = std::nullopt; }; } diff --git a/src/compiler/package.h b/src/compiler/package.h index c13ef3bb..69b4df8d 100644 --- a/src/compiler/package.h +++ b/src/compiler/package.h @@ -1,9 +1,10 @@ -#ifndef __SNOWBALL_CTX_H__ -#define __SNOWBALL_CTX_H__ +#ifndef __SNOWBALL_PACKAGE_CONFIG_H__ +#define __SNOWBALL_PACKAGE_CONFIG_H__ #include +#include namespace snowball { @@ -21,11 +22,11 @@ struct PackageConfigBase { struct Build { std::vector linkage_libs; } build; -} +}; using PackageConfig = std::optional; } -#endif // __SNOWBALL_CTX_H__ +#endif // __SNOWBALL_PACKAGE_CONFIG_H__