Refactored expression parsing.
This commit is contained in:
parent
0e739755b7
commit
e5bf7d754f
@ -87,17 +87,19 @@ ExpressionPointer parseExpressionContent(const std::string &expressionIdentifier
|
|||||||
{
|
{
|
||||||
context.parser.skipWhiteSpace();
|
context.parser.skipWhiteSpace();
|
||||||
|
|
||||||
ExpressionPointer expression;
|
|
||||||
|
|
||||||
if (expressionIdentifier == "and")
|
if (expressionIdentifier == "and")
|
||||||
expression = expressions::And::parse(context, parameters, parseExpression);
|
return expressions::And::parse(context, parameters, parseExpression);
|
||||||
else if (expressionIdentifier == "or")
|
|
||||||
expression = expressions::Or::parse(context, parameters, parseExpression);
|
if (expressionIdentifier == "or")
|
||||||
else if (expressionIdentifier == "not")
|
return expressions::Or::parse(context, parameters, parseExpression);
|
||||||
expression = expressions::Not::parse(context, parameters, parseExpression);
|
|
||||||
else if (expressionIdentifier == "imply")
|
if (expressionIdentifier == "not")
|
||||||
expression = expressions::Imply::parse(context, parameters, parseExpression);
|
return expressions::Not::parse(context, parameters, parseExpression);
|
||||||
else if (expressionIdentifier == "exists"
|
|
||||||
|
if (expressionIdentifier == "imply")
|
||||||
|
return expressions::Imply::parse(context, parameters, parseExpression);
|
||||||
|
|
||||||
|
if (expressionIdentifier == "exists"
|
||||||
|| expressionIdentifier == "forall"
|
|| expressionIdentifier == "forall"
|
||||||
|| expressionIdentifier == "-"
|
|| expressionIdentifier == "-"
|
||||||
|| expressionIdentifier == "="
|
|| expressionIdentifier == "="
|
||||||
@ -113,23 +115,19 @@ ExpressionPointer parseExpressionContent(const std::string &expressionIdentifier
|
|||||||
{
|
{
|
||||||
throwUnsupported(context.parser, expressionIdentifier);
|
throwUnsupported(context.parser, expressionIdentifier);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
// Check if predicate with that name exists
|
|
||||||
const auto match = std::find_if(context.predicateDeclarations.cbegin(), context.predicateDeclarations.cend(),
|
|
||||||
[&](const auto &predicate)
|
|
||||||
{
|
|
||||||
return predicate->name() == expressionIdentifier;
|
|
||||||
});
|
|
||||||
|
|
||||||
// If predicate exists, parse it
|
// Check if predicate with that name exists
|
||||||
if (match != context.predicateDeclarations.cend())
|
const auto match = std::find_if(context.predicateDeclarations.cbegin(), context.predicateDeclarations.cend(),
|
||||||
expression = expressions::Predicate::parse(expressionIdentifier, context, parameters);
|
[&](const auto &predicate)
|
||||||
else
|
{
|
||||||
throw utils::ParserException(context.parser, "Expression \"" + expressionIdentifier + "\" not allowed in this context");
|
return predicate->name() == expressionIdentifier;
|
||||||
}
|
});
|
||||||
|
|
||||||
return expression;
|
// If predicate exists, parse it
|
||||||
|
if (match != context.predicateDeclarations.cend())
|
||||||
|
return expressions::Predicate::parse(expressionIdentifier, context, parameters);
|
||||||
|
|
||||||
|
throw utils::ParserException(context.parser, "Expression \"" + expressionIdentifier + "\" not allowed in this context");
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -165,8 +163,9 @@ ExpressionPointer parseEffectBodyExpressionContent(const std::string &expression
|
|||||||
ExpressionPointer expression;
|
ExpressionPointer expression;
|
||||||
|
|
||||||
if (expressionIdentifier == "not")
|
if (expressionIdentifier == "not")
|
||||||
expression = expressions::Not::parse(context, parameters, parsePredicate);
|
return expressions::Not::parse(context, parameters, parsePredicate);
|
||||||
else if (expressionIdentifier == "="
|
|
||||||
|
if (expressionIdentifier == "="
|
||||||
|| expressionIdentifier == "assign"
|
|| expressionIdentifier == "assign"
|
||||||
|| expressionIdentifier == "scale-up"
|
|| expressionIdentifier == "scale-up"
|
||||||
|| expressionIdentifier == "scale-down"
|
|| expressionIdentifier == "scale-down"
|
||||||
@ -175,23 +174,19 @@ ExpressionPointer parseEffectBodyExpressionContent(const std::string &expression
|
|||||||
{
|
{
|
||||||
throwUnsupported(context.parser, expressionIdentifier);
|
throwUnsupported(context.parser, expressionIdentifier);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
// Check if predicate with that name exists
|
|
||||||
const auto match = std::find_if(context.predicateDeclarations.cbegin(), context.predicateDeclarations.cend(),
|
|
||||||
[&](const auto &predicate)
|
|
||||||
{
|
|
||||||
return predicate->name() == expressionIdentifier;
|
|
||||||
});
|
|
||||||
|
|
||||||
// If predicate exists, parse it
|
// Check if predicate with that name exists
|
||||||
if (match != context.predicateDeclarations.cend())
|
const auto match = std::find_if(context.predicateDeclarations.cbegin(), context.predicateDeclarations.cend(),
|
||||||
expression = expressions::Predicate::parse(expressionIdentifier, context, parameters);
|
[&](const auto &predicate)
|
||||||
else
|
{
|
||||||
throw utils::ParserException(context.parser, "Expression \"" + expressionIdentifier + "\" not allowed in this context");
|
return predicate->name() == expressionIdentifier;
|
||||||
}
|
});
|
||||||
|
|
||||||
return expression;
|
// If predicate exists, parse it
|
||||||
|
if (match != context.predicateDeclarations.cend())
|
||||||
|
return expressions::Predicate::parse(expressionIdentifier, context, parameters);
|
||||||
|
|
||||||
|
throw utils::ParserException(context.parser, "Expression \"" + expressionIdentifier + "\" not allowed in this context");
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
Reference in New Issue
Block a user