Commit 66343065 authored by Alejandro Suarez Hernandez's avatar Alejandro Suarez Hernandez
Browse files

some modifications in parsing to support total effects

parent a0bcd273
......@@ -41,7 +41,7 @@ BOOST_AUTO_TEST_CASE(spaces)
BOOST_AUTO_TEST_CASE(test_parse_predicate)
{
std::string str("at(lettuce,east), cost(2.5), r(), s(");
std::string str("at(lettuce,east), cost(2.5), r(), s( -> forall");
TokenV tokens = decompose(str);
INFO(tokens);
std::size_t cursor = 0;
......
......@@ -47,6 +47,11 @@ TokenV decompose(const std::string& in)
tokens.push_back({"NOT", ""});
cursor += 2;
}
else if (in_clean.compare(cursor, 2, "->") == 0)
{
tokens.push_back({"RIGHTARROW", ""});
cursor += 2;
}
else if (in_clean[cursor] == '(')
{
tokens.push_back({"PAR_OPEN", ""});
......@@ -69,12 +74,19 @@ TokenV decompose(const std::string& in)
}
else
{
std::size_t end = in_clean.find_first_of(",()\\", cursor);
std::size_t end = in_clean.find_first_of(",()\\-", cursor);
if (end == std::string::npos) end = in_clean.length();
std::size_t len = end - cursor;
std::string substr = in_clean.substr(cursor, len);
std::string type = is_number(substr)? "NUMBER" : "SYMBOL";
tokens.push_back({type, substr});
if (substr == "forall")
{
tokens.push_back({"FUNCTIONAL", "FORALL"});
}
else
{
std::string type = is_number(substr)? "NUMBER" : "SYMBOL";
tokens.push_back({type, substr});
}
cursor = end;
}
}
......@@ -255,10 +267,16 @@ 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_next_effect(const TokenV& tokens, std::size_t& cursor)
{
enum State {EXPECTING_ADD_OR_DEL, OK, KO};
State state = EXPECTING_ADD_OR_DEL;
enum State {EXPECTING_EFFECT, OK, KO};
State state = EXPECTING_EFFECT;
bool delete_effect = false;
Effect::Ptr effect = nullptr;
std::size_t idx = cursor;
......@@ -267,7 +285,12 @@ Effect::Ptr parse_next_effect(const TokenV& tokens, std::size_t& cursor)
const Token& token = tokens[idx];
switch (state)
{
case EXPECTING_ADD_OR_DEL:
case EXPECTING_EFFECT:
//if (token.first == "FUNCTIONAL")
//{
//effect = parse_functional(tokens, idx);
//state = effect? OK : KO;
//}
if (token.first == "NOT")
{
delete_effect = not delete_effect;
......
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