Commit 5480b534 authored by Alejandro Suarez Hernandez's avatar Alejandro Suarez Hernandez
Browse files

parsing total effects

parent 510e8fdc
......@@ -124,3 +124,10 @@ BOOST_AUTO_TEST_CASE(test_parse_effects)
BOOST_CHECK_EQUAL((*effectv)[1]->to_str(), "at(X,Z)");
}
BOOST_AUTO_TEST_CASE(test_forall_effects)
{
std::string str1("p(U, V), forall(p(x,Y),q(Y) -> r(),\\+q(Y)), q(Z)");
auto effects = parse_effects(str1);
INFO(*effects);
}
......@@ -267,11 +267,41 @@ Query::Ptr parse_query(const std::string& str)
return parse_query(tokens, cursor);
}
//Effect::Ptr parse_functional(const TokenV& tokens, std::size_t& cursor)
//{
//enum State { };
//return nullptr;
//}
Effect::Ptr parse_forall(const TokenV& tokens, std::size_t& cursor)
{
std::size_t idx = cursor;
Effect::Ptr forall = nullptr;
TokenV fst, snd;
if (tokens[++idx].first == "PAR_OPEN")
{
int parcount = 1;
bool end_fst = false;
while (not end_fst)
{
++idx;
if (tokens[idx].first == "PAR_OPEN") ++parcount;
else if (tokens[idx].first == "PAR_CLOSE") --parcount;
end_fst = tokens[idx].first == "RIGHTARROW";
if (end_fst) fst.push_back({"EOF", ""});
else fst.push_back(tokens[idx]);
}
while (parcount)
{
++idx;
if (tokens[idx].first == "PAR_OPEN") ++parcount;
else if (tokens[idx].first == "PAR_CLOSE") --parcount;
if (parcount) snd.push_back(tokens[idx]);
else snd.push_back({"EOF", ""});
}
std::size_t vcursor1 = 0;
std::size_t vcursor2 = 0;
Query::Ptr q = parse_query(fst, vcursor1);
Effect::Ptr e = parse_effects(snd, vcursor2);
if (q and e) forall.reset(new TotalEffect(q, e));
cursor = idx + 1;
}
return forall;
}
Effect::Ptr parse_next_effect(const TokenV& tokens, std::size_t& cursor)
{
......@@ -286,12 +316,12 @@ Effect::Ptr parse_next_effect(const TokenV& tokens, std::size_t& cursor)
switch (state)
{
case EXPECTING_EFFECT:
//if (token.first == "FUNCTIONAL")
//{
//effect = parse_functional(tokens, idx);
//state = effect? OK : KO;
//}
if (token.first == "NOT")
if (token.first == "FUNCTIONAL")
{
effect = parse_forall(tokens, idx);
state = effect? OK : KO;
}
else if (token.first == "NOT")
{
delete_effect = not delete_effect;
++idx;
......@@ -315,10 +345,8 @@ Effect::Ptr parse_next_effect(const TokenV& tokens, std::size_t& cursor)
return effect;
}
Effect::Ptr parse_effects(const std::string& str)
{
TokenV tokens = decompose(str);
std::size_t cursor = 0;
Effect::Ptr parse_effects(const TokenV& tokens, std::size_t& cursor)
{
auto effects = std::make_shared<EffectV>();
while (Effect::Ptr effect = parse_next_effect(tokens, cursor))
{
......@@ -327,6 +355,13 @@ Effect::Ptr parse_effects(const std::string& str)
return effects->size() == 1? (*effects)[0] : effects;
}
Effect::Ptr parse_effects(const std::string& str)
{
TokenV tokens = decompose(str);
std::size_t cursor = 0;
return parse_effects(tokens, cursor);
}
}
......@@ -26,6 +26,10 @@ Query::Ptr parse_query(const std::string& str);
Effect::Ptr parse_next_effect(const TokenV& tokens, std::size_t& cursor);
Effect::Ptr parse_forall(const TokenV& tokens, std::size_t& cursor);
Effect::Ptr parse_effects(const TokenV& tokens, std::size_t& cursor);
Effect::Ptr parse_effects(const std::string& str);
} /* end namespace imagine_planner */
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment