Made unsupported expressions a separate type for disambiguation to fix issues with unsupported features.
This commit is contained in:
parent
591d3fcafd
commit
e0dd9833a3
@ -62,6 +62,9 @@ class PrimitiveType;
|
||||
using PrimitiveTypePointer = std::unique_ptr<PrimitiveType>;
|
||||
using PrimitiveTypes = std::vector<PrimitiveTypePointer>;
|
||||
|
||||
class Unsupported;
|
||||
using UnsupportedPointer = std::unique_ptr<Unsupported>;
|
||||
|
||||
class Variable;
|
||||
using VariablePointer = std::unique_ptr<Variable>;
|
||||
using Variables = std::vector<VariablePointer>;
|
||||
@ -85,6 +88,7 @@ class Expression
|
||||
PredicateDeclaration,
|
||||
Predicate,
|
||||
PrimitiveType,
|
||||
Unsupported,
|
||||
Variable
|
||||
};
|
||||
|
||||
|
40
include/plasp/pddl/expressions/Unsupported.h
Normal file
40
include/plasp/pddl/expressions/Unsupported.h
Normal file
@ -0,0 +1,40 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSIONS__UNSUPPORTED_H
|
||||
#define __PLASP__PDDL__EXPRESSIONS__UNSUPPORTED_H
|
||||
|
||||
#include <plasp/pddl/Context.h>
|
||||
#include <plasp/pddl/Expression.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace expressions
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Unsupported
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Unsupported: public ExpressionCRTP<Unsupported>
|
||||
{
|
||||
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
|
@ -11,6 +11,7 @@
|
||||
#include <plasp/pddl/expressions/Or.h>
|
||||
#include <plasp/pddl/expressions/Predicate.h>
|
||||
#include <plasp/pddl/expressions/PredicateDeclaration.h>
|
||||
#include <plasp/pddl/expressions/Unsupported.h>
|
||||
#include <plasp/utils/IO.h>
|
||||
#include <plasp/utils/ParserException.h>
|
||||
|
||||
@ -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<std::string>("(");
|
||||
if (!parser.probe<std::string>("("))
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <plasp/pddl/Problem.h>
|
||||
#include <plasp/pddl/expressions/At.h>
|
||||
#include <plasp/pddl/expressions/Predicate.h>
|
||||
#include <plasp/pddl/expressions/Unsupported.h>
|
||||
#include <plasp/utils/ParserException.h>
|
||||
|
||||
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> InitialState::parseDeclaration(Context &context,
|
||||
ExpressionContext &expressionContext)
|
||||
{
|
||||
@ -35,7 +29,7 @@ std::unique_ptr<InitialState> InitialState::parseDeclaration(Context &context,
|
||||
auto initialState = std::make_unique<InitialState>(InitialState());
|
||||
|
||||
const auto parseInitialStateElement =
|
||||
[&]()
|
||||
[&]() -> ExpressionPointer
|
||||
{
|
||||
ExpressionPointer expression;
|
||||
|
||||
@ -58,12 +52,7 @@ std::unique_ptr<InitialState> 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);
|
||||
|
47
src/plasp/pddl/expressions/Unsupported.cpp
Normal file
47
src/plasp/pddl/expressions/Unsupported.cpp
Normal file
@ -0,0 +1,47 @@
|
||||
#include <plasp/pddl/expressions/Unsupported.h>
|
||||
|
||||
#include <plasp/pddl/Identifier.h>
|
||||
#include <plasp/pddl/IO.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace expressions
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Unsupported
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
UnsupportedPointer Unsupported::parse(Context &context)
|
||||
{
|
||||
auto &parser = context.parser;
|
||||
|
||||
auto expression = std::make_unique<Unsupported>(Unsupported());
|
||||
|
||||
parser.expect<std::string>("(");
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -530,9 +530,17 @@ void Parser::expect<bool>(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;
|
||||
}
|
||||
|
21
tests/TestPDDLTranslation.cpp
Normal file
21
tests/TestPDDLTranslation.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <boost/iostreams/stream.hpp>
|
||||
#include <boost/iostreams/device/null.hpp>
|
||||
|
||||
#include <plasp/pddl/Description.h>
|
||||
#include <plasp/pddl/TranslatorASP.h>
|
||||
|
||||
using namespace plasp::pddl;
|
||||
|
||||
boost::iostreams::stream<boost::iostreams::null_sink> 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());
|
||||
}
|
Reference in New Issue
Block a user