Implemented type requirement checking for problem objects.
This commit is contained in:
parent
bf0e636d57
commit
993d14d409
@ -25,6 +25,7 @@ class Constant: public Expression
|
||||
static void parseTypedDeclaration(Context &context, Domain &domain);
|
||||
static void parseTypedDeclarations(Context &context, Domain &domain);
|
||||
static void parseTypedDeclaration(Context &context, Problem &problem);
|
||||
static void parseTypedDeclarations(Context &context, Problem &problem);
|
||||
|
||||
static Constant *parseAndFind(Context &context, const ExpressionContext &expressionContext);
|
||||
|
||||
|
@ -235,12 +235,7 @@ void Problem::parseObjectSection()
|
||||
m_context.parser.skipWhiteSpace();
|
||||
|
||||
// Store constants
|
||||
while (m_context.parser.currentCharacter() != ')')
|
||||
{
|
||||
expressions::Constant::parseTypedDeclaration(m_context, *this);
|
||||
|
||||
m_context.parser.skipWhiteSpace();
|
||||
}
|
||||
expressions::Constant::parseTypedDeclarations(m_context, *this);
|
||||
|
||||
m_context.parser.expect<std::string>(")");
|
||||
}
|
||||
|
@ -113,6 +113,28 @@ void Constant::parseTypedDeclarations(Context &context, Domain &domain)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Constant::parseTypedDeclarations(Context &context, Problem &problem)
|
||||
{
|
||||
while (context.parser.currentCharacter() != ')')
|
||||
parseTypedDeclaration(context, problem);
|
||||
|
||||
if (problem.objects().empty())
|
||||
return;
|
||||
|
||||
// Check correct use of typing requirement
|
||||
const auto typingUsed = (problem.objects().back()->type() != nullptr);
|
||||
const auto typingDeclared = problem.domain().hasRequirement(Requirement::Type::Typing)
|
||||
|| problem.hasRequirement(Requirement::Type::Typing);
|
||||
|
||||
if (!typingUsed && typingDeclared)
|
||||
throw utils::ParserException(context.parser, "Constant has undeclared type");
|
||||
|
||||
if (typingUsed && !typingDeclared)
|
||||
throw utils::ParserException(context.parser, "Typing used but not declared as a requirement");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Constant *Constant::parseAndFind(Context &context, const ExpressionContext &expressionContext)
|
||||
{
|
||||
context.parser.skipWhiteSpace();
|
||||
|
Reference in New Issue
Block a user