Skip to content

Commit

Permalink
some renamings
Browse files Browse the repository at this point in the history
  • Loading branch information
drexlerd committed Oct 18, 2023
1 parent 8821018 commit f4a2550
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 39 deletions.
16 changes: 6 additions & 10 deletions include/dlplan/common/parsers/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,11 @@ namespace dlplan::common::parsers
typedef error_handler<iterator_type> error_handler_type;


/* The error counter */
struct error_counter_tag;
/* In case we need to provide context in the future. */
struct parsing_context_tag;

struct error_counter_type {
int count = 0;

void increment() {
count += 1;
}
struct parsing_context_type {
bool error_reported = false;
};


Expand All @@ -46,8 +42,8 @@ namespace dlplan::common::parsers
error_handler_tag,
std::reference_wrapper<error_handler_type>,
x3::context<
error_counter_tag,
std::reference_wrapper<error_counter_type>,
parsing_context_tag,
std::reference_wrapper<parsing_context_type>,
phrase_context_type>>
context_type;

Expand Down
6 changes: 3 additions & 3 deletions include/dlplan/common/parsers/error_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ namespace dlplan::common::parsers
Iterator& /*first*/, Iterator const& /*last*/
, Exception const& x, Context const& context) {
{
auto& error_counter = x3::get<error_counter_tag>(context).get();
if (error_counter.count > 0) {
auto& parsing_context = x3::get<parsing_context_tag>(context).get();
if (parsing_context.error_reported) {
// We only print the first occurence of an error
return x3::error_handler_result::fail;
}
error_counter.increment();
parsing_context.error_reported = true;

std::string which = x.which();
// Use our message if defined
Expand Down
38 changes: 17 additions & 21 deletions src/core/element_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,13 @@ std::shared_ptr<const Concept> SyntacticElementFactoryImpl::parse_concept(Syntac

// Our error handler
error_handler_type error_handler(iter, end, std::cerr, filename);
// Our error counter
error_counter_type error_counter;
parsing_context_type parsing_context;
auto const parser =
// we pass our error handler to the parser so we can access
// it later on in our on_error and on_sucess handlers
with<error_counter_tag>(std::ref(error_counter)) [
with<parsing_context_tag>(std::ref(parsing_context)) [
with<error_handler_tag>(std::ref(error_handler)) [
dlplan::core::parsers::elements::stage_1::concept()
dlplan::core::parsers::elements::stage_1::concept()
]
];

Expand All @@ -93,10 +92,10 @@ std::shared_ptr<const Concept> SyntacticElementFactoryImpl::parse_concept(Syntac
using boost::spirit::x3::ascii::space;
bool success = phrase_parse(iter, end, parser, space, ast);
if (!success) {
throw std::runtime_error("Unsuccessful parse.");
throw std::runtime_error("Failed parse.");
}
if (iter != end) {
throw std::runtime_error("Unsuccessful parse. Did not consume whole input.");
throw std::runtime_error("Failed parse. Did not consume whole input.");
}

/* Stage 2 parse */
Expand All @@ -120,12 +119,11 @@ std::shared_ptr<const Role> SyntacticElementFactoryImpl::parse_role(SyntacticEle

// Our error handler
error_handler_type error_handler(iter, end, std::cerr, filename);
// Our error counter
error_counter_type error_counter;
parsing_context_type parsing_context;
auto const parser =
// we pass our error handler to the parser so we can access
// it later on in our on_error and on_sucess handlers
with<error_counter_tag>(std::ref(error_counter)) [
with<parsing_context_tag>(std::ref(parsing_context)) [
with<error_handler_tag>(std::ref(error_handler)) [
dlplan::core::parsers::elements::stage_1::role()
]
Expand All @@ -138,10 +136,10 @@ std::shared_ptr<const Role> SyntacticElementFactoryImpl::parse_role(SyntacticEle
using boost::spirit::x3::ascii::space;
bool success = phrase_parse(iter, end, parser, space, ast);
if (!success) {
throw std::runtime_error("Unsuccessful parse.");
throw std::runtime_error("Failed parse.");
}
if (iter != end) {
throw std::runtime_error("Unsuccessful parse. Did not consume whole input.");
throw std::runtime_error("Failed parse. Did not consume whole input.");
}

/* Stage 2 parse */
Expand All @@ -165,12 +163,11 @@ std::shared_ptr<const Boolean> SyntacticElementFactoryImpl::parse_boolean(Syntac

// Our error handler
error_handler_type error_handler(iter, end, std::cerr, filename);
// Our error counter
error_counter_type error_counter;
parsing_context_type parsing_context;
auto const parser =
// we pass our error handler to the parser so we can access
// it later on in our on_error and on_sucess handlers
with<error_counter_tag>(std::ref(error_counter)) [
with<parsing_context_tag>(std::ref(parsing_context)) [
with<error_handler_tag>(std::ref(error_handler)) [
dlplan::core::parsers::elements::stage_1::boolean()
]
Expand All @@ -183,10 +180,10 @@ std::shared_ptr<const Boolean> SyntacticElementFactoryImpl::parse_boolean(Syntac
using boost::spirit::x3::ascii::space;
bool success = phrase_parse(iter, end, parser, space, ast);
if (!success) {
throw std::runtime_error("Unsuccessful parse.");
throw std::runtime_error("Failed parse.");
}
if (iter != end) {
throw std::runtime_error("Unsuccessful parse. Did not consume whole input.");
throw std::runtime_error("Failed parse. Did not consume whole input.");
}

/* Stage 2 parse */
Expand All @@ -210,12 +207,11 @@ std::shared_ptr<const Numerical> SyntacticElementFactoryImpl::parse_numerical(Sy

// Our error handler
error_handler_type error_handler(iter, end, std::cerr, filename);
// Our error counter
error_counter_type error_counter;
parsing_context_type parsing_context;
auto const parser =
// we pass our error handler to the parser so we can access
// it later on in our on_error and on_sucess handlers
with<error_counter_tag>(std::ref(error_counter)) [
with<parsing_context_tag>(std::ref(parsing_context)) [
with<error_handler_tag>(std::ref(error_handler)) [
dlplan::core::parsers::elements::stage_1::numerical()
]
Expand All @@ -228,10 +224,10 @@ std::shared_ptr<const Numerical> SyntacticElementFactoryImpl::parse_numerical(Sy
using boost::spirit::x3::ascii::space;
bool success = phrase_parse(iter, end, parser, space, ast);
if (!success) {
throw std::runtime_error("Unsuccessful parse.");
throw std::runtime_error("Failed parse.");
}
if (iter != end) {
throw std::runtime_error("Unsuccessful parse. Did not consume whole input.");
throw std::runtime_error("Failed parse. Did not consume whole input.");
}

/* Stage 2 parse */
Expand Down
9 changes: 4 additions & 5 deletions src/policy/policy_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,11 @@ std::shared_ptr<const Policy> PolicyFactoryImpl::parse_policy(

// Our error handler
error_handler_type error_handler(iter, end, std::cerr, filename);
// Our error counter
error_counter_type error_counter;
parsing_context_type parsing_context;
auto const parser =
// we pass our error handler to the parser so we can access
// it later on in our on_error and on_sucess handlers
with<error_counter_tag>(std::ref(error_counter)) [
with<parsing_context_tag>(std::ref(parsing_context)) [
with<error_handler_tag>(std::ref(error_handler)) [
dlplan::policy::parsers::policy::stage_1::policy()
]
Expand All @@ -62,10 +61,10 @@ std::shared_ptr<const Policy> PolicyFactoryImpl::parse_policy(
using boost::spirit::x3::ascii::space;
bool success = phrase_parse(iter, end, parser, space, ast);
if (!success) {
throw std::runtime_error("Unsuccessful parse.");
throw std::runtime_error("Failed parse.");
}
if (iter != end) {
throw std::runtime_error("Unsuccessful parse. Did not consume whole input.");
throw std::runtime_error("Failed parse. Did not consume whole input.");
}

/* Stage 2 parse */
Expand Down

0 comments on commit f4a2550

Please sign in to comment.