Added AST representation for “equals” expressions.
This commit is contained in:
parent
9199b68080
commit
716b4801aa
@ -292,6 +292,19 @@ struct Either: public NAry<Either<Argument>, Argument>
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
template<class ArgumentLeft, class ArgumentRight>
|
||||||
|
struct Equals: public Binary<Equals<ArgumentLeft, ArgumentRight>, ArgumentLeft, ArgumentRight>
|
||||||
|
{
|
||||||
|
static constexpr const auto Identifier = "=";
|
||||||
|
|
||||||
|
explicit Equals(ArgumentLeft &&argumentLeft, ArgumentRight &&argumentRight)
|
||||||
|
: Binary<Equals<ArgumentLeft, ArgumentRight>, ArgumentLeft, ArgumentRight>(std::move(argumentLeft), std::move(argumentRight))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
template<class Argument>
|
template<class Argument>
|
||||||
struct Exists: public Quantified<Exists<Argument>, Argument>
|
struct Exists: public Quantified<Exists<Argument>, Argument>
|
||||||
{
|
{
|
||||||
|
@ -70,6 +70,10 @@ template<class Argument>
|
|||||||
struct Either;
|
struct Either;
|
||||||
template<class Argument>
|
template<class Argument>
|
||||||
using EitherPointer = std::unique_ptr<Either<Argument>>;
|
using EitherPointer = std::unique_ptr<Either<Argument>>;
|
||||||
|
template<class ArgumentLeft, class ArgumentRight>
|
||||||
|
struct Equals;
|
||||||
|
template<class ArgumentLeft, class ArgumentRight>
|
||||||
|
using EqualsPointer = std::unique_ptr<Equals<ArgumentLeft, ArgumentRight>>;
|
||||||
template<class Argument>
|
template<class Argument>
|
||||||
struct Exists;
|
struct Exists;
|
||||||
template<class Argument>
|
template<class Argument>
|
||||||
@ -136,8 +140,8 @@ using Terms = std::vector<Term>;
|
|||||||
|
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
// TODO: add missing types
|
|
||||||
using AtomicFormulaT = Variant<
|
using AtomicFormulaT = Variant<
|
||||||
|
EqualsPointer<Term, Term>,
|
||||||
PredicatePointer>;
|
PredicatePointer>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,6 +267,14 @@ inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Either<
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
template<class ArgumentLeft, class ArgumentRight>
|
||||||
|
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Equals<ArgumentLeft, ArgumentRight> &equals, pddl::detail::PrintContext &printContext)
|
||||||
|
{
|
||||||
|
return print(stream, static_cast<const Binary<Equals<ArgumentLeft, ArgumentRight>, ArgumentLeft, ArgumentRight> &>(equals), printContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
template<class Argument>
|
template<class Argument>
|
||||||
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Exists<Argument> &exists, pddl::detail::PrintContext &printContext)
|
inline colorlog::ColorStream &print(colorlog::ColorStream &stream, const Exists<Argument> &exists, pddl::detail::PrintContext &printContext)
|
||||||
{
|
{
|
||||||
|
@ -65,6 +65,15 @@ void collectFreeVariables(const ast::AndPointer<Argument> &and_, std::vector<nor
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
template<class ArgumentLeft, class ArgumentRight>
|
||||||
|
void collectFreeVariables(const ast::EqualsPointer<ArgumentLeft, ArgumentRight> &equals, std::vector<normalizedAST::VariableDeclaration *> &freeVariables, VariableStack &variableStack)
|
||||||
|
{
|
||||||
|
collectFreeVariables(equals->argumentLeft, freeVariables, variableStack);
|
||||||
|
collectFreeVariables(equals->argumentRight, freeVariables, variableStack);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
template<class Argument>
|
template<class Argument>
|
||||||
void collectFreeVariables(const ast::ExistsPointer<Argument> &exists, std::vector<normalizedAST::VariableDeclaration *> &freeVariables, VariableStack &variableStack)
|
void collectFreeVariables(const ast::ExistsPointer<Argument> &exists, std::vector<normalizedAST::VariableDeclaration *> &freeVariables, VariableStack &variableStack)
|
||||||
{
|
{
|
||||||
|
@ -17,13 +17,20 @@ namespace detail
|
|||||||
|
|
||||||
normalizedAST::AtomicFormula normalize(ast::AtomicFormula &&atomicFormula)
|
normalizedAST::AtomicFormula normalize(ast::AtomicFormula &&atomicFormula)
|
||||||
{
|
{
|
||||||
|
const auto handleEquals =
|
||||||
|
[&](ast::EqualsPointer<ast::Term, ast::Term> &) -> normalizedAST::AtomicFormula
|
||||||
|
{
|
||||||
|
// TODO: implement
|
||||||
|
throw NormalizationException("“=” expressions currently unsupported by normalization");
|
||||||
|
};
|
||||||
|
|
||||||
const auto handlePredicate =
|
const auto handlePredicate =
|
||||||
[&](ast::PredicatePointer &predicate) -> normalizedAST::AtomicFormula
|
[&](ast::PredicatePointer &predicate) -> normalizedAST::AtomicFormula
|
||||||
{
|
{
|
||||||
return std::move(predicate);
|
return std::move(predicate);
|
||||||
};
|
};
|
||||||
|
|
||||||
return atomicFormula.match(handlePredicate);
|
return atomicFormula.match(handleEquals, handlePredicate);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
Reference in New Issue
Block a user