Skip to content

Commit

Permalink
Add parse_error_t.
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinH committed Nov 13, 2024
1 parent 791568a commit 93c60b3
Show file tree
Hide file tree
Showing 28 changed files with 45 additions and 11 deletions.
2 changes: 2 additions & 0 deletions include/tao/pegtl/buffer/buffer_input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "../config.hpp"
#include "../count_position.hpp"
#include "../parse_error.hpp"
#include "../pointer_position.hpp"

#include "buffer_common.hpp"
Expand All @@ -24,6 +25,7 @@ namespace TAO_PEGTL_NAMESPACE::internal
using error_position_t = count_position;
using offset_position_t = count_position;
using rewind_position_t = pointer_position< data_t >;
using parse_error_t = parse_error< error_position_t >;

using buffer_common< Buffer >::buffer_common;

Expand Down
2 changes: 2 additions & 0 deletions include/tao/pegtl/buffer/buffer_input_with_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "../config.hpp"
#include "../count_position.hpp"
#include "../parse_error.hpp"
#include "../pointer_position.hpp"
#include "../position_with_source.hpp"

Expand All @@ -30,6 +31,7 @@ namespace TAO_PEGTL_NAMESPACE::internal
using error_position_t = position_with_source< ErrorSource, count_position >;
using offset_position_t = count_position;
using rewind_position_t = pointer_position< data_t >;
using parse_error_t = parse_error< error_position_t >;

static_assert( std::is_same_v< InputSource, ErrorSource >, "TODO?" );

Expand Down
2 changes: 2 additions & 0 deletions include/tao/pegtl/buffer/text_buffer_input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <cstddef>

#include "../config.hpp"
#include "../parse_error.hpp"
#include "../text_position.hpp"

#include "../internal/choose_text_traits.hpp"
Expand All @@ -25,6 +26,7 @@ namespace TAO_PEGTL_NAMESPACE::internal
using error_position_t = text_position;
using offset_position_t = text_position;
using rewind_position_t = text_position;
using parse_error_t = parse_error< error_position_t >;

using eol_rule = Eol;

Expand Down
2 changes: 2 additions & 0 deletions include/tao/pegtl/buffer/text_buffer_input_with_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <utility>

#include "../config.hpp"
#include "../parse_error.hpp"
#include "../position_with_source.hpp"
#include "../text_position.hpp"

Expand All @@ -31,6 +32,7 @@ namespace TAO_PEGTL_NAMESPACE::internal
using error_position_t = position_with_source< ErrorSource, text_position >;
using offset_position_t = text_position;
using rewind_position_t = text_position;
using parse_error_t = parse_error< error_position_t >;

using eol_rule = Eol;

Expand Down
2 changes: 2 additions & 0 deletions include/tao/pegtl/contrib/input_with_offset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <utility>

#include "../config.hpp"
#include "../parse_error.hpp"

namespace TAO_PEGTL_NAMESPACE
{
Expand All @@ -20,6 +21,7 @@ namespace TAO_PEGTL_NAMESPACE
using error_position_t = typename Input::error_position_t;
using offset_position_t = typename Input::offset_position_t;
using rewind_position_t = typename Input::rewind_position_t;
using parse_error_t = parse_error< error_position_t >;

template< typename... Ts >
explicit input_with_offset( offset_position_t&& s, Ts&&... ts )
Expand Down
2 changes: 2 additions & 0 deletions include/tao/pegtl/internal/action_input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <cstddef>

#include "../config.hpp"
#include "../parse_error.hpp"

#include "input_with_funcs.hpp"

Expand All @@ -21,6 +22,7 @@ namespace TAO_PEGTL_NAMESPACE::internal
using input_t = ParseInput;
using error_position_t = typename ParseInput::error_position_t;
using rewind_position_t = typename ParseInput::rewind_position_t;
using parse_error_t = parse_error< error_position_t >;

action_input_impl( const rewind_position_t& begin, const ParseInput& input ) noexcept
: m_saved( begin ),
Expand Down
2 changes: 2 additions & 0 deletions include/tao/pegtl/internal/argv_input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <cstring>

#include "../config.hpp"
#include "../parse_error.hpp"

#include "input_with_start.hpp"
#include "view_input.hpp"
Expand All @@ -23,6 +24,7 @@ namespace TAO_PEGTL_NAMESPACE::internal
{}

using error_position_t = typename input_with_start< view_input< char > >::error_position_t;
using parse_error_t = parse_error< error_position_t >;

[[nodiscard]] const char* begin_of_line( const error_position_t& pos, const std::size_t max = 135 ) const noexcept
{
Expand Down
2 changes: 2 additions & 0 deletions include/tao/pegtl/internal/argv_input_with_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <string>

#include "../config.hpp"
#include "../parse_error.hpp"

#include "argv_input.hpp"
#include "input_with_source.hpp"
Expand All @@ -28,6 +29,7 @@ namespace TAO_PEGTL_NAMESPACE::internal
{}

using error_position_t = typename input_with_source< std::string, std::string, argv_input >::error_position_t;
using parse_error_t = parse_error< error_position_t >;

[[nodiscard]] const char* begin_of_line( const error_position_t& pos, const std::size_t max = 135 ) const noexcept
{
Expand Down
2 changes: 2 additions & 0 deletions include/tao/pegtl/internal/copy_input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include "../config.hpp"
#include "../count_position.hpp"
#include "../parse_error.hpp"
#include "../pointer_position.hpp"

namespace TAO_PEGTL_NAMESPACE::internal
Expand All @@ -25,6 +26,7 @@ namespace TAO_PEGTL_NAMESPACE::internal
using error_position_t = count_position;
using offset_position_t = count_position;
using rewind_position_t = pointer_position< data_t >;
using parse_error_t = parse_error< error_position_t >;

copy_input( const data_t* in_begin, const data_t* in_end )
: m_container( in_begin, in_end ),
Expand Down
2 changes: 2 additions & 0 deletions include/tao/pegtl/internal/input_with_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <utility>

#include "../config.hpp"
#include "../parse_error.hpp"
#include "../position_with_source.hpp"

#include "dependent_false.hpp"
Expand All @@ -25,6 +26,7 @@ namespace TAO_PEGTL_NAMESPACE::internal
using error_position_t = position_with_source< ErrorSource, typename Input::error_position_t >;
using offset_position_t = typename Input::offset_position_t;
using rewind_position_t = typename Input::rewind_position_t;
using parse_error_t = parse_error< error_position_t >;

template< typename S, typename... Ts >
explicit input_with_source( S&& s, Ts&&... ts )
Expand Down
2 changes: 2 additions & 0 deletions include/tao/pegtl/internal/input_with_start.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "../config.hpp"
#include "../count_position.hpp"
#include "../parse_error.hpp"
#include "../pointer_position.hpp"

namespace TAO_PEGTL_NAMESPACE::internal
Expand All @@ -22,6 +23,7 @@ namespace TAO_PEGTL_NAMESPACE::internal
using error_position_t = count_position;
using offset_position_t = count_position;
using rewind_position_t = pointer_position< data_t >;
using parse_error_t = parse_error< error_position_t >;

template< typename... As >
explicit input_with_start( As&&... as ) noexcept
Expand Down
2 changes: 2 additions & 0 deletions include/tao/pegtl/internal/lazy_input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "../config.hpp"
#include "../normal.hpp"
#include "../nothing.hpp"
#include "../parse_error.hpp"
#include "../rewind_mode.hpp"
#include "../text_position.hpp"

Expand All @@ -34,6 +35,7 @@ namespace TAO_PEGTL_NAMESPACE::internal
using error_position_t = text_position;
using offset_position_t = text_position;
using rewind_position_t = typename Input::rewind_position_t;
using parse_error_t = parse_error< error_position_t >;

using eol_rule = Eol;

Expand Down
2 changes: 2 additions & 0 deletions include/tao/pegtl/internal/mmap_input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "../config.hpp"
#include "../count_position.hpp"
#include "../parse_error.hpp"
#include "../pointer_position.hpp"

#include "mmap_file_base.hpp"
Expand All @@ -25,6 +26,7 @@ namespace TAO_PEGTL_NAMESPACE::internal
using error_position_t = count_position;
using offset_position_t = count_position;
using rewind_position_t = pointer_position< data_t >;
using parse_error_t = parse_error< error_position_t >;

explicit mmap_input( const std::filesystem::path& path )
: mmap_file_base( path ),
Expand Down
2 changes: 2 additions & 0 deletions include/tao/pegtl/internal/rematch_input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <cstddef>

#include "../config.hpp"
#include "../parse_error.hpp"
#include "../pointer_position.hpp"

#include "input_with_fakes.hpp"
Expand All @@ -26,6 +27,7 @@ namespace TAO_PEGTL_NAMESPACE::internal
using error_position_t = typename Input::error_position_t;
// offset_position_t
using rewind_position_t = pointer_position< data_t >;
using parse_error_t = parse_error< error_position_t >;

rematch_input_impl( Guard& m, Input& in ) noexcept
: m_guard( m ),
Expand Down
2 changes: 2 additions & 0 deletions include/tao/pegtl/internal/text_input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "../config.hpp"
#include "../normal.hpp"
#include "../nothing.hpp"
#include "../parse_error.hpp"
#include "../pointer_position.hpp"
#include "../rewind_mode.hpp"
#include "../text_position.hpp"
Expand All @@ -34,6 +35,7 @@ namespace TAO_PEGTL_NAMESPACE::internal
using error_position_t = text_position;
using offset_position_t = text_position;
using rewind_position_t = text_position;
using parse_error_t = parse_error< error_position_t >;

using eol_rule = Eol;

Expand Down
2 changes: 2 additions & 0 deletions include/tao/pegtl/internal/text_input_with_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "../config.hpp"
#include "../normal.hpp"
#include "../nothing.hpp"
#include "../parse_error.hpp"
#include "../position_with_source.hpp"
#include "../rewind_mode.hpp"
#include "../text_position.hpp"
Expand All @@ -38,6 +39,7 @@ namespace TAO_PEGTL_NAMESPACE::internal
using error_position_t = position_with_source< ErrorSource, text_position >;
using offset_position_t = text_position;
using rewind_position_t = text_position;
using parse_error_t = parse_error< error_position_t >;

using eol_rule = Eol;

Expand Down
2 changes: 2 additions & 0 deletions include/tao/pegtl/internal/view_input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <vector>

#include "../config.hpp"
#include "../parse_error.hpp"
#include "../pointer_position.hpp"

#include "type_traits.hpp"
Expand All @@ -27,6 +28,7 @@ namespace TAO_PEGTL_NAMESPACE::internal
using error_position_t = pointer_position< data_t >;
using offset_position_t = void;
using rewind_position_t = pointer_position< data_t >;
using parse_error_t = parse_error< error_position_t >;

view_input( const data_t* b, const data_t* e ) noexcept
: m_current( b ),
Expand Down
2 changes: 1 addition & 1 deletion src/example/pegtl/abnf2_record.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape)
pegtl::abnf2::control >( in );
std::cout << v;
}
catch( const pegtl::parse_error< input_t::error_position_t >& e ) {
catch( const decltype( in )::parse_error_t& e ) {
const auto& p = e.position_object();
std::cerr << e.what() << '\n'
<< in.line_view_at( p ) << '\n'
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 @@ -789,7 +789,7 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape)
std::cout << abnf::to_string( rule ) << '\n';
}
}
catch( const parse_error< text_file_input<>::error_position_t >& e ) {
catch( const decltype( in )::parse_error_t& e ) {
const auto& p = e.position_object();
std::cerr << e.what() << '\n'
<< in.line_view_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 @@ -509,7 +509,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< input_t::error_position_t >& e ) {
catch( const decltype( in )::parse_error_t& e ) {
const auto& p = e.position_object();
std::cerr << e.what() << '\n'
<< argv[ i ] << '\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< typename pegtl::argv_input<>::error_position_t >& e ) {
catch( const decltype( in )::parse_error_t& e ) {
const auto& p = e.position_object();
std::cerr << e.what() << std::endl
<< in.line_view_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 @@ -175,7 +175,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< input_t::error_position_t >& e ) {
catch( const decltype( in )::parse_error_t& e ) {
const auto& p = e.position_object();
std::cerr << e.what() << '\n'
<< in.line_view_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< input_t::error_position_t >& e ) {
catch( const decltype( in )::parse_error_t& e ) {
const auto& p = e.position_object();
std::cerr << e.what() << '\n'
<< in.line_view_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 @@ -43,7 +43,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< input_t::error_position_t >& e ) {
catch( const decltype( in )::parse_error_t& e ) {
const auto& p = e.position_object();
std::cerr << e.what() << '\n'
<< in.line_view_at( p ) << '\n'
Expand Down
2 changes: 1 addition & 1 deletion src/example/pegtl/json_record.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape)
pegtl::json::null >::parse< example::grammar >( in );
std::cout << v;
}
catch( const pegtl::parse_error< input_t::error_position_t >& e ) {
catch( const decltype( in )::parse_error_t& e ) {
const auto& p = e.position_object();
std::cerr << e.what() << '\n'
<< in.line_view_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 @@ -32,7 +32,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< input_t::error_position_t >& e ) {
catch( const decltype( in )::parse_error_t& e ) {
const auto& p = e.position_object();
std::cerr << e.what() << '\n'
<< in.line_view_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 @@ -31,7 +31,7 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape)
try {
parse< proto3::proto >( in );
}
catch( const parse_error< input_t::error_position_t >& e ) {
catch( const decltype( in )::parse_error_t& e ) {
const auto& p = e.position_object();
std::cerr << e.what() << '\n'
<< in.line_view_at( p ) << '\n'
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 @@ -25,7 +25,7 @@ namespace TAO_PEGTL_NAMESPACE
try {
parse< seq< identifier, eol, identifier, one< ' ' >, must< digit > > >( in );
}
catch( const parse_error< text_position_with_source >& e ) {
catch( const typename decltype( in )::parse_error_t& e ) {
TAO_PEGTL_TEST_ASSERT( e.what() == "test_source@2:5(8): parse error matching " + rulename );

TAO_PEGTL_TEST_ASSERT( e.message() == "parse error matching " + rulename );
Expand Down

0 comments on commit 93c60b3

Please sign in to comment.