Skip to content

Commit

Permalink
better object parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipDeegan committed Sep 30, 2024
1 parent c78569c commit 050ad4f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 19 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build_nix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ jobs:
KLOG=3 ./mkn build -dtKa "-std=c++17 -fPIC" -O 2 -g 0 -W 9
KLOG=3 ./mkn build -Op test_mod -a "-std=c++17 -fPIC" -O 2 -g 0 -W 9
KLOG=3 ./mkn build test pack -Op test -a "-std=c++17 -fPIC" -O 2 -g 0 -W 9
KLOG=3 ./mkn build -dtOp format -a "-std=c++17 -fPIC" -O 2 -g 0 -W 9
ldd bin/build/mkn
2 changes: 1 addition & 1 deletion inc/maiken/project.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace maiken {

struct ProjectInfo {
std::string local /*&*/, profiles, name, version /*#*/, scm;
std::string local /*&*/, profiles, name, version /*#*/, scm, bon = "";

ProjectInfo static PARSE_LINE(std::string const& line);
};
Expand Down
7 changes: 5 additions & 2 deletions mkn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
name: mkn
version: master
property:
DATE: 29-SEP-2024
DATE: 30-SEP-2024

parent: bin
mode: none
Expand Down Expand Up @@ -67,11 +67,14 @@ profile:
main: server.cpp
mode: none

- name: format
- name: format_a
mod:
- name: clang.format
version: ${version}
init:
style: file
paths: .

- name: format
mod: |
clang.format{init:{style: google, paths: .}}
19 changes: 5 additions & 14 deletions src/maiken/mods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,13 @@ void maiken::Application::mod(mkn::kul::hash::set::String& mods, std::vector<YAM
auto& node = mod_nodes.emplace_back();

ProjectInfo pInfo = ProjectInfo::PARSE_LINE(mod);

auto& [local, profiles, proj, version, scm] = pInfo;
// KLOG(INF) << proj;
std::string objs;
auto& [local, profiles, proj, version, scm, curlies] = pInfo;

if (!node[STR_SCM] && scm.size()) node[STR_SCM] = scm;
if (!node[STR_PROFILE] && profiles.size()) node[STR_PROFILE] = profiles;

{
auto lbrak = proj.find("{"), rbrak = proj.rfind("}");
if (lbrak != std::string::npos) {
if (rbrak == std::string::npos) KEXIT(1, "Invalid -m - missing right } bracket");
objs = proj.substr(lbrak), proj = proj.substr(0, lbrak);
}

auto am = proj.find("&"), ha = proj.find("#");
auto const am = proj.find("&"), ha = proj.find("#");
if (proj == this->project().root()[STR_NAME].Scalar()) {
node[STR_LOCAL] = ".";
if (am != std::string::npos || ha != std::string::npos)
Expand All @@ -88,7 +79,7 @@ void maiken::Application::mod(mkn::kul::hash::set::String& mods, std::vector<YAM
"location");
}

auto if_set = [&](auto& v, auto n) {
auto const if_set = [&](auto& v, auto n) {
if (v.size()) n = v;
};
if_set(local, node[STR_LOCAL]);
Expand All @@ -108,8 +99,8 @@ void maiken::Application::mod(mkn::kul::hash::set::String& mods, std::vector<YAM
}
if (!proj.empty()) node[STR_NAME] = proj;

if (objs.size())
for (auto const p : mkn::kul::bon::from(objs)) node[p.first] = p.second;
if (curlies.size())
for (auto const p : mkn::kul::bon::from("{" + curlies + "}")) node[p.first] = p.second;

YAML::Emitter out;
out << node;
Expand Down
6 changes: 4 additions & 2 deletions src/project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "maiken/project.hpp"

maiken::ProjectInfo maiken::ProjectInfo::PARSE_LINE(std::string const& line) {
std::string local /*&*/, profiles, proj = line, version /*#*/, scm;
std::string local /*&*/, profiles, proj = line, version /*#*/, scm, bon;

auto get_between = [&](auto& var, auto lbrak, auto rbrak) {
auto between = maiken::string::between_rm_str(proj, lbrak, rbrak);
Expand All @@ -46,6 +46,8 @@ maiken::ProjectInfo maiken::ProjectInfo::PARSE_LINE(std::string const& line) {

if (!get_between(scm, "(", ")")) KEXIT(1, "Invalid -m - missing right ) bracket");
if (!get_between(profiles, "[", "]")) KEXIT(1, "Invalid -m - missing right ] bracket");
if (!get_between(bon, "{", "}")) KEXIT(1, "Invalid -m - missing right } bracket");

mkn::kul::String::REPLACE_ALL(profiles, ",", " ");

auto am = proj.find("&"), ha = proj.find("#");
Expand All @@ -61,7 +63,7 @@ maiken::ProjectInfo maiken::ProjectInfo::PARSE_LINE(std::string const& line) {
if (version.size() == 0 && scm.size() && !Github::GET_LATEST(scm, version)) version = "";
#endif

return {local, profiles, proj, version, scm.size() ? scm : proj};
return {local, profiles, proj, version, scm.size() ? scm : proj, bon};
}

mkn::kul::yaml::Validator maiken::Project::validator() const {
Expand Down

0 comments on commit 050ad4f

Please sign in to comment.