From e0dd9833a309bed7d6b391c2114fce1ebb05df7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Tue, 14 Jun 2016 01:31:22 +0200 Subject: [PATCH] Made unsupported expressions a separate type for disambiguation to fix issues with unsupported features. --- include/plasp/pddl/Expression.h | 4 ++ include/plasp/pddl/expressions/Unsupported.h | 40 +++++++++++++++++ src/plasp/pddl/Expression.cpp | 47 ++++---------------- src/plasp/pddl/InitialState.cpp | 17 ++----- src/plasp/pddl/expressions/Unsupported.cpp | 47 ++++++++++++++++++++ src/plasp/utils/Parser.cpp | 8 ++++ tests/TestPDDLTranslation.cpp | 21 +++++++++ 7 files changed, 132 insertions(+), 52 deletions(-) create mode 100644 include/plasp/pddl/expressions/Unsupported.h create mode 100644 src/plasp/pddl/expressions/Unsupported.cpp create mode 100644 tests/TestPDDLTranslation.cpp diff --git a/include/plasp/pddl/Expression.h b/include/plasp/pddl/Expression.h index fb2f009..055a4c0 100644 --- a/include/plasp/pddl/Expression.h +++ b/include/plasp/pddl/Expression.h @@ -62,6 +62,9 @@ class PrimitiveType; using PrimitiveTypePointer = std::unique_ptr; using PrimitiveTypes = std::vector; +class Unsupported; +using UnsupportedPointer = std::unique_ptr; + class Variable; using VariablePointer = std::unique_ptr; using Variables = std::vector; @@ -85,6 +88,7 @@ class Expression PredicateDeclaration, Predicate, PrimitiveType, + Unsupported, Variable }; diff --git a/include/plasp/pddl/expressions/Unsupported.h b/include/plasp/pddl/expressions/Unsupported.h new file mode 100644 index 0000000..6be1be4 --- /dev/null +++ b/include/plasp/pddl/expressions/Unsupported.h @@ -0,0 +1,40 @@ +#ifndef __PLASP__PDDL__EXPRESSIONS__UNSUPPORTED_H +#define __PLASP__PDDL__EXPRESSIONS__UNSUPPORTED_H + +#include +#include + +namespace plasp +{ +namespace pddl +{ +namespace expressions +{ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// +// Unsupported +// +//////////////////////////////////////////////////////////////////////////////////////////////////// + +class Unsupported: public ExpressionCRTP +{ + public: + static const Expression::Type ExpressionType = Expression::Type::Unsupported; + + static UnsupportedPointer parse(Context &context); + + public: + const std::string &type() const; + + private: + std::string m_type; +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +} +} +} + +#endif diff --git a/src/plasp/pddl/Expression.cpp b/src/plasp/pddl/Expression.cpp index fd6b667..0dfe022 100644 --- a/src/plasp/pddl/Expression.cpp +++ b/src/plasp/pddl/Expression.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -30,13 +31,6 @@ ExpressionPointer parsePredicate(Context &context, ExpressionContext &expression //////////////////////////////////////////////////////////////////////////////////////////////////// -inline void warnUnsupported(Context &context, const std::string &expressionIdentifier) -{ - context.logger.parserWarning(context.parser, "Expression type \"" + expressionIdentifier + "\" currently unsupported in this context"); -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// - ExpressionPointer parsePreconditionExpression(Context &context, ExpressionContext &expressionContext) { @@ -63,12 +57,7 @@ ExpressionPointer parsePreconditionExpression(Context &context, const auto expressionIdentifier = parser.parseIdentifier(isIdentifier); parser.seek(position); - warnUnsupported(context, expressionIdentifier); - - parser.seek(expressionIdentifierPosition); - skipSection(parser); - - return nullptr; + return expressions::Unsupported::parse(context); } parser.seek(position); @@ -118,12 +107,7 @@ ExpressionPointer parseExpression(Context &context, ExpressionContext &expressio const auto expressionIdentifier = parser.parseIdentifier(isIdentifier); parser.seek(position); - warnUnsupported(context, expressionIdentifier); - - parser.seek(expressionIdentifierPosition); - skipSection(parser); - - return nullptr; + return expressions::Unsupported::parse(context); } parser.seek(expressionIdentifierPosition); @@ -157,12 +141,7 @@ ExpressionPointer parseEffectExpression(Context &context, ExpressionContext &exp const auto expressionIdentifier = parser.parseIdentifier(isIdentifier); parser.seek(position); - warnUnsupported(context, expressionIdentifier); - - parser.seek(expressionIdentifierPosition); - skipSection(parser); - - return nullptr; + return expressions::Unsupported::parse(context); } parser.seek(position); @@ -200,12 +179,7 @@ ExpressionPointer parseEffectBodyExpression(Context &context, ExpressionContext const auto expressionIdentifier = parser.parseIdentifier(isIdentifier); parser.seek(position); - warnUnsupported(context, expressionIdentifier); - - parser.seek(expressionIdentifierPosition); - skipSection(parser); - - return nullptr; + return expressions::Unsupported::parse(context); } parser.seek(expressionIdentifierPosition); @@ -255,7 +229,8 @@ ExpressionPointer parseAtomicFormula(Context &context, ExpressionContext &expres const auto position = parser.position(); - parser.expect("("); + if (!parser.probe("(")) + return nullptr; const auto expressionIdentifierPosition = parser.position(); @@ -265,14 +240,10 @@ ExpressionPointer parseAtomicFormula(Context &context, ExpressionContext &expres const auto expressionIdentifier = parser.parseIdentifier(isIdentifier); parser.seek(position); - warnUnsupported(context, expressionIdentifier); - - parser.seek(expressionIdentifierPosition); - skipSection(parser); - - return nullptr; + return expressions::Unsupported::parse(context); } + parser.seek(position); return nullptr; } diff --git a/src/plasp/pddl/InitialState.cpp b/src/plasp/pddl/InitialState.cpp index 741441d..65ebd35 100644 --- a/src/plasp/pddl/InitialState.cpp +++ b/src/plasp/pddl/InitialState.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include namespace plasp @@ -20,13 +21,6 @@ namespace pddl // //////////////////////////////////////////////////////////////////////////////////////////////////// -inline void warnUnsupported(Context &context, const std::string &expressionIdentifier) -{ - context.logger.parserWarning(context.parser, "Expression type \"" + expressionIdentifier + "\" currently unsupported in this context"); -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// - std::unique_ptr InitialState::parseDeclaration(Context &context, ExpressionContext &expressionContext) { @@ -35,7 +29,7 @@ std::unique_ptr InitialState::parseDeclaration(Context &context, auto initialState = std::make_unique(InitialState()); const auto parseInitialStateElement = - [&]() + [&]() -> ExpressionPointer { ExpressionPointer expression; @@ -58,12 +52,7 @@ std::unique_ptr InitialState::parseDeclaration(Context &context, const auto expressionIdentifier = parser.parseIdentifier(isIdentifier); parser.seek(position); - warnUnsupported(context, expressionIdentifier); - - parser.seek(expressionIdentifierPosition); - skipSection(parser); - - return ExpressionPointer(); + return expressions::Unsupported::parse(context); } parser.seek(expressionIdentifierPosition); diff --git a/src/plasp/pddl/expressions/Unsupported.cpp b/src/plasp/pddl/expressions/Unsupported.cpp new file mode 100644 index 0000000..cffed55 --- /dev/null +++ b/src/plasp/pddl/expressions/Unsupported.cpp @@ -0,0 +1,47 @@ +#include + +#include +#include + +namespace plasp +{ +namespace pddl +{ +namespace expressions +{ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// +// Unsupported +// +//////////////////////////////////////////////////////////////////////////////////////////////////// + +UnsupportedPointer Unsupported::parse(Context &context) +{ + auto &parser = context.parser; + + auto expression = std::make_unique(Unsupported()); + + parser.expect("("); + + expression->m_type = parser.parseIdentifier(isIdentifier); + + context.logger.parserWarning(context.parser, "Expression type \"" + expression->m_type + "\" currently unsupported in this context"); + + skipSection(parser); + + return expression; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +const std::string &Unsupported::type() const +{ + return m_type; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +} +} +} diff --git a/src/plasp/utils/Parser.cpp b/src/plasp/utils/Parser.cpp index c1aacc4..bfb21c0 100644 --- a/src/plasp/utils/Parser.cpp +++ b/src/plasp/utils/Parser.cpp @@ -530,9 +530,17 @@ void Parser::expect(const bool &expectedValue) bool Parser::probeNumber() { + const auto previousPosition = position(); + + skipWhiteSpace(); + while (!std::iswspace(currentCharacter())) if (!std::isdigit(currentCharacter())) + { + seek(previousPosition); + return false; + } return true; } diff --git a/tests/TestPDDLTranslation.cpp b/tests/TestPDDLTranslation.cpp new file mode 100644 index 0000000..fd27803 --- /dev/null +++ b/tests/TestPDDLTranslation.cpp @@ -0,0 +1,21 @@ +#include + +#include +#include + +#include +#include + +using namespace plasp::pddl; + +boost::iostreams::stream nullStream((boost::iostreams::null_sink())); + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +TEST(PDDLTranslationTests, CheckIssues) +{ + // Check that translating domains without typing information works + const auto description = Description::fromFile("data/issues/issue-4.pddl"); + const auto translator = TranslatorASP(description, nullStream); + ASSERT_NO_THROW(translator.translate()); +}