Refactored parsing variable lists to reuse it with quantified expressions.
This commit is contained in:
parent
6f3769f364
commit
ca6664feb2
@ -58,7 +58,6 @@ boost::intrusive_ptr<Derived> Binary<Derived>::parse(Context &context,
|
||||
|
||||
auto expression = boost::intrusive_ptr<Derived>(new Derived);
|
||||
|
||||
// Assume that expression identifier (imply, exists, etc.) is already parsed
|
||||
// Parse arguments of the expression
|
||||
expression->Binary<Derived>::setArgument(0, parseExpression(context, expressionContext));
|
||||
expression->Binary<Derived>::setArgument(1, parseExpression(context, expressionContext));
|
||||
|
@ -63,7 +63,6 @@ boost::intrusive_ptr<Derived> NAry<Derived>::parse(Context &context,
|
||||
|
||||
parser.skipWhiteSpace();
|
||||
|
||||
// Assume that expression identifier (and, or, etc.) is already parsed
|
||||
// Parse arguments of the expression
|
||||
while (parser.currentCharacter() != ')')
|
||||
{
|
||||
|
@ -21,8 +21,10 @@ class Variable: public ExpressionCRTP<Variable>
|
||||
public:
|
||||
static const Expression::Type ExpressionType = Expression::Type::Variable;
|
||||
|
||||
static void parseTypedDeclaration(Context &context, ExpressionContext &expressionContext);
|
||||
static void parseTypedDeclarations(Context &context, ExpressionContext &expressionContext);
|
||||
static void parseTypedDeclaration(Context &context, ExpressionContext &expressionContext,
|
||||
Variables &variables);
|
||||
static void parseTypedDeclarations(Context &context, ExpressionContext &expressionContext,
|
||||
Variables &variables);
|
||||
|
||||
static VariablePointer parseAndFind(Context &context,
|
||||
const ExpressionContext &expressionContext);
|
||||
|
@ -32,7 +32,7 @@ void Action::parseDeclaration(Context &context, Domain &domain)
|
||||
ExpressionContext expressionContext(domain, action->m_parameters);
|
||||
|
||||
// Read parameters
|
||||
expressions::Variable::parseTypedDeclarations(context, expressionContext);
|
||||
expressions::Variable::parseTypedDeclarations(context, expressionContext, action->m_parameters);
|
||||
|
||||
parser.expect<std::string>(")");
|
||||
|
||||
|
@ -42,7 +42,7 @@ void PredicateDeclaration::parse(Context &context, Domain &domain)
|
||||
ExpressionContext expressionContext(domain, predicate->m_parameters);
|
||||
|
||||
// Parse arguments
|
||||
expressions::Variable::parseTypedDeclarations(context, expressionContext);
|
||||
expressions::Variable::parseTypedDeclarations(context, expressionContext, predicate->m_parameters);
|
||||
|
||||
context.parser.expect<std::string>(")");
|
||||
|
||||
|
@ -63,10 +63,10 @@ void Variable::parseDeclaration(Context &context, Variables ¶meters)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Variable::parseTypedDeclaration(Context &context, ExpressionContext &expressionContext)
|
||||
void Variable::parseTypedDeclaration(Context &context, ExpressionContext &expressionContext,
|
||||
Variables &variables)
|
||||
{
|
||||
auto &parser = context.parser;
|
||||
auto &variables = expressionContext.parameters;
|
||||
|
||||
// Parse and store variable itself
|
||||
parseDeclaration(context, variables);
|
||||
@ -108,22 +108,23 @@ void Variable::parseTypedDeclaration(Context &context, ExpressionContext &expres
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Variable::parseTypedDeclarations(Context &context, ExpressionContext &expressionContext)
|
||||
void Variable::parseTypedDeclarations(Context &context, ExpressionContext &expressionContext,
|
||||
Variables &variables)
|
||||
{
|
||||
auto &parser = context.parser;
|
||||
|
||||
while (parser.currentCharacter() != ')')
|
||||
{
|
||||
parseTypedDeclaration(context, expressionContext);
|
||||
parseTypedDeclaration(context, expressionContext, variables);
|
||||
|
||||
parser.skipWhiteSpace();
|
||||
}
|
||||
|
||||
if (expressionContext.parameters.empty())
|
||||
if (variables.empty())
|
||||
return;
|
||||
|
||||
// Check correct use of typing requirement
|
||||
const auto typingUsed = (expressionContext.parameters.back()->type() != nullptr);
|
||||
const auto typingUsed = (variables.back()->type() != nullptr);
|
||||
|
||||
// If types are given, check that typing is a requirement
|
||||
if (typingUsed)
|
||||
|
Reference in New Issue
Block a user