diff --git a/include/plasp/pddl/IO.h b/include/plasp/pddl/IO.h new file mode 100644 index 0000000..6f40781 --- /dev/null +++ b/include/plasp/pddl/IO.h @@ -0,0 +1,46 @@ +#ifndef __PLASP__PDDL__IO_H +#define __PLASP__PDDL__IO_H + +#include + +#include + +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 diff --git a/src/plasp/pddl/Domain.cpp b/src/plasp/pddl/Domain.cpp index 340c819..5296870 100644 --- a/src/plasp/pddl/Domain.cpp +++ b/src/plasp/pddl/Domain.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -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 + "\""); } diff --git a/src/plasp/pddl/Problem.cpp b/src/plasp/pddl/Problem.cpp index 5a154bc..34b0df4 100644 --- a/src/plasp/pddl/Problem.cpp +++ b/src/plasp/pddl/Problem.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -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 + "\""); }