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,8 +115,7 @@ ExpressionPointer parseExpressionContent(const std::string &expressionIdentifier
|
|||||||
{
|
{
|
||||||
throwUnsupported(context.parser, expressionIdentifier);
|
throwUnsupported(context.parser, expressionIdentifier);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
// Check if predicate with that name exists
|
// Check if predicate with that name exists
|
||||||
const auto match = std::find_if(context.predicateDeclarations.cbegin(), context.predicateDeclarations.cend(),
|
const auto match = std::find_if(context.predicateDeclarations.cbegin(), context.predicateDeclarations.cend(),
|
||||||
[&](const auto &predicate)
|
[&](const auto &predicate)
|
||||||
@ -124,12 +125,9 @@ ExpressionPointer parseExpressionContent(const std::string &expressionIdentifier
|
|||||||
|
|
||||||
// If predicate exists, parse it
|
// If predicate exists, parse it
|
||||||
if (match != context.predicateDeclarations.cend())
|
if (match != context.predicateDeclarations.cend())
|
||||||
expression = expressions::Predicate::parse(expressionIdentifier, context, parameters);
|
return expressions::Predicate::parse(expressionIdentifier, context, parameters);
|
||||||
else
|
|
||||||
throw utils::ParserException(context.parser, "Expression \"" + expressionIdentifier + "\" not allowed in this context");
|
|
||||||
}
|
|
||||||
|
|
||||||
return expression;
|
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,8 +174,7 @@ ExpressionPointer parseEffectBodyExpressionContent(const std::string &expression
|
|||||||
{
|
{
|
||||||
throwUnsupported(context.parser, expressionIdentifier);
|
throwUnsupported(context.parser, expressionIdentifier);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
// Check if predicate with that name exists
|
// Check if predicate with that name exists
|
||||||
const auto match = std::find_if(context.predicateDeclarations.cbegin(), context.predicateDeclarations.cend(),
|
const auto match = std::find_if(context.predicateDeclarations.cbegin(), context.predicateDeclarations.cend(),
|
||||||
[&](const auto &predicate)
|
[&](const auto &predicate)
|
||||||
@ -186,12 +184,9 @@ ExpressionPointer parseEffectBodyExpressionContent(const std::string &expression
|
|||||||
|
|
||||||
// If predicate exists, parse it
|
// If predicate exists, parse it
|
||||||
if (match != context.predicateDeclarations.cend())
|
if (match != context.predicateDeclarations.cend())
|
||||||
expression = expressions::Predicate::parse(expressionIdentifier, context, parameters);
|
return expressions::Predicate::parse(expressionIdentifier, context, parameters);
|
||||||
else
|
|
||||||
throw utils::ParserException(context.parser, "Expression \"" + expressionIdentifier + "\" not allowed in this context");
|
|
||||||
}
|
|
||||||
|
|
||||||
return expression;
|
throw utils::ParserException(context.parser, "Expression \"" + expressionIdentifier + "\" not allowed in this context");
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
Reference in New Issue
Block a user