Skip to content

Commit

Permalink
added flag to lift some error checking
Browse files Browse the repository at this point in the history
  • Loading branch information
drexlerd committed May 26, 2024
1 parent 7310845 commit c3576e2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions include/loki/details/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class DomainParser
friend class ProblemParser;

public:
DomainParser(const fs::path& file_path, bool quiet = true);
DomainParser(const fs::path& file_path, bool strict = false, bool quiet = true);

/// @brief Get factories to create additional PDDL objects.
PDDLFactories& get_factories();
Expand Down Expand Up @@ -73,7 +73,7 @@ class ProblemParser
Problem m_problem;

public:
explicit ProblemParser(const fs::path& file_path, DomainParser& domain_parser, bool quiet = true);
explicit ProblemParser(const fs::path& file_path, DomainParser& domain_parser, bool strict = false, bool quiet = true);

/// @brief Get position caches to be able to reference back to the input PDDL file.
const PDDLPositionCache& get_position_cache() const;
Expand Down
5 changes: 4 additions & 1 deletion include/loki/details/pddl/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,19 @@ struct Context
PDDLPositionCache& positions;
// For referencing to existing bindings
ScopeStack& scopes;
// For strict error checking
bool strict;
// For checking that certain PDDL objects were referenced at least once
ReferencedPDDLObjects references;
// For convenience, to avoid an additional parameter during semantic parsing
Requirements requirements;
std::unordered_set<Predicate> derived_predicates;

Context(PDDLFactories& factories_, PDDLPositionCache& positions_, ScopeStack& scopes_) :
Context(PDDLFactories& factories_, PDDLPositionCache& positions_, ScopeStack& scopes_, bool strict_ = false) :
factories(factories_),
positions(positions_),
scopes(scopes_),
strict(strict_),
references(ReferencedPDDLObjects()),
requirements(nullptr)
{
Expand Down
8 changes: 4 additions & 4 deletions src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
namespace loki
{

DomainParser::DomainParser(const fs::path& file_path, bool quiet) :
DomainParser::DomainParser(const fs::path& file_path, bool strict, bool quiet) :
m_file_path(file_path),
m_source(loki::read_file(file_path)),
m_position_cache(nullptr),
Expand All @@ -60,7 +60,7 @@ DomainParser::DomainParser(const fs::path& file_path, bool quiet) :
m_position_cache = std::make_unique<PDDLPositionCache>(x3_error_handler, file_path);
m_scopes = std::make_unique<ScopeStack>(m_position_cache->get_error_handler());

auto context = Context(m_factories, *m_position_cache, *m_scopes);
auto context = Context(m_factories, *m_position_cache, *m_scopes, strict);
// Initialize global scope
context.scopes.open_scope();

Expand Down Expand Up @@ -101,7 +101,7 @@ const PDDLPositionCache& DomainParser::get_position_cache() const { return *m_po

const Domain& DomainParser::get_domain() const { return m_domain; }

ProblemParser::ProblemParser(const fs::path& file_path, DomainParser& domain_parser, bool quiet) :
ProblemParser::ProblemParser(const fs::path& file_path, DomainParser& domain_parser, bool strict, bool quiet) :
m_file_path(file_path),
m_source(loki::read_file(file_path)),
m_position_cache(nullptr),
Expand All @@ -125,7 +125,7 @@ ProblemParser::ProblemParser(const fs::path& file_path, DomainParser& domain_par
m_position_cache = std::make_unique<PDDLPositionCache>(x3_error_handler, file_path);
m_scopes = std::make_unique<ScopeStack>(m_position_cache->get_error_handler(), domain_parser.m_scopes.get());

auto context = Context(domain_parser.m_factories, *m_position_cache, *m_scopes);
auto context = Context(domain_parser.m_factories, *m_position_cache, *m_scopes, strict);

// Initialize global scope
context.scopes.open_scope();
Expand Down
7 changes: 5 additions & 2 deletions src/pddl/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,11 @@ Problem parse(const ast::Problem& problem_node, Context& context, const Domain&
}

// Check references
test_object_references(objects, context);
test_predicate_references(derived_predicates, context);
if (context.strict)
{
test_object_references(objects, context);
test_predicate_references(derived_predicates, context);
}

/* Structure section */
auto axioms = AxiomList();
Expand Down

0 comments on commit c3576e2

Please sign in to comment.