diff --git a/include/dlplan/common/parsers/config.hpp b/include/dlplan/common/parsers/config.hpp index 9c1464ee..2fa659a5 100644 --- a/include/dlplan/common/parsers/config.hpp +++ b/include/dlplan/common/parsers/config.hpp @@ -23,15 +23,11 @@ namespace dlplan::common::parsers typedef error_handler 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; }; @@ -46,8 +42,8 @@ namespace dlplan::common::parsers error_handler_tag, std::reference_wrapper, x3::context< - error_counter_tag, - std::reference_wrapper, + parsing_context_tag, + std::reference_wrapper, phrase_context_type>> context_type; diff --git a/include/dlplan/common/parsers/error_handler.hpp b/include/dlplan/common/parsers/error_handler.hpp index c02a8c6f..9605dddc 100644 --- a/include/dlplan/common/parsers/error_handler.hpp +++ b/include/dlplan/common/parsers/error_handler.hpp @@ -31,12 +31,12 @@ namespace dlplan::common::parsers Iterator& /*first*/, Iterator const& /*last*/ , Exception const& x, Context const& context) { { - auto& error_counter = x3::get(context).get(); - if (error_counter.count > 0) { + auto& parsing_context = x3::get(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 diff --git a/src/core/element_factory.cpp b/src/core/element_factory.cpp index db0816cd..d5d88557 100644 --- a/src/core/element_factory.cpp +++ b/src/core/element_factory.cpp @@ -75,14 +75,13 @@ std::shared_ptr 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(std::ref(error_counter)) [ + with(std::ref(parsing_context)) [ with(std::ref(error_handler)) [ - dlplan::core::parsers::elements::stage_1::concept() + dlplan::core::parsers::elements::stage_1::concept() ] ]; @@ -93,10 +92,10 @@ std::shared_ptr 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 */ @@ -120,12 +119,11 @@ std::shared_ptr 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(std::ref(error_counter)) [ + with(std::ref(parsing_context)) [ with(std::ref(error_handler)) [ dlplan::core::parsers::elements::stage_1::role() ] @@ -138,10 +136,10 @@ std::shared_ptr 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 */ @@ -165,12 +163,11 @@ std::shared_ptr 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(std::ref(error_counter)) [ + with(std::ref(parsing_context)) [ with(std::ref(error_handler)) [ dlplan::core::parsers::elements::stage_1::boolean() ] @@ -183,10 +180,10 @@ std::shared_ptr 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 */ @@ -210,12 +207,11 @@ std::shared_ptr 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(std::ref(error_counter)) [ + with(std::ref(parsing_context)) [ with(std::ref(error_handler)) [ dlplan::core::parsers::elements::stage_1::numerical() ] @@ -228,10 +224,10 @@ std::shared_ptr 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 */ diff --git a/src/policy/policy_factory.cpp b/src/policy/policy_factory.cpp index 1b05807c..bd6d5607 100644 --- a/src/policy/policy_factory.cpp +++ b/src/policy/policy_factory.cpp @@ -44,12 +44,11 @@ std::shared_ptr 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(std::ref(error_counter)) [ + with(std::ref(parsing_context)) [ with(std::ref(error_handler)) [ dlplan::policy::parsers::policy::stage_1::policy() ] @@ -62,10 +61,10 @@ std::shared_ptr 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 */