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

View File

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