Skip to content

Commit

Permalink
added "EMBED" to the urlrules
Browse files Browse the repository at this point in the history
  • Loading branch information
LabRicecat committed Mar 20, 2023
1 parent c399ba2 commit 2d9039f
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
29 changes: 29 additions & 0 deletions inc/pagelist.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@ struct Rule {
// 1 -> after
// 2 -> instead
int script_handle = 1;
std::vector<std::pair<std::string,int>> embedded;

void merge(Rule rule) {
symbols = rule.symbols;
link = rule.link;
positions = rule.positions;
defaults = rule.defaults;
scripts = rule.scripts;
script_handle = rule.script_handle;
embedded = rule.embedded;
}
};
using RuleList = std::unordered_map<std::string,Rule>;
Expand Down Expand Up @@ -189,6 +193,31 @@ static inline std::unordered_map<std::string,std::function<std::string(std::vect

return "";
}},
{"EMBED",[](std::vector<KittenToken> args, Rule*& rule, RuleList& rules) -> std::string {
HASRULE();
NEEDARG(2);
NOSTRING(0);
NOSTRING(1);
std::pair<std::string,int> emb;

if(args[0].src == "BEFORE") {
emb.second = 0;
}
else if(args[0].src == "AFTER") {
emb.second = 1;
}
else if(args[0].src == "INSTEAD") {
emb.second = 2;
}
else ERR("unknown option: " + args[0].src);

if(args[1].src.front() != '{') ERR("expected {capsule}");
args[1].src.erase(args[1].src.begin());
args[1].src.pop_back();
emb.first = args[1].src;
rule->embedded.push_back(emb);
return "";
}}
};
#undef NEEDARG
#undef NOSTRING
Expand Down
32 changes: 30 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,24 @@ int main(int argc,char** argv) {
auto url = ask_to_resolve(project,2);
if(url.link == "") return 1;

if(url.rule.script_handle == 1)
bool dnl = true;
Interpreter emb_interpreter;
bake_extension(get_extension(),emb_interpreter.settings);
load_extensions(emb_interpreter);
for(auto i : url.rule.embedded) {
dnl &= i.second != 2;
if(i.second == 0) {
emb_interpreter.pre_process(i.first).on_error([&](Interpreter& i) {
print_message("ERROR","in embed: " + i.error());
}).otherwise([](Interpreter& i) {
i.run().on_error([&](Interpreter& j) {
print_message("ERROR","in embed: " + j.error());
});
});
}
}

if(url.rule.script_handle == 1 && dnl)
error = download_project(url.link);

if(error != "")
Expand All @@ -267,7 +284,18 @@ int main(int argc,char** argv) {
}
}
}
if(url.rule.script_handle == 0)
for(auto i : url.rule.embedded) {
if(i.second == 1) {
emb_interpreter.pre_process(i.first).on_error([&](Interpreter& i) {
print_message("ERROR","in embed: " + i.error());
}).otherwise([](Interpreter& i) {
i.run().on_error([&](Interpreter& j) {
print_message("ERROR","in embed: " + j.error());
});
});
}
}
if(url.rule.script_handle == 0 && dnl)
error = download_project(url.link);

print_message("RESULT","Successfully installed!");
Expand Down
1 change: 1 addition & 0 deletions src/pagelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

RuleList process_rulelist(std::string source) {
KittenLexer line_lexer = KittenLexer()
.add_capsule('{','}')
.add_ignore(' ')
.add_linebreak(';')
.add_con_extract(is_message_split_sign)
Expand Down

0 comments on commit 2d9039f

Please sign in to comment.