Skip to content

Commit

Permalink
Hide exception template.
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinH committed Jul 9, 2023
1 parent 6a78bc4 commit fe639ef
Show file tree
Hide file tree
Showing 17 changed files with 25 additions and 23 deletions.
6 changes: 3 additions & 3 deletions include/tao/pegtl/contrib/nested_exceptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ namespace TAO_PEGTL_NAMESPACE::nested
internal::inspector< Exceptions... >::inspect( ptr, visitor );
}

[[nodiscard]] inline std::vector< parse_error< position > > flatten( const std::exception_ptr& ptr = std::current_exception() )
[[nodiscard]] inline std::vector< parse_error > flatten( const std::exception_ptr& ptr = std::current_exception() )
{
std::vector< parse_error< position > > result;
inspect< parse_error< position > >( ptr, [ &result ]( const parse_error< position >& e, const std::size_t /*unused*/ ) {
std::vector< parse_error > result;
inspect< parse_error >( ptr, [ &result ]( const parse_error& e, const std::size_t /*unused*/ ) {
result.emplace_back( e );
} );
return result;
Expand Down
12 changes: 7 additions & 5 deletions include/tao/pegtl/parse_error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ namespace TAO_PEGTL_NAMESPACE
struct disambiguate_t {}; // TODO: Integrate extract_position into parse_error with SFINAE?

template< typename Position >
class parse_error
class parse_error_template
: public parse_error_base
{
public:
using position_t = Position;

template< typename Object >
parse_error( const std::string& msg, const Object& obj )
: parse_error( msg, internal::extract_position( obj ), disambiguate_t() )
parse_error_template( const std::string& msg, const Object& obj )
: parse_error_template( msg, internal::extract_position( obj ), disambiguate_t() )
{}

[[nodiscard]] const position_t& position_object() const noexcept
Expand All @@ -41,14 +41,16 @@ namespace TAO_PEGTL_NAMESPACE
protected:
const position_t m_position;

parse_error( const std::string& msg, const Position& pos, const disambiguate_t /*unused*/ )
parse_error_template( const std::string& msg, const Position& pos, const disambiguate_t /*unused*/ )
: parse_error_base( msg, internal::stream_to_string( pos ) ),
m_position( pos )
{}
};

template< typename Object >
parse_error( const std::string&, const Object& ) -> parse_error< std::decay_t< decltype( internal::extract_position( std::declval< Object >() ) ) > >;
parse_error_template( const std::string&, const Object& ) -> parse_error_template< std::decay_t< decltype( internal::extract_position( std::declval< Object >() ) ) > >;

using parse_error = parse_error_template< position >; // Temporary -- when the inputs are templated over the position class the parse_error_template will be renamed to parse_error.

} // namespace TAO_PEGTL_NAMESPACE

Expand Down
2 changes: 1 addition & 1 deletion src/example/pegtl/abnf2pegtl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape)
std::cout << abnf::to_string( rule ) << '\n';
}
}
catch( const parse_error< position >& e ) {
catch( const parse_error& e ) {
const auto& p = e.position_object();
std::cerr << e.what() << '\n'
<< in.line_at( p ) << '\n'
Expand Down
2 changes: 1 addition & 1 deletion src/example/pegtl/expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ int main( int argc, char** argv )
assert( res.string_stack.size() == 1 );
std::cout << "Result: " << res.string_stack.at( 0 ) << std::endl;
}
catch( const TAO_PEGTL_NAMESPACE::parse_error< TAO_PEGTL_NAMESPACE::position >& e ) {
catch( const TAO_PEGTL_NAMESPACE::parse_error& e ) {
const auto& p = e.position_object();
std::cerr << e.what() << '\n'
<< in.line_at( p ) << '\n'
Expand Down
2 changes: 1 addition & 1 deletion src/example/pegtl/json_ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape)
const auto root = pegtl::parse_tree::parse< example::grammar, example::selector, pegtl::nothing, example::control >( in );
pegtl::parse_tree::print_dot( std::cout, *root );
}
catch( const pegtl::parse_error< pegtl::position >& e ) {
catch( const pegtl::parse_error& e ) {
const auto& p = e.position_object();
std::cerr << e.what() << std::endl
<< in.line_at( p ) << std::endl
Expand Down
2 changes: 1 addition & 1 deletion src/example/pegtl/json_build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape)
try {
pegtl::parse< example::grammar, example::action, example::control >( in, state );
}
catch( const pegtl::parse_error< pegtl::position >& e ) {
catch( const pegtl::parse_error& e ) {
const auto& p = e.position_object();
std::cerr << e.what() << '\n'
<< in.line_at( p ) << '\n'
Expand Down
2 changes: 1 addition & 1 deletion src/example/pegtl/json_coverage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape)
try {
pegtl::coverage< example::grammar, pegtl::nothing, example::control >( in, result );
}
catch( const pegtl::parse_error< pegtl::position >& e ) {
catch( const pegtl::parse_error& e ) {
const auto& p = e.position_object();
std::cerr << e.what() << '\n'
<< in.line_at( p ) << '\n'
Expand Down
2 changes: 1 addition & 1 deletion src/example/pegtl/json_parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape)
try {
pegtl::parse< example::grammar, example::action, example::control >( in );
}
catch( const pegtl::parse_error< pegtl::position >& e ) {
catch( const pegtl::parse_error& e ) {
const auto& p = e.position_object();
std::cerr << e.what() << '\n'
<< in.line_at( p ) << '\n'
Expand Down
2 changes: 1 addition & 1 deletion src/example/pegtl/json_trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape)
try {
pegtl::standard_trace< example::grammar, pegtl::nothing, example::control >( in );
}
catch( const pegtl::parse_error< pegtl::position >& e ) {
catch( const pegtl::parse_error& e ) {
const auto& p = e.position_object();
std::cerr << e.what() << '\n'
<< in.line_at( p ) << '\n'
Expand Down
2 changes: 1 addition & 1 deletion src/example/pegtl/proto3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape)
try {
parse< proto3::proto >( in );
}
catch( const parse_error< position >& e ) {
catch( const parse_error& e ) {
const auto& p = e.position_object();
std::cerr << e.what() << '\n'
<< in.line_at( p ) << '\n'
Expand Down
2 changes: 1 addition & 1 deletion src/example/pegtl/s_expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape)
try {
TAO_PEGTL_NAMESPACE::parse< sexpr::main, sexpr::action >( in, fn );
}
catch( const TAO_PEGTL_NAMESPACE::parse_error< TAO_PEGTL_NAMESPACE::position >& e ) {
catch( const TAO_PEGTL_NAMESPACE::parse_error& e ) {
const auto& p = e.position_object();
std::cerr << e.what() << '\n'
<< in.line_at( p ) << '\n'
Expand Down
2 changes: 1 addition & 1 deletion src/test/pegtl/contrib_unescape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace TAO_PEGTL_NAMESPACE
try {
return !parse< unstring, unaction >( in, s );
}
catch( const parse_error< position >& ) {
catch( const parse_error& ) {
}
return true;
#else
Expand Down
2 changes: 1 addition & 1 deletion src/test/pegtl/error_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace TAO_PEGTL_NAMESPACE
parse< test1::grammar, nothing, test1::control >( memory_input( "c", __FUNCTION__ ) );
TAO_PEGTL_TEST_UNREACHABLE; // LCOV_EXCL_LINE
}
catch( const parse_error< position >& e ) {
catch( const parse_error& e ) {
TAO_PEGTL_TEST_ASSERT( e.message() == "test123" );
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/pegtl/error_message_2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace TAO_PEGTL_NAMESPACE
parse< test2::grammar >( memory_input( "c", __FUNCTION__ ) );
TAO_PEGTL_TEST_UNREACHABLE; // LCOV_EXCL_LINE
}
catch( const parse_error< position >& e ) {
catch( const parse_error& e ) {
TAO_PEGTL_TEST_ASSERT( e.message() == "test123" );
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/pegtl/error_message_3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace TAO_PEGTL_NAMESPACE
parse< test3::grammar >( memory_input( "c", __FUNCTION__ ) );
TAO_PEGTL_TEST_UNREACHABLE; // LCOV_EXCL_LINE
}
catch( const parse_error< position >& e ) {
catch( const parse_error& e ) {
TAO_PEGTL_TEST_ASSERT( e.message() == "test123" );
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/pegtl/parse_error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace TAO_PEGTL_NAMESPACE
try {
parse< seq< identifier, eol, identifier, one< ' ' >, must< digit > > >( in );
}
catch( const parse_error< position >& e ) {
catch( const parse_error& e ) {
TAO_PEGTL_TEST_ASSERT( e.what() == "test_source:2:5: parse error matching " + rulename );

TAO_PEGTL_TEST_ASSERT( e.message() == "parse error matching " + rulename );
Expand Down
2 changes: 1 addition & 1 deletion src/test/pegtl/position.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ namespace TAO_PEGTL_NAMESPACE

void test_nested_asserts()
{
const std::vector< parse_error< position > > errors = nested::flatten();
const std::vector< parse_error > errors = nested::flatten();
TAO_PEGTL_TEST_ASSERT( errors.size() == 2 );
TAO_PEGTL_TEST_ASSERT( errors[ 0 ].position_object().source == "inner" );
TAO_PEGTL_TEST_ASSERT( errors[ 0 ].position_object().byte == 1 );
Expand Down

0 comments on commit fe639ef

Please sign in to comment.