Skip to content

Commit

Permalink
added some more exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
drexlerd committed Apr 22, 2024
1 parent 7d6d02a commit 164578d
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 0 deletions.
16 changes: 16 additions & 0 deletions include/loki/details/pddl/exceptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,22 @@ class MultiDefinitionObjectError : public SemanticParserError
MultiDefinitionObjectError(const std::string& name, const std::string& error_handler_output);
};

/* Function */

class IllformedFunctionDefinitionMissingValue : public SemanticParserError
{
public:
IllformedFunctionDefinitionMissingValue(const FunctionSkeleton& function, const Function& values, const std::string& error_handler_output);
};

class IllformedFunctionDefinitionMultipleValues : public SemanticParserError
{
public:
IllformedFunctionDefinitionMultipleValues(const FunctionSkeleton& function_skeleton,
const Function& ground_function,
const std::string& error_handler_output);
};

/* Compatibility errors */
class MismatchedDomainError : public SemanticParserError
{
Expand Down
20 changes: 20 additions & 0 deletions src/pddl/exceptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
#include "loki/details/pddl/exceptions.hpp"

#include "loki/details/pddl/domain.hpp"
#include "loki/details/pddl/function.hpp"
#include "loki/details/pddl/function_skeleton.hpp"
#include "loki/details/pddl/object.hpp"
#include "loki/details/pddl/predicate.hpp"

#include <string>
Expand Down Expand Up @@ -174,6 +176,24 @@ MultiDefinitionObjectError::MultiDefinitionObjectError(const std::string& name,
{
}

/* Function*/
IllformedFunctionDefinitionMissingValue::IllformedFunctionDefinitionMissingValue(const FunctionSkeleton& function_skeleton,
const Function& values,
const std::string& error_handler_output) :
SemanticParserError("The function with name \"" + function_skeleton->str() + "\n misses a value definition in the initial state for arguments \""
+ values->str() + "\".",
error_handler_output)
{
}

IllformedFunctionDefinitionMultipleValues::IllformedFunctionDefinitionMultipleValues(const FunctionSkeleton& function_skeleton,
const Function& ground_function,
const std::string& error_handler_output) :
SemanticParserError("The function with name \"" + function_skeleton->str() + "\n has multiple values defined for \"" + ground_function->str() + "\".",
error_handler_output)
{
}

/* Compatibility errors */
MismatchedDomainError::MismatchedDomainError(const Domain& domain, const std::string& domain_name, const std::string& error_handler_output) :
SemanticParserError("Mismatched domain names \"" + domain->get_name() + "!=" + domain_name + ".", error_handler_output)
Expand Down
1 change: 1 addition & 0 deletions src/pddl/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ Problem parse(const ast::Problem& problem_node, Context& context, const Domain&
std::visit(UnpackingVisitor(initial_literals, numeric_fluents), initial_element);
}
}

/* Goal section */
auto goal_condition = std::optional<Condition>();
if (problem_node.goal.has_value())
Expand Down
3 changes: 3 additions & 0 deletions src/pddl/parser/initial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ namespace loki

std::vector<std::variant<GroundLiteral, NumericFluent>> parse(const ast::Initial& initial_node, Context& context)
{
// TODO: IllformedFunctionDefinitionMissingValue and IllformedFunctionDefinitionMultipleValues using value_definitions.
std::unordered_map<FunctionSkeleton, std::unordered_set<Function>> value_definitions;

auto initial_element_list = std::vector<std::variant<GroundLiteral, NumericFluent>>();
for (const auto& initial_element : initial_node.initial_elements)
{
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/pddl/factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <gtest/gtest.h>
#include <loki/details/pddl/factory.hpp>
#include <loki/details/pddl/object.hpp>
#include <loki/details/pddl/term.hpp>

namespace loki::domain::tests
{
Expand Down Expand Up @@ -54,4 +55,19 @@ TEST(LokiTests, FactoryIteratorEmptyTest)
EXPECT_EQ(objects.size(), 0);
}

TEST(LokiTests, FactoryVariantTest)
{
PDDLFactory<ObjectImpl> objects(2);
PDDLFactory<TermImpl> terms(2);
const auto object_0 = objects.get_or_create<ObjectImpl>("object_0", TypeList());
const auto object_1 = objects.get_or_create<ObjectImpl>("object_1", TypeList());

const auto term_0_object_0 = terms.get_or_create<TermObjectImpl>(object_0);
const auto term_1_object_0 = terms.get_or_create<TermObjectImpl>(object_0);
const auto term_2_object_1 = terms.get_or_create<TermObjectImpl>(object_1);

EXPECT_EQ(term_0_object_0, term_1_object_0);
EXPECT_NE(term_0_object_0, term_2_object_1);
}

}

0 comments on commit 164578d

Please sign in to comment.