patrick
/
plasp
Archived
1
0
Fork 0

Extracted function for skipping entire sections.

This commit is contained in:
Patrick Lühne 2016-06-08 00:13:53 +02:00
parent abfa3b3ca1
commit 9360f4295a
3 changed files with 65 additions and 66 deletions

46
include/plasp/pddl/IO.h Normal file
View File

@ -0,0 +1,46 @@
#ifndef __PLASP__PDDL__IO_H
#define __PLASP__PDDL__IO_H
#include <iostream>
#include <plasp/utils/Parser.h>
namespace plasp
{
namespace pddl
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// IO
//
////////////////////////////////////////////////////////////////////////////////////////////////////
const auto skipSection =
[](utils::Parser &parser)
{
size_t openParentheses = 1;
while (true)
{
const auto character = parser.currentCharacter();
parser.advance();
if (character == '(')
openParentheses++;
else if (character == ')')
{
openParentheses--;
if (openParentheses == 0)
return;
}
}
};
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
#endif

View File

@ -4,6 +4,7 @@
#include <plasp/pddl/ConsistencyException.h>
#include <plasp/pddl/Identifier.h>
#include <plasp/pddl/IO.h>
#include <plasp/pddl/expressions/Constant.h>
#include <plasp/pddl/expressions/PredicateDeclaration.h>
#include <plasp/pddl/expressions/PrimitiveType.h>
@ -152,30 +153,6 @@ void Domain::parseSection()
const auto sectionIdentifier = m_context.parser.parseIdentifier(isIdentifier);
const auto skipSection =
[&]()
{
std::cout << "Skipping section " << sectionIdentifier << std::endl;
size_t openParentheses = 1;
while (true)
{
const auto character = m_context.parser.currentCharacter();
m_context.parser.advance();
if (character == '(')
openParentheses++;
else if (character == ')')
{
openParentheses--;
if (openParentheses == 0)
return;
}
}
};
// TODO: check order of the sections
if (sectionIdentifier == "requirements")
parseRequirementSection();
@ -185,16 +162,16 @@ void Domain::parseSection()
parseConstantSection();
else if (sectionIdentifier == "predicates")
parsePredicateSection();
else if (sectionIdentifier == "functions")
skipSection();
else if (sectionIdentifier == "constraints")
skipSection();
else if (sectionIdentifier == "action")
parseActionSection();
else if (sectionIdentifier == "durative-action")
skipSection();
else if (sectionIdentifier == "derived")
skipSection();
else if (sectionIdentifier == "functions"
|| sectionIdentifier == "constraints"
|| sectionIdentifier == "durative-action"
|| sectionIdentifier == "derived")
{
std::cout << "Skipping section " << sectionIdentifier << std::endl;
skipSection(m_context.parser);
}
else
throw utils::ParserException(m_context.parser, "Unknown domain section \"" + sectionIdentifier + "\"");
}

View File

@ -4,6 +4,7 @@
#include <plasp/pddl/Domain.h>
#include <plasp/pddl/Identifier.h>
#include <plasp/pddl/IO.h>
#include <plasp/pddl/expressions/Constant.h>
#include <plasp/utils/IO.h>
#include <plasp/utils/ParserException.h>
@ -109,30 +110,6 @@ void Problem::parseSection()
const auto sectionIdentifier = m_context.parser.parseIdentifier(isIdentifier);
const auto skipSection =
[&]()
{
std::cout << "Skipping section " << sectionIdentifier << std::endl;
size_t openParentheses = 1;
while (true)
{
const auto character = m_context.parser.currentCharacter();
m_context.parser.advance();
if (character == '(')
openParentheses++;
else if (character == ')')
{
openParentheses--;
if (openParentheses == 0)
return;
}
}
};
// TODO: check order of the sections
if (sectionIdentifier == "domain")
parseDomainSection();
@ -140,16 +117,15 @@ void Problem::parseSection()
parseRequirementSection();
else if (sectionIdentifier == "objects")
parseObjectSection();
else if (sectionIdentifier == "init")
skipSection();
else if (sectionIdentifier == "goal")
skipSection();
else if (sectionIdentifier == "constraints")
skipSection();
else if (sectionIdentifier == "metric")
skipSection();
else if (sectionIdentifier == "length")
skipSection();
else if (sectionIdentifier == "init"
|| sectionIdentifier == "goal"
|| sectionIdentifier == "constraints"
|| sectionIdentifier == "metric"
|| sectionIdentifier == "length")
{
std::cout << "Skipping section " << sectionIdentifier << std::endl;
skipSection(m_context.parser);
}
else
throw utils::ParserException(m_context.parser, "Unknown problem section \"" + sectionIdentifier + "\"");
}