diff --git a/doc/Changelog.md b/doc/Changelog.md index 126cbcb48..e59f37c92 100644 --- a/doc/Changelog.md +++ b/doc/Changelog.md @@ -39,6 +39,9 @@ * Moved `end_of_line()` from input member function to global function of same name. * Makefile generates binaries in `build/bin/` instead of `build/src/`. * Makefile generates dependencies in `build/dep/` instead of `build/src/`. +* Renamed contrib "limit_depth" functionality to "check_depth". +* Renamed contrib "check_bytes" functionality to "check_count". +* Renamed contrib "limit_bytes" functionality to "limit_count". * Removed rule `bytes` and replaced with `many` for different data types. * Removed support for `boost::filesystem` and `std::experimental::filesystem`. * Removed support for building an amalgamated header. diff --git a/include/tao/pegtl.hpp b/include/tao/pegtl.hpp index 3d02e5419..3c20c305b 100644 --- a/include/tao/pegtl.hpp +++ b/include/tao/pegtl.hpp @@ -14,6 +14,7 @@ #include "pegtl/parse.hpp" #include "pegtl/print.hpp" #include "pegtl/rules.hpp" +#include "pegtl/tags.hpp" #include "pegtl/utf8.hpp" #include "pegtl/version.hpp" #include "pegtl/visit.hpp" @@ -40,4 +41,10 @@ #include "pegtl/line_view_at.hpp" +#include "pegtl/count_position.hpp" +#include "pegtl/pointer_position.hpp" +#include "pegtl/position_with_source.hpp" +#include "pegtl/text_position.hpp" +#include "pegtl/text_position_with_source.hpp" + #endif diff --git a/include/tao/pegtl/analyze_traits.hpp b/include/tao/pegtl/analyze_traits.hpp index e7601a130..a4da4eaeb 100644 --- a/include/tao/pegtl/analyze_traits.hpp +++ b/include/tao/pegtl/analyze_traits.hpp @@ -115,13 +115,13 @@ namespace TAO_PEGTL_NAMESPACE : analyze_opt_traits<> {}; - template< typename Name > - struct analyze_traits< Name, internal::eol > + template< typename Name, typename Eol > + struct analyze_traits< Name, internal::eol< Eol > > : analyze_any_traits<> {}; - template< typename Name > - struct analyze_traits< Name, internal::eolf > + template< typename Name, typename Eol > + struct analyze_traits< Name, internal::eolf< Eol > > : analyze_opt_traits<> {}; diff --git a/include/tao/pegtl/ascii.hpp b/include/tao/pegtl/ascii.hpp index 94b85e6be..f22a91b19 100644 --- a/include/tao/pegtl/ascii.hpp +++ b/include/tao/pegtl/ascii.hpp @@ -44,7 +44,7 @@ namespace TAO_PEGTL_NAMESPACE template< char Lo, char Hi > struct range : internal::range< internal::result_on_found::success, internal::peek_char, Lo, Hi > {}; template< char... Cs > struct ranges : internal::ranges< internal::peek_char, Cs... > {}; struct seven : internal::range< internal::result_on_found::success, internal::peek_char, static_cast< char >( 0 ), static_cast< char >( 127 ) > {}; - struct shebang : internal::seq< internal::string< '#', '!' >, internal::until< internal::eolf > > {}; + struct shebang : internal::seq< internal::string< '#', '!' >, internal::until< internal::eolf< void > > > {}; struct sp : internal::one< internal::result_on_found::success, internal::peek_char, ' ' > {}; struct space : internal::one< internal::result_on_found::success, internal::peek_char, ' ', '\n', '\r', '\t', '\v', '\f' > {}; template< char... Cs > struct string : internal::string< Cs... > {}; diff --git a/include/tao/pegtl/contrib/check_bytes.hpp b/include/tao/pegtl/contrib/check_count.hpp similarity index 93% rename from include/tao/pegtl/contrib/check_bytes.hpp rename to include/tao/pegtl/contrib/check_count.hpp index 25a14d06b..6a5f8e5ce 100644 --- a/include/tao/pegtl/contrib/check_bytes.hpp +++ b/include/tao/pegtl/contrib/check_count.hpp @@ -2,8 +2,8 @@ // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) -#ifndef TAO_PEGTL_CONTRIB_CHECK_BYTES_HPP -#define TAO_PEGTL_CONTRIB_CHECK_BYTES_HPP +#ifndef TAO_PEGTL_CONTRIB_CHECK_COUNT_HPP +#define TAO_PEGTL_CONTRIB_CHECK_COUNT_HPP #include "../apply_mode.hpp" #include "../config.hpp" @@ -21,7 +21,7 @@ namespace TAO_PEGTL_NAMESPACE { template< std::size_t Maximum > - struct check_bytes + struct check_count : maybe_nothing { template< typename Rule, diff --git a/include/tao/pegtl/contrib/limit_depth.hpp b/include/tao/pegtl/contrib/check_depth.hpp similarity index 91% rename from include/tao/pegtl/contrib/limit_depth.hpp rename to include/tao/pegtl/contrib/check_depth.hpp index 3dbcf53b6..a06aa80e1 100644 --- a/include/tao/pegtl/contrib/limit_depth.hpp +++ b/include/tao/pegtl/contrib/check_depth.hpp @@ -2,8 +2,8 @@ // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) -#ifndef TAO_PEGTL_CONTRIB_LIMIT_DEPTH_HPP -#define TAO_PEGTL_CONTRIB_LIMIT_DEPTH_HPP +#ifndef TAO_PEGTL_CONTRIB_CHECK_DEPTH_HPP +#define TAO_PEGTL_CONTRIB_CHECK_DEPTH_HPP #include "../apply_mode.hpp" #include "../config.hpp" @@ -21,7 +21,7 @@ namespace TAO_PEGTL_NAMESPACE { template< std::size_t Maximum > - struct limit_depth + struct check_depth : maybe_nothing { static constexpr const char* error_message = "maximum parser rule nesting depth exceeded"; @@ -41,7 +41,7 @@ namespace TAO_PEGTL_NAMESPACE const auto dg( in.make_depth_guard() ); if( dg.current_depth() > Maximum ) { #if defined( __cpp_exceptions ) - Control< limit_depth >::raise( in ); + Control< check_depth >::raise( in ); #else std::fputs( "maximum parser rule nesting depth exceeded\n", stderr ); std::terminate(); diff --git a/include/tao/pegtl/contrib/http.hpp b/include/tao/pegtl/contrib/http.hpp index f8b89467e..2075402a5 100644 --- a/include/tao/pegtl/contrib/http.hpp +++ b/include/tao/pegtl/contrib/http.hpp @@ -14,6 +14,7 @@ #include "../nothing.hpp" #include "../remove_first_state.hpp" #include "../rules.hpp" +#include "../tags.hpp" #include "../utf8.hpp" #include "abnf.hpp" @@ -166,7 +167,7 @@ namespace TAO_PEGTL_NAMESPACE::http } break; } - in.template consume< internal::eol_exclude_tag >( i ); + in.template consume< eol_exclude_tag >( i ); return i > 0; } }; @@ -192,7 +193,7 @@ namespace TAO_PEGTL_NAMESPACE::http [[nodiscard]] static bool match( ParseInput& in, const std::size_t size, States&&... /*unused*/ ) { if( in.size( size ) >= size ) { - in.template consume< internal::eol_unknown_tag >( size ); + in.template consume< eol_unknown_tag >( size ); return true; } return false; diff --git a/include/tao/pegtl/contrib/integer.hpp b/include/tao/pegtl/contrib/integer.hpp index 68b7a96ed..9e69a3f15 100644 --- a/include/tao/pegtl/contrib/integer.hpp +++ b/include/tao/pegtl/contrib/integer.hpp @@ -22,8 +22,7 @@ #include "../parse.hpp" #include "../parse_error.hpp" #include "../rules.hpp" - -#include "../internal/text_eol_tags.hpp" +#include "../tags.hpp" namespace TAO_PEGTL_NAMESPACE { diff --git a/include/tao/pegtl/contrib/limit_bytes.hpp b/include/tao/pegtl/contrib/limit_count.hpp similarity index 80% rename from include/tao/pegtl/contrib/limit_bytes.hpp rename to include/tao/pegtl/contrib/limit_count.hpp index bbcc3ccb5..105980623 100644 --- a/include/tao/pegtl/contrib/limit_bytes.hpp +++ b/include/tao/pegtl/contrib/limit_count.hpp @@ -2,8 +2,8 @@ // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) -#ifndef TAO_PEGTL_CONTRIB_LIMIT_BYTES_HPP -#define TAO_PEGTL_CONTRIB_LIMIT_BYTES_HPP +#ifndef TAO_PEGTL_CONTRIB_LIMIT_COUNT_HPP +#define TAO_PEGTL_CONTRIB_LIMIT_COUNT_HPP #include @@ -30,11 +30,11 @@ namespace TAO_PEGTL_NAMESPACE MemoryInput& m_in; const char* m_end; - explicit bytes_guard( MemoryInput& in_in ) noexcept - : m_in( in_in ), - m_end( in_in.end() ) + explicit bytes_guard( MemoryInput& in ) noexcept + : m_in( in ), + m_end( in.end() ) { - m_in.private_set_end( m_in.begin() + std::min( m_in.size(), Maximum ) ); + m_in.private_set_end( m_in.start() + ( std::min )( m_in.size(), Maximum ) ); } bytes_guard( bytes_guard&& ) = delete; @@ -45,8 +45,8 @@ namespace TAO_PEGTL_NAMESPACE m_in.private_set_end( m_end ); } - bytes_guard& operator=( bytes_guard&& ) = delete; - bytes_guard& operator=( const bytes_guard& ) = delete; + void operator=( bytes_guard&& ) = delete; + void operator=( const bytes_guard& ) = delete; }; // C++17 does not allow for partial deduction guides. @@ -54,7 +54,7 @@ namespace TAO_PEGTL_NAMESPACE } // namespace internal template< std::size_t Maximum > - struct limit_bytes + struct limit_count : maybe_nothing { static constexpr const char* error_message = "maximum allowed rule consumption reached"; @@ -74,7 +74,7 @@ namespace TAO_PEGTL_NAMESPACE if( TAO_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, st... ) ) { if( in.empty() && ( bg.m_end != in.current() ) ) { #if defined( __cpp_exceptions ) - Control< limit_bytes >::raise( in ); + Control< limit_count >::raise( in ); #else std::fputs( "maximum allowed rule consumption reached\n", stderr ); std::terminate(); diff --git a/include/tao/pegtl/contrib/parse_tree.hpp b/include/tao/pegtl/contrib/parse_tree.hpp index 4c1e1f028..ae7710844 100644 --- a/include/tao/pegtl/contrib/parse_tree.hpp +++ b/include/tao/pegtl/contrib/parse_tree.hpp @@ -15,7 +15,6 @@ #include #include -#include "remove_first_state.hpp" #include "shuffle_states.hpp" #include "../apply_mode.hpp" @@ -26,6 +25,7 @@ #include "../normal.hpp" #include "../nothing.hpp" #include "../parse.hpp" +#include "../remove_first_state.hpp" #include "../rewind_mode.hpp" #include "../internal/enable_control.hpp" @@ -57,8 +57,8 @@ namespace TAO_PEGTL_NAMESPACE::parse_tree ~basic_node() = default; // no assignment either - basic_node& operator=( const basic_node& ) = delete; - basic_node& operator=( basic_node&& ) = delete; + void operator=( const basic_node& ) = delete; + void operator=( basic_node&& ) = delete; [[nodiscard]] bool is_root() const noexcept { diff --git a/include/tao/pegtl/contrib/raw_string.hpp b/include/tao/pegtl/contrib/raw_string.hpp index efc628e95..d832391f3 100644 --- a/include/tao/pegtl/contrib/raw_string.hpp +++ b/include/tao/pegtl/contrib/raw_string.hpp @@ -15,8 +15,7 @@ #include "../eol.hpp" #include "../rewind_mode.hpp" #include "../rules.hpp" - -#include "../internal/text_eol_tags.hpp" +#include "../tags.hpp" namespace TAO_PEGTL_NAMESPACE { @@ -45,7 +44,7 @@ namespace TAO_PEGTL_NAMESPACE case Open: marker_size = i + 1; in.template consume< eol_exclude_tag >( marker_size ); - (void)Control< eol >::template match< A, M, Action, Control >( in ); + (void)Control< eol< void > >::template match< A, M, Action, Control >( in ); return true; case Marker: break; @@ -211,7 +210,7 @@ namespace TAO_PEGTL_NAMESPACE std::size_t marker_size; if( Control< internal::raw_string_open< Open, Marker > >::template match< A, M, Action, Control >( in, marker_size ) ) { if( Control< content >::template match< A, M, Action, Control >( in, marker_size, st... ) ) { - in.template consume< internal::eol_exclude_tag >( marker_size ); + in.template consume< eol_exclude_tag >( marker_size ); return true; } } diff --git a/include/tao/pegtl/count_position.hpp b/include/tao/pegtl/count_position.hpp index e871671f8..40809d4e4 100644 --- a/include/tao/pegtl/count_position.hpp +++ b/include/tao/pegtl/count_position.hpp @@ -24,12 +24,12 @@ namespace TAO_PEGTL_NAMESPACE {} }; - [[nodiscard]] inline bool operator==( const count_position& l, const count_position& r ) noexcept + [[nodiscard]] inline bool operator==( const count_position l, const count_position r ) noexcept { return l.count == r.count; } - [[nodiscard]] inline bool operator!=( const count_position& l, const count_position& r ) noexcept + [[nodiscard]] inline bool operator!=( const count_position l, const count_position r ) noexcept { return !( l == r ); } diff --git a/include/tao/pegtl/inputs.hpp b/include/tao/pegtl/inputs.hpp index 2498c2539..f56215ae4 100644 --- a/include/tao/pegtl/inputs.hpp +++ b/include/tao/pegtl/inputs.hpp @@ -8,12 +8,13 @@ #include #include "config.hpp" +#include "eol.hpp" #include "internal/inputs.hpp" namespace TAO_PEGTL_NAMESPACE { - using argv_input = internal::input_with_fakes< internal::input_with_peeks< internal::argv_input > >; // TODO: Add input_with_start? + using argv_input = internal::input_with_fakes< internal::input_with_peeks< internal::input_with_start< internal::input_with_lines< ascii::lf, internal::argv_input > > > >; template< typename Container > using copy_input = internal::input_with_fakes< internal::input_with_peeks< internal::copy_input< Container > > >; using file_input = internal::input_with_fakes< internal::input_with_peeks< internal::file_input > >; @@ -21,7 +22,7 @@ namespace TAO_PEGTL_NAMESPACE template< typename Data > using view_input = internal::input_with_fakes< internal::input_with_peeks< internal::view_input< Data > > >; // TODO: Add input_with_start? - using argv_input_with_source = internal::input_with_fakes< internal::input_with_peeks< internal::argv_input_with_source > >; // TODO: Add input_with_start? + using argv_input_with_source = internal::input_with_fakes< internal::input_with_peeks< internal::input_with_start< internal::input_with_lines< ascii::lf, internal::argv_input_with_source > > > >; template< typename Container > using copy_input_with_source = internal::input_with_fakes< internal::input_with_peeks< internal::input_with_source< std::string, internal::copy_input< Container > > > >; using file_input_with_source = internal::input_with_fakes< internal::input_with_peeks< internal::file_input_with_source< file_input > > >; diff --git a/include/tao/pegtl/internal/buffer_input.hpp b/include/tao/pegtl/internal/buffer_input.hpp index 64843d838..abde6bcb5 100644 --- a/include/tao/pegtl/internal/buffer_input.hpp +++ b/include/tao/pegtl/internal/buffer_input.hpp @@ -74,6 +74,11 @@ namespace TAO_PEGTL_NAMESPACE::internal return m_current + offset; } + [[nodiscard]] const data_t* previous( const error_position_t saved ) const noexcept + { + return m_current - m_position.count + saved.count; + } + [[nodiscard]] const data_t* previous( const rewind_position_t saved ) const noexcept { return saved.data; diff --git a/include/tao/pegtl/internal/bump_traits.hpp b/include/tao/pegtl/internal/bump_traits.hpp index 3cd543aec..67796d519 100644 --- a/include/tao/pegtl/internal/bump_traits.hpp +++ b/include/tao/pegtl/internal/bump_traits.hpp @@ -9,6 +9,7 @@ #include #include "../config.hpp" +#include "../tags.hpp" #include "any.hpp" #include "at.hpp" @@ -17,7 +18,6 @@ #include "eolf.hpp" #include "everything.hpp" #include "many.hpp" -#include "text_eol_tags.hpp" #include "until.hpp" namespace TAO_PEGTL_NAMESPACE::internal @@ -91,12 +91,12 @@ namespace TAO_PEGTL_NAMESPACE::internal {}; template< typename Eol > - struct bump_traits< Eol, until< eol > > + struct bump_traits< Eol, until< eol< void > > > : bump_traits< Eol, eol_exclude_tag > {}; template< typename Eol > - struct bump_traits< Eol, until< eolf > > + struct bump_traits< Eol, until< eolf< void > > > : bump_traits< Eol, eol_exclude_tag > {}; diff --git a/include/tao/pegtl/internal/copy_input.hpp b/include/tao/pegtl/internal/copy_input.hpp index bbc26f81a..9a2d9106b 100644 --- a/include/tao/pegtl/internal/copy_input.hpp +++ b/include/tao/pegtl/internal/copy_input.hpp @@ -76,6 +76,11 @@ namespace TAO_PEGTL_NAMESPACE::internal return m_current + offset; } + [[nodiscard]] const data_t* previous( const error_position_t saved ) const noexcept + { + return start() + saved.count; + } + [[nodiscard]] const data_t* previous( const rewind_position_t saved ) const noexcept { return saved.data; diff --git a/include/tao/pegtl/internal/eol.hpp b/include/tao/pegtl/internal/eol.hpp index 51954335f..ca25b504e 100644 --- a/include/tao/pegtl/internal/eol.hpp +++ b/include/tao/pegtl/internal/eol.hpp @@ -11,14 +11,35 @@ #include "../type_list.hpp" #include "enable_control.hpp" -#include "text_eol_tags.hpp" namespace TAO_PEGTL_NAMESPACE::internal { + template< typename Eol > struct eol { using rule_t = eol; - using subs_t = empty_list; // Not quite true, but good enough and we can't really do better. + using subs_t = empty_list; // TODO? + + template< apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, States&&... st ) + { + using eol_impl = typename Eol::rule_t; + return Control< eol_impl >::template match< apply_mode::nothing, M, Action, Control >( in, st... ); + } + }; + + template<> + struct eol< void > + { + using rule_t = eol; + using subs_t = empty_list; template< apply_mode A, rewind_mode M, @@ -36,8 +57,8 @@ namespace TAO_PEGTL_NAMESPACE::internal } }; - template<> - inline constexpr bool enable_control< eol > = false; + template< typename Eol > + inline constexpr bool enable_control< eol< Eol > > = false; } // namespace TAO_PEGTL_NAMESPACE::internal diff --git a/include/tao/pegtl/internal/eolf.hpp b/include/tao/pegtl/internal/eolf.hpp index a80597202..1da730355 100644 --- a/include/tao/pegtl/internal/eolf.hpp +++ b/include/tao/pegtl/internal/eolf.hpp @@ -13,6 +13,7 @@ namespace TAO_PEGTL_NAMESPACE::internal { + template< typename Eol > struct eolf { using rule_t = eolf; @@ -28,12 +29,12 @@ namespace TAO_PEGTL_NAMESPACE::internal typename... States > [[nodiscard]] static bool match( ParseInput& in, States&&... st ) { - return in.empty() || eol::match< A, M, Action, Control >( in, st... ); + return in.empty() || eol< Eol >::template match< A, M, Action, Control >( in, st... ); } }; - template<> - inline constexpr bool enable_control< eolf > = false; + template< typename Eol > + inline constexpr bool enable_control< eolf< Eol > > = false; } // namespace TAO_PEGTL_NAMESPACE::internal diff --git a/include/tao/pegtl/internal/input_with_start.hpp b/include/tao/pegtl/internal/input_with_start.hpp index 67df46831..0759dc04f 100644 --- a/include/tao/pegtl/internal/input_with_start.hpp +++ b/include/tao/pegtl/internal/input_with_start.hpp @@ -15,19 +15,19 @@ namespace TAO_PEGTL_NAMESPACE::internal { - template< typename Data = char > + template< typename Input = view_input< char > > class input_with_start - : public view_input< Data > + : public Input { public: - using base_t = view_input< Data >; - using data_t = Data; + using base_t = Input; + using data_t = typename Input::data_t; using error_position_t = count_position; using rewind_position_t = pointer_position< data_t >; template< typename... As > explicit input_with_start( As&&... as ) noexcept - : view_input< Data >( std::forward< As >( as )... ), + : Input( std::forward< As >( as )... ), m_start( this->current() ) {} @@ -36,6 +36,13 @@ namespace TAO_PEGTL_NAMESPACE::internal return m_start; } + using Input::previous; + + [[nodiscard]] const data_t* previous( const error_position_t saved ) const noexcept + { + return m_start + saved.count; + } + void restart() noexcept { this->m_current = m_start; @@ -46,10 +53,10 @@ namespace TAO_PEGTL_NAMESPACE::internal return previous_position( this->rewind_position() ); } - // [[nodiscard]] auto previous_position( const error_position_t saved ) const noexcept - // { - // return saved; - // } + [[nodiscard]] auto previous_position( const error_position_t saved ) const noexcept + { + return saved; + } [[nodiscard]] auto previous_position( const rewind_position_t saved ) const noexcept { diff --git a/include/tao/pegtl/internal/rematch_input.hpp b/include/tao/pegtl/internal/rematch_input.hpp index 532284185..101202d20 100644 --- a/include/tao/pegtl/internal/rematch_input.hpp +++ b/include/tao/pegtl/internal/rematch_input.hpp @@ -15,6 +15,7 @@ #include "input_with_peeks.hpp" #include "input_with_start.hpp" #include "rewind_guard.hpp" +#include "view_input.hpp" namespace TAO_PEGTL_NAMESPACE::internal { @@ -22,7 +23,7 @@ namespace TAO_PEGTL_NAMESPACE::internal class rematch_view_input { public: - using base_t = input_with_peeks< input_with_fakes< input_with_start< typename Input::data_t > > >; + using base_t = input_with_peeks< input_with_fakes< input_with_start< view_input< typename Input::data_t > > > >; using data_t = typename Input::data_t; using error_position_t = typename Input::error_position_t; using rewind_position_t = pointer_position< data_t >; diff --git a/include/tao/pegtl/internal/rewind_adapt.hpp b/include/tao/pegtl/internal/rewind_adapt.hpp index d62d86bad..653279f82 100644 --- a/include/tao/pegtl/internal/rewind_adapt.hpp +++ b/include/tao/pegtl/internal/rewind_adapt.hpp @@ -12,13 +12,13 @@ namespace TAO_PEGTL_NAMESPACE::internal { template< typename Data > - [[nodiscard]] const Data* rewind_adapt( const Data* start, const count_position c ) noexcept + [[nodiscard]] const Data* rewind_adapt( const Data* start, const count_position& c ) noexcept { return start + c.count; } template< typename Data > - [[nodiscard]] const Data* rewind_adapt( const Data* /*unused*/, const pointer_position< Data > p ) noexcept + [[nodiscard]] const Data* rewind_adapt( const Data* /*unused*/, const pointer_position< Data >& p ) noexcept { return p.data; } diff --git a/include/tao/pegtl/internal/text_eol_bump.hpp b/include/tao/pegtl/internal/text_eol_bump.hpp index d5cd6a01f..a808c9d3c 100644 --- a/include/tao/pegtl/internal/text_eol_bump.hpp +++ b/include/tao/pegtl/internal/text_eol_bump.hpp @@ -8,7 +8,6 @@ #include "../config.hpp" #include "bump_traits.hpp" -#include "text_eol_tags.hpp" namespace TAO_PEGTL_NAMESPACE::internal { diff --git a/include/tao/pegtl/internal/view_input.hpp b/include/tao/pegtl/internal/view_input.hpp index 234fea48c..a271211dd 100644 --- a/include/tao/pegtl/internal/view_input.hpp +++ b/include/tao/pegtl/internal/view_input.hpp @@ -95,6 +95,8 @@ namespace TAO_PEGTL_NAMESPACE::internal return m_current + offset; } + // [[nodiscard]] const data_t* previosu( const error_position_t saved ) const noexcept + [[nodiscard]] const data_t* previous( const rewind_position_t saved ) const noexcept { return saved.data; diff --git a/include/tao/pegtl/line_view_at.hpp b/include/tao/pegtl/line_view_at.hpp index 2bdcea245..9507f7a36 100644 --- a/include/tao/pegtl/line_view_at.hpp +++ b/include/tao/pegtl/line_view_at.hpp @@ -6,6 +6,7 @@ #define TAO_PEGTL_LINE_VIEW_AT_HPP #include +#include #include "apply_mode.hpp" #include "config.hpp" @@ -13,6 +14,7 @@ #include "nothing.hpp" #include "rewind_mode.hpp" +#include "internal/argv_input.hpp" #include "internal/at.hpp" #include "internal/eolf.hpp" #include "internal/scan_input.hpp" @@ -20,18 +22,32 @@ namespace TAO_PEGTL_NAMESPACE { + // The assumption is that argv consists of strings without eols. + + template< typename Input, typename Position > + [[nodiscard]] auto begin_of_line( const Input& in, const Position& /*unused*/ ) noexcept -> std::enable_if_t< std::is_base_of_v< internal::argv_input, Input >, const char* > + { + return in.start(); + } + + template< typename Input, typename Position > + [[nodiscard]] auto end_of_line_or_file( const Input& in, const Position& /*unused*/ ) noexcept -> std::enable_if_t< std::is_base_of_v< internal::argv_input, Input >, const char* > + { + return in.end(); + } + template< typename Input, typename Position > - [[nodiscard]] const char* begin_of_line( const Input& in, const Position& p ) noexcept + [[nodiscard]] auto begin_of_line( const Input& in, const Position& p ) noexcept -> std::enable_if_t< !std::is_base_of_v< internal::argv_input, Input >, decltype( in.current() ) > { - return in.at( p ) - ( p.column - 1 ); + return in.previous( p ) - ( p.column - 1 ); } template< typename Input, typename Position > - [[nodiscard]] const char* end_of_line_or_file( const Input& in, const Position& p ) noexcept + [[nodiscard]] auto end_of_line_or_file( const Input& in, const Position& p ) noexcept -> std::enable_if_t< !std::is_base_of_v< internal::argv_input, Input >, decltype( in.current() ) > { - using grammar = internal::until< internal::at< internal::eolf > >; - internal::scan_input< typename Input::data_t > i2( in.at( p ), in.end() ); // TODO: Start before in.at( p ) to correctly handle the middle of a multi-token EOL. - (void)normal< grammar >::match< apply_mode::nothing, rewind_mode::optional, nothing, normal >( i2 ); + using grammar = internal::until< internal::at< internal::eolf< typename Input::eol_rule > > >; + internal::scan_input< typename Input::data_t > i2( in.previous( p ), in.end() ); // TODO: Start before in.at( p ) to correctly handle the middle of a multi-token EOL. + (void)normal< grammar >::template match< apply_mode::nothing, rewind_mode::optional, nothing, normal >( i2 ); return i2.current(); } diff --git a/include/tao/pegtl/parse.hpp b/include/tao/pegtl/parse.hpp index 79b357af5..a0c5da1ab 100644 --- a/include/tao/pegtl/parse.hpp +++ b/include/tao/pegtl/parse.hpp @@ -25,6 +25,7 @@ namespace TAO_PEGTL_NAMESPACE typename... States > auto parse( ParseInput&& in, States&&... st ) { + static_assert( !std::is_const_v< ParseInput > ); return Control< Rule >::template match< A, M, Action, Control >( in, st... ); } @@ -38,6 +39,7 @@ namespace TAO_PEGTL_NAMESPACE typename... States > auto parse_nested( const Ambient& am, ParseInput&& in, States&&... st ) { + static_assert( !std::is_const_v< ParseInput > ); #if defined( __cpp_exceptions ) try { return parse< Rule, Action, Control, A, M >( in, st... ); diff --git a/include/tao/pegtl/position_with_source.hpp b/include/tao/pegtl/position_with_source.hpp index 396545b21..0770e874b 100644 --- a/include/tao/pegtl/position_with_source.hpp +++ b/include/tao/pegtl/position_with_source.hpp @@ -2,15 +2,15 @@ // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) -#ifndef TAO_PEGTL_INTERNAL_POSITION_WITH_SOURCE_HPP -#define TAO_PEGTL_INTERNAL_POSITION_WITH_SOURCE_HPP +#ifndef TAO_PEGTL_POSITION_WITH_SOURCE_HPP +#define TAO_PEGTL_POSITION_WITH_SOURCE_HPP #include #include #include "config.hpp" -namespace TAO_PEGTL_NAMESPACE::internal +namespace TAO_PEGTL_NAMESPACE { template< typename Source, typename Position > struct position_with_source @@ -53,6 +53,6 @@ namespace TAO_PEGTL_NAMESPACE::internal return os << p.source << '@' << p.base(); } -} // namespace TAO_PEGTL_NAMESPACE::internal +} // namespace TAO_PEGTL_NAMESPACE #endif diff --git a/include/tao/pegtl/rules.hpp b/include/tao/pegtl/rules.hpp index 253759047..1638935c8 100644 --- a/include/tao/pegtl/rules.hpp +++ b/include/tao/pegtl/rules.hpp @@ -27,8 +27,8 @@ namespace TAO_PEGTL_NAMESPACE template< typename... Rules > struct disable : internal::disable< Rules... > {}; template< typename... Rules > struct enable : internal::enable< Rules... > {}; struct eof : internal::eof {}; - struct eol : internal::eol {}; - struct eolf : internal::eolf {}; + struct eol : internal::eol< void > {}; + struct eolf : internal::eolf< void > {}; struct everything : internal::everything< std::size_t > {}; struct failure : internal::failure {}; template< auto Function, typename Peek = void > struct function : internal::function< decltype( Function ), Function, Peek > {}; diff --git a/include/tao/pegtl/internal/text_eol_tags.hpp b/include/tao/pegtl/tags.hpp similarity index 69% rename from include/tao/pegtl/internal/text_eol_tags.hpp rename to include/tao/pegtl/tags.hpp index 9fb2098d1..bea962703 100644 --- a/include/tao/pegtl/internal/text_eol_tags.hpp +++ b/include/tao/pegtl/tags.hpp @@ -2,12 +2,12 @@ // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) -#ifndef TAO_PEGTL_INTERNAL_TEXT_EOL_TAGS_HPP -#define TAO_PEGTL_INTERNAL_TEXT_EOL_TAGS_HPP +#ifndef TAO_PEGTL_TAGS_HPP +#define TAO_PEGTL_TAGS_HPP -#include "../config.hpp" +#include "config.hpp" -namespace TAO_PEGTL_NAMESPACE::internal +namespace TAO_PEGTL_NAMESPACE { struct eol_exclude_tag { @@ -24,6 +24,6 @@ namespace TAO_PEGTL_NAMESPACE::internal using rule_t = eol_unknown_tag; }; -} // namespace TAO_PEGTL_NAMESPACE::internal +} // namespace TAO_PEGTL_NAMESPACE #endif diff --git a/include/tao/pegtl/text_position_with_source.hpp b/include/tao/pegtl/text_position_with_source.hpp new file mode 100644 index 000000000..e1f2705a4 --- /dev/null +++ b/include/tao/pegtl/text_position_with_source.hpp @@ -0,0 +1,23 @@ +// Copyright (c) 2023 Dr. Colin Hirsch and Daniel Frey +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) + +#ifndef TAO_PEGTL_INTERNAL_TEXT_POSITION_WITH_SOURCE_HPP +#define TAO_PEGTL_INTERNAL_TEXT_POSITION_WITH_SOURCE_HPP + +#include +#include + +#include "config.hpp" + +#include "position_with_source.hpp" +#include "text_position.hpp" + +namespace TAO_PEGTL_NAMESPACE +{ + using text_position_with_path = position_with_source< std::filesystem::path, text_position >; + using text_position_with_source = position_with_source< std::string, text_position >; + +} // namespace TAO_PEGTL_NAMESPACE + +#endif diff --git a/src/example/pegtl/analyze.cc b/src/example/pegtl/analyze.cc deleted file mode 100644 index fae02a098..000000000 --- a/src/example/pegtl/analyze.cc +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) 2017-2023 Dr. Colin Hirsch and Daniel Frey -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) - -#include - -#include - -using namespace TAO_PEGTL_NAMESPACE; - -struct bar; - -struct foo - : sor< digit, bar > -{}; - -struct bar - : plus< foo > // seq< foo, opt< bar > > -{}; - -int main() // NOLINT(bugprone-exception-escape) -{ - if( analyze< foo >( 1 ) != 0 ) { - std::cerr << "there are problems" << std::endl; - return 1; - } - return 0; -} diff --git a/src/example/pegtl/analyze.cpp b/src/example/pegtl/analyze.cpp new file mode 100644 index 000000000..42453ef0d --- /dev/null +++ b/src/example/pegtl/analyze.cpp @@ -0,0 +1,35 @@ +// Copyright (c) 2017-2023 Dr. Colin Hirsch and Daniel Frey +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) + +#include + +#include + +using namespace TAO_PEGTL_NAMESPACE; + +struct bar; + +struct foo + : sor< digit, bar > +{}; + +struct bar + : plus< foo > // seq< foo, opt< bar > > +{}; + +// We expect problems because if the next character in the input is not a +// digit then matching bar will attempt to match foo, which will attempt to +// match bar again (after failing digit), and so on ad infinitum. Which is +// of course exaclty the kind of problem the grammar analysis is supposed +// to detect and complain about... + +int main() // NOLINT(bugprone-exception-escape) +{ + if( analyze< foo >( 1 ) != 0 ) { + std::cerr << "There are problems!" << std::endl; + return 1; + } + std::cerr << "No problems found -- which is itself a problem because we were expecting some!" << std::endl; + return 0; +} diff --git a/src/example/pegtl/calculator.cc b/src/example/pegtl/calculator.cpp similarity index 98% rename from src/example/pegtl/calculator.cc rename to src/example/pegtl/calculator.cpp index 76997f3fa..757ca0ec7 100644 --- a/src/example/pegtl/calculator.cc +++ b/src/example/pegtl/calculator.cpp @@ -14,7 +14,7 @@ // Include the analyze function that checks // a grammar for possible infinite cycles. -#include +#include namespace pegtl = TAO_PEGTL_NAMESPACE; @@ -25,8 +25,7 @@ namespace calculator // number indicates a lower priority. enum class order : int - { - }; + {}; // For each binary operator known to the calculator we need an // instance of the following data structure with the priority, @@ -239,7 +238,7 @@ namespace calculator // usually be an associated action: To push the matched operator onto // the operator stack. s.push( i->second ); - in.bump( t.size() ); + in.template consume< eol_exclude_tag >( t.size() ); return true; } } @@ -354,7 +353,7 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) std::cout << s.finish() << std::endl; } else { - std::cerr << "parse error for: " << argv[ i ] << std::endl; + std::cerr << "Parse error for: " << argv[ i ] << std::endl; } } return 0; diff --git a/src/example/pegtl/chomsky_hierarchy.cc b/src/example/pegtl/chomsky_hierarchy.cpp similarity index 98% rename from src/example/pegtl/chomsky_hierarchy.cc rename to src/example/pegtl/chomsky_hierarchy.cpp index 5832f3bee..a11934ae5 100644 --- a/src/example/pegtl/chomsky_hierarchy.cc +++ b/src/example/pegtl/chomsky_hierarchy.cpp @@ -55,7 +55,7 @@ namespace example return false; } } - in.bump_in_this_line( count ); + in.template consume< pegtl::eol_exclude_tag >( count ); return true; } return false; diff --git a/src/example/pegtl/csv1.cc b/src/example/pegtl/csv1.cpp similarity index 96% rename from src/example/pegtl/csv1.cc rename to src/example/pegtl/csv1.cpp index 4d9d24b31..9dc627731 100644 --- a/src/example/pegtl/csv1.cc +++ b/src/example/pegtl/csv1.cpp @@ -90,10 +90,10 @@ namespace csv1 int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) { for( int i = 1; i < argc; ++i ) { - pegtl::file_input in( argv[ i ] ); + pegtl::lazy_file_input< pegtl::ascii::lf_crlf > in( argv[ i ] ); csv1::result_data data; if( !pegtl::parse< pegtl::seq< csv1::file >, csv1::action, csv1::control >( in, data ) ) { - std::cerr << "parse error" << std::endl; + std::cerr << "Parse error!" << std::endl; return 1; } for( const auto& line : data ) { diff --git a/src/example/pegtl/csv2.cc b/src/example/pegtl/csv2.cpp similarity index 98% rename from src/example/pegtl/csv2.cc rename to src/example/pegtl/csv2.cpp index ba3b4ce0f..e5fa52842 100644 --- a/src/example/pegtl/csv2.cc +++ b/src/example/pegtl/csv2.cpp @@ -175,7 +175,7 @@ namespace csv2 int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) { for( int i = 1; i < argc; ++i ) { - pegtl::file_input in( argv[ i ] ); + pegtl::lazy_file_input< pegtl::ascii::lf_crlf > in( argv[ i ] ); constexpr unsigned number_of_columns = 3; csv2::result_data< number_of_columns > data; if( pegtl::parse< pegtl::seq< csv2::file< number_of_columns > >, csv2::action >( in, data ) ) { diff --git a/src/example/pegtl/dynamic_match.cc b/src/example/pegtl/dynamic_match.cpp similarity index 96% rename from src/example/pegtl/dynamic_match.cc rename to src/example/pegtl/dynamic_match.cpp index 76213ef02..55ce8c9aa 100644 --- a/src/example/pegtl/dynamic_match.cc +++ b/src/example/pegtl/dynamic_match.cpp @@ -10,7 +10,7 @@ #include -#include +#include namespace pegtl = TAO_PEGTL_NAMESPACE; @@ -40,7 +40,7 @@ namespace dynamic { if( in.size( id.size() ) >= id.size() ) { if( std::memcmp( in.current(), id.data(), id.size() ) == 0 ) { - in.bump( id.size() ); + in.template consume< pegtl::eol_unknown_tag >( id.size() ); return true; } } diff --git a/src/example/pegtl/expression.cc b/src/example/pegtl/expression.cpp similarity index 98% rename from src/example/pegtl/expression.cc rename to src/example/pegtl/expression.cpp index 1f9dc9a36..acfa471f5 100644 --- a/src/example/pegtl/expression.cc +++ b/src/example/pegtl/expression.cpp @@ -98,7 +98,7 @@ namespace TAO_PEGTL_NAMESPACE::expression { if( in.size( sv.size() ) >= sv.size() ) { if( std::memcmp( in.current(), sv.data(), sv.size() ) == 0 ) { - in.bump( sv.size() ); + in.template consume< eol_exclude_tag >( sv.size() ); return true; } } @@ -111,7 +111,7 @@ namespace TAO_PEGTL_NAMESPACE::expression const std::size_t max = std::min( max_length, in.size( max_length ) ); for( std::string op( in.current(), max ); !op.empty(); op.pop_back() ) { if( const auto i = std::find_if( ops.begin(), ops.end(), [ = ]( const OperatorInfo& info ) { return info.name == op; } ); i != ops.end() ) { - in.bump( op.size() ); + in.template consume< eol_exclude_tag >( op.size() ); return &*i; } } @@ -124,7 +124,7 @@ namespace TAO_PEGTL_NAMESPACE::expression const std::size_t max = std::min( max_length, in.size( max_length ) ); for( std::string op( in.current(), max ); !op.empty(); op.pop_back() ) { if( const auto i = std::find_if( ops.begin(), ops.end(), [ = ]( const OperatorInfo& info ) { return info.name == op; } ); ( i != ops.end() ) && ( i->left_binding_power >= min_precedence ) ) { - in.bump( op.size() ); + in.template consume< eol_exclude_tag >( op.size() ); return &*i; } } @@ -508,11 +508,11 @@ 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& e ) { + catch( const TAO_PEGTL_NAMESPACE::parse_error< TAO_PEGTL_NAMESPACE::count_position >& e ) { const auto& p = e.position_object(); std::cerr << e.what() << '\n' - << line_view_at( in, p ) << '\n' - << std::setw( int( p.column ) ) << '^' << '\n'; + << argv[ i ] << '\n' + << std::setw( int( p.count ) ) << '^' << '\n'; } } return 0; diff --git a/src/example/pegtl/hello_world.cc b/src/example/pegtl/hello_world.cpp similarity index 99% rename from src/example/pegtl/hello_world.cc rename to src/example/pegtl/hello_world.cpp index 40eb9dd92..8568ad628 100644 --- a/src/example/pegtl/hello_world.cc +++ b/src/example/pegtl/hello_world.cpp @@ -37,7 +37,6 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) { if( argc > 1 ) { std::string name; - pegtl::argv_input in( argv, 1 ); if( pegtl::parse< hello::grammar, hello::action >( in, name ) ) { std::cout << "Good bye, " << name << "!" << std::endl; diff --git a/src/example/pegtl/indent_aware.cc b/src/example/pegtl/indent_aware.cpp similarity index 98% rename from src/example/pegtl/indent_aware.cc rename to src/example/pegtl/indent_aware.cpp index beba07a8b..1c900b4ff 100644 --- a/src/example/pegtl/indent_aware.cc +++ b/src/example/pegtl/indent_aware.cpp @@ -215,7 +215,7 @@ namespace example int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) { for( int i = 1; i < argc; ++i ) { - pegtl::file_input in( argv[ i ] ); + pegtl::text_file_input_with_source< pegtl::ascii::lf_crlf > in( argv[ i ] ); example::state is; pegtl::parse< example::grammar, example::action >( in, is ); } diff --git a/src/example/pegtl/iri.cc b/src/example/pegtl/iri.cpp similarity index 92% rename from src/example/pegtl/iri.cc rename to src/example/pegtl/iri.cpp index 508a56ff9..a5a345c3e 100644 --- a/src/example/pegtl/iri.cc +++ b/src/example/pegtl/iri.cpp @@ -31,7 +31,7 @@ struct IRI std::string query; std::string fragment; - explicit IRI( const std::string& iri ); + explicit IRI( pegtl::argv_input_with_source& ); }; namespace iri @@ -76,11 +76,10 @@ namespace iri } // namespace iri -IRI::IRI( const std::string& iri ) +IRI::IRI( pegtl::argv_input_with_source& in ) { using grammar = pegtl::must< pegtl::iri::IRI >; - pegtl::memory_input input( iri, "iri" ); - pegtl::parse< grammar, iri::action >( input, *this ); + pegtl::parse< grammar, iri::action >( in, *this ); } int main( int argc, char** argv ) @@ -88,7 +87,8 @@ int main( int argc, char** argv ) try { for( int i = 1; i < argc; ++i ) { std::cout << "Parsing " << argv[ i ] << std::endl; - const IRI iri( argv[ i ] ); + pegtl::argv_input_with_source in( argv, i ); + const IRI iri( in ); std::cout << "IRI.scheme: " << iri.scheme << std::endl; std::cout << "IRI.authority: " << iri.authority << std::endl; std::cout << "IRI.userinfo: " << iri.userinfo << std::endl; diff --git a/src/example/pegtl/json_analyze.cc b/src/example/pegtl/json_analyze.cpp similarity index 94% rename from src/example/pegtl/json_analyze.cc rename to src/example/pegtl/json_analyze.cpp index 44a552faf..2042550ac 100644 --- a/src/example/pegtl/json_analyze.cc +++ b/src/example/pegtl/json_analyze.cpp @@ -5,7 +5,7 @@ #include #include -#include +#include #include namespace pegtl = TAO_PEGTL_NAMESPACE; diff --git a/src/example/pegtl/json_build.cc b/src/example/pegtl/json_build.cpp similarity index 96% rename from src/example/pegtl/json_build.cc rename to src/example/pegtl/json_build.cpp index 83ff2380f..de9108c00 100644 --- a/src/example/pegtl/json_build.cc +++ b/src/example/pegtl/json_build.cpp @@ -165,16 +165,16 @@ namespace example int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) { if( argc != 2 ) { - std::cerr << "usage: " << argv[ 0 ] << " \n"; + std::cerr << "usage: " << argv[ 0 ] << " \n"; } else { example::json_state state; - pegtl::file_input in( argv[ 1 ] ); + pegtl::text_file_input< pegtl::ascii::lf > in( argv[ 1 ] ); #if defined( __cpp_exceptions ) try { pegtl::parse< example::grammar, example::action, example::control >( in, state ); } - catch( const pegtl::parse_error& e ) { + catch( const pegtl::parse_error< pegtl::text_position >& e ) { const auto& p = e.position_object(); std::cerr << e.what() << '\n' << line_view_at( in, p ) << '\n' @@ -182,7 +182,6 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) return 1; } #else - if( !pegtl::parse< example::grammar, example::action, example::control >( in, state ) ) { std::cerr << "error occurred" << std::endl; return 1; diff --git a/src/example/pegtl/json_count.cc b/src/example/pegtl/json_count.cpp similarity index 97% rename from src/example/pegtl/json_count.cc rename to src/example/pegtl/json_count.cpp index efda8bf01..77c046b9a 100644 --- a/src/example/pegtl/json_count.cc +++ b/src/example/pegtl/json_count.cpp @@ -60,7 +60,7 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) counter_state cs; for( int i = 1; i < argc; ++i ) { - file_input in( argv[ i ] ); + text_file_input< ascii::lf > in( argv[ i ] ); parse< grammar, nothing, counter >( in, cs ); } std::cout << std::right << std::setw( 72 ) << "RULE NAME" << std::left << " START SUCCESS FAILURE" << std::endl; diff --git a/src/example/pegtl/json_coverage.cc b/src/example/pegtl/json_coverage.cpp similarity index 91% rename from src/example/pegtl/json_coverage.cc rename to src/example/pegtl/json_coverage.cpp index 3c89f0701..ebb9cf371 100644 --- a/src/example/pegtl/json_coverage.cc +++ b/src/example/pegtl/json_coverage.cpp @@ -28,13 +28,13 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) return 1; } - pegtl::file_input in( argv[ 1 ] ); + pegtl::text_file_input< pegtl::ascii::lf > in( argv[ 1 ] ); pegtl::coverage_result result; #if defined( __cpp_exceptions ) try { pegtl::coverage< example::grammar, pegtl::nothing, example::control >( in, result ); } - catch( const pegtl::parse_error& e ) { + catch( const pegtl::parse_error< pegtl::text_position >& e ) { const auto& p = e.position_object(); std::cerr << e.what() << '\n' << line_view_at( in, p ) << '\n' diff --git a/src/example/pegtl/json_parse.cc b/src/example/pegtl/json_parse.cpp similarity index 82% rename from src/example/pegtl/json_parse.cc rename to src/example/pegtl/json_parse.cpp index 3c1a6e5d4..195e7379f 100644 --- a/src/example/pegtl/json_parse.cc +++ b/src/example/pegtl/json_parse.cpp @@ -8,8 +8,7 @@ #include #include #include -#include -#include +#include #include "json_errors.hpp" @@ -25,7 +24,7 @@ namespace example template<> struct action< pegtl::json::value > - : pegtl::limit_depth< 42 > + : pegtl::check_depth< 42 > {}; } // namespace example @@ -38,17 +37,16 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) << "Example: " << argv[ 0 ] << " '{\"foo\":[42,null]}'" << std::endl; return 1; } - - pegtl::input_with_depth< pegtl::argv_input<> > in( argv, 1 ); + pegtl::input_with_depth< pegtl::argv_input > in( argv, 1 ); #if defined( __cpp_exceptions ) try { pegtl::parse< example::grammar, example::action, example::control >( in ); } - catch( const pegtl::parse_error& e ) { + catch( const pegtl::parse_error< pegtl::count_position >& e ) { const auto& p = e.position_object(); std::cerr << e.what() << '\n' << line_view_at( in, p ) << '\n' - << std::setw( int( p.column ) ) << '^' << std::endl; + << std::setw( int( p.count ) ) << '^' << std::endl; return 1; } #else diff --git a/src/example/pegtl/json_print_debug.cc b/src/example/pegtl/json_print_debug.cpp similarity index 91% rename from src/example/pegtl/json_print_debug.cc rename to src/example/pegtl/json_print_debug.cpp index ee344aa81..972fb7a51 100644 --- a/src/example/pegtl/json_print_debug.cc +++ b/src/example/pegtl/json_print_debug.cpp @@ -5,7 +5,7 @@ #include #include -#include +#include int main() // NOLINT(bugprone-exception-escape) { diff --git a/src/example/pegtl/json_print_names.cc b/src/example/pegtl/json_print_names.cpp similarity index 91% rename from src/example/pegtl/json_print_names.cc rename to src/example/pegtl/json_print_names.cpp index 7df4fbe67..427cb56b8 100644 --- a/src/example/pegtl/json_print_names.cc +++ b/src/example/pegtl/json_print_names.cpp @@ -5,7 +5,7 @@ #include #include -#include +#include int main() // NOLINT(bugprone-exception-escape) { diff --git a/src/example/pegtl/lua53_analyze.cc b/src/example/pegtl/lua53_analyze.cpp similarity index 94% rename from src/example/pegtl/lua53_analyze.cc rename to src/example/pegtl/lua53_analyze.cpp index 572046486..c4b647d76 100644 --- a/src/example/pegtl/lua53_analyze.cc +++ b/src/example/pegtl/lua53_analyze.cpp @@ -13,7 +13,7 @@ int main() #include -#include +#include #include "lua53.hpp" diff --git a/src/example/pegtl/lua53_parse.cc b/src/example/pegtl/lua53_parse.cpp similarity index 87% rename from src/example/pegtl/lua53_parse.cc rename to src/example/pegtl/lua53_parse.cpp index 95ad94ea3..b83141908 100644 --- a/src/example/pegtl/lua53_parse.cc +++ b/src/example/pegtl/lua53_parse.cpp @@ -18,7 +18,7 @@ int main() int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) { for( int i = 1; i < argc; ++i ) { - TAO_PEGTL_NAMESPACE::file_input in( argv[ i ] ); + TAO_PEGTL_NAMESPACE::lazy_file_input< TAO_PEGTL_NAMESPACE::ascii::lf_crlf > in( argv[ i ] ); const auto r = TAO_PEGTL_NAMESPACE::parse< lua53::grammar >( in ); std::cout << argv[ i ] << " " << r << std::endl; } diff --git a/src/example/pegtl/modulus_match.cc b/src/example/pegtl/modulus_match.cpp similarity index 94% rename from src/example/pegtl/modulus_match.cc rename to src/example/pegtl/modulus_match.cpp index 2ebf1c790..992da400c 100644 --- a/src/example/pegtl/modulus_match.cc +++ b/src/example/pegtl/modulus_match.cpp @@ -19,7 +19,7 @@ namespace modulus { if( !in.empty() ) { if( ( ( *in.current() ) % M ) == R ) { - in.bump( 1 ); + in.template consume< eol_exclude_tag >( 1 ); return true; } } diff --git a/src/example/pegtl/proto3.cc b/src/example/pegtl/proto3.cpp similarity index 86% rename from src/example/pegtl/proto3.cc rename to src/example/pegtl/proto3.cpp index 5352fe126..58a99f5c0 100644 --- a/src/example/pegtl/proto3.cc +++ b/src/example/pegtl/proto3.cpp @@ -14,7 +14,7 @@ int main() #include #include -#include +#include #include "proto3.hpp" @@ -27,11 +27,11 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) } for( int i = 1; i < argc; ++i ) { - file_input in( argv[ i ] ); + text_file_input< ascii::lf_crlf > in( argv[ i ] ); try { parse< proto3::proto >( in ); } - catch( const parse_error& e ) { + catch( const parse_error< text_position >& e ) { const auto& p = e.position_object(); std::cerr << e.what() << '\n' << line_view_at( in, p ) << '\n' diff --git a/src/example/pegtl/random_order.cc b/src/example/pegtl/random_order.cpp similarity index 100% rename from src/example/pegtl/random_order.cc rename to src/example/pegtl/random_order.cpp diff --git a/src/example/pegtl/recover.cc b/src/example/pegtl/recover.cpp similarity index 100% rename from src/example/pegtl/recover.cc rename to src/example/pegtl/recover.cpp diff --git a/src/example/pegtl/s_expression.cc b/src/example/pegtl/s_expression.cpp similarity index 85% rename from src/example/pegtl/s_expression.cc rename to src/example/pegtl/s_expression.cpp index 688525fb1..508feb5d6 100644 --- a/src/example/pegtl/s_expression.cc +++ b/src/example/pegtl/s_expression.cpp @@ -15,7 +15,7 @@ int main() #include #include -#include +#include namespace sexpr { @@ -75,7 +75,7 @@ namespace sexpr // last string literal that we use as filename here, and // the input is passed on for chained error messages (as // in "error in line x file foo included from file bar...) - pegtl::file_input i2( fn ); + pegtl::text_file_input_with_source< pegtl::ascii::lf_crlf > i2( fn ); pegtl::parse_nested< main, sexpr::action >( in, i2, f2 ); } }; @@ -93,11 +93,13 @@ 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& e ) { + catch( const TAO_PEGTL_NAMESPACE::parse_error< TAO_PEGTL_NAMESPACE::count_position >& e ) { const auto& p = e.position_object(); - std::cerr << e.what() << '\n' - << line_view_at( in, p ) << '\n' - << std::setw( int( p.column ) ) << '^' << '\n'; + std::cerr << e.what() << " @ " << p << std::endl; + } + catch( const TAO_PEGTL_NAMESPACE::parse_error< TAO_PEGTL_NAMESPACE::text_position_with_path >& e ) { + const auto& p = e.position_object(); + std::cerr << e.what() << " @ " << p << std::endl; } } return 0; diff --git a/src/example/pegtl/sum.cc b/src/example/pegtl/sum.cpp similarity index 96% rename from src/example/pegtl/sum.cc rename to src/example/pegtl/sum.cpp index d632e5a6e..9d0099067 100644 --- a/src/example/pegtl/sum.cc +++ b/src/example/pegtl/sum.cpp @@ -60,7 +60,7 @@ int main() break; } double d = 0.0; - memory_input in( str, "std::cin" ); + view_input_with_source< char > in( "std::cin", str ); if( parse< sum::grammar, sum::action >( in, d ) ) { std::cout << "parsing OK; sum = " << d << std::endl; } diff --git a/src/example/pegtl/symbol_table.cc b/src/example/pegtl/symbol_table.cpp similarity index 97% rename from src/example/pegtl/symbol_table.cc rename to src/example/pegtl/symbol_table.cpp index 3b10a9813..f00fcd5fd 100644 --- a/src/example/pegtl/symbol_table.cc +++ b/src/example/pegtl/symbol_table.cpp @@ -106,7 +106,7 @@ namespace example int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) { for( int i = 1; i < argc; ++i ) { - pegtl::file_input in( argv[ i ] ); + pegtl::text_file_input< pegtl::ascii::lf_crlf > in( argv[ i ] ); example::state st; pegtl::parse< example::grammar, example::action >( in, st ); for( const auto& j : st.symbol_table ) { diff --git a/src/example/pegtl/temporary.cc b/src/example/pegtl/temporary.cc deleted file mode 100644 index 009891984..000000000 --- a/src/example/pegtl/temporary.cc +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int main() -{ - return 0; -} diff --git a/src/example/pegtl/token_input.cpp b/src/example/pegtl/token_input.cpp index a9f674cff..51fb4749a 100644 --- a/src/example/pegtl/token_input.cpp +++ b/src/example/pegtl/token_input.cpp @@ -30,7 +30,7 @@ namespace TAO_PEGTL_NAMESPACE static bool match( ParseInput& in ) { if( ( !in.empty() ) && ( in.current()->type == Value ) ) { - in.template consume< internal::eol_exclude_tag >( 1 ); + in.template consume< eol_exclude_tag >( 1 ); return true; } return false; diff --git a/src/example/pegtl/unescape.cc b/src/example/pegtl/unescape.cpp similarity index 98% rename from src/example/pegtl/unescape.cc rename to src/example/pegtl/unescape.cpp index 7ae3b96e8..ce3deb23f 100644 --- a/src/example/pegtl/unescape.cc +++ b/src/example/pegtl/unescape.cpp @@ -52,7 +52,7 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) { for( int i = 1; i < argc; ++i ) { std::string s; - argv_input in( argv, i ); + argv_input_with_source in( argv, i ); if( parse< example::padded, example::action >( in, s ) ) { std::cout << "argv[ " << i << " ] = " << s << std::endl; } diff --git a/src/example/pegtl/uri.cc b/src/example/pegtl/uri.cpp similarity index 92% rename from src/example/pegtl/uri.cc rename to src/example/pegtl/uri.cpp index 6704d5415..d05369316 100644 --- a/src/example/pegtl/uri.cc +++ b/src/example/pegtl/uri.cpp @@ -30,7 +30,7 @@ struct URI std::string query; std::string fragment; - explicit URI( const std::string& uri ); + explicit URI( pegtl::argv_input_with_source& ); }; namespace uri @@ -75,11 +75,10 @@ namespace uri } // namespace uri -URI::URI( const std::string& uri ) +URI::URI( pegtl::argv_input_with_source& in ) { using grammar = pegtl::must< pegtl::uri::URI >; - pegtl::memory_input input( uri, "uri" ); - pegtl::parse< grammar, uri::action >( input, *this ); + pegtl::parse< grammar, uri::action >( in, *this ); } int main( int argc, char** argv ) @@ -87,7 +86,8 @@ int main( int argc, char** argv ) try { for( int i = 1; i < argc; ++i ) { std::cout << "Parsing " << argv[ i ] << std::endl; - const URI uri( argv[ i ] ); + pegtl::argv_input_with_source in( argv, i ); + const URI uri( in ); std::cout << "URI.scheme: " << uri.scheme << std::endl; std::cout << "URI.authority: " << uri.authority << std::endl; std::cout << "URI.userinfo: " << uri.userinfo << std::endl; diff --git a/src/example/pegtl/uri_print_debug.cc b/src/example/pegtl/uri_print_debug.cpp similarity index 93% rename from src/example/pegtl/uri_print_debug.cc rename to src/example/pegtl/uri_print_debug.cpp index f71c8c0f3..39aa7e2cb 100644 --- a/src/example/pegtl/uri_print_debug.cc +++ b/src/example/pegtl/uri_print_debug.cpp @@ -13,7 +13,7 @@ int main() #include -#include +#include #include int main() // NOLINT(bugprone-exception-escape) diff --git a/src/example/pegtl/uri_print_names.cc b/src/example/pegtl/uri_print_names.cpp similarity index 93% rename from src/example/pegtl/uri_print_names.cc rename to src/example/pegtl/uri_print_names.cpp index 1e766fdbd..e8ff220f0 100644 --- a/src/example/pegtl/uri_print_names.cc +++ b/src/example/pegtl/uri_print_names.cpp @@ -13,7 +13,7 @@ int main() #include -#include +#include #include int main() // NOLINT(bugprone-exception-escape) diff --git a/src/test/pegtl/check_bytes.cc b/src/test/pegtl/contrib_check_count.cpp similarity index 76% rename from src/test/pegtl/check_bytes.cc rename to src/test/pegtl/contrib_check_count.cpp index 32ac3a42b..a4ebdad40 100644 --- a/src/test/pegtl/check_bytes.cc +++ b/src/test/pegtl/contrib_check_count.cpp @@ -2,9 +2,10 @@ // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) -#include - #include "test.hpp" +#include "test_inputs.hpp" + +#include namespace TAO_PEGTL_NAMESPACE { @@ -23,25 +24,25 @@ namespace TAO_PEGTL_NAMESPACE template<> struct test_action< test_rule > - : check_bytes< 5 > + : check_count< 5 > {}; void unit_test() { - memory_input<> i1( __FUNCTION__, "aaa" ); + test::text_input< ascii::lf > i1( "aaa" ); const auto r1 = parse< test_grammar >( i1 ); TAO_PEGTL_TEST_ASSERT( r1 ); - memory_input<> i2( __FUNCTION__, "aaaaaaaaaaa" ); + test::text_input< ascii::lf > i2( "aaaaaaaaaaa" ); const auto r2 = parse< test_grammar >( i2 ); TAO_PEGTL_TEST_ASSERT( r2 ); - memory_input<> i3( __FUNCTION__, "aaa" ); + test::text_input< ascii::lf > i3( "aaa" ); const auto r3 = parse< test_grammar, test_action >( i3 ); TAO_PEGTL_TEST_ASSERT( r3 ); #if defined( __cpp_exceptions ) - memory_input<> i4( __FUNCTION__, "aaaaaaaaaaa" ); + test::text_input< ascii::lf > i4( "aaaaaaaaaaa" ); TAO_PEGTL_TEST_THROWS( parse< test_grammar, test_action >( i4 ) ); #endif } diff --git a/src/test/pegtl/contrib_limit_depth.cc b/src/test/pegtl/contrib_check_depth.cpp similarity index 73% rename from src/test/pegtl/contrib_limit_depth.cc rename to src/test/pegtl/contrib_check_depth.cpp index b32055ccc..ae7dd809f 100644 --- a/src/test/pegtl/contrib_limit_depth.cc +++ b/src/test/pegtl/contrib_check_depth.cpp @@ -2,10 +2,11 @@ // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) -#include -#include - #include "test.hpp" +#include "test_inputs.hpp" + +#include +#include namespace TAO_PEGTL_NAMESPACE { @@ -24,27 +25,27 @@ namespace TAO_PEGTL_NAMESPACE template<> struct test_action< test_recursive > - : limit_depth< 5 > + : check_depth< 5 > {}; void unit_test() { - using memory_input_with_depth = input_with_depth< memory_input<> >; + using memory_input_with_depth = input_with_depth< test::text_input< ascii::lf > >; - memory_input_with_depth i1( "aaa", __FUNCTION__ ); + memory_input_with_depth i1( "aaa" ); const auto r1 = parse< test_grammar >( i1 ); TAO_PEGTL_TEST_ASSERT( r1 ); - memory_input_with_depth i2( "aaaaaaaaaaa", __FUNCTION__ ); + memory_input_with_depth i2( "aaaaaaaaaaa" ); const auto r2 = parse< test_grammar >( i2 ); TAO_PEGTL_TEST_ASSERT( r2 ); - memory_input_with_depth i3( "aaa", __FUNCTION__ ); + memory_input_with_depth i3( "aaa" ); const auto r3 = parse< test_grammar, test_action >( i3 ); TAO_PEGTL_TEST_ASSERT( r3 ); #if defined( __cpp_exceptions ) - memory_input_with_depth i4( "aaaaaaaaaaa", __FUNCTION__ ); + memory_input_with_depth i4( "aaaaaaaaaaa" ); TAO_PEGTL_TEST_THROWS( parse< test_grammar, test_action >( i4 ) ); #endif } diff --git a/src/test/pegtl/contrib_if_then.cc b/src/test/pegtl/contrib_if_then.cpp similarity index 100% rename from src/test/pegtl/contrib_if_then.cc rename to src/test/pegtl/contrib_if_then.cpp diff --git a/src/test/pegtl/limit_bytes.cc b/src/test/pegtl/contrib_limit_count.cpp similarity index 72% rename from src/test/pegtl/limit_bytes.cc rename to src/test/pegtl/contrib_limit_count.cpp index 880ba361f..687328d48 100644 --- a/src/test/pegtl/limit_bytes.cc +++ b/src/test/pegtl/contrib_limit_count.cpp @@ -2,9 +2,10 @@ // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) -#include - #include "test.hpp" +#include "test_inputs.hpp" + +#include namespace TAO_PEGTL_NAMESPACE { @@ -23,25 +24,27 @@ namespace TAO_PEGTL_NAMESPACE template<> struct test_action< test_rule > - : limit_bytes< 5 > + : limit_count< 5 > {}; void unit_test() { - memory_input<> i1( __FUNCTION__, "aaa" ); + using test_input = internal::input_with_fakes< internal::input_with_peeks< internal::input_with_start< internal::view_input< char > > > >; + + test_input i1( "aaa" ); const auto r1 = parse< test_grammar >( i1 ); TAO_PEGTL_TEST_ASSERT( r1 ); - memory_input<> i2( __FUNCTION__, "aaaaaaaaaaa" ); + test_input i2( "aaaaaaaaaaa" ); const auto r2 = parse< test_grammar >( i2 ); TAO_PEGTL_TEST_ASSERT( r2 ); - memory_input<> i3( __FUNCTION__, "aaa" ); + test_input i3( "aaa" ); const auto r3 = parse< test_grammar, test_action >( i3 ); TAO_PEGTL_TEST_ASSERT( r3 ); #if defined( __cpp_exceptions ) - memory_input<> i4( __FUNCTION__, "aaaaaaaaaaa" ); + test_input i4( "aaaaaaaaaaa" ); TAO_PEGTL_TEST_THROWS( parse< test_grammar, test_action >( i4 ) ); #endif } diff --git a/src/test/pegtl/error_message_1.cpp b/src/test/pegtl/error_message_1.cpp index 649d7f33f..75d24b160 100644 --- a/src/test/pegtl/error_message_1.cpp +++ b/src/test/pegtl/error_message_1.cpp @@ -42,7 +42,7 @@ namespace TAO_PEGTL_NAMESPACE void unit_test() { try { - parse< test1::grammar, nothing, test1::control >( test::text_input< ascii::lf >( "c", __FUNCTION__ ) ); + parse< test1::grammar, nothing, test1::control >( test::text_input< ascii::lf >( "c" ) ); TAO_PEGTL_TEST_UNREACHABLE; // LCOV_EXCL_LINE } catch( const parse_error_base& e ) { diff --git a/src/test/pegtl/error_message_2.cpp b/src/test/pegtl/error_message_2.cpp index 280899eb1..116905a85 100644 --- a/src/test/pegtl/error_message_2.cpp +++ b/src/test/pegtl/error_message_2.cpp @@ -30,7 +30,7 @@ namespace TAO_PEGTL_NAMESPACE void unit_test() { try { - parse< test2::grammar >( test::text_input< ascii::lf >( "c", __FUNCTION__ ) ); + parse< test2::grammar >( test::text_input< ascii::lf >( "c" ) ); TAO_PEGTL_TEST_UNREACHABLE; // LCOV_EXCL_LINE } catch( const parse_error_base& e ) { diff --git a/src/test/pegtl/error_message_3.cpp b/src/test/pegtl/error_message_3.cpp index 9e734855a..44fdb471b 100644 --- a/src/test/pegtl/error_message_3.cpp +++ b/src/test/pegtl/error_message_3.cpp @@ -34,7 +34,7 @@ namespace TAO_PEGTL_NAMESPACE void unit_test() { try { - parse< test3::grammar >( test::text_input< ascii::lf >( "c", __FUNCTION__ ) ); + parse< test3::grammar >( test::text_input< ascii::lf >( "c" ) ); TAO_PEGTL_TEST_UNREACHABLE; // LCOV_EXCL_LINE } catch( const parse_error_base& e ) { diff --git a/src/test/pegtl/internal_base_inputs.cpp b/src/test/pegtl/internal_base_inputs.cpp index 3653203d2..0b145baf7 100644 --- a/src/test/pegtl/internal_base_inputs.cpp +++ b/src/test/pegtl/internal_base_inputs.cpp @@ -223,13 +223,13 @@ namespace TAO_PEGTL_NAMESPACE void test_01_start() { { - internal::input_with_start< char > in( data_01 ); + internal::input_with_start< internal::view_input< char > > in( data_01 ); test_01( in ); } { - internal::input_with_start< char > in( data_01 ); + internal::input_with_start< internal::view_input< char > > in( data_01 ); test_01_view( in ); } { - internal::input_with_start< char > in( data_01 ); + internal::input_with_start< internal::view_input< char > > in( data_01 ); test_01_copy( in ); } } diff --git a/src/test/pegtl/rule_function.cpp b/src/test/pegtl/rule_function.cpp index f1749e19e..68ae853d3 100644 --- a/src/test/pegtl/rule_function.cpp +++ b/src/test/pegtl/rule_function.cpp @@ -26,28 +26,28 @@ namespace TAO_PEGTL_NAMESPACE [[nodiscard]] bool func0( test::text_input< ascii::lf >& in ) { called = true; - in.consume< internal::eol_exclude_tag >( 1 ); + in.consume< eol_exclude_tag >( 1 ); return true; } [[nodiscard]] bool func0n( test::text_input< ascii::lf >& in ) noexcept { called = true; - in.consume< internal::eol_exclude_tag >( 1 ); + in.consume< eol_exclude_tag >( 1 ); return true; } [[nodiscard]] bool func1( test::text_input< ascii::lf >& in, int /*unused*/, char*& /*unused*/, const double& /*unused*/ ) { called = true; - in.consume< internal::eol_exclude_tag >( 1 ); + in.consume< eol_exclude_tag >( 1 ); return true; } [[nodiscard]] bool func1n( test::text_input< ascii::lf >& in, int /*unused*/, char*& /*unused*/, const double& /*unused*/ ) noexcept { called = true; - in.consume< internal::eol_exclude_tag >( 1 ); + in.consume< eol_exclude_tag >( 1 ); return true; } diff --git a/src/test/pegtl/test_inputs.hpp b/src/test/pegtl/test_inputs.hpp index 24cb91505..ad9dfe770 100644 --- a/src/test/pegtl/test_inputs.hpp +++ b/src/test/pegtl/test_inputs.hpp @@ -13,7 +13,7 @@ namespace TAO_PEGTL_NAMESPACE::test { template< typename Eol > - using lazy_input = internal::input_with_peeks< internal::lazy_input< Eol, internal::input_with_fakes< internal::input_with_start< char > > > >; + using lazy_input = internal::input_with_peeks< internal::lazy_input< Eol, internal::input_with_fakes< internal::input_with_start< internal::view_input< char > > > > >; template< typename Eol > using text_input = internal::input_with_peeks< internal::text_input< Eol, internal::input_with_fakes< internal::view_input< char > > > >;