Checking type requirement.
This commit is contained in:
parent
af2f9290c6
commit
75fbb5fb48
@ -137,32 +137,36 @@ const std::vector<std::unique_ptr<Action>> &Domain::actions() const
|
|||||||
|
|
||||||
void Domain::parseSection()
|
void Domain::parseSection()
|
||||||
{
|
{
|
||||||
m_context.parser.expect<std::string>("(");
|
auto &parser = m_context.parser;
|
||||||
m_context.parser.expect<std::string>(":");
|
|
||||||
|
|
||||||
const auto sectionIdentifier = m_context.parser.parseIdentifier(isIdentifier);
|
parser.expect<std::string>("(");
|
||||||
|
parser.expect<std::string>(":");
|
||||||
|
|
||||||
// TODO: check order of the sections
|
// TODO: check order of the sections
|
||||||
if (sectionIdentifier == "requirements")
|
if (parser.probe<std::string>("requirements"))
|
||||||
parseRequirementSection();
|
parseRequirementSection();
|
||||||
else if (sectionIdentifier == "types")
|
else if (parser.probe<std::string>("types"))
|
||||||
parseTypeSection();
|
parseTypeSection();
|
||||||
else if (sectionIdentifier == "constants")
|
else if (parser.probe<std::string>("constants"))
|
||||||
parseConstantSection();
|
parseConstantSection();
|
||||||
else if (sectionIdentifier == "predicates")
|
else if (parser.probe<std::string>("predicates"))
|
||||||
parsePredicateSection();
|
parsePredicateSection();
|
||||||
else if (sectionIdentifier == "action")
|
else if (parser.probe<std::string>("action"))
|
||||||
parseActionSection();
|
parseActionSection();
|
||||||
else if (sectionIdentifier == "functions"
|
else if (parser.probe<std::string>("functions")
|
||||||
|| sectionIdentifier == "constraints"
|
|| parser.probe<std::string>("constraints")
|
||||||
|| sectionIdentifier == "durative-action"
|
|| parser.probe<std::string>("durative-action")
|
||||||
|| sectionIdentifier == "derived")
|
|| parser.probe<std::string>("derived"))
|
||||||
{
|
{
|
||||||
|
const auto sectionIdentifier = parser.parseIdentifier(isIdentifier);
|
||||||
std::cout << "Skipping section " << sectionIdentifier << std::endl;
|
std::cout << "Skipping section " << sectionIdentifier << std::endl;
|
||||||
skipSection(m_context.parser);
|
skipSection(m_context.parser);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
const auto sectionIdentifier = parser.parseIdentifier(isIdentifier);
|
||||||
throw utils::ParserException(m_context.parser, "Unknown domain section \"" + sectionIdentifier + "\"");
|
throw utils::ParserException(m_context.parser, "Unknown domain section \"" + sectionIdentifier + "\"");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -245,10 +249,13 @@ void Domain::computeDerivedRequirements()
|
|||||||
|
|
||||||
void Domain::parseTypeSection()
|
void Domain::parseTypeSection()
|
||||||
{
|
{
|
||||||
|
if (!hasRequirement(Requirement::Type::Typing))
|
||||||
|
throw utils::ParserException(m_context.parser, "Typing used but not declared as a requirement");
|
||||||
|
|
||||||
m_context.parser.skipWhiteSpace();
|
m_context.parser.skipWhiteSpace();
|
||||||
|
|
||||||
// Store types and their parent types
|
// Store types and their parent types
|
||||||
while (m_context.parser.currentCharacter() != ')')
|
while (!m_context.parser.probe(')'))
|
||||||
{
|
{
|
||||||
if (m_context.parser.currentCharacter() == '(')
|
if (m_context.parser.currentCharacter() == '(')
|
||||||
throw utils::ParserException(m_context.parser, "Only primitive types are allowed in type section");
|
throw utils::ParserException(m_context.parser, "Only primitive types are allowed in type section");
|
||||||
@ -257,8 +264,6 @@ void Domain::parseTypeSection()
|
|||||||
|
|
||||||
m_context.parser.skipWhiteSpace();
|
m_context.parser.skipWhiteSpace();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_context.parser.expect<std::string>(")");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -85,6 +85,9 @@ void PrimitiveType::parseTypedDeclaration(Context &context, Domain &domain)
|
|||||||
if (!context.parser.probe('-'))
|
if (!context.parser.probe('-'))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (!domain.hasRequirement(Requirement::Type::Typing))
|
||||||
|
throw utils::ParserException(context.parser, "Typing used but not declared as a requirement");
|
||||||
|
|
||||||
// If existing, parse and store parent type
|
// If existing, parse and store parent type
|
||||||
auto *parentType = parseAndFindOrCreate(context, domain);
|
auto *parentType = parseAndFindOrCreate(context, domain);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user