diff --git a/Makefile b/Makefile
index ac9430683..b2334e6b6 100644
--- a/Makefile
+++ b/Makefile
@@ -37,10 +37,10 @@ CXXFLAGS ?= -Wall -Wextra -Wshadow -Werror -O3 $(MINGW_CXXFLAGS)
HEADERS := $(shell find include -name '*.hpp')
SOURCES := $(shell find src -name '*.cpp')
-DEPENDS := $(SOURCES:%.cpp=build/%.d)
-BINARIES := $(SOURCES:%.cpp=build/%)
+DEPENDS := $(SOURCES:src/%.cpp=build/dep/%.d)
+BINARIES := $(SOURCES:src/%.cpp=build/bin/%)
-UNIT_TESTS := $(filter build/src/test/%,$(BINARIES))
+UNIT_TESTS := $(filter build/bin/test/%,$(BINARIES))
.PHONY: all
all: compile check
@@ -57,11 +57,12 @@ clean:
@rm -rf build/*
@find . -name '*~' -delete
-build/%.d: %.cpp Makefile
+build/dep/%.d: src/%.cpp Makefile
@mkdir -p $(@D)
$(CXX) $(CXXSTD) -Iinclude $(CPPFLAGS) -MM -MQ $@ $< -o $@
-build/%: %.cpp build/%.d
+build/bin/%: src/%.cpp build/dep/%.d
+ @mkdir -p $(@D)
$(CXX) $(CXXSTD) -Iinclude $(CPPFLAGS) $(CXXFLAGS) $< $(LDFLAGS) -o $@
ifeq ($(findstring $(MAKECMDGOALS),clean),)
diff --git a/doc/Changelog.md b/doc/Changelog.md
index edbb8063a..da878399b 100644
--- a/doc/Changelog.md
+++ b/doc/Changelog.md
@@ -9,6 +9,7 @@
* Added [control function](Control-and-Debug.md) to throw nested exceptions.
* Changed `parse_error` to contain only one `position`, and:
* Changed to **nested exceptions** for nested [parsing errors](Errors-and-Exceptions.md).
+* Removed `action_t` type alias from all input classes in favour of using `internal::action_input`.
* Added functions to visit and flatten [nested exceptions](Contrib-and-Examples.md#taopegtlcontribnested_exceptionshpp).
* Added new customization point for error messages.
* Added optional source line output for the tracer.
@@ -32,6 +33,9 @@
* Moved `line_at()` from input member function to global function `line_view_at()`.
* Moved `begin_of_line()` from input member function to global function of same name.
* 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/`.
+* 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.
* Removed support for Visual Studio 2017.
diff --git a/doc/Rule-Reference.md b/doc/Rule-Reference.md
index d0191ff26..485a387b1 100644
--- a/doc/Rule-Reference.md
+++ b/doc/Rule-Reference.md
@@ -651,9 +651,10 @@ Atomic rules do not rely on other rules.
###### `bof`
-* Succeeds at "beginning-of-file", i.e. when the input's `byte()` member function returns zero.
+* Succeeds at "beginning-of-file", i.e. when the input is at its start.
* Does not consume input.
-* Does **not** work with inputs that don't have a `byte()` member function.
+* Requires an input `in` with the `in.start()` member function, and/or
+* requires an input `in` where `in`direct_position()` has a `count` member.
* [Meta data] and [implementation] mapping:
- `bof::rule_t` is `internal::bof`
@@ -661,18 +662,11 @@ Atomic rules do not rely on other rules.
* Succeeds at "beginning-of-line", i.e. when the input's `column()` member function returns one.
* Does not consume input.
-* Does **not** work with inputs that don't have a `column()` member function.
+* Requires an input with eager text position tracking, more precisely:
+* Requires an input `in` where `in.direct_position().column` is available.
* [Meta data] and [implementation] mapping:
- `bol::rule_t` is `internal::bol`
-###### `bytes< Num >`
-
-* Succeeds when the input contains at least `Num` further bytes.
-* Consumes these `Num` bytes from the input.
-* [Meta data] and [implementation] mapping:
- - `bytes< 0 >::rule_t` is `internal::success`
- - `bytes< Num >::rule_t` is `internal::bytes< Num >`
-
###### `eof`
* Succeeds at "end-of-file", i.e. when the input is empty or all input has been consumed.
@@ -874,6 +868,15 @@ ASCII rules do not usually rely on other rules.
* Matches and consumes a single ASCII lower-case alphabetic character.
* [Equivalent] to `range< 'a', 'z' >`.
+###### `many< Num >`
+
+* Succeeds when the input contains at least `Num` further bytes.
+* Consumes these `Num` bytes from the input.
+* [Equivalent] to `rep< N, any >`.
+* [Meta data] and [implementation] mapping:
+ - `many< 0 >::rule_t` is `internal::success`
+ - `many< Num >::rule_t` is `internal::many< Num, internal::peek_char >`
+
###### `not_one< C... >`
* Succeeds when the input is not empty, and:
@@ -1068,6 +1071,12 @@ Unicode rules do not rely on other rules.
* [Equivalent] to `one< 0xfeff >`.
+###### `many< Num >`
+
+* Succeeds when the input contains at least `Num` further code points.
+* Consumes these `Num` code points from the input.
+* [Equivalent] to `rep< N, any >`.
+
###### `not_one< C... >`
* Succeeds when the input is not empty, and:
@@ -1475,6 +1484,12 @@ Binary rules do not rely on other rules.
* Succeeds when the input contains at least N bytes.
* Consumes N bytes when it succeeds.
+###### `many< Num >`
+
+* Succeeds when the input contains at least `Num` times N bytes.
+* Consumes these `Num` * N bytes from the input.
+* [Equivalent] to `rep< N, any >`.
+
###### `mask_not_one< M, C... >`
* Succeeds when the input contains at least N bytes, and:
@@ -1570,7 +1585,6 @@ Binary rules do not rely on other rules.
* [`bof`](#bof) [(atomic rules)](#atomic-rules)
* [`bol`](#bol) [(atomic rules)](#atomic-rules)
* [`bom`](#bom) [(unicode rules)](#unicode-rules)
-* [`bytes< Num >`](#bytes-num-) [(atomic rules)](#atomic-rules)
* [`canonical_combining_class< V >`](#canonical_combining_class-v-) [(icu rules)](#icu-rules-for-value-properties)
* [`case_sensitive`](#case_sensitive) [(icu rules)](#icu-rules-for-binary-properties)
* [`cntrl`](#cntrl) [(ascii rules)](#ascii-rules)
@@ -1636,6 +1650,9 @@ Binary rules do not rely on other rules.
* [`logical_order_exception`](#logical_order_exception) [(icu rules)](#icu-rules-for-binary-properties)
* [`lower`](#lower) [(ascii rules)](#ascii-rules)
* [`lowercase`](#lowercase) [(icu rules)](#icu-rules-for-binary-properties)
+* [`many< Num >`](#many-num-) [(ascii rules)](#ascii-rules)
+* [`many< Num >`](#many-num--1) [(unicode rules)](#unicode-rules)
+* [`many< Num >`](#many-num--2) [(binary rules)](#binary-rules)
* [`mask_not_one< M, C... >`](#mask_not_one-m-c-) [(binary rules)](#binary-rules)
* [`mask_not_range< M, C, D >`](#mask_not_range-m-c-d-) [(binary rules)](#binary-rules)
* [`mask_one< M, C... >`](#mask_one-m-c-) [(binary rules)](#binary-rules)
diff --git a/include/tao/pegtl.hpp b/include/tao/pegtl.hpp
index f8f1969c0..3d02e5419 100644
--- a/include/tao/pegtl.hpp
+++ b/include/tao/pegtl.hpp
@@ -5,46 +5,39 @@
#ifndef TAO_PEGTL_HPP
#define TAO_PEGTL_HPP
+#include "pegtl/ascii.hpp"
#include "pegtl/config.hpp"
-
#include "pegtl/demangle.hpp"
-#include "pegtl/parse.hpp"
-#include "pegtl/version.hpp"
-
-#include "pegtl/ascii.hpp"
#include "pegtl/eol.hpp"
+#include "pegtl/forward.hpp"
+#include "pegtl/inputs.hpp"
+#include "pegtl/parse.hpp"
+#include "pegtl/print.hpp"
#include "pegtl/rules.hpp"
#include "pegtl/utf8.hpp"
+#include "pegtl/version.hpp"
+#include "pegtl/visit.hpp"
-#include "pegtl/argv_input.hpp"
-#include "pegtl/buffer_input.hpp"
-#include "pegtl/cstream_input.hpp"
-#include "pegtl/file_input.hpp"
-#include "pegtl/istream_input.hpp"
-#include "pegtl/memory_input.hpp"
-#include "pegtl/read_input.hpp"
-#include "pegtl/string_input.hpp"
-
-#include "pegtl/line_view_at.hpp"
-
+#include "pegtl/add_guard.hpp"
+#include "pegtl/add_state.hpp"
#include "pegtl/change_action.hpp"
#include "pegtl/change_action_and_state.hpp"
#include "pegtl/change_action_and_states.hpp"
#include "pegtl/change_control.hpp"
#include "pegtl/change_state.hpp"
#include "pegtl/change_states.hpp"
-
+#include "pegtl/control_action.hpp"
#include "pegtl/disable_action.hpp"
#include "pegtl/enable_action.hpp"
-
-#include "pegtl/discard_input.hpp"
-#include "pegtl/discard_input_on_failure.hpp"
-#include "pegtl/discard_input_on_success.hpp"
-
-#include "pegtl/visit.hpp"
+#include "pegtl/remove_first_state.hpp"
+#include "pegtl/remove_last_states.hpp"
#if defined( __cpp_exceptions )
#include "pegtl/must_if.hpp"
+#include "pegtl/parse_error.hpp"
+#include "pegtl/parse_error_base.hpp"
#endif
+#include "pegtl/line_view_at.hpp"
+
#endif
diff --git a/include/tao/pegtl/contrib/instantiate.hpp b/include/tao/pegtl/add_guard.hpp
similarity index 70%
rename from include/tao/pegtl/contrib/instantiate.hpp
rename to include/tao/pegtl/add_guard.hpp
index 61ac3a623..00b3cd798 100644
--- a/include/tao/pegtl/contrib/instantiate.hpp
+++ b/include/tao/pegtl/add_guard.hpp
@@ -2,19 +2,19 @@
// 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_INSTANTIATE_HPP
-#define TAO_PEGTL_CONTRIB_INSTANTIATE_HPP
+#ifndef TAO_PEGTL_ADD_GUARD_HPP
+#define TAO_PEGTL_ADD_GUARD_HPP
-#include "../apply_mode.hpp"
-#include "../config.hpp"
-#include "../match.hpp"
-#include "../nothing.hpp"
-#include "../rewind_mode.hpp"
+#include "apply_mode.hpp"
+#include "config.hpp"
+#include "match.hpp"
+#include "nothing.hpp"
+#include "rewind_mode.hpp"
namespace TAO_PEGTL_NAMESPACE
{
- template< typename T >
- struct instantiate
+ template< typename AddGuard >
+ struct add_guard
: maybe_nothing
{
template< typename Rule,
@@ -28,7 +28,7 @@ namespace TAO_PEGTL_NAMESPACE
typename... States >
[[nodiscard]] static bool match( ParseInput& in, States&&... st )
{
- const T t( static_cast< const ParseInput& >( in ), st... );
+ const AddGuard guard( static_cast< const ParseInput& >( in ), st... );
return TAO_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, st... );
}
};
diff --git a/include/tao/pegtl/contrib/add_state.hpp b/include/tao/pegtl/add_state.hpp
similarity index 89%
rename from include/tao/pegtl/contrib/add_state.hpp
rename to include/tao/pegtl/add_state.hpp
index f7e2c0635..f3814bf28 100644
--- a/include/tao/pegtl/contrib/add_state.hpp
+++ b/include/tao/pegtl/add_state.hpp
@@ -2,18 +2,18 @@
// 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_ADD_STATE_HPP
-#define TAO_PEGTL_CONTRIB_ADD_STATE_HPP
+#ifndef TAO_PEGTL_ADD_STATE_HPP
+#define TAO_PEGTL_ADD_STATE_HPP
#include
-#include "../apply_mode.hpp"
-#include "../config.hpp"
-#include "../match.hpp"
-#include "../nothing.hpp"
-#include "../rewind_mode.hpp"
+#include "apply_mode.hpp"
+#include "config.hpp"
+#include "match.hpp"
+#include "nothing.hpp"
+#include "rewind_mode.hpp"
-#include "../internal/dependent_false.hpp"
+#include "internal/dependent_false.hpp"
namespace TAO_PEGTL_NAMESPACE
{
diff --git a/include/tao/pegtl/contrib/analyze.hpp b/include/tao/pegtl/analyze.hpp
similarity index 97%
rename from include/tao/pegtl/contrib/analyze.hpp
rename to include/tao/pegtl/analyze.hpp
index 3d4b7f139..6f7802b3d 100644
--- a/include/tao/pegtl/contrib/analyze.hpp
+++ b/include/tao/pegtl/analyze.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_ANALYZE_HPP
-#define TAO_PEGTL_CONTRIB_ANALYZE_HPP
+#ifndef TAO_PEGTL_ANALYZE_HPP
+#define TAO_PEGTL_ANALYZE_HPP
#include
#include
@@ -15,8 +15,8 @@
#include
#include
-#include "../config.hpp"
-#include "../demangle.hpp"
+#include "config.hpp"
+#include "demangle.hpp"
#include "analyze_traits.hpp"
diff --git a/include/tao/pegtl/contrib/analyze_traits.hpp b/include/tao/pegtl/analyze_traits.hpp
similarity index 93%
rename from include/tao/pegtl/contrib/analyze_traits.hpp
rename to include/tao/pegtl/analyze_traits.hpp
index e720f0d2c..236edf2f4 100644
--- a/include/tao/pegtl/contrib/analyze_traits.hpp
+++ b/include/tao/pegtl/analyze_traits.hpp
@@ -2,17 +2,16 @@
// 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_ANALYZE_TRAITS_HPP
-#define TAO_PEGTL_CONTRIB_ANALYZE_TRAITS_HPP
+#ifndef TAO_PEGTL_ANALYZE_TRAITS_HPP
+#define TAO_PEGTL_ANALYZE_TRAITS_HPP
#include
-#include "../ascii.hpp"
-#include "../config.hpp"
-#include "../rules.hpp"
-#include "../type_list.hpp"
-
+#include "ascii.hpp"
+#include "config.hpp"
#include "forward.hpp"
+#include "rules.hpp"
+#include "type_list.hpp"
namespace TAO_PEGTL_NAMESPACE
{
@@ -91,11 +90,6 @@ namespace TAO_PEGTL_NAMESPACE
: analyze_opt_traits<>
{};
- template< typename Name, unsigned Cnt >
- struct analyze_traits< Name, internal::bytes< Cnt > >
- : std::conditional_t< ( Cnt != 0 ), analyze_any_traits<>, analyze_opt_traits<> >
- {};
-
template< typename Name, template< typename... > class Control, typename... Rules >
struct analyze_traits< Name, internal::control< Control, Rules... > >
: analyze_traits< Name, typename seq< Rules... >::rule_t >
@@ -106,11 +100,6 @@ namespace TAO_PEGTL_NAMESPACE
: analyze_traits< Name, typename seq< Rules... >::rule_t >
{};
- template< typename Name >
- struct analyze_traits< Name, internal::discard >
- : analyze_opt_traits<>
- {};
-
template< typename Name, typename... Rules >
struct analyze_traits< Name, internal::enable< Rules... > >
: analyze_traits< Name, typename seq< Rules... >::rule_t >
@@ -156,6 +145,11 @@ namespace TAO_PEGTL_NAMESPACE
: std::conditional_t< ( sizeof...( Cs ) != 0 ), analyze_any_traits<>, analyze_opt_traits<> >
{};
+ template< typename Name, unsigned Count, typename Peek >
+ struct analyze_traits< Name, internal::many< Count, Peek > >
+ : std::conditional_t< ( Count != 0 ), analyze_any_traits<>, analyze_opt_traits<> >
+ {};
+
template< typename Name, typename... Rules >
struct analyze_traits< Name, internal::not_at< Rules... > >
: analyze_traits< Name, typename opt< Rules... >::rule_t >
@@ -211,11 +205,6 @@ namespace TAO_PEGTL_NAMESPACE
: analyze_traits< Name, typename opt< Rules... >::rule_t >
{};
- template< typename Name, unsigned Amount >
- struct analyze_traits< Name, internal::require< Amount > >
- : analyze_opt_traits<>
- {};
-
template< typename Name, typename Rule, typename... Rules >
struct analyze_traits< Name, internal::seq< Rule, Rules... > >
: analyze_seq_traits< Rule, Rules... >
diff --git a/include/tao/pegtl/argv_input.hpp b/include/tao/pegtl/argv_input.hpp
deleted file mode 100644
index b94ec5273..000000000
--- a/include/tao/pegtl/argv_input.hpp
+++ /dev/null
@@ -1,50 +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)
-
-#ifndef TAO_PEGTL_ARGV_INPUT_HPP
-#define TAO_PEGTL_ARGV_INPUT_HPP
-
-#include
-#include
-#include
-#include
-
-#include "config.hpp"
-#include "eol.hpp"
-#include "memory_input.hpp"
-#include "tracking_mode.hpp"
-
-namespace TAO_PEGTL_NAMESPACE
-{
- namespace internal
- {
- [[nodiscard]] inline std::string make_argv_source( const std::size_t argn )
- {
- std::ostringstream oss;
- oss << "argv[" << argn << ']';
- return std::move( oss ).str();
- }
-
- } // namespace internal
-
- template< tracking_mode P = tracking_mode::eager, typename Eol = ascii::lf_crlf >
- struct argv_input
- : memory_input< P, Eol >
- {
- template< typename T >
- argv_input( char** argv, const std::size_t argn, T&& in_source )
- : memory_input< P, Eol >( static_cast< const char* >( argv[ argn ] ), std::forward< T >( in_source ) )
- {}
-
- argv_input( char** argv, const std::size_t argn )
- : argv_input( argv, argn, internal::make_argv_source( argn ) )
- {}
- };
-
- template< typename... Ts >
- argv_input( Ts&&... ) -> argv_input<>;
-
-} // namespace TAO_PEGTL_NAMESPACE
-
-#endif
diff --git a/include/tao/pegtl/ascii.hpp b/include/tao/pegtl/ascii.hpp
index ed4416ad1..56473ae89 100644
--- a/include/tao/pegtl/ascii.hpp
+++ b/include/tao/pegtl/ascii.hpp
@@ -7,6 +7,7 @@
#include "config.hpp"
+#include "internal/peek_direct.hpp"
#include "internal/result_on_found.hpp"
#include "internal/rules.hpp"
@@ -33,6 +34,7 @@ namespace TAO_PEGTL_NAMESPACE
template< char... Cs > struct istring : internal::istring< Cs... > {};
template< char... Cs > struct keyword : internal::seq< internal::string< Cs... >, internal::not_at< internal::identifier_other > > { static_assert( sizeof...( Cs ) > 0 ); };
struct lower : internal::range< internal::result_on_found::success, internal::peek_char, 'a', 'z' > {};
+ template< unsigned Count > struct many : internal::many< Count, internal::peek_char > {};
template< char... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_char, Cs... > {};
template< char Lo, char Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_char, Lo, Hi > {};
struct nul : internal::one< internal::result_on_found::success, internal::peek_char, static_cast< char >( 0 ) > {};
diff --git a/include/tao/pegtl/buffer_input.hpp b/include/tao/pegtl/buffer_input.hpp
deleted file mode 100644
index fd99b9960..000000000
--- a/include/tao/pegtl/buffer_input.hpp
+++ /dev/null
@@ -1,245 +0,0 @@
-// Copyright (c) 2016-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_BUFFER_INPUT_HPP
-#define TAO_PEGTL_BUFFER_INPUT_HPP
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#if defined( __cpp_exceptions )
-#include
-#else
-#include
-#include
-#endif
-
-#include "config.hpp"
-#include "eol.hpp"
-#include "memory_input.hpp"
-#include "position.hpp"
-#include "tracking_mode.hpp"
-
-#include "internal/action_input.hpp"
-#include "internal/bump.hpp"
-#include "internal/inputerator.hpp"
-#include "internal/rewind_guard.hpp"
-
-namespace TAO_PEGTL_NAMESPACE
-{
- template< typename Reader, typename Eol = ascii::lf_crlf, typename Source = std::string, std::size_t Chunk = 64 >
- class buffer_input
- {
- public:
- using data_t = char;
- using reader_t = Reader;
-
- using eol_rule = Eol;
- using source_t = Source;
-
- using rewind_position_t = internal::large_position;
-
- using action_t = internal::action_input< buffer_input >;
-
- static constexpr std::size_t chunk_size = Chunk;
- static constexpr tracking_mode tracking_mode_v = tracking_mode::eager;
-
- template< typename T, typename... As >
- buffer_input( T&& in_source, const std::size_t maximum, As&&... as )
- : m_reader( std::forward< As >( as )... ),
- m_maximum( maximum + Chunk ),
- m_buffer( new char[ maximum + Chunk ] ),
- m_current( m_buffer.get() ),
- m_end( m_buffer.get() ),
- m_source( std::forward< T >( in_source ) )
- {
- static_assert( Chunk != 0, "zero chunk size not implemented" );
- assert( m_maximum > maximum ); // Catches overflow; change to >= when zero chunk size is implemented.
- }
-
- buffer_input( const buffer_input& ) = delete;
- buffer_input( buffer_input&& ) = delete;
-
- ~buffer_input() = default;
-
- buffer_input& operator=( const buffer_input& ) = delete;
- buffer_input& operator=( buffer_input&& ) = delete;
-
- [[nodiscard]] bool empty()
- {
- require( 1 );
- return m_current.data == m_end;
- }
-
- [[nodiscard]] std::size_t size( const std::size_t amount )
- {
- require( amount );
- return buffer_occupied();
- }
-
- [[nodiscard]] const char* current() const noexcept
- {
- return m_current.data;
- }
-
- [[nodiscard]] const char* end( const std::size_t amount )
- {
- require( amount );
- return m_end;
- }
-
- [[nodiscard]] std::size_t byte() const noexcept
- {
- return m_current.byte;
- }
-
- [[nodiscard]] std::size_t line() const noexcept
- {
- return m_current.line;
- }
-
- [[nodiscard]] std::size_t column() const noexcept
- {
- return m_current.column;
- }
-
- [[nodiscard]] const Source& source() const noexcept
- {
- return m_source;
- }
-
- [[nodiscard]] char peek_char( const std::size_t offset = 0 ) const noexcept
- {
- return m_current.data[ offset ];
- }
-
- [[nodiscard]] std::uint8_t peek_uint8( const std::size_t offset = 0 ) const noexcept
- {
- return static_cast< std::uint8_t >( peek_char( offset ) );
- }
-
- void bump( const std::size_t in_count = 1 ) noexcept
- {
- internal::bump( m_current, in_count, '\n' );
- }
-
- void bump_in_this_line( const std::size_t in_count = 1 ) noexcept
- {
- internal::bump_in_this_line( m_current, in_count );
- }
-
- void bump_to_next_line( const std::size_t in_count = 1 ) noexcept
- {
- internal::bump_to_next_line( m_current, in_count );
- }
-
- void discard() noexcept
- {
- if( m_current.data > m_buffer.get() + Chunk ) {
- const auto s = m_end - m_current.data;
- std::memmove( m_buffer.get(), m_current.data, s );
- m_current.data = m_buffer.get();
- m_end = m_buffer.get() + s;
- }
- }
-
- void require( const std::size_t amount )
- {
- if( m_current.data + amount <= m_end ) {
- return;
- }
- if( m_current.data + amount > m_buffer.get() + m_maximum ) {
-#if defined( __cpp_exceptions )
- throw std::overflow_error( "require() beyond end of buffer" );
-#else
- std::fputs( "overflow error: require() beyond end of buffer\n", stderr );
- std::terminate();
-#endif
- }
- m_end += m_reader( m_end, ( std::min )( buffer_free_after_end(), ( std::max )( amount - buffer_occupied(), Chunk ) ) );
- }
-
- template< rewind_mode M >
- [[nodiscard]] internal::rewind_guard< M, buffer_input > make_rewind_guard() noexcept
- {
- return internal::rewind_guard< M, buffer_input >( this );
- }
-
- void rewind_position( const rewind_position_t& data ) noexcept
- {
- m_current = data;
- }
-
- [[nodiscard]] position current_position() const
- {
- return position( m_current );
- }
-
- [[nodiscard]] position previous_position( const rewind_position_t& it ) const
- {
- return position( it, m_source );
- }
-
- [[nodiscard]] const auto& rewind_position() const noexcept
- {
- return m_current;
- }
-
- [[nodiscard]] std::size_t buffer_capacity() const noexcept
- {
- return m_maximum;
- }
-
- [[nodiscard]] std::size_t buffer_occupied() const noexcept
- {
- assert( m_end >= m_current.data );
- return static_cast< std::size_t >( m_end - m_current.data );
- }
-
- [[nodiscard]] std::size_t buffer_free_before_current() const noexcept
- {
- assert( m_current.data >= m_buffer.get() );
- return static_cast< std::size_t >( m_current.data - m_buffer.get() );
- }
-
- [[nodiscard]] std::size_t buffer_free_after_end() const noexcept
- {
- assert( m_buffer.get() + m_maximum >= m_end );
- return static_cast< std::size_t >( m_buffer.get() + m_maximum - m_end );
- }
-
- template< apply_mode A,
- rewind_mode M,
- template< typename... >
- class Action,
- template< typename... >
- class Control,
- typename ParseInput,
- typename... States >
- [[nodiscard]] static bool match_eol( ParseInput& in, States&&... st )
- {
- if( Control< typename Eol::rule_t >::template match< A, M, Action, Control >( in, st... ) ) {
- // in.template consume< eol_consume_tag >( 0 );
- return true;
- }
- return false;
- }
-
- private:
- Reader m_reader;
- std::size_t m_maximum;
- std::unique_ptr< char[] > m_buffer;
- rewind_position_t m_current;
- char* m_end;
- const Source m_source;
- };
-
-} // namespace TAO_PEGTL_NAMESPACE
-
-#endif
diff --git a/include/tao/pegtl/contrib/integer.hpp b/include/tao/pegtl/contrib/integer.hpp
index 8556cd68b..d956332de 100644
--- a/include/tao/pegtl/contrib/integer.hpp
+++ b/include/tao/pegtl/contrib/integer.hpp
@@ -17,13 +17,12 @@
#include
#include "../ascii.hpp"
+#include "../analyze_traits.hpp"
#include "../config.hpp"
#include "../parse.hpp"
#include "../parse_error.hpp"
#include "../rules.hpp"
-#include "analyze_traits.hpp"
-
namespace TAO_PEGTL_NAMESPACE
{
struct unsigned_rule_old
@@ -154,12 +153,12 @@ namespace TAO_PEGTL_NAMESPACE
if( !in.empty() ) {
const char c = in.peek_char();
if( is_digit( c ) ) {
- in.bump_in_this_line();
+ in.template consume< unsigned >( 1 );
if( c == '0' ) {
return in.empty() || ( !is_digit( in.peek_char() ) );
}
while( ( !in.empty() ) && is_digit( in.peek_char() ) ) {
- in.bump_in_this_line();
+ in.template consume< unsigned >( 1 );
}
return true;
}
@@ -178,14 +177,14 @@ namespace TAO_PEGTL_NAMESPACE
char c = in.peek_char();
if( is_digit( c ) ) {
if( c == '0' ) {
- in.bump_in_this_line();
+ in.template consume< unsigned >( 1 );
return in.empty() || ( !is_digit( in.peek_char() ) );
}
do {
if( !accumulate_digit< Unsigned, Maximum >( st, c ) ) {
throw TAO_PEGTL_NAMESPACE::parse_error( "integer overflow", in );
}
- in.bump_in_this_line();
+ in.template consume< unsigned >( 1 );
} while( ( !in.empty() ) && is_digit( c = in.peek_char() ) );
return true;
}
@@ -204,7 +203,7 @@ namespace TAO_PEGTL_NAMESPACE
char c = in.peek_char();
if( c == '0' ) {
if( ( in.size( 2 ) < 2 ) || ( !is_digit( in.peek_char( 1 ) ) ) ) {
- in.bump_in_this_line();
+ in.template consume< unsigned >( 1 );
return true;
}
return false;
@@ -218,7 +217,7 @@ namespace TAO_PEGTL_NAMESPACE
}
++b;
} while( ( !in.empty() ) && is_digit( c = in.peek_char( b ) ) );
- in.bump_in_this_line( b );
+ in.template consume< unsigned >( b );
return true;
}
}
diff --git a/include/tao/pegtl/contrib/internal/endian.hpp b/include/tao/pegtl/contrib/internal/endian.hpp
deleted file mode 100644
index 43d90b9d6..000000000
--- a/include/tao/pegtl/contrib/internal/endian.hpp
+++ /dev/null
@@ -1,78 +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)
-
-#ifndef TAO_PEGTL_CONTRIB_INTERNAL_ENDIAN_HPP
-#define TAO_PEGTL_CONTRIB_INTERNAL_ENDIAN_HPP
-
-#include
-#include
-
-#include "../../config.hpp"
-
-#if defined( _WIN32 ) && !defined( __MINGW32__ ) && !defined( __CYGWIN__ )
-#include "endian_win.hpp"
-#else
-#include "endian_gcc.hpp"
-#endif
-
-namespace TAO_PEGTL_NAMESPACE::internal
-{
- enum class endian
- {
-#if defined( _WIN32 )
- little = 0,
- big = 1,
- native = little
-#elif defined( __BYTE_ORDER__ )
- little = __ORDER_LITTLE_ENDIAN__,
- big = __ORDER_BIG_ENDIAN__,
- native = __BYTE_ORDER__
-#else
-#error Unknown endianness.
-#endif
- };
-
- template< typename N >
- [[nodiscard]] N h_to_be( const N n ) noexcept
- {
- return N( to_and_from_be< sizeof( N ) >::convert( n ) );
- }
-
- template< typename N >
- [[nodiscard]] N be_to_h( const N n ) noexcept
- {
- return h_to_be( n );
- }
-
- template< typename N >
- [[nodiscard]] N be_to_h( const void* p ) noexcept
- {
- N n;
- std::memcpy( &n, p, sizeof( n ) );
- return internal::be_to_h( n );
- }
-
- template< typename N >
- [[nodiscard]] N h_to_le( const N n ) noexcept
- {
- return N( to_and_from_le< sizeof( N ) >::convert( n ) );
- }
-
- template< typename N >
- [[nodiscard]] N le_to_h( const N n ) noexcept
- {
- return h_to_le( n );
- }
-
- template< typename N >
- [[nodiscard]] N le_to_h( const void* p ) noexcept
- {
- N n;
- std::memcpy( &n, p, sizeof( n ) );
- return internal::le_to_h( n );
- }
-
-} // namespace TAO_PEGTL_NAMESPACE::internal
-
-#endif
diff --git a/include/tao/pegtl/contrib/internal/endian_gcc.hpp b/include/tao/pegtl/contrib/internal/endian_gcc.hpp
deleted file mode 100644
index c261be2b4..000000000
--- a/include/tao/pegtl/contrib/internal/endian_gcc.hpp
+++ /dev/null
@@ -1,201 +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)
-
-#ifndef TAO_PEGTL_CONTRIB_INTERNAL_ENDIAN_GCC_HPP
-#define TAO_PEGTL_CONTRIB_INTERNAL_ENDIAN_GCC_HPP
-
-#include
-#include
-
-#include "../../config.hpp"
-
-namespace TAO_PEGTL_NAMESPACE::internal
-{
-#if !defined( __BYTE_ORDER__ )
-#error No byte order defined!
-#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
-
- template< std::size_t S >
- struct to_and_from_be
- {
- template< typename T >
- [[nodiscard]] static T convert( const T n ) noexcept
- {
- return n;
- }
- };
-
- template< std::size_t S >
- struct to_and_from_le;
-
- template<>
- struct to_and_from_le< 1 >
- {
- [[nodiscard]] static std::uint8_t convert( const std::uint8_t n ) noexcept
- {
- return n;
- }
-
- [[nodiscard]] static std::int8_t convert( const std::int8_t n ) noexcept
- {
- return n;
- }
- };
-
- template<>
- struct to_and_from_le< 2 >
- {
- [[nodiscard]] static std::int16_t convert( const std::int16_t n ) noexcept
- {
- return static_cast< std::int16_t >( __builtin_bswap16( static_cast< std::uint16_t >( n ) ) );
- }
-
- [[nodiscard]] static std::uint16_t convert( const std::uint16_t n ) noexcept
- {
- return __builtin_bswap16( n );
- }
- };
-
- template<>
- struct to_and_from_le< 4 >
- {
- [[nodiscard]] static float convert( float n ) noexcept
- {
- std::uint32_t u;
- std::memcpy( &u, &n, 4 );
- u = convert( u );
- std::memcpy( &n, &u, 4 );
- return n;
- }
-
- [[nodiscard]] static std::int32_t convert( const std::int32_t n ) noexcept
- {
- return static_cast< std::int32_t >( __builtin_bswap32( static_cast< std::uint32_t >( n ) ) );
- }
-
- [[nodiscard]] static std::uint32_t convert( const std::uint32_t n ) noexcept
- {
- return __builtin_bswap32( n );
- }
- };
-
- template<>
- struct to_and_from_le< 8 >
- {
- [[nodiscard]] static double convert( double n ) noexcept
- {
- std::uint64_t u;
- std::memcpy( &u, &n, 8 );
- u = convert( u );
- std::memcpy( &n, &u, 8 );
- return n;
- }
-
- [[nodiscard]] static std::int64_t convert( const std::int64_t n ) noexcept
- {
- return static_cast< std::int64_t >( __builtin_bswap64( static_cast< std::uint64_t >( n ) ) );
- }
-
- [[nodiscard]] static std::uint64_t convert( const std::uint64_t n ) noexcept
- {
- return __builtin_bswap64( n );
- }
- };
-
-#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
-
- template< std::size_t S >
- struct to_and_from_le
- {
- template< typename T >
- [[nodiscard]] static T convert( const T n ) noexcept
- {
- return n;
- }
- };
-
- template< std::size_t S >
- struct to_and_from_be;
-
- template<>
- struct to_and_from_be< 1 >
- {
- [[nodiscard]] static std::int8_t convert( const std::int8_t n ) noexcept
- {
- return n;
- }
-
- [[nodiscard]] static std::uint8_t convert( const std::uint8_t n ) noexcept
- {
- return n;
- }
- };
-
- template<>
- struct to_and_from_be< 2 >
- {
- [[nodiscard]] static std::int16_t convert( const std::int16_t n ) noexcept
- {
- return static_cast< std::int16_t >( __builtin_bswap16( static_cast< std::uint16_t >( n ) ) );
- }
-
- [[nodiscard]] static std::uint16_t convert( const std::uint16_t n ) noexcept
- {
- return __builtin_bswap16( n );
- }
- };
-
- template<>
- struct to_and_from_be< 4 >
- {
- [[nodiscard]] static float convert( float n ) noexcept
- {
- std::uint32_t u;
- std::memcpy( &u, &n, 4 );
- u = convert( u );
- std::memcpy( &n, &u, 4 );
- return n;
- }
-
- [[nodiscard]] static std::int32_t convert( const std::int32_t n ) noexcept
- {
- return static_cast< std::int32_t >( __builtin_bswap32( static_cast< std::uint32_t >( n ) ) );
- }
-
- [[nodiscard]] static std::uint32_t convert( const std::uint32_t n ) noexcept
- {
- return __builtin_bswap32( n );
- }
- };
-
- template<>
- struct to_and_from_be< 8 >
- {
- [[nodiscard]] static double convert( double n ) noexcept
- {
- std::uint64_t u;
- std::memcpy( &u, &n, 8 );
- u = convert( u );
- std::memcpy( &n, &u, 8 );
- return n;
- }
-
- [[nodiscard]] static std::int64_t convert( const std::int64_t n ) noexcept
- {
- return static_cast< std::int64_t >( __builtin_bswap64( static_cast< std::uint64_t >( n ) ) );
- }
-
- [[nodiscard]] static std::uint64_t convert( const std::uint64_t n ) noexcept
- {
- return __builtin_bswap64( n );
- }
- };
-
-#else
-#error Unknown host byte order!
-#endif
-
-} // namespace TAO_PEGTL_NAMESPACE::internal
-
-#endif
diff --git a/include/tao/pegtl/contrib/internal/endian_win.hpp b/include/tao/pegtl/contrib/internal/endian_win.hpp
deleted file mode 100644
index c0b1851ec..000000000
--- a/include/tao/pegtl/contrib/internal/endian_win.hpp
+++ /dev/null
@@ -1,105 +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)
-
-#ifndef TAO_PEGTL_CONTRIB_INTERNAL_ENDIAN_WIN_HPP
-#define TAO_PEGTL_CONTRIB_INTERNAL_ENDIAN_WIN_HPP
-
-#include
-#include
-#include
-
-#include "../../config.hpp"
-
-namespace TAO_PEGTL_NAMESPACE::internal
-{
- template< std::size_t S >
- struct to_and_from_le
- {
- template< typename T >
- [[nodiscard]] static T convert( const T t ) noexcept
- {
- return t;
- }
- };
-
- template< std::size_t S >
- struct to_and_from_be;
-
- template<>
- struct to_and_from_be< 1 >
- {
- [[nodiscard]] static std::int8_t convert( const std::int8_t n ) noexcept
- {
- return n;
- }
-
- [[nodiscard]] static std::uint8_t convert( const std::uint8_t n ) noexcept
- {
- return n;
- }
- };
-
- template<>
- struct to_and_from_be< 2 >
- {
- [[nodiscard]] static std::int16_t convert( const std::int16_t n ) noexcept
- {
- return std::int16_t( _byteswap_ushort( std::uint16_t( n ) ) );
- }
-
- [[nodiscard]] static std::uint16_t convert( const std::uint16_t n ) noexcept
- {
- return _byteswap_ushort( n );
- }
- };
-
- template<>
- struct to_and_from_be< 4 >
- {
- [[nodiscard]] static float convert( float n ) noexcept
- {
- std::uint32_t u;
- std::memcpy( &u, &n, 4 );
- u = convert( u );
- std::memcpy( &n, &u, 4 );
- return n;
- }
-
- [[nodiscard]] static std::int32_t convert( const std::int32_t n ) noexcept
- {
- return std::int32_t( _byteswap_ulong( std::uint32_t( n ) ) );
- }
-
- [[nodiscard]] static std::uint32_t convert( const std::uint32_t n ) noexcept
- {
- return _byteswap_ulong( n );
- }
- };
-
- template<>
- struct to_and_from_be< 8 >
- {
- [[nodiscard]] static double convert( double n ) noexcept
- {
- std::uint64_t u;
- std::memcpy( &u, &n, 8 );
- u = convert( u );
- std::memcpy( &n, &u, 8 );
- return n;
- }
-
- [[nodiscard]] static std::int64_t convert( const std::int64_t n ) noexcept
- {
- return std::int64_t( _byteswap_uint64( std::uint64_t( n ) ) );
- }
-
- [[nodiscard]] static std::uint64_t convert( const std::uint64_t n ) noexcept
- {
- return _byteswap_uint64( n );
- }
- };
-
-} // namespace TAO_PEGTL_NAMESPACE::internal
-
-#endif
diff --git a/include/tao/pegtl/contrib/internal/peek_mask_uint.hpp b/include/tao/pegtl/contrib/internal/peek_mask_uint.hpp
deleted file mode 100644
index 6fafc9117..000000000
--- a/include/tao/pegtl/contrib/internal/peek_mask_uint.hpp
+++ /dev/null
@@ -1,54 +0,0 @@
-// Copyright (c) 2018-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_CONTRIB_INTERNAL_PEEK_MASK_UINT_HPP
-#define TAO_PEGTL_CONTRIB_INTERNAL_PEEK_MASK_UINT_HPP
-
-#include
-#include
-
-#include "../../internal/data_and_size.hpp"
-
-#include "read_uint.hpp"
-
-namespace TAO_PEGTL_NAMESPACE::internal
-{
- template< typename R, typename R::type M >
- struct peek_mask_uint_impl
- {
- using data_t = typename R::type;
- using pair_t = data_and_size< data_t >;
-
- template< typename ParseInput >
- [[nodiscard]] static pair_t peek( ParseInput& in ) noexcept( noexcept( in.size( sizeof( data_t ) ) ) )
- {
- if( in.size( sizeof( data_t ) ) < sizeof( data_t ) ) {
- return { 0, 0 };
- }
- const data_t data = R::read( in.current() ) & M;
- return { data, sizeof( data_t ) };
- }
- };
-
- template< std::uint16_t M >
- using peek_mask_uint16_be = peek_mask_uint_impl< read_uint16_be, M >;
-
- template< std::uint16_t M >
- using peek_mask_uint16_le = peek_mask_uint_impl< read_uint16_le, M >;
-
- template< std::uint32_t M >
- using peek_mask_uint32_be = peek_mask_uint_impl< read_uint32_be, M >;
-
- template< std::uint32_t M >
- using peek_mask_uint32_le = peek_mask_uint_impl< read_uint32_le, M >;
-
- template< std::uint64_t M >
- using peek_mask_uint64_be = peek_mask_uint_impl< read_uint64_be, M >;
-
- template< std::uint64_t M >
- using peek_mask_uint64_le = peek_mask_uint_impl< read_uint64_le, M >;
-
-} // namespace TAO_PEGTL_NAMESPACE::internal
-
-#endif
diff --git a/include/tao/pegtl/contrib/internal/peek_uint.hpp b/include/tao/pegtl/contrib/internal/peek_uint.hpp
deleted file mode 100644
index 8151f2a3f..000000000
--- a/include/tao/pegtl/contrib/internal/peek_uint.hpp
+++ /dev/null
@@ -1,45 +0,0 @@
-// Copyright (c) 2018-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_CONTRIB_INTERNAL_PEEK_UINT_HPP
-#define TAO_PEGTL_CONTRIB_INTERNAL_PEEK_UINT_HPP
-
-#include
-#include
-
-#include "../../internal/data_and_size.hpp"
-
-#include "read_uint.hpp"
-
-namespace TAO_PEGTL_NAMESPACE::internal
-{
- template< typename R >
- struct peek_uint_impl
- {
- using data_t = typename R::type;
- using pair_t = data_and_size< data_t >;
-
- template< typename ParseInput >
- [[nodiscard]] static pair_t peek( ParseInput& in ) noexcept( noexcept( in.size( sizeof( data_t ) ) ) )
- {
- if( in.size( sizeof( data_t ) ) < sizeof( data_t ) ) {
- return { 0, 0 };
- }
- const data_t data = R::read( in.current() );
- return { data, sizeof( data_t ) };
- }
- };
-
- using peek_uint16_be = peek_uint_impl< read_uint16_be >;
- using peek_uint16_le = peek_uint_impl< read_uint16_le >;
-
- using peek_uint32_be = peek_uint_impl< read_uint32_be >;
- using peek_uint32_le = peek_uint_impl< read_uint32_le >;
-
- using peek_uint64_be = peek_uint_impl< read_uint64_be >;
- using peek_uint64_le = peek_uint_impl< read_uint64_le >;
-
-} // namespace TAO_PEGTL_NAMESPACE::internal
-
-#endif
diff --git a/include/tao/pegtl/contrib/internal/peek_uint8.hpp b/include/tao/pegtl/contrib/internal/peek_uint8.hpp
deleted file mode 100644
index 9e343eb2d..000000000
--- a/include/tao/pegtl/contrib/internal/peek_uint8.hpp
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright (c) 2018-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_CONTRIB_INTERNAL_PEEK_UINT8_HPP
-#define TAO_PEGTL_CONTRIB_INTERNAL_PEEK_UINT8_HPP
-
-#include
-#include
-
-#include "../../internal/data_and_size.hpp"
-
-namespace TAO_PEGTL_NAMESPACE::internal
-{
- struct peek_uint8
- {
- using data_t = std::uint8_t;
- using pair_t = data_and_size< std::uint8_t >;
-
- template< typename ParseInput >
- [[nodiscard]] static pair_t peek( ParseInput& in ) noexcept( noexcept( in.empty() ) )
- {
- if( in.empty() ) {
- return { 0, 0 };
- }
- return { in.peek_uint8(), 1 };
- }
- };
-
-} // namespace TAO_PEGTL_NAMESPACE::internal
-
-#endif
diff --git a/include/tao/pegtl/contrib/internal/peek_utf16.hpp b/include/tao/pegtl/contrib/internal/peek_utf16.hpp
deleted file mode 100644
index b4ab1091c..000000000
--- a/include/tao/pegtl/contrib/internal/peek_utf16.hpp
+++ /dev/null
@@ -1,54 +0,0 @@
-// Copyright (c) 2014-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_CONTRIB_INTERNAL_PEEK_UTF16_HPP
-#define TAO_PEGTL_CONTRIB_INTERNAL_PEEK_UTF16_HPP
-
-#include
-
-#include "../../internal/data_and_size.hpp"
-
-#include "read_uint.hpp"
-
-namespace TAO_PEGTL_NAMESPACE::internal
-{
- template< typename R >
- struct peek_utf16_impl
- {
- using data_t = char32_t;
- using pair_t = data_and_size< char32_t >;
-
- using short_t = std::make_unsigned< char16_t >::type;
-
- static_assert( sizeof( short_t ) == 2 );
- static_assert( sizeof( char16_t ) == 2 );
-
- template< typename ParseInput >
- [[nodiscard]] static pair_t peek( ParseInput& in ) noexcept( noexcept( in.size( 4 ) ) )
- {
- if( in.size( 2 ) < 2 ) {
- return { 0, 0 };
- }
- const char32_t t = R::read( in.current() );
- if( ( t < 0xd800 ) || ( t > 0xdfff ) ) {
- return { t, 2 };
- }
- if( ( t >= 0xdc00 ) || ( in.size( 4 ) < 4 ) ) {
- return { 0, 0 };
- }
- const char32_t u = R::read( in.current() + 2 );
- if( ( u >= 0xdc00 ) && ( u <= 0xdfff ) ) {
- const auto cp = ( ( ( t & 0x03ff ) << 10 ) | ( u & 0x03ff ) ) + 0x10000;
- return { cp, 4 };
- }
- return { 0, 0 };
- }
- };
-
- using peek_utf16_be = peek_utf16_impl< read_uint16_be >;
- using peek_utf16_le = peek_utf16_impl< read_uint16_le >;
-
-} // namespace TAO_PEGTL_NAMESPACE::internal
-
-#endif
diff --git a/include/tao/pegtl/contrib/internal/peek_utf32.hpp b/include/tao/pegtl/contrib/internal/peek_utf32.hpp
deleted file mode 100644
index a32170d94..000000000
--- a/include/tao/pegtl/contrib/internal/peek_utf32.hpp
+++ /dev/null
@@ -1,43 +0,0 @@
-// Copyright (c) 2014-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_CONTRIB_INTERNAL_PEEK_UTF32_HPP
-#define TAO_PEGTL_CONTRIB_INTERNAL_PEEK_UTF32_HPP
-
-#include
-
-#include "../../internal/data_and_size.hpp"
-
-#include "read_uint.hpp"
-
-namespace TAO_PEGTL_NAMESPACE::internal
-{
- template< typename R >
- struct peek_utf32_impl
- {
- using data_t = char32_t;
- using pair_t = data_and_size< char32_t >;
-
- static_assert( sizeof( char32_t ) == 4 );
-
- template< typename ParseInput >
- [[nodiscard]] static pair_t peek( ParseInput& in ) noexcept( noexcept( in.size( 4 ) ) )
- {
- if( in.size( 4 ) < 4 ) {
- return { 0, 0 };
- }
- const char32_t t = R::read( in.current() );
- if( ( t <= 0x10ffff ) && !( t >= 0xd800 && t <= 0xdfff ) ) {
- return { t, 4 };
- }
- return { 0, 0 };
- }
- };
-
- using peek_utf32_be = peek_utf32_impl< read_uint32_be >;
- using peek_utf32_le = peek_utf32_impl< read_uint32_le >;
-
-} // namespace TAO_PEGTL_NAMESPACE::internal
-
-#endif
diff --git a/include/tao/pegtl/contrib/internal/read_uint.hpp b/include/tao/pegtl/contrib/internal/read_uint.hpp
deleted file mode 100644
index 63f61c786..000000000
--- a/include/tao/pegtl/contrib/internal/read_uint.hpp
+++ /dev/null
@@ -1,76 +0,0 @@
-// Copyright (c) 2018-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_CONTRIB_INTERNAL_READ_UINT_HPP
-#define TAO_PEGTL_CONTRIB_INTERNAL_READ_UINT_HPP
-
-#include
-
-#include "endian.hpp"
-
-namespace TAO_PEGTL_NAMESPACE::internal
-{
- struct read_uint16_be
- {
- using type = std::uint16_t;
-
- [[nodiscard]] static std::uint16_t read( const void* d ) noexcept
- {
- return be_to_h< std::uint16_t >( d );
- }
- };
-
- struct read_uint16_le
- {
- using type = std::uint16_t;
-
- [[nodiscard]] static std::uint16_t read( const void* d ) noexcept
- {
- return le_to_h< std::uint16_t >( d );
- }
- };
-
- struct read_uint32_be
- {
- using type = std::uint32_t;
-
- [[nodiscard]] static std::uint32_t read( const void* d ) noexcept
- {
- return be_to_h< std::uint32_t >( d );
- }
- };
-
- struct read_uint32_le
- {
- using type = std::uint32_t;
-
- [[nodiscard]] static std::uint32_t read( const void* d ) noexcept
- {
- return le_to_h< std::uint32_t >( d );
- }
- };
-
- struct read_uint64_be
- {
- using type = std::uint64_t;
-
- [[nodiscard]] static std::uint64_t read( const void* d ) noexcept
- {
- return be_to_h< std::uint64_t >( d );
- }
- };
-
- struct read_uint64_le
- {
- using type = std::uint64_t;
-
- [[nodiscard]] static std::uint64_t read( const void* d ) noexcept
- {
- return le_to_h< std::uint64_t >( d );
- }
- };
-
-} // namespace TAO_PEGTL_NAMESPACE::internal
-
-#endif
diff --git a/include/tao/pegtl/contrib/nested_exceptions.hpp b/include/tao/pegtl/contrib/nested_exceptions.hpp
index 90f4c623e..e010dda54 100644
--- a/include/tao/pegtl/contrib/nested_exceptions.hpp
+++ b/include/tao/pegtl/contrib/nested_exceptions.hpp
@@ -98,10 +98,10 @@ namespace TAO_PEGTL_NAMESPACE::nested
internal::inspector< Exceptions... >::inspect( ptr, visitor );
}
- [[nodiscard]] inline std::vector< parse_error > flatten( const std::exception_ptr& ptr = std::current_exception() )
+ [[nodiscard]] inline std::vector< parse_error_base > flatten( const std::exception_ptr& ptr = std::current_exception() )
{
- std::vector< parse_error > result;
- inspect< parse_error >( ptr, [ &result ]( const parse_error& e, const std::size_t /*unused*/ ) {
+ std::vector< parse_error_base > result;
+ inspect< parse_error_base >( ptr, [ &result ]( const parse_error_base& e, const std::size_t /*unused*/ ) {
result.emplace_back( e );
} );
return result;
diff --git a/include/tao/pegtl/contrib/parse_tree.hpp b/include/tao/pegtl/contrib/parse_tree.hpp
index bc60f46a0..4c1e1f028 100644
--- a/include/tao/pegtl/contrib/parse_tree.hpp
+++ b/include/tao/pegtl/contrib/parse_tree.hpp
@@ -22,7 +22,7 @@
#include "../config.hpp"
#include "../demangle.hpp"
#include "../eol.hpp"
-#include "../memory_input.hpp"
+#include "../inputs.hpp"
#include "../normal.hpp"
#include "../nothing.hpp"
#include "../parse.hpp"
@@ -30,7 +30,6 @@
#include "../internal/enable_control.hpp"
#include "../internal/has_unwind.hpp"
-#include "../internal/inputerator.hpp"
namespace TAO_PEGTL_NAMESPACE::parse_tree
{
@@ -44,8 +43,8 @@ namespace TAO_PEGTL_NAMESPACE::parse_tree
std::string_view type;
Source source;
- TAO_PEGTL_NAMESPACE::internal::large_position m_begin;
- TAO_PEGTL_NAMESPACE::internal::large_position m_end;
+ TAO_PEGTL_NAMESPACE::internal::legacy_error_position m_begin;
+ TAO_PEGTL_NAMESPACE::internal::legacy_error_position m_end;
// each node will be default constructed
basic_node() = default;
@@ -116,8 +115,8 @@ namespace TAO_PEGTL_NAMESPACE::parse_tree
template< typename... States >
void remove_content( States&&... /*unused*/ ) noexcept
{
- m_begin = TAO_PEGTL_NAMESPACE::internal::large_position();
- m_end = TAO_PEGTL_NAMESPACE::internal::large_position();
+ m_begin = TAO_PEGTL_NAMESPACE::internal::legacy_error_position();
+ m_end = TAO_PEGTL_NAMESPACE::internal::legacy_error_position();
}
// all non-root nodes are initialized by calling this method
@@ -126,14 +125,14 @@ namespace TAO_PEGTL_NAMESPACE::parse_tree
{
set_type< Rule >();
source = in.source();
- m_begin = TAO_PEGTL_NAMESPACE::internal::large_position( in.rewind_position() );
+ m_begin = TAO_PEGTL_NAMESPACE::internal::legacy_error_position( in.rewind_position() );
}
// if parsing of the rule succeeded, this method is called
template< typename Rule, typename ParseInput, typename... States >
void success( const ParseInput& in, States&&... /*unused*/ ) noexcept
{
- m_end = TAO_PEGTL_NAMESPACE::internal::large_position( in.rewind_position() );
+ m_end = TAO_PEGTL_NAMESPACE::internal::legacy_error_position( in.rewind_position() );
}
// if parsing of the rule failed, this method is called
diff --git a/include/tao/pegtl/contrib/predicates.hpp b/include/tao/pegtl/contrib/predicates.hpp
deleted file mode 100644
index ad30169bc..000000000
--- a/include/tao/pegtl/contrib/predicates.hpp
+++ /dev/null
@@ -1,133 +0,0 @@
-// Copyright (c) 2020-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_CONTRIB_PREDICATES_HPP
-#define TAO_PEGTL_CONTRIB_PREDICATES_HPP
-
-#include "../config.hpp"
-#include "../type_list.hpp"
-
-#include "../internal/bump_help.hpp"
-#include "../internal/dependent_false.hpp"
-#include "../internal/enable_control.hpp"
-#include "../internal/failure.hpp"
-#include "../internal/peek_char.hpp"
-#include "../internal/peek_utf8.hpp"
-
-#include "analyze_traits.hpp"
-
-namespace TAO_PEGTL_NAMESPACE
-{
- namespace internal
- {
- template< typename Peek, typename... Ps >
- struct predicates_and_test
- {
- using peek_t = Peek;
- using data_t = typename Peek::data_t;
-
- [[nodiscard]] static constexpr bool test_impl( const data_t c ) noexcept
- {
- return ( Ps::test_one( c ) && ... ); // TODO: Static assert that Ps::peek_t is the same as peek_t?!
- }
- };
-
- template< typename Peek, typename P >
- struct predicate_not_test
- {
- using peek_t = Peek;
- using data_t = typename Peek::data_t;
-
- [[nodiscard]] static constexpr bool test_impl( const data_t c ) noexcept
- {
- return !P::test_one( c ); // TODO: Static assert that P::peek_t is the same as peek_t?!
- }
- };
-
- template< typename Peek, typename... Ps >
- struct predicates_or_test
- {
- using peek_t = Peek;
- using data_t = typename Peek::data_t;
-
- [[nodiscard]] static constexpr bool test_impl( const data_t c ) noexcept
- {
- return ( Ps::test_one( c ) || ... ); // TODO: Static assert that Ps::peek_t is the same as peek_t?!
- }
- };
-
- template< template< typename, typename... > class Test, typename Peek, typename... Ps >
- struct predicates
- : private Test< Peek, Ps... >
- {
- using peek_t = Peek;
- using data_t = typename Peek::data_t;
-
- using rule_t = predicates;
- using subs_t = empty_list;
-
- using base_t = Test< Peek, Ps... >;
-
- [[nodiscard]] static constexpr bool test_one( const data_t c ) noexcept
- {
- return Test< Peek, Ps... >::test_impl( c );
- }
-
- [[nodiscard]] static constexpr bool test_any( const data_t c ) noexcept
- {
- return Test< Peek, Ps... >::test_impl( c );
- }
-
- template< typename ParseInput >
- [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( Peek::peek( in ) ) )
- {
- if( const auto t = Peek::peek( in ) ) {
- if( test_one( t.data ) ) {
- bump_help< predicates >( in, t.size );
- return true;
- }
- }
- return false;
- }
- };
-
- template< template< typename, typename... > class Test, typename Peek >
- struct predicates< Test, Peek >
- {
- static_assert( dependent_false< Peek >, "Empty predicate list is not allowed!" );
- };
-
- template< template< typename, typename... > class Test, typename Peek, typename... Ps >
- inline constexpr bool enable_control< predicates< Test, Peek, Ps... > > = false;
-
- } // namespace internal
-
- inline namespace ascii
- {
- // clang-format off
- template< typename... Ps > struct predicates_and : internal::predicates< internal::predicates_and_test, internal::peek_char, Ps... > {};
- template< typename P > struct predicate_not : internal::predicates< internal::predicate_not_test, internal::peek_char, P > {};
- template< typename... Ps > struct predicates_or : internal::predicates< internal::predicates_or_test, internal::peek_char, Ps... > {};
- // clang-format on
-
- } // namespace ascii
-
- namespace utf8
- {
- // clang-format off
- template< typename... Ps > struct predicates_and : internal::predicates< internal::predicates_and_test, internal::peek_utf8, Ps... > {};
- template< typename P > struct predicate_not : internal::predicates< internal::predicate_not_test, internal::peek_utf8, P > {};
- template< typename... Ps > struct predicates_or : internal::predicates< internal::predicates_or_test, internal::peek_utf8, Ps... > {};
- // clang-format on
-
- } // namespace utf8
-
- template< typename Name, template< typename, typename... > class Test, typename Peek, typename... Ps >
- struct analyze_traits< Name, internal::predicates< Test, Peek, Ps... > >
- : analyze_any_traits<>
- {};
-
-} // namespace TAO_PEGTL_NAMESPACE
-
-#endif
diff --git a/include/tao/pegtl/contrib/raw_string.hpp b/include/tao/pegtl/contrib/raw_string.hpp
index 245443322..6a46ffe49 100644
--- a/include/tao/pegtl/contrib/raw_string.hpp
+++ b/include/tao/pegtl/contrib/raw_string.hpp
@@ -8,14 +8,14 @@
#include
#include
+#include "../analyze_traits.hpp"
#include "../apply_mode.hpp"
#include "../ascii.hpp"
#include "../config.hpp"
+#include "../eol.hpp"
#include "../rewind_mode.hpp"
#include "../rules.hpp"
-#include "analyze_traits.hpp"
-
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
@@ -33,7 +33,7 @@ namespace TAO_PEGTL_NAMESPACE
template< typename... >
class Control,
typename ParseInput >
- [[nodiscard]] static bool match( ParseInput& in, std::size_t& marker_size ) noexcept( noexcept( in.size( 0 ) ) )
+ [[nodiscard]] static bool match( ParseInput& in, std::size_t& marker_size ) noexcept( noexcept( in.size( 42 ) ) )
{
if( in.empty() || ( in.peek_char( 0 ) != Open ) ) {
return false;
@@ -42,8 +42,8 @@ namespace TAO_PEGTL_NAMESPACE
switch( const auto c = in.peek_char( i ) ) {
case Open:
marker_size = i + 1;
- in.bump_in_this_line( marker_size );
- (void)in.template match_eol< A, M, Action, Control >( in );
+ in.template consume< raw_string_open >( marker_size );
+ (void)Control< eol >::template match< A, M, Action, Control >( in );
return true;
case Marker:
break;
@@ -71,7 +71,7 @@ namespace TAO_PEGTL_NAMESPACE
template< typename... >
class Control,
typename ParseInput >
- [[nodiscard]] static bool match( ParseInput& in, const std::size_t& marker_size ) noexcept( noexcept( in.size( 0 ) ) )
+ [[nodiscard]] static bool match( ParseInput& in, const std::size_t& marker_size ) noexcept( noexcept( in.size( 42 ) ) )
{
if( in.size( marker_size ) < marker_size ) {
return false;
@@ -121,7 +121,7 @@ namespace TAO_PEGTL_NAMESPACE
if( in.empty() ) {
return false;
}
- in.bump();
+ in.template consume< raw_string_until >( 1 );
}
return m( true );
}
@@ -209,7 +209,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.bump_in_this_line( marker_size );
+ in.template consume< raw_string >( marker_size );
return true;
}
}
diff --git a/include/tao/pegtl/contrib/rep_one_min_max.hpp b/include/tao/pegtl/contrib/rep_one_min_max.hpp
index bb9ed76cc..0a5a84906 100644
--- a/include/tao/pegtl/contrib/rep_one_min_max.hpp
+++ b/include/tao/pegtl/contrib/rep_one_min_max.hpp
@@ -8,15 +8,11 @@
#include
#include
+#include "../analyze_traits.hpp"
#include "../config.hpp"
#include "../type_list.hpp"
-#include "../internal/bump_help.hpp"
-#include "../internal/bytes.hpp"
#include "../internal/enable_control.hpp"
-#include "../internal/opt.hpp"
-
-#include "analyze_traits.hpp"
namespace TAO_PEGTL_NAMESPACE
{
@@ -30,13 +26,7 @@ namespace TAO_PEGTL_NAMESPACE
static_assert( Min <= Max );
- [[nodiscard]] static constexpr bool test_one( const char c ) noexcept
- {
- static_assert( ( Min == 1 ) && ( Max == 1 ) );
- return C == c;
- }
-
- [[nodiscard]] static constexpr bool test_any( const char c ) noexcept
+ [[nodiscard]] static constexpr bool test( const char c ) noexcept
{
return C == c;
}
@@ -53,7 +43,7 @@ namespace TAO_PEGTL_NAMESPACE
++i;
}
if( ( Min <= i ) && ( i <= Max ) ) {
- bump_help< rep_one_min_max >( in, i );
+ in.template consume< rep_one_min_max >( i );
return true;
}
return false;
@@ -66,7 +56,7 @@ namespace TAO_PEGTL_NAMESPACE
using rule_t = rep_one_min_max;
using subs_t = empty_list;
- [[nodiscard]] static constexpr bool test_any( const char c ) noexcept
+ [[nodiscard]] static constexpr bool test( const char c ) noexcept
{
return C == c;
}
@@ -80,7 +70,7 @@ namespace TAO_PEGTL_NAMESPACE
++i;
}
if( i <= Max ) {
- bump_help< rep_one_min_max >( in, i );
+ in.template consume< rep_one_min_max >( i );
return true;
}
return false;
diff --git a/include/tao/pegtl/contrib/control_action.hpp b/include/tao/pegtl/control_action.hpp
similarity index 95%
rename from include/tao/pegtl/contrib/control_action.hpp
rename to include/tao/pegtl/control_action.hpp
index edff6bde5..a7f3d73e8 100644
--- a/include/tao/pegtl/contrib/control_action.hpp
+++ b/include/tao/pegtl/control_action.hpp
@@ -2,14 +2,14 @@
// 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_CONTROL_ACTION_HPP
-#define TAO_PEGTL_CONTRIB_CONTROL_ACTION_HPP
+#ifndef TAO_PEGTL_CONTROL_ACTION_HPP
+#define TAO_PEGTL_CONTROL_ACTION_HPP
#include
-#include "../config.hpp"
-#include "../match.hpp"
-#include "../nothing.hpp"
+#include "config.hpp"
+#include "match.hpp"
+#include "nothing.hpp"
namespace TAO_PEGTL_NAMESPACE
{
diff --git a/include/tao/pegtl/count_position.hpp b/include/tao/pegtl/count_position.hpp
new file mode 100644
index 000000000..e871671f8
--- /dev/null
+++ b/include/tao/pegtl/count_position.hpp
@@ -0,0 +1,44 @@
+// Copyright (c) 2021-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_COUNT_POSITION_HPP
+#define TAO_PEGTL_COUNT_POSITION_HPP
+
+#include
+#include
+#include
+
+#include "config.hpp"
+
+namespace TAO_PEGTL_NAMESPACE
+{
+ struct count_position
+ {
+ std::size_t count = 0;
+
+ count_position() noexcept = default;
+
+ explicit count_position( const std::size_t in_count ) noexcept
+ : count( in_count )
+ {}
+ };
+
+ [[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
+ {
+ return !( l == r );
+ }
+
+ inline std::ostream& operator<<( std::ostream& os, const count_position p )
+ {
+ return os << p.count;
+ }
+
+} // namespace TAO_PEGTL_NAMESPACE
+
+#endif
diff --git a/include/tao/pegtl/cstream_input.hpp b/include/tao/pegtl/cstream_input.hpp
deleted file mode 100644
index 0c7c96c63..000000000
--- a/include/tao/pegtl/cstream_input.hpp
+++ /dev/null
@@ -1,33 +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)
-
-#ifndef TAO_PEGTL_CSTREAM_INPUT_HPP
-#define TAO_PEGTL_CSTREAM_INPUT_HPP
-
-#include
-
-#include "buffer_input.hpp"
-#include "config.hpp"
-#include "eol.hpp"
-
-#include "internal/cstream_reader.hpp"
-
-namespace TAO_PEGTL_NAMESPACE
-{
- template< typename Eol = ascii::lf_crlf, std::size_t Chunk = 64 >
- struct cstream_input
- : buffer_input< internal::cstream_reader, Eol, std::string, Chunk >
- {
- template< typename T >
- cstream_input( std::FILE* in_stream, const std::size_t in_maximum, T&& in_source )
- : buffer_input< internal::cstream_reader, Eol, std::string, Chunk >( std::forward< T >( in_source ), in_maximum, in_stream )
- {}
- };
-
- template< typename... Ts >
- cstream_input( Ts&&... ) -> cstream_input<>;
-
-} // namespace TAO_PEGTL_NAMESPACE
-
-#endif
diff --git a/include/tao/pegtl/discard_input.hpp b/include/tao/pegtl/discard_input.hpp
deleted file mode 100644
index 0cac8ecc6..000000000
--- a/include/tao/pegtl/discard_input.hpp
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright (c) 2019-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_DISCARD_INPUT_HPP
-#define TAO_PEGTL_DISCARD_INPUT_HPP
-
-#include "apply_mode.hpp"
-#include "config.hpp"
-#include "match.hpp"
-#include "nothing.hpp"
-#include "rewind_mode.hpp"
-
-namespace TAO_PEGTL_NAMESPACE
-{
- struct discard_input
- : maybe_nothing
- {
- template< typename Rule,
- 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 )
- {
- const bool result = TAO_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, st... );
- in.discard();
- return result;
- }
- };
-
-} // namespace TAO_PEGTL_NAMESPACE
-
-#endif
diff --git a/include/tao/pegtl/discard_input_on_failure.hpp b/include/tao/pegtl/discard_input_on_failure.hpp
deleted file mode 100644
index 12cea02e1..000000000
--- a/include/tao/pegtl/discard_input_on_failure.hpp
+++ /dev/null
@@ -1,40 +0,0 @@
-// Copyright (c) 2019-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_DISCARD_INPUT_ON_FAILURE_HPP
-#define TAO_PEGTL_DISCARD_INPUT_ON_FAILURE_HPP
-
-#include "apply_mode.hpp"
-#include "config.hpp"
-#include "match.hpp"
-#include "nothing.hpp"
-#include "rewind_mode.hpp"
-
-namespace TAO_PEGTL_NAMESPACE
-{
- struct discard_input_on_failure
- : maybe_nothing
- {
- template< typename Rule,
- 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 )
- {
- const bool result = TAO_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, st... );
- if( !result ) {
- in.discard();
- }
- return result;
- }
- };
-
-} // namespace TAO_PEGTL_NAMESPACE
-
-#endif
diff --git a/include/tao/pegtl/discard_input_on_success.hpp b/include/tao/pegtl/discard_input_on_success.hpp
deleted file mode 100644
index 0ed60d8bd..000000000
--- a/include/tao/pegtl/discard_input_on_success.hpp
+++ /dev/null
@@ -1,40 +0,0 @@
-// Copyright (c) 2019-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_DISCARD_INPUT_ON_SUCCESS_HPP
-#define TAO_PEGTL_DISCARD_INPUT_ON_SUCCESS_HPP
-
-#include "apply_mode.hpp"
-#include "config.hpp"
-#include "match.hpp"
-#include "nothing.hpp"
-#include "rewind_mode.hpp"
-
-namespace TAO_PEGTL_NAMESPACE
-{
- struct discard_input_on_success
- : maybe_nothing
- {
- template< typename Rule,
- 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 )
- {
- const bool result = TAO_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, st... );
- if( result ) {
- in.discard();
- }
- return result;
- }
- };
-
-} // namespace TAO_PEGTL_NAMESPACE
-
-#endif
diff --git a/include/tao/pegtl/eol.hpp b/include/tao/pegtl/eol.hpp
index 8e7b9b5c1..017369a25 100644
--- a/include/tao/pegtl/eol.hpp
+++ b/include/tao/pegtl/eol.hpp
@@ -8,7 +8,7 @@
#include "config.hpp"
#include "internal/one.hpp"
-#include "internal/peek_char.hpp"
+#include "internal/peek_direct.hpp"
#include "internal/result_on_found.hpp"
#include "internal/sor.hpp"
#include "internal/string.hpp"
diff --git a/include/tao/pegtl/file_input.hpp b/include/tao/pegtl/file_input.hpp
deleted file mode 100644
index de9d0d27c..000000000
--- a/include/tao/pegtl/file_input.hpp
+++ /dev/null
@@ -1,45 +0,0 @@
-// Copyright (c) 2015-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_FILE_INPUT_HPP
-#define TAO_PEGTL_FILE_INPUT_HPP
-
-#include "config.hpp"
-#include "eol.hpp"
-#include "tracking_mode.hpp"
-
-#if defined( __unix__ ) || ( defined( __APPLE__ ) && defined( __MACH__ ) )
-#include // Required for _POSIX_MAPPED_FILES
-#endif
-
-#if defined( _POSIX_MAPPED_FILES ) || defined( _WIN32 )
-#include "mmap_input.hpp"
-#else
-#include "read_input.hpp"
-#endif
-
-namespace TAO_PEGTL_NAMESPACE
-{
-#if defined( _POSIX_MAPPED_FILES ) || defined( _WIN32 )
- template< tracking_mode P = tracking_mode::eager, typename Eol = ascii::lf_crlf >
- struct file_input
- : mmap_input< P, Eol >
- {
- using mmap_input< P, Eol >::mmap_input;
- };
-#else
- template< tracking_mode P = tracking_mode::eager, typename Eol = ascii::lf_crlf >
- struct file_input
- : read_input< P, Eol >
- {
- using read_input< P, Eol >::read_input;
- };
-#endif
-
- template< typename... Ts >
- explicit file_input( Ts&&... ) -> file_input<>;
-
-} // namespace TAO_PEGTL_NAMESPACE
-
-#endif
diff --git a/include/tao/pegtl/contrib/forward.hpp b/include/tao/pegtl/forward.hpp
similarity index 71%
rename from include/tao/pegtl/contrib/forward.hpp
rename to include/tao/pegtl/forward.hpp
index 16905c654..bb27664a2 100644
--- a/include/tao/pegtl/contrib/forward.hpp
+++ b/include/tao/pegtl/forward.hpp
@@ -2,16 +2,19 @@
// 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_FORWARD_HPP
-#define TAO_PEGTL_CONTRIB_FORWARD_HPP
+#ifndef TAO_PEGTL_FORWARD_HPP
+#define TAO_PEGTL_FORWARD_HPP
-#include "../config.hpp"
+#include "config.hpp"
namespace TAO_PEGTL_NAMESPACE
{
template< typename Name, typename Rule, typename = void >
struct analyze_traits;
+ template< typename Rule, typename = void >
+ struct invert_traits;
+
} // namespace TAO_PEGTL_NAMESPACE
#endif
diff --git a/include/tao/pegtl/contrib/icu/internal.hpp b/include/tao/pegtl/icu/internal.hpp
similarity index 82%
rename from include/tao/pegtl/contrib/icu/internal.hpp
rename to include/tao/pegtl/icu/internal.hpp
index 78b032395..f7b656015 100644
--- a/include/tao/pegtl/contrib/icu/internal.hpp
+++ b/include/tao/pegtl/icu/internal.hpp
@@ -2,17 +2,16 @@
// 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_ICU_INTERNAL_HPP
-#define TAO_PEGTL_CONTRIB_ICU_INTERNAL_HPP
+#ifndef TAO_PEGTL_ICU_INTERNAL_HPP
+#define TAO_PEGTL_ICU_INTERNAL_HPP
#include
#include "../analyze_traits.hpp"
+#include "../config.hpp"
+#include "../type_list.hpp"
-#include "../../config.hpp"
-#include "../../type_list.hpp"
-
-#include "../../internal/enable_control.hpp"
+#include "../internal/enable_control.hpp"
namespace TAO_PEGTL_NAMESPACE
{
@@ -29,7 +28,7 @@ namespace TAO_PEGTL_NAMESPACE
using rule_t = binary_property;
using subs_t = empty_list;
- [[nodiscard]] static bool test_one( const data_t c ) noexcept
+ [[nodiscard]] static bool test( const data_t c ) noexcept
{
return u_hasBinaryProperty( c, P ) == V;
}
@@ -38,8 +37,8 @@ namespace TAO_PEGTL_NAMESPACE
[[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( Peek::peek( in ) ) )
{
if( const auto t = Peek::peek( in ) ) {
- if( test_one( t.data ) ) {
- in.bump( t.size );
+ if( test( t.data() ) ) {
+ in.template consume< binary_property >( t.size() );
return true;
}
}
@@ -56,7 +55,7 @@ namespace TAO_PEGTL_NAMESPACE
using rule_t = property_value;
using subs_t = empty_list;
- [[nodiscard]] static bool test_one( const data_t c ) noexcept
+ [[nodiscard]] static bool test( const data_t c ) noexcept
{
return u_getIntPropertyValue( c, P ) == V;
}
@@ -65,8 +64,8 @@ namespace TAO_PEGTL_NAMESPACE
[[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( Peek::peek( in ) ) )
{
if( const auto t = Peek::peek( in ) ) {
- if( test_one( t.data ) ) {
- in.bump( t.size );
+ if( test( t.data() ) ) {
+ in.template consume< property_value >( t.size() );
return true;
}
}
diff --git a/include/tao/pegtl/contrib/icu/utf16.hpp b/include/tao/pegtl/icu/utf16.hpp
similarity index 99%
rename from include/tao/pegtl/contrib/icu/utf16.hpp
rename to include/tao/pegtl/icu/utf16.hpp
index 418419df0..58517115c 100644
--- a/include/tao/pegtl/contrib/icu/utf16.hpp
+++ b/include/tao/pegtl/icu/utf16.hpp
@@ -2,15 +2,14 @@
// 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_ICU_UTF16_HPP
-#define TAO_PEGTL_CONTRIB_ICU_UTF16_HPP
+#ifndef TAO_PEGTL_ICU_UTF16_HPP
+#define TAO_PEGTL_ICU_UTF16_HPP
-#include "../../config.hpp"
+#include "../config.hpp"
+#include "../utf16.hpp"
#include "internal.hpp"
-#include "../utf16.hpp"
-
#include "../internal/peek_utf16.hpp"
namespace TAO_PEGTL_NAMESPACE
diff --git a/include/tao/pegtl/contrib/icu/utf32.hpp b/include/tao/pegtl/icu/utf32.hpp
similarity index 99%
rename from include/tao/pegtl/contrib/icu/utf32.hpp
rename to include/tao/pegtl/icu/utf32.hpp
index a830cdd0c..e35dd33fe 100644
--- a/include/tao/pegtl/contrib/icu/utf32.hpp
+++ b/include/tao/pegtl/icu/utf32.hpp
@@ -2,15 +2,14 @@
// 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_ICU_UTF32_HPP
-#define TAO_PEGTL_CONTRIB_ICU_UTF32_HPP
+#ifndef TAO_PEGTL_ICU_UTF32_HPP
+#define TAO_PEGTL_ICU_UTF32_HPP
-#include "../../config.hpp"
+#include "../config.hpp"
+#include "../utf32.hpp"
#include "internal.hpp"
-#include "../utf32.hpp"
-
#include "../internal/peek_utf32.hpp"
namespace TAO_PEGTL_NAMESPACE
diff --git a/include/tao/pegtl/contrib/icu/utf8.hpp b/include/tao/pegtl/icu/utf8.hpp
similarity index 97%
rename from include/tao/pegtl/contrib/icu/utf8.hpp
rename to include/tao/pegtl/icu/utf8.hpp
index 065837dc4..c9e6f4050 100644
--- a/include/tao/pegtl/contrib/icu/utf8.hpp
+++ b/include/tao/pegtl/icu/utf8.hpp
@@ -2,16 +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_CONTRIB_ICU_UTF8_HPP
-#define TAO_PEGTL_CONTRIB_ICU_UTF8_HPP
+#ifndef TAO_PEGTL_ICU_UTF8_HPP
+#define TAO_PEGTL_ICU_UTF8_HPP
-#include "../../config.hpp"
+#include "../config.hpp"
+#include "../utf8.hpp"
#include "internal.hpp"
-#include "../../utf8.hpp"
-
-#include "../../internal/peek_utf8.hpp"
+#include "../internal/peek_utf8.hpp"
namespace TAO_PEGTL_NAMESPACE::utf8::icu
{
diff --git a/include/tao/pegtl/inputs.hpp b/include/tao/pegtl/inputs.hpp
new file mode 100644
index 000000000..ce3bb9631
--- /dev/null
+++ b/include/tao/pegtl/inputs.hpp
@@ -0,0 +1,59 @@
+// Copyright (c) 2021-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_INPUTS_HPP
+#define TAO_PEGTL_INPUTS_HPP
+
+#include
+
+#include "config.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?
+ 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 > >;
+ using read_input = internal::input_with_fakes< internal::input_with_peeks< internal::read_input > >;
+ 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?
+ 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 > >;
+ template< typename Data >
+ using view_input_with_source = internal::input_with_fakes< internal::input_with_peeks< internal::input_with_source< std::string, internal::view_input< Data > > > >; // TODO: Add input_with_start?
+
+ template< typename Eol >
+ using lazy_copy_input = internal::input_with_fakes< internal::input_with_peeks< internal::lazy_input< Eol, internal::copy_input< std::string > > > >;
+ template< typename Eol >
+ using text_copy_input = internal::input_with_fakes< internal::input_with_peeks< internal::text_input< Eol, internal::copy_input< std::string > > > >;
+ template< typename Eol >
+ using lazy_file_input = internal::input_with_fakes< internal::input_with_peeks< internal::lazy_input< Eol, internal::file_input > > >;
+ template< typename Eol >
+ using text_file_input = internal::input_with_fakes< internal::input_with_peeks< internal::text_input< Eol, internal::file_input > > >;
+ template< typename Eol >
+ using lazy_view_input = internal::input_with_fakes< internal::input_with_peeks< internal::lazy_input< Eol, internal::view_input< char > > > >; // TODO: Add input_with_start?
+ template< typename Eol >
+ using text_view_input = internal::input_with_fakes< internal::input_with_peeks< internal::text_input< Eol, internal::view_input< char > > > >; // TODO: Add input_with_start?
+
+ template< typename Eol >
+ using lazy_copy_input_with_source = internal::input_with_fakes< internal::input_with_peeks< internal::lazy_input_with_source< Eol, std::string, internal::copy_input< std::string > > > >;
+ template< typename Eol >
+ using text_copy_input_with_source = internal::input_with_fakes< internal::input_with_peeks< internal::text_input_with_source< Eol, std::string, internal::copy_input< std::string > > > >;
+ template< typename Eol >
+ using lazy_file_input_with_source = internal::input_with_fakes< internal::input_with_peeks< internal::lazy_file_input_with_source< Eol > > >;
+ template< typename Eol >
+ using text_file_input_with_source = internal::input_with_fakes< internal::input_with_peeks< internal::text_file_input_with_source< Eol > > >;
+ template< typename Eol >
+ using lazy_view_input_with_source = internal::input_with_fakes< internal::input_with_peeks< internal::lazy_input_with_source< Eol, std::string, internal::view_input< char > > > >; // TODO: Add input_with_start?
+ template< typename Eol >
+ using text_view_input_with_source = internal::input_with_fakes< internal::input_with_peeks< internal::text_input_with_source< Eol, std::string, internal::view_input< char > > > >; // TODO: Add input_with_start?
+
+} // namespace TAO_PEGTL_NAMESPACE
+
+#endif
diff --git a/include/tao/pegtl/internal/action_input.hpp b/include/tao/pegtl/internal/action_input.hpp
index aa60659a1..320868d71 100644
--- a/include/tao/pegtl/internal/action_input.hpp
+++ b/include/tao/pegtl/internal/action_input.hpp
@@ -12,37 +12,40 @@
#include "../config.hpp"
+#include "input_with_peeks.hpp"
+
namespace TAO_PEGTL_NAMESPACE::internal
{
template< typename ParseInput >
- class action_input
+ class action_input_impl
{
public:
using data_t = typename ParseInput::data_t;
using input_t = ParseInput;
+ using error_position_t = typename ParseInput::error_position_t;
using rewind_position_t = typename ParseInput::rewind_position_t;
- action_input( const rewind_position_t& in_begin, const ParseInput& in_input ) noexcept
- : m_begin( in_begin ),
- m_input( in_input )
+ action_input_impl( const rewind_position_t& begin, const ParseInput& input ) noexcept
+ : m_saved( begin ),
+ m_input( input )
{}
- action_input( action_input&& ) = delete;
- action_input( const action_input& ) = delete;
+ action_input_impl( action_input_impl&& ) = delete;
+ action_input_impl( const action_input_impl& ) = delete;
- ~action_input() = default;
+ ~action_input_impl() = default;
- void operator=( action_input&& ) = delete;
- void operator=( const action_input& ) = delete;
+ void operator=( action_input_impl&& ) = delete;
+ void operator=( const action_input_impl& ) = delete;
[[nodiscard]] const auto* begin() const noexcept
{
- return m_begin.data;
+ return m_input.previous( m_saved );
}
- [[nodiscard]] const auto* current() const noexcept
+ [[nodiscard]] const auto* current( const std::size_t offset = 0 ) const noexcept
{
- return m_begin.data;
+ return m_input.previous( m_saved ) + offset;
}
[[nodiscard]] const auto* end() const noexcept
@@ -57,46 +60,13 @@ namespace TAO_PEGTL_NAMESPACE::internal
[[nodiscard]] std::size_t size() const noexcept
{
- return std::size_t( end() - m_begin.data );
+ return std::size_t( end() - begin() );
}
[[nodiscard]] std::string string() const
{
static_assert( sizeof( data_t ) == 1 );
- return std::string( static_cast< const char* >( m_begin.data ), size() );
- }
-
- [[nodiscard]] std::string_view string_view() const noexcept
- {
- static_assert( sizeof( data_t ) == 1 );
- return std::string_view( static_cast< const char* >( m_begin.data ), size() );
- }
-
- [[nodiscard]] data_t peek( const std::size_t offset = 0 ) const noexcept
- {
- return m_begin.data[ offset ];
- }
-
- template< typename T >
- [[nodiscard]] T peek_as( const std::size_t offset = 0 ) const noexcept
- {
- static_assert( sizeof( T ) == sizeof( data_t ) );
- return static_cast< T >( peek( offset ) );
- }
-
- [[nodiscard]] char peek_char( const std::size_t offset = 0 ) const noexcept
- {
- return peek_as< char >( offset );
- }
-
- [[nodiscard]] std::byte peek_byte( const std::size_t offset = 0 ) const noexcept
- {
- return peek_as< std::byte >( offset );
- }
-
- [[nodiscard]] std::uint8_t peek_uint8( const std::size_t offset = 0 ) const noexcept
- {
- return peek_as< std::uint8_t >( offset );
+ return std::string( static_cast< const char* >( begin() ), size() );
}
[[nodiscard]] const ParseInput& input() const noexcept
@@ -106,19 +76,27 @@ namespace TAO_PEGTL_NAMESPACE::internal
[[nodiscard]] decltype( auto ) current_position() const
{
- return m_input.previous_position( m_begin ); // NOTE: O(n) with lazy inputs -- n is return value!
+ return m_input.previous_position( m_saved ); // NOTE: O(n) with lazy inputs!
}
[[nodiscard]] const rewind_position_t& rewind_position() const noexcept
{
- return m_begin;
+ return m_saved;
+ }
+
+ [[nodiscard]] decltype( auto ) direct_source() const noexcept
+ {
+ return m_input.direct_source(); // Not all inputs have this.
}
protected:
- const rewind_position_t m_begin;
+ const rewind_position_t m_saved;
const ParseInput& m_input;
};
+ template< typename ParseInput >
+ using action_input = input_with_peeks< action_input_impl< ParseInput > >;
+
} // namespace TAO_PEGTL_NAMESPACE::internal
#endif
diff --git a/include/tao/pegtl/internal/any.hpp b/include/tao/pegtl/internal/any.hpp
index bc742d4d9..6eea218a6 100644
--- a/include/tao/pegtl/internal/any.hpp
+++ b/include/tao/pegtl/internal/any.hpp
@@ -5,12 +5,12 @@
#ifndef TAO_PEGTL_INTERNAL_ANY_HPP
#define TAO_PEGTL_INTERNAL_ANY_HPP
-#include "enable_control.hpp"
-#include "peek_char.hpp"
-
#include "../config.hpp"
#include "../type_list.hpp"
+#include "enable_control.hpp"
+#include "peek_direct.hpp"
+
namespace TAO_PEGTL_NAMESPACE::internal
{
template< typename Peek >
@@ -25,12 +25,7 @@ namespace TAO_PEGTL_NAMESPACE::internal
using rule_t = any;
using subs_t = empty_list;
- [[nodiscard]] static bool test_one( const char /*unused*/ ) noexcept
- {
- return true;
- }
-
- [[nodiscard]] static bool test_any( const char /*unused*/ ) noexcept
+ [[nodiscard]] static bool test( const char /*unused*/ ) noexcept
{
return true;
}
@@ -38,8 +33,10 @@ namespace TAO_PEGTL_NAMESPACE::internal
template< typename ParseInput >
[[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( in.empty() ) )
{
+ static_assert( sizeof( *in.current() ) == 1 );
+
if( !in.empty() ) {
- in.bump();
+ in.template consume< any >( 1 );
return true;
}
return false;
@@ -55,12 +52,7 @@ namespace TAO_PEGTL_NAMESPACE::internal
using rule_t = any;
using subs_t = empty_list;
- [[nodiscard]] static bool test_one( const data_t /*unused*/ ) noexcept
- {
- return true;
- }
-
- [[nodiscard]] static bool test_any( const data_t /*unused*/ ) noexcept
+ [[nodiscard]] static bool test( const data_t /*unused*/ ) noexcept
{
return true;
}
@@ -69,7 +61,7 @@ namespace TAO_PEGTL_NAMESPACE::internal
[[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( Peek::peek( in ) ) )
{
if( const auto t = Peek::peek( in ) ) {
- in.bump( t.size );
+ in.template consume< any >( t.size() );
return true;
}
return false;
diff --git a/include/tao/pegtl/internal/apply.hpp b/include/tao/pegtl/internal/apply.hpp
index 36877b66f..62971c68d 100644
--- a/include/tao/pegtl/internal/apply.hpp
+++ b/include/tao/pegtl/internal/apply.hpp
@@ -5,6 +5,7 @@
#ifndef TAO_PEGTL_INTERNAL_APPLY_HPP
#define TAO_PEGTL_INTERNAL_APPLY_HPP
+#include "action_input.hpp"
#include "apply_single.hpp"
#include "enable_control.hpp"
@@ -32,8 +33,7 @@ namespace TAO_PEGTL_NAMESPACE::internal
[[nodiscard]] static bool match( [[maybe_unused]] ParseInput& in, [[maybe_unused]] States&&... st )
{
if constexpr( ( A == apply_mode::action ) && ( sizeof...( Actions ) > 0 ) ) {
- using action_t = typename ParseInput::action_t;
- const action_t i2( in.rewind_position(), in ); // No data -- range is from begin to begin.
+ const action_input< ParseInput > i2( in.rewind_position(), in ); // No data -- range is from begin to begin.
return ( apply_single< Actions >::match( i2, st... ) && ... );
}
else {
diff --git a/include/tao/pegtl/internal/argv_input.hpp b/include/tao/pegtl/internal/argv_input.hpp
new file mode 100644
index 000000000..d6d055f53
--- /dev/null
+++ b/include/tao/pegtl/internal/argv_input.hpp
@@ -0,0 +1,27 @@
+// Copyright (c) 2014-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_ARGV_INPUT_HPP
+#define TAO_PEGTL_INTERNAL_ARGV_INPUT_HPP
+
+#include
+
+#include "../config.hpp"
+
+#include "view_input.hpp"
+
+namespace TAO_PEGTL_NAMESPACE::internal
+{
+ class argv_input
+ : public view_input< char >
+ {
+ public:
+ argv_input( char** argv, const int argn )
+ : view_input< char >( argv[ argn ], std::strlen( argv[ argn ] ) )
+ {}
+ };
+
+} // namespace TAO_PEGTL_NAMESPACE::internal
+
+#endif
diff --git a/include/tao/pegtl/internal/argv_input_with_source.hpp b/include/tao/pegtl/internal/argv_input_with_source.hpp
new file mode 100644
index 000000000..f1418ad2d
--- /dev/null
+++ b/include/tao/pegtl/internal/argv_input_with_source.hpp
@@ -0,0 +1,29 @@
+// Copyright (c) 2014-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_ARGV_INPUT_WITH_SOURCE_HPP
+#define TAO_PEGTL_INTERNAL_ARGV_INPUT_WITH_SOURCE_HPP
+
+#include
+
+#include "../config.hpp"
+
+#include "argv_input.hpp"
+#include "input_with_source.hpp"
+#include "stream_to_string.hpp"
+
+namespace TAO_PEGTL_NAMESPACE::internal
+{
+ class argv_input_with_source
+ : public input_with_source< std::string, argv_input >
+ {
+ public:
+ argv_input_with_source( char** argv, const int argn )
+ : input_with_source< std::string, argv_input >( stream_to_string( "argv[", argn, ']' ), argv, argn )
+ {}
+ };
+
+} // namespace TAO_PEGTL_NAMESPACE::internal
+
+#endif
diff --git a/include/tao/pegtl/internal/bof.hpp b/include/tao/pegtl/internal/bof.hpp
index 4bf5751ec..5e66b914e 100644
--- a/include/tao/pegtl/internal/bof.hpp
+++ b/include/tao/pegtl/internal/bof.hpp
@@ -5,11 +5,12 @@
#ifndef TAO_PEGTL_INTERNAL_BOF_HPP
#define TAO_PEGTL_INTERNAL_BOF_HPP
-#include "enable_control.hpp"
-
#include "../config.hpp"
#include "../type_list.hpp"
+#include "enable_control.hpp"
+#include "has_start.hpp"
+
namespace TAO_PEGTL_NAMESPACE::internal
{
struct bof
@@ -20,7 +21,12 @@ namespace TAO_PEGTL_NAMESPACE::internal
template< typename ParseInput >
[[nodiscard]] static bool match( ParseInput& in ) noexcept
{
- return in.byte() == 0;
+ if constexpr( has_start< ParseInput > ) {
+ return in.current() == in.start();
+ }
+ else {
+ return in.direct_position().count == 0;
+ }
}
};
diff --git a/include/tao/pegtl/internal/bol.hpp b/include/tao/pegtl/internal/bol.hpp
index 32ed3be87..fa567084e 100644
--- a/include/tao/pegtl/internal/bol.hpp
+++ b/include/tao/pegtl/internal/bol.hpp
@@ -20,7 +20,7 @@ namespace TAO_PEGTL_NAMESPACE::internal
template< typename ParseInput >
[[nodiscard]] static bool match( ParseInput& in ) noexcept
{
- return in.column() == 1;
+ return in.direct_position().column == 1;
}
};
diff --git a/include/tao/pegtl/internal/bump.hpp b/include/tao/pegtl/internal/bump.hpp
deleted file mode 100644
index c45360058..000000000
--- a/include/tao/pegtl/internal/bump.hpp
+++ /dev/null
@@ -1,46 +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)
-
-#ifndef TAO_PEGTL_INTERNAL_BUMP_HPP
-#define TAO_PEGTL_INTERNAL_BUMP_HPP
-
-#include "inputerator.hpp"
-
-#include "../config.hpp"
-
-namespace TAO_PEGTL_NAMESPACE::internal
-{
- inline void bump( large_position& iter, const std::size_t count, const int ch ) noexcept
- {
- for( std::size_t i = 0; i < count; ++i ) {
- if( iter.data[ i ] == ch ) {
- ++iter.line;
- iter.column = 1;
- }
- else {
- ++iter.column;
- }
- }
- iter.byte += count;
- iter.data += count;
- }
-
- inline void bump_in_this_line( large_position& iter, const std::size_t count ) noexcept
- {
- iter.data += count;
- iter.byte += count;
- iter.column += count;
- }
-
- inline void bump_to_next_line( large_position& iter, const std::size_t count ) noexcept
- {
- ++iter.line;
- iter.byte += count;
- iter.column = 1;
- iter.data += count;
- }
-
-} // namespace TAO_PEGTL_NAMESPACE::internal
-
-#endif
diff --git a/include/tao/pegtl/internal/bump_help.hpp b/include/tao/pegtl/internal/bump_help.hpp
deleted file mode 100644
index 483aa677e..000000000
--- a/include/tao/pegtl/internal/bump_help.hpp
+++ /dev/null
@@ -1,27 +0,0 @@
-// Copyright (c) 2015-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_BUMP_HELP_HPP
-#define TAO_PEGTL_INTERNAL_BUMP_HELP_HPP
-
-#include
-
-#include "../config.hpp"
-
-namespace TAO_PEGTL_NAMESPACE::internal
-{
- template< typename Rule, typename ParseInput >
- void bump_help( ParseInput& in, const std::size_t count )
- {
- if constexpr( Rule::test_any( '\n' ) ) {
- in.bump( count );
- }
- else {
- in.bump_in_this_line( count );
- }
- }
-
-} // namespace TAO_PEGTL_NAMESPACE::internal
-
-#endif
diff --git a/include/tao/pegtl/internal/bump_traits.hpp b/include/tao/pegtl/internal/bump_traits.hpp
new file mode 100644
index 000000000..430f0dd20
--- /dev/null
+++ b/include/tao/pegtl/internal/bump_traits.hpp
@@ -0,0 +1,90 @@
+// 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_BUMP_TRAITS_HPP
+#define TAO_PEGTL_INTERNAL_BUMP_TRAITS_HPP
+
+#include
+
+#include "../config.hpp"
+
+#include "any.hpp"
+#include "many.hpp"
+#include "text_eol_tags.hpp"
+
+namespace TAO_PEGTL_NAMESPACE::internal
+{
+ template< typename Eol, typename Rule, typename = void >
+ struct bump_traits
+ {
+ // template< typename Data, typename Position >
+ // static void bump( Position& pos, const Data* /*unused*/, const std::size_t count ) noexcept
+ // {
+ // pos.column += count;
+ // pos.count += count;
+ // }
+
+ template< typename Data, typename Position >
+ static void bump( Position& pos, const Data* data, const std::size_t count ) noexcept
+ {
+ text_eol_scan< Eol >( pos, data, data + count );
+ }
+ };
+
+ template< typename Eol >
+ struct bump_traits< Eol, eol_exclude_tag >
+ {
+ template< typename Data, typename Position >
+ static void bump( Position& pos, const Data* /*unused*/, const std::size_t count ) noexcept
+ {
+ pos.column += count;
+ pos.count += count;
+ }
+ };
+
+ template< typename Eol >
+ struct bump_traits< Eol, eol_matched_tag >
+ {
+ template< typename Data, typename Position >
+ static void bump( Position& pos, const Data* /*unused*/, const std::size_t count ) noexcept
+ {
+ pos.line++;
+ pos.column = 1; // TODO: Incrementing column while matching Eol is redundant!
+ pos.count += count;
+ }
+ };
+
+ template< typename Eol >
+ struct bump_traits< Eol, eol_unknown_tag >
+ {
+ template< typename Data, typename Position >
+ static void bump( Position& pos, const Data* data, const std::size_t count )
+ {
+ text_eol_scan< Eol >( pos, data, data + count );
+ }
+ };
+
+ template< typename Eol, typename Peek >
+ struct bump_traits< Eol, any< Peek > >
+ {
+ template< typename Data, typename Position >
+ static void bump( Position& pos, const Data* data, const std::size_t count )
+ {
+ text_eol_scan< Eol >( pos, data, data + count );
+ }
+ };
+
+ template< typename Eol, unsigned Count, typename Peek >
+ struct bump_traits< Eol, many< Count, Peek > >
+ {
+ template< typename Data, typename Position >
+ static void bump( Position& pos, const Data* data, const std::size_t count )
+ {
+ text_eol_scan< Eol >( pos, data, data + count );
+ }
+ };
+
+} // namespace TAO_PEGTL_NAMESPACE::internal
+
+#endif
diff --git a/include/tao/pegtl/internal/bytes.hpp b/include/tao/pegtl/internal/bytes.hpp
deleted file mode 100644
index b192d4d8a..000000000
--- a/include/tao/pegtl/internal/bytes.hpp
+++ /dev/null
@@ -1,43 +0,0 @@
-// Copyright (c) 2014-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_BYTES_HPP
-#define TAO_PEGTL_INTERNAL_BYTES_HPP
-
-#include "enable_control.hpp"
-#include "success.hpp"
-
-#include "../config.hpp"
-#include "../type_list.hpp"
-
-namespace TAO_PEGTL_NAMESPACE::internal
-{
- template< unsigned Cnt >
- struct bytes
- {
- using rule_t = bytes;
- using subs_t = empty_list;
-
- template< typename ParseInput >
- [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( in.size( 0 ) ) )
- {
- if( in.size( Cnt ) >= Cnt ) {
- in.bump( Cnt );
- return true;
- }
- return false;
- }
- };
-
- template<>
- struct bytes< 0 >
- : success
- {};
-
- template< unsigned Cnt >
- inline constexpr bool enable_control< bytes< Cnt > > = false;
-
-} // namespace TAO_PEGTL_NAMESPACE::internal
-
-#endif
diff --git a/include/tao/pegtl/internal/copy_input.hpp b/include/tao/pegtl/internal/copy_input.hpp
new file mode 100644
index 000000000..e86675228
--- /dev/null
+++ b/include/tao/pegtl/internal/copy_input.hpp
@@ -0,0 +1,143 @@
+// Copyright (c) 2014-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_COPY_INPUT_HPP
+#define TAO_PEGTL_INTERNAL_COPY_INPUT_HPP
+
+#include
+#include
+#include
+#include
+#include
+
+#include "../config.hpp"
+#include "../count_position.hpp"
+#include "../pointer_position.hpp"
+
+#include "rewind_guard.hpp"
+
+namespace TAO_PEGTL_NAMESPACE::internal
+{
+ template< typename Container = std::string >
+ class copy_input
+ {
+ public:
+ using data_t = typename Container::value_type;
+ using error_position_t = count_position;
+ using rewind_position_t = pointer_position< data_t >;
+
+ copy_input( const data_t* in_begin, const data_t* in_end )
+ : m_container( in_begin, in_end ),
+ m_current( m_container.data() )
+ {}
+
+ copy_input( const data_t* in_begin, const std::size_t in_size )
+ : copy_input( in_begin, in_begin + in_size )
+ {}
+
+ explicit copy_input( Container&& in_data ) noexcept
+ : m_container( std::move( in_data ) ),
+ m_current( m_container.data() )
+ {}
+
+ explicit copy_input( const Container& in_data )
+ : m_container( in_data ),
+ m_current( m_container.data() )
+ {}
+
+ template< std::size_t Size >
+ explicit copy_input( const std::array< data_t, Size >& in_array )
+ : copy_input( in_array.data(), in_array.size() )
+ {}
+
+ explicit copy_input( const std::initializer_list< data_t >& init )
+ : m_container( init ),
+ m_current( m_container.data() )
+ {}
+
+ [[nodiscard]] bool empty() const noexcept
+ {
+ return size() == 0;
+ }
+
+ [[nodiscard]] std::size_t size() const noexcept
+ {
+ return end() - current();
+ }
+
+ [[nodiscard]] const data_t* start() const noexcept
+ {
+ return m_container.data();
+ }
+
+ [[nodiscard]] const data_t* current( const std::size_t offset = 0 ) const noexcept
+ {
+ return m_current + offset;
+ }
+
+ [[nodiscard]] const data_t* previous( const rewind_position_t saved ) const noexcept
+ {
+ return saved.data;
+ }
+
+ [[nodiscard]] const data_t* end() const noexcept
+ {
+ return m_container.data() + m_container.size();
+ }
+
+ void restart() noexcept
+ {
+ m_current = m_container.data();
+ }
+
+ template< typename Rule >
+ void consume( const std::size_t count ) noexcept
+ {
+ m_current += count;
+ }
+
+ template< rewind_mode M >
+ [[nodiscard]] auto make_rewind_guard() noexcept
+ {
+ return rewind_guard< M, copy_input >( this ); // TODO: With C++23 "deducing this" we don't need to re-implement this in derived classes that change the rewind position.
+ }
+
+ [[nodiscard]] auto rewind_position() const noexcept
+ {
+ return rewind_position_t( m_current );
+ }
+
+ void rewind_to_position( const rewind_position_t saved ) noexcept
+ {
+ m_current = previous( saved );
+ }
+
+ [[nodiscard]] auto current_position() const noexcept
+ {
+ return previous_position( rewind_position() );
+ }
+
+ // [[nodiscard]] auto previous_position( const error_position_t saved ) const noexcept
+ // {
+ // return saved;
+ // }
+
+ [[nodiscard]] auto previous_position( const rewind_position_t saved ) const noexcept
+ {
+ return error_position_t( saved.data - m_container.data() );
+ }
+
+ void private_set_current( const data_t* in_current ) noexcept
+ {
+ m_current = in_current;
+ }
+
+ protected:
+ Container m_container;
+ const data_t* m_current;
+ };
+
+} // namespace TAO_PEGTL_NAMESPACE::internal
+
+#endif
diff --git a/include/tao/pegtl/internal/cstream_reader.hpp b/include/tao/pegtl/internal/cstream_reader.hpp
deleted file mode 100644
index ace1a07bb..000000000
--- a/include/tao/pegtl/internal/cstream_reader.hpp
+++ /dev/null
@@ -1,59 +0,0 @@
-// Copyright (c) 2016-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_CSTREAM_READER_HPP
-#define TAO_PEGTL_INTERNAL_CSTREAM_READER_HPP
-
-#include
-#include
-#include
-
-#if defined( __cpp_exceptions )
-#include
-#else
-#include
-#endif
-
-#include "../config.hpp"
-
-namespace TAO_PEGTL_NAMESPACE::internal
-{
- struct cstream_reader
- {
- explicit cstream_reader( std::FILE* s ) noexcept
- : m_cstream( s )
- {
- assert( m_cstream != nullptr );
- }
-
- [[nodiscard]] std::size_t operator()( char* buffer, const std::size_t length ) const
- {
- if( const auto r = std::fread( buffer, 1, length, m_cstream ) ) {
- return r;
- }
- if( std::feof( m_cstream ) != 0 ) {
- return 0;
- }
-
- // Please contact us if you know how to provoke the following exception.
- // The example on cppreference.com doesn't work, at least not on macOS.
-
- // LCOV_EXCL_START
-#if defined( __cpp_exceptions )
- const auto ec = std::ferror( m_cstream );
- assert( ec != 0 );
- throw std::system_error( ec, std::system_category(), "std::fread() failed" );
-#else
- std::fputs( "std::fread() failed\n", stderr );
- std::terminate();
-#endif
- // LCOV_EXCL_STOP
- }
-
- std::FILE* m_cstream;
- };
-
-} // namespace TAO_PEGTL_NAMESPACE::internal
-
-#endif
diff --git a/include/tao/pegtl/internal/cstring_reader.hpp b/include/tao/pegtl/internal/cstring_reader.hpp
deleted file mode 100644
index 4a680cd92..000000000
--- a/include/tao/pegtl/internal/cstring_reader.hpp
+++ /dev/null
@@ -1,41 +0,0 @@
-// Copyright (c) 2016-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_CSTRING_READER_HPP
-#define TAO_PEGTL_INTERNAL_CSTRING_READER_HPP
-
-#include
-#include
-
-#include "../config.hpp"
-
-namespace TAO_PEGTL_NAMESPACE::internal
-{
- struct cstring_reader
- {
- explicit cstring_reader( const char* zero_terminated ) noexcept
- : m_cstring( zero_terminated )
- {
- assert( m_cstring != nullptr );
- }
-
- [[nodiscard]] std::size_t operator()( char* buffer, const std::size_t length ) noexcept
- {
- std::size_t i = 0;
- char c;
-
- while( ( i < length ) && ( ( c = m_cstring[ i ] ) != 0 ) ) {
- *buffer++ = c;
- ++i;
- }
- m_cstring += i;
- return i;
- }
-
- const char* m_cstring;
- };
-
-} // namespace TAO_PEGTL_NAMESPACE::internal
-
-#endif
diff --git a/include/tao/pegtl/internal/data_and_size.hpp b/include/tao/pegtl/internal/data_and_size.hpp
index ee1cdfb64..d15430fe6 100644
--- a/include/tao/pegtl/internal/data_and_size.hpp
+++ b/include/tao/pegtl/internal/data_and_size.hpp
@@ -6,26 +6,84 @@
#define TAO_PEGTL_INTERNAL_DATA_AND_SIZE_HPP
#include
+#include
#include "../config.hpp"
namespace TAO_PEGTL_NAMESPACE::internal
{
- template< typename Data >
- struct data_and_size
+ template< typename Data, typename Size = std::uint8_t >
+ class data_and_size
{
- Data data;
- std::size_t size;
+ public:
+ static_assert( !std::is_pointer_v< Data > );
+ static_assert( !std::is_reference_v< Data > );
+ static_assert( !std::is_member_pointer_v< Data > );
+
+ data_and_size() noexcept = default;
- using data_t = Data;
+ data_and_size( const Data d, const Size s ) noexcept
+ : m_data( d ),
+ m_size( s )
+ {}
+
+ [[nodiscard]] Size size() const noexcept
+ {
+ return m_size;
+ }
+
+ [[nodiscard]] Data data() const noexcept
+ {
+ return m_data;
+ }
[[nodiscard]] explicit operator bool() const noexcept
{
- return size > 0;
+ return m_size > 0;
+ }
+
+ void mask_with( const Data mask ) noexcept
+ {
+ m_data &= mask;
}
+
+ private:
+ Data m_data;
+ Size m_size = 0;
};
- using bool_and_size = data_and_size< bool >;
+ template< typename Data >
+ class data_and_size< Data, void >
+ {
+ public:
+ static_assert( !std::is_pointer_v< Data > );
+ static_assert( !std::is_reference_v< Data > );
+ static_assert( !std::is_member_pointer_v< Data > );
+
+ data_and_size() noexcept = default;
+
+ explicit data_and_size( const Data* d ) noexcept
+ : m_data( d )
+ {}
+
+ [[nodiscard]] static std::size_t size() noexcept
+ {
+ return 1;
+ }
+
+ [[nodiscard]] const Data& data() const noexcept
+ {
+ return *m_data;
+ }
+
+ [[nodiscard]] explicit operator bool() const noexcept
+ {
+ return m_data != nullptr;
+ }
+
+ private:
+ const Data* m_data = nullptr;
+ };
} // namespace TAO_PEGTL_NAMESPACE::internal
diff --git a/include/tao/pegtl/internal/discard.hpp b/include/tao/pegtl/internal/discard.hpp
deleted file mode 100644
index fb609248e..000000000
--- a/include/tao/pegtl/internal/discard.hpp
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright (c) 2016-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_DISCARD_HPP
-#define TAO_PEGTL_INTERNAL_DISCARD_HPP
-
-#include "enable_control.hpp"
-
-#include "../config.hpp"
-#include "../type_list.hpp"
-
-namespace TAO_PEGTL_NAMESPACE::internal
-{
- struct discard
- {
- using rule_t = discard;
- using subs_t = empty_list;
-
- template< typename ParseInput >
- [[nodiscard]] static bool match( ParseInput& in ) noexcept
- {
- static_assert( noexcept( in.discard() ) );
- in.discard();
- return true;
- }
- };
-
- template<>
- inline constexpr bool enable_control< discard > = false;
-
-} // namespace TAO_PEGTL_NAMESPACE::internal
-
-#endif
diff --git a/include/tao/pegtl/internal/enable_control.hpp b/include/tao/pegtl/internal/enable_control.hpp
index 9650594b2..a442a359a 100644
--- a/include/tao/pegtl/internal/enable_control.hpp
+++ b/include/tao/pegtl/internal/enable_control.hpp
@@ -5,19 +5,10 @@
#ifndef TAO_PEGTL_INTERNAL_ENABLE_CONTROL_HPP
#define TAO_PEGTL_INTERNAL_ENABLE_CONTROL_HPP
-#include
-
#include "../config.hpp"
namespace TAO_PEGTL_NAMESPACE::internal
{
- // This class is a simple tagging mechanism.
- // By default, enable_control< Rule > is 'true'.
- // Each internal (!) rule that should be hidden
- // from the control and action class' callbacks
- // simply specializes enable_control<> to return
- // 'true' for the above expression.
-
template< typename Rule >
inline constexpr bool enable_control = true;
diff --git a/include/tao/pegtl/internal/endian.hpp b/include/tao/pegtl/internal/endian.hpp
new file mode 100644
index 000000000..56d17ef9b
--- /dev/null
+++ b/include/tao/pegtl/internal/endian.hpp
@@ -0,0 +1,50 @@
+// 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)
+
+#ifndef TAO_PEGTL_INTERNAL_ENDIAN_HPP
+#define TAO_PEGTL_INTERNAL_ENDIAN_HPP
+
+#include
+
+#include "../config.hpp"
+
+namespace TAO_PEGTL_NAMESPACE::internal
+{
+ struct big_endian
+ {
+ template< typename T >
+ [[nodiscard]] static T from( const T n ) noexcept;
+
+ template< typename T >
+ [[nodiscard]] static T from( const void* p ) noexcept
+ {
+ T n;
+ std::memcpy( &n, p, sizeof( n ) );
+ return from( n );
+ }
+ };
+
+ struct little_endian
+ {
+ template< typename T >
+ [[nodiscard]] static T from( const T n ) noexcept;
+
+ template< typename T >
+ [[nodiscard]] static T from( const void* p ) noexcept
+ {
+ T n;
+ std::memcpy( &n, p, sizeof( n ) );
+ return from( n );
+ }
+ };
+
+} // namespace TAO_PEGTL_NAMESPACE::internal
+
+#if defined( _WIN32 ) && !defined( __MINGW32__ ) && !defined( __CYGWIN__ )
+#include "endian_win.hpp"
+#else
+#include "endian_gcc.hpp"
+#endif
+
+#endif
diff --git a/include/tao/pegtl/internal/endian_gcc.hpp b/include/tao/pegtl/internal/endian_gcc.hpp
new file mode 100644
index 000000000..e64a7c707
--- /dev/null
+++ b/include/tao/pegtl/internal/endian_gcc.hpp
@@ -0,0 +1,101 @@
+// 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)
+
+#ifndef TAO_PEGTL_INTERNAL_ENDIAN_GCC_HPP
+#define TAO_PEGTL_INTERNAL_ENDIAN_GCC_HPP
+
+#include
+#include
+
+#include "../config.hpp"
+
+#include "dependent_false.hpp"
+
+namespace TAO_PEGTL_NAMESPACE::internal
+{
+#if !defined( __BYTE_ORDER__ )
+#error No byte order defined!
+#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+
+#define TAO_PEGTL_BIG_ENDIAN 1
+
+#define TAO_PEGTL_ENDIAN_SUFFIXED( iDeNTiFieR ) iDeNTiFieR ## be
+
+ template< typename T >
+ T big_endian::from( const T n ) noexcept
+ {
+ static_assert( std::is_integral_v< T > || std::is_enum_v< T > );
+ return n;
+ }
+
+ template< typename T >
+ T little_endian::from( const T n ) noexcept
+ {
+ static_assert( std::is_integral_v< T > || std::is_enum_v< T > );
+
+ if constexpr( sizeof( T ) == 1 ) {
+ return n;
+ }
+ else if constexpr( sizeof( T ) == 2 ) {
+ return static_cast< T >( __builtin_bswap16( static_cast< std::uint16_t >( n ) ) );
+ }
+ else if constexpr( sizeof( T ) == 4 ) {
+ return static_cast< T >( __builtin_bswap32( static_cast< std::uint32_t >( n ) ) );
+ }
+ else if constexpr( sizeof( T ) == 8 ) {
+ return static_cast< T >( __builtin_bswap64( static_cast< std::uint64_t >( n ) ) );
+ }
+ else {
+ static_assert( dependent_false< T > );
+ }
+ }
+
+ using other_endian = little_endian;
+ using native_endian = big_endian;
+
+#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+
+#define TAO_PEGTL_LITTLE_ENDIAN 1
+
+#define TAO_PEGTL_ENDIAN_SUFFIXED( iDeNTiFieR ) iDeNTiFieR ## le
+
+ template< typename T >
+ T little_endian::from( const T n ) noexcept
+ {
+ static_assert( std::is_integral_v< T > || std::is_enum_v< T > );
+ return n;
+ }
+
+ template< typename T >
+ T big_endian::from( const T n ) noexcept
+ {
+ static_assert( std::is_integral_v< T > || std::is_enum_v< T > );
+
+ if constexpr( sizeof( T ) == 1 ) {
+ return n;
+ }
+ else if constexpr( sizeof( T ) == 2 ) {
+ return static_cast< T >( __builtin_bswap16( static_cast< std::uint16_t >( n ) ) );
+ }
+ else if constexpr( sizeof( T ) == 4 ) {
+ return static_cast< T >( __builtin_bswap32( static_cast< std::uint32_t >( n ) ) );
+ }
+ else if constexpr( sizeof( T ) == 8 ) {
+ return static_cast< T >( __builtin_bswap64( static_cast< std::uint64_t >( n ) ) );
+ }
+ else {
+ static_assert( dependent_false< T > );
+ }
+ }
+
+ using other_endian = big_endian;
+ using native_endian = little_endian;
+
+#else
+#error Unknown byte order!
+#endif
+
+} // namespace TAO_PEGTL_NAMESPACE::internal
+
+#endif
diff --git a/include/tao/pegtl/internal/endian_win.hpp b/include/tao/pegtl/internal/endian_win.hpp
new file mode 100644
index 000000000..e0aadf3a5
--- /dev/null
+++ b/include/tao/pegtl/internal/endian_win.hpp
@@ -0,0 +1,55 @@
+// 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)
+
+#ifndef TAO_PEGTL_INTERNAL_ENDIAN_WIN_HPP
+#define TAO_PEGTL_INTERNAL_ENDIAN_WIN_HPP
+
+#include
+#include
+
+#include "../config.hpp"
+
+#include "dependent_false.hpp"
+
+namespace TAO_PEGTL_NAMESPACE::internal
+{
+ // Windows has never and will never do big endian?
+
+#define TAO_PEGTL_ENDIAN_SUFFIXED( iDeNTiFieR ) iDeNTiFieR ## le
+
+ template< typename T >
+ T little_endian::from( const T n ) noexcept
+ {
+ static_assert( std::is_integral_v< T > || std::is_enum_v< T > );
+ return n;
+ }
+
+ template< typename T >
+ T big_endian::from( const T n ) noexcept
+ {
+ static_assert( std::is_integral_v< T > || std::is_enum_v< T > );
+
+ if constexpr( sizeof( T ) == 1 ) {
+ return n;
+ }
+ else if constexpr( sizeof( T ) == 2 ) {
+ return static_cast< T >( _byteswap_ushort( static_cast< std::uint16_t >( n ) ) );
+ }
+ else if constexpr( sizeof( T ) == 4 ) {
+ return static_cast< T >( _byteswap_ulong( static_cast< std::uint32_t >( n ) ) );
+ }
+ else if constexpr( sizeof( T ) == 8 ) {
+ return static_cast< T >( _byteswap_uint64( static_cast< std::uint64_t >( n ) ) );
+ }
+ else {
+ static_assert( dependent_false< T > );
+ }
+ }
+
+ using other_endian = big_endian;
+ using native_endian = little_endian;
+
+} // namespace TAO_PEGTL_NAMESPACE::internal
+
+#endif
diff --git a/include/tao/pegtl/internal/enum_invert_bool.hpp b/include/tao/pegtl/internal/enum_invert_bool.hpp
new file mode 100644
index 000000000..3d3d130f0
--- /dev/null
+++ b/include/tao/pegtl/internal/enum_invert_bool.hpp
@@ -0,0 +1,25 @@
+// Copyright (c) 2014-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_ENUM_INVERT_BOOL_HPP
+#define TAO_PEGTL_INTERNAL_ENUM_INVERT_BOOL_HPP
+
+#include
+
+#include "../config.hpp"
+
+namespace TAO_PEGTL_NAMESPACE::internal
+{
+ template< typename Enum >
+ [[nodiscard]] constexpr Enum enum_invert_bool( const Enum e ) noexcept
+ {
+ static_assert( std::is_enum_v< Enum > );
+ static_assert( std::is_same_v< std::underlying_type_t< Enum >, bool > );
+
+ return Enum( !bool( e ) );
+ }
+
+} // namespace TAO_PEGTL_NAMESPACE::internal
+
+#endif
diff --git a/include/tao/pegtl/internal/eol.hpp b/include/tao/pegtl/internal/eol.hpp
index c6c6cb3ef..0cf130234 100644
--- a/include/tao/pegtl/internal/eol.hpp
+++ b/include/tao/pegtl/internal/eol.hpp
@@ -5,17 +5,20 @@
#ifndef TAO_PEGTL_INTERNAL_EOL_HPP
#define TAO_PEGTL_INTERNAL_EOL_HPP
+#include "../apply_mode.hpp"
#include "../config.hpp"
+#include "../rewind_mode.hpp"
#include "../type_list.hpp"
#include "enable_control.hpp"
+#include "text_eol_tags.hpp"
namespace TAO_PEGTL_NAMESPACE::internal
{
struct eol
{
using rule_t = eol;
- using subs_t = empty_list;
+ using subs_t = empty_list; // Should be eol_rule, but we don't know that here yet...
template< apply_mode A,
rewind_mode M,
@@ -27,7 +30,12 @@ namespace TAO_PEGTL_NAMESPACE::internal
typename... States >
[[nodiscard]] static bool match( ParseInput& in, States&&... st )
{
- return in.template match_eol< A, M, Action, Control >( in, st... );
+ using eol_rule = typename ParseInput::eol_rule;
+ if( Control< typename eol_rule::rule_t >::template match< A, M, Action, Control >( in, st... ) ) {
+ // in.template consume< eol_matched_tag >( 0 ); // TODO: Can we optimise the above line to not perform position updates and do this instead?
+ return true;
+ }
+ return false;
}
};
diff --git a/include/tao/pegtl/internal/eolf.hpp b/include/tao/pegtl/internal/eolf.hpp
index f78fc0c96..a80597202 100644
--- a/include/tao/pegtl/internal/eolf.hpp
+++ b/include/tao/pegtl/internal/eolf.hpp
@@ -9,6 +9,7 @@
#include "../type_list.hpp"
#include "enable_control.hpp"
+#include "eol.hpp"
namespace TAO_PEGTL_NAMESPACE::internal
{
@@ -27,7 +28,7 @@ namespace TAO_PEGTL_NAMESPACE::internal
typename... States >
[[nodiscard]] static bool match( ParseInput& in, States&&... st )
{
- return in.empty() || in.template match_eol< A, M, Action, Control >( in, st... );
+ return in.empty() || eol::match< A, M, Action, Control >( in, st... );
}
};
diff --git a/include/tao/pegtl/internal/everything.hpp b/include/tao/pegtl/internal/everything.hpp
index b3e9dd960..f82f87417 100644
--- a/include/tao/pegtl/internal/everything.hpp
+++ b/include/tao/pegtl/internal/everything.hpp
@@ -19,9 +19,9 @@ namespace TAO_PEGTL_NAMESPACE::internal
using subs_t = empty_list;
template< typename ParseInput >
- [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( in.size( 0 ) ) )
+ [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( in.size( 42 ) ) )
{
- in.bump( in.size( Size( -1 ) ) );
+ in.template consume< everything >( in.size( Size( -1 ) ) );
return true;
}
};
diff --git a/include/tao/pegtl/internal/file_input.hpp b/include/tao/pegtl/internal/file_input.hpp
new file mode 100644
index 000000000..de6a8b067
--- /dev/null
+++ b/include/tao/pegtl/internal/file_input.hpp
@@ -0,0 +1,43 @@
+// Copyright (c) 2014-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_FILE_INPUT_HPP
+#define TAO_PEGTL_INTERNAL_FILE_INPUT_HPP
+
+#include "../config.hpp"
+
+#include "mmap_file_base.hpp"
+
+#if defined( TAO_PEGTL_MMAP_AVAILABLE )
+
+#include "mmap_input.hpp"
+
+namespace TAO_PEGTL_NAMESPACE::internal
+{
+ class file_input
+ : public mmap_input< char >
+ {
+ public:
+ using mmap_input< char >::mmap_input;
+ };
+
+} // namespace TAO_PEGTL_NAMESPACE::internal
+
+#else
+
+#include "read_input.hpp"
+
+namespace TAO_PEGTL_NAMESPACE::internal
+{
+ class file_input
+ : public read_input
+ {
+ public:
+ using read_input::read_input;
+ };
+
+} // namespace TAO_PEGTL_NAMESPACE::internal
+
+#endif
+#endif
diff --git a/include/tao/pegtl/internal/file_input_with_source.hpp b/include/tao/pegtl/internal/file_input_with_source.hpp
new file mode 100644
index 000000000..fbcc4e138
--- /dev/null
+++ b/include/tao/pegtl/internal/file_input_with_source.hpp
@@ -0,0 +1,60 @@
+// Copyright (c) 2021-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_FILE_INPUT_WITH_SOURCE_HPP
+#define TAO_PEGTL_INTERNAL_FILE_INPUT_WITH_SOURCE_HPP
+
+#include
+#include
+
+#include "../config.hpp"
+#include "../position_with_source.hpp"
+
+#include "file_input.hpp"
+
+namespace TAO_PEGTL_NAMESPACE::internal
+{
+ class file_input_with_source
+ : public file_input
+ {
+ public:
+ using base_t = file_input;
+ using data_t = file_input::data_t;
+ using error_position_t = position_with_source< std::filesystem::path, file_input::error_position_t >;
+ using rewind_position_t = file_input::rewind_position_t;
+
+ template< typename... Ts >
+ explicit file_input_with_source( std::filesystem::path&& s, Ts&&... ts )
+ : file_input( static_cast< const std::filesystem::path& >( s ), std::forward< Ts >( ts )... ),
+ m_source( std::move( s ) )
+ {}
+
+ template< typename... Ts >
+ explicit file_input_with_source( const std::filesystem::path& s, Ts&&... ts )
+ : file_input( s, std::forward< Ts >( ts )... ),
+ m_source( s )
+ {}
+
+ [[nodiscard]] auto current_position() const
+ {
+ return error_position_t( m_source, file_input::current_position() );
+ }
+
+ [[nodiscard]] auto previous_position( const rewind_position_t& saved ) const
+ {
+ return error_position_t( m_source, file_input::previous_position( saved ) );
+ }
+
+ [[nodiscard]] const std::filesystem::path& direct_source() const noexcept
+ {
+ return m_source;
+ }
+
+ protected:
+ std::filesystem::path m_source;
+ };
+
+} // namespace TAO_PEGTL_NAMESPACE::internal
+
+#endif
diff --git a/include/tao/pegtl/internal/file_text_input_with_source.hpp b/include/tao/pegtl/internal/file_text_input_with_source.hpp
new file mode 100644
index 000000000..a53eff469
--- /dev/null
+++ b/include/tao/pegtl/internal/file_text_input_with_source.hpp
@@ -0,0 +1,72 @@
+// Copyright (c) 2021-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_FILE_INPUT_WITH_SOURCE_HPP
+#define TAO_PEGTL_INTERNAL_FILE_INPUT_WITH_SOURCE_HPP
+
+#include
+
+#include "../config.hpp"
+#include "../position_with_source.hpp"
+
+namespace TAO_PEGTL_NAMESPACE::internal
+{
+ template< typename Source, typename Input >
+ class file_input_with_source
+ : public Input
+ {
+ public:
+ using base_t = Input;
+ using data_t = typename Input::data_t;
+ using error_position_t = position_with_source< Source, typename Input::error_position_t >;
+ using rewind_position_t = typename Input::rewind_position_t;
+#error
+ template< typename S, typename... Ts >
+ file_input_with_source( S&& s, Ts&&... ts )
+ : m_source( std::forward< S >( s ) ),
+ Input( std::forward< Ts >( ts )... )
+ {}
+
+ [[nodiscard]] const auto& current_position() const noexcept
+ {
+ return m_position;
+ }
+
+ [[nodiscard]] const auto& previous_position( const rewind_position_t& saved ) const
+ {
+ return saved;
+ }
+
+ [[nodiscard]] std::size_t direct_count() const noexcept // TODO: Keep?
+ {
+ return m_position.count;
+ }
+
+ [[nodiscard]] std::size_t direct_line() const noexcept // TODO: Keep?
+ {
+ return m_position.line;
+ }
+
+ [[nodiscard]] std::size_t direct_column() const noexcept // TODO: Keep?
+ {
+ return m_position.column;
+ }
+
+ [[nodiscard]] const Source& direct_source() const noexcept // TODO: Keep?
+ {
+ return m_source;
+ }
+
+ [[nodiscard]] const auto& direct_position() const noexcept
+ {
+ return m_position;
+ }
+
+ protected:
+ error_position_t m_position;
+ };
+
+} // namespace TAO_PEGTL_NAMESPACE::internal
+
+#endif
diff --git a/include/tao/pegtl/internal/has_eol_rule.hpp b/include/tao/pegtl/internal/has_eol_rule.hpp
new file mode 100644
index 000000000..9722cc933
--- /dev/null
+++ b/include/tao/pegtl/internal/has_eol_rule.hpp
@@ -0,0 +1,25 @@
+// 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_HAS_EOL_RULE_HPP
+#define TAO_PEGTL_INTERNAL_HAS_EOL_RULE_HPP
+
+#include
+
+#include "../config.hpp"
+
+namespace TAO_PEGTL_NAMESPACE::internal
+{
+ template< typename Input >
+ using has_eol_rule_impl = typename Input::eol_rule;
+
+ template< typename, typename = void >
+ inline constexpr bool has_eol_rule = false;
+
+ template< typename Input >
+ inline constexpr bool has_eol_rule< Input, std::void_t< has_eol_rule_impl< Input > > > = true;
+
+} // namespace TAO_PEGTL_NAMESPACE::internal
+
+#endif
diff --git a/include/tao/pegtl/internal/has_start.hpp b/include/tao/pegtl/internal/has_start.hpp
new file mode 100644
index 000000000..12eb69210
--- /dev/null
+++ b/include/tao/pegtl/internal/has_start.hpp
@@ -0,0 +1,22 @@
+// 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_HAS_START_HPP
+#define TAO_PEGTL_INTERNAL_HAS_START_HPP
+
+#include
+
+#include "../config.hpp"
+
+namespace TAO_PEGTL_NAMESPACE::internal
+{
+ template< typename Input, typename = void >
+ inline constexpr bool has_start = false;
+
+ template< typename Input >
+ inline constexpr bool has_start< Input, decltype( (void)std::declval< Input >().start() ) > = true;
+
+} // namespace TAO_PEGTL_NAMESPACE::internal
+
+#endif
diff --git a/include/tao/pegtl/internal/identifier.hpp b/include/tao/pegtl/internal/identifier.hpp
index 6dc90a6fc..87e66c6ac 100644
--- a/include/tao/pegtl/internal/identifier.hpp
+++ b/include/tao/pegtl/internal/identifier.hpp
@@ -5,13 +5,13 @@
#ifndef TAO_PEGTL_INTERNAL_IDENTIFIER_HPP
#define TAO_PEGTL_INTERNAL_IDENTIFIER_HPP
-#include "peek_char.hpp"
+#include "../config.hpp"
+
+#include "peek_direct.hpp"
#include "ranges.hpp"
#include "seq.hpp"
#include "star.hpp"
-#include "../config.hpp"
-
namespace TAO_PEGTL_NAMESPACE::internal
{
using identifier_first = ranges< peek_char, 'a', 'z', 'A', 'Z', '_' >;
diff --git a/include/tao/pegtl/internal/if_apply.hpp b/include/tao/pegtl/internal/if_apply.hpp
index 8e3745a3a..621d3f4b3 100644
--- a/include/tao/pegtl/internal/if_apply.hpp
+++ b/include/tao/pegtl/internal/if_apply.hpp
@@ -5,6 +5,7 @@
#ifndef TAO_PEGTL_INTERNAL_IF_APPLY_HPP
#define TAO_PEGTL_INTERNAL_IF_APPLY_HPP
+#include "action_input.hpp"
#include "apply_single.hpp"
#include "enable_control.hpp"
@@ -32,10 +33,9 @@ namespace TAO_PEGTL_NAMESPACE::internal
[[nodiscard]] static bool match( ParseInput& in, States&&... st )
{
if constexpr( ( A == apply_mode::action ) && ( sizeof...( Actions ) != 0 ) ) {
- using action_t = typename ParseInput::action_t;
auto m = in.template make_rewind_guard< rewind_mode::required >();
if( Control< Rule >::template match< apply_mode::action, rewind_mode::optional, Action, Control >( in, st... ) ) {
- const action_t i2( m.rewind_position(), in );
+ const action_input< ParseInput > i2( m.rewind_position(), in );
return m( ( apply_single< Actions >::match( i2, st... ) && ... ) );
}
return false;
diff --git a/include/tao/pegtl/internal/input_with_fakes.hpp b/include/tao/pegtl/internal/input_with_fakes.hpp
new file mode 100644
index 000000000..3f49a2839
--- /dev/null
+++ b/include/tao/pegtl/internal/input_with_fakes.hpp
@@ -0,0 +1,48 @@
+// Copyright (c) 2021-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_INPUT_WITH_FAKES_HPP
+#define TAO_PEGTL_INTERNAL_INPUT_WITH_FAKES_HPP
+
+#include
+#include
+
+#include "../config.hpp"
+
+namespace TAO_PEGTL_NAMESPACE::internal
+{
+ template< typename Input >
+ class input_with_fakes
+ : public Input
+ {
+ public:
+ using Input::Input;
+
+ [[nodiscard]] decltype( auto ) end( const std::size_t /*unused*/ = 0 ) const noexcept( noexcept( std::declval< Input >().size() ) )
+ {
+ return Input::end();
+ }
+
+ [[nodiscard]] std::size_t size( const std::size_t /*unused*/ = 0 ) const noexcept( noexcept( std::declval< Input >().size() ) )
+ {
+ return Input::size();
+ }
+
+ // [[nodiscard]] std::size_t size( const std::size_t /*unused*/, const std::size_t /*unused*/ ) noexcept( noexcept( std::declval< Input >().size() ) )
+ // {
+ // return Input::size();
+ // }
+
+ void require( const std::size_t /*unused*/ ) noexcept
+ {}
+
+ void discard() noexcept
+ {}
+
+ // The buffer_foo() member functions are only for actual buffer inputs.
+ };
+
+} // namespace TAO_PEGTL_NAMESPACE::internal
+
+#endif
diff --git a/include/tao/pegtl/internal/input_with_lines.hpp b/include/tao/pegtl/internal/input_with_lines.hpp
new file mode 100644
index 000000000..0b40954ac
--- /dev/null
+++ b/include/tao/pegtl/internal/input_with_lines.hpp
@@ -0,0 +1,32 @@
+// Copyright (c) 2021-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_INPUT_WITH_LINES_HPP
+#define TAO_PEGTL_INTERNAL_INPUT_WITH_LINES_HPP
+
+#include "../config.hpp"
+
+namespace TAO_PEGTL_NAMESPACE::internal
+{
+ template< typename Eol, typename Input >
+ class input_with_lines
+ : public Input
+ {
+ public:
+ using eol_rule = Eol;
+
+ using Input::Input;
+ };
+
+ template< typename Input >
+ class input_with_lines< void, Input >
+ : public Input
+ {
+ public:
+ using Input::Input;
+ };
+
+} // namespace TAO_PEGTL_NAMESPACE::internal
+
+#endif
diff --git a/include/tao/pegtl/internal/input_with_peeks.hpp b/include/tao/pegtl/internal/input_with_peeks.hpp
new file mode 100644
index 000000000..184c6c6bc
--- /dev/null
+++ b/include/tao/pegtl/internal/input_with_peeks.hpp
@@ -0,0 +1,80 @@
+// Copyright (c) 2021-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_INPUT_WITH_PEEKS_HPP
+#define TAO_PEGTL_INTERNAL_INPUT_WITH_PEEKS_HPP
+
+#include
+#include
+#include
+#include
+
+#include "../config.hpp"
+
+namespace TAO_PEGTL_NAMESPACE::internal
+{
+ template< typename Input >
+ class input_with_peeks
+ : public Input
+ {
+ public:
+ using Input::Input;
+
+ using data_t = typename Input::data_t;
+
+ [[nodiscard]] const data_t& peek( const std::size_t offset = 0 ) const noexcept
+ {
+ return *this->current( offset );
+ }
+
+ template< typename T >
+ [[nodiscard]] T peek_as( const std::size_t offset = 0 ) const noexcept
+ {
+ static_assert( sizeof( T ) == sizeof( data_t ) );
+ return static_cast< T >( *this->current( offset ) );
+ }
+
+ [[nodiscard]] char peek_char( const std::size_t offset = 0 ) const noexcept
+ {
+ return peek_as< char >( offset );
+ }
+
+ [[nodiscard]] std::byte peek_byte( const std::size_t offset = 0 ) const noexcept
+ {
+ return peek_as< std::byte >( offset );
+ }
+
+ [[nodiscard]] std::int8_t peek_int8( const std::size_t offset = 0 ) const noexcept
+ {
+ return peek_as< std::int8_t >( offset );
+ }
+
+ [[nodiscard]] std::uint8_t peek_uint8( const std::size_t offset = 0 ) const noexcept
+ {
+ return peek_as< std::uint8_t >( offset );
+ }
+
+ // [[nodiscard]] std::span< data_t > span() const noexcept
+
+ [[nodiscard]] std::string string() const
+ {
+ static_assert( sizeof( char ) == sizeof( data_t ) );
+ return std::string( static_cast< const char* >( this->current() ), this->size() );
+ }
+
+ [[nodiscard]] std::string_view string_view() const noexcept
+ {
+ static_assert( sizeof( char ) == sizeof( data_t ) );
+ return std::string_view( static_cast< const char* >( this->current() ), this->size() );
+ }
+
+ [[nodiscard]] std::vector< data_t > vector() const
+ {
+ return std::vector< data_t >( this->current(), this->current() + this->size() );
+ }
+ };
+
+} // namespace TAO_PEGTL_NAMESPACE::internal
+
+#endif
diff --git a/include/tao/pegtl/internal/input_with_source.hpp b/include/tao/pegtl/internal/input_with_source.hpp
new file mode 100644
index 000000000..6f89ed5f6
--- /dev/null
+++ b/include/tao/pegtl/internal/input_with_source.hpp
@@ -0,0 +1,52 @@
+// Copyright (c) 2021-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_INPUT_WITH_SOURCE_HPP
+#define TAO_PEGTL_INTERNAL_INPUT_WITH_SOURCE_HPP
+
+#include
+
+#include "../config.hpp"
+#include "../position_with_source.hpp"
+
+namespace TAO_PEGTL_NAMESPACE::internal
+{
+ template< typename Source, typename Input >
+ class input_with_source
+ : public Input
+ {
+ public:
+ using base_t = Input;
+ using data_t = typename Input::data_t;
+ using error_position_t = position_with_source< Source, typename Input::error_position_t >;
+ using rewind_position_t = typename Input::rewind_position_t;
+
+ template< typename S, typename... Ts >
+ explicit input_with_source( S&& s, Ts&&... ts )
+ : Input( std::forward< Ts >( ts )... ),
+ m_source( std::forward< S >( s ) )
+ {}
+
+ [[nodiscard]] auto current_position() const
+ {
+ return error_position_t( m_source, Input::current_position() );
+ }
+
+ [[nodiscard]] auto previous_position( const rewind_position_t& saved ) const
+ {
+ return error_position_t( m_source, Input::previous_position( saved ) );
+ }
+
+ [[nodiscard]] const Source& direct_source() const noexcept
+ {
+ return m_source;
+ }
+
+ protected:
+ Source m_source;
+ };
+
+} // namespace TAO_PEGTL_NAMESPACE::internal
+
+#endif
diff --git a/include/tao/pegtl/internal/input_with_start.hpp b/include/tao/pegtl/internal/input_with_start.hpp
new file mode 100644
index 000000000..038fef74a
--- /dev/null
+++ b/include/tao/pegtl/internal/input_with_start.hpp
@@ -0,0 +1,65 @@
+// Copyright (c) 2021-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_INPUT_WITH_START_HPP
+#define TAO_PEGTL_INTERNAL_INPUT_WITH_START_HPP
+
+#include
+#include
+
+#include "../config.hpp"
+#include "../count_position.hpp"
+
+#include "view_input.hpp"
+
+namespace TAO_PEGTL_NAMESPACE::internal
+{
+ template< typename Data = char >
+ class input_with_start
+ : public view_input< Data >
+ {
+ public:
+ using base_t = view_input< Data >;
+ using data_t = Data;
+ 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 )... ),
+ m_start( this->current() )
+ {}
+
+ [[nodiscard]] const data_t* start() const noexcept
+ {
+ return m_start;
+ }
+
+ void restart() noexcept
+ {
+ this->m_current = m_start;
+ }
+
+ [[nodiscard]] auto current_position() const noexcept
+ {
+ return previous_position( this->rewind_position() );
+ }
+
+ // [[nodiscard]] auto previous_position( const error_position_t saved ) const noexcept
+ // {
+ // return saved;
+ // }
+
+ [[nodiscard]] auto previous_position( const rewind_position_t saved ) const noexcept
+ {
+ return count_position( saved.data - m_start );
+ }
+
+ protected:
+ const data_t* m_start;
+ };
+
+} // TAO_PEGTL_NAMESPACE::internal
+
+#endif
diff --git a/include/tao/pegtl/internal/inputerator.hpp b/include/tao/pegtl/internal/inputerator.hpp
deleted file mode 100644
index 132d0b2d9..000000000
--- a/include/tao/pegtl/internal/inputerator.hpp
+++ /dev/null
@@ -1,76 +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)
-
-#ifndef TAO_PEGTL_INTERNAL_INPUTERATOR_HPP
-#define TAO_PEGTL_INTERNAL_INPUTERATOR_HPP
-
-#include
-#include
-
-#include "../config.hpp"
-
-namespace TAO_PEGTL_NAMESPACE::internal
-{
- template< typename T >
- struct basic_small_position
- {
- basic_small_position() noexcept = default;
-
- explicit basic_small_position( const T* in_data ) noexcept
- : data( in_data )
- {}
-
- basic_small_position( basic_small_position&& ) noexcept = default;
- basic_small_position( const basic_small_position& ) noexcept = default;
-
- ~basic_small_position() = default;
-
- basic_small_position& operator=( basic_small_position&& ) noexcept = default;
- basic_small_position& operator=( const basic_small_position& ) noexcept = default;
-
- const T* data = nullptr;
- };
-
- using small_position = basic_small_position< char >;
-
- struct large_position
- {
- large_position() noexcept = default;
-
- explicit large_position( const char* in_data ) noexcept
- : data( in_data )
- {}
-
- explicit large_position( const small_position& in_small ) noexcept
- : large_position( in_small.data )
- {}
-
- large_position( const char* in_data, const std::size_t in_byte, const std::size_t in_line, const std::size_t in_column ) noexcept
- : data( in_data ),
- byte( in_byte ),
- line( in_line ),
- column( in_column )
- {
- assert( in_line != 0 );
- assert( in_column != 0 );
- }
-
- large_position( large_position&& ) noexcept = default;
- large_position( const large_position& ) noexcept = default;
-
- ~large_position() = default;
-
- large_position& operator=( large_position&& ) noexcept = default;
- large_position& operator=( const large_position& ) noexcept = default;
-
- const char* data = nullptr;
-
- std::size_t byte = 0;
- std::size_t line = 1;
- std::size_t column = 1;
- };
-
-} // namespace TAO_PEGTL_NAMESPACE::internal
-
-#endif
diff --git a/include/tao/pegtl/internal/inputs.hpp b/include/tao/pegtl/internal/inputs.hpp
new file mode 100644
index 000000000..8c12e7265
--- /dev/null
+++ b/include/tao/pegtl/internal/inputs.hpp
@@ -0,0 +1,30 @@
+// Copyright (c) 2021-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_INPUTS_HPP
+#define TAO_PEGTL_INTERNAL_INPUTS_HPP
+
+#include "argv_input.hpp"
+#include "copy_input.hpp"
+#include "file_input.hpp"
+#include "lazy_input.hpp"
+#include "read_input.hpp"
+#include "text_input.hpp"
+#include "view_input.hpp"
+
+#include "input_with_fakes.hpp"
+#include "input_with_lines.hpp"
+#include "input_with_peeks.hpp"
+#include "input_with_source.hpp"
+#include "input_with_start.hpp"
+
+#include "argv_input_with_source.hpp"
+#include "file_input_with_source.hpp"
+#include "lazy_input_with_source.hpp"
+#include "text_input_with_source.hpp"
+
+#include "lazy_file_input_with_source.hpp"
+#include "text_file_input_with_source.hpp"
+
+#endif
diff --git a/include/tao/pegtl/internal/istream_reader.hpp b/include/tao/pegtl/internal/istream_reader.hpp
deleted file mode 100644
index 8c4356e7b..000000000
--- a/include/tao/pegtl/internal/istream_reader.hpp
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright (c) 2016-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_ISTREAM_READER_HPP
-#define TAO_PEGTL_INTERNAL_ISTREAM_READER_HPP
-
-#include
-
-#if defined( __cpp_exceptions )
-#include
-#else
-#include
-#include
-#endif
-
-#include "../config.hpp"
-
-namespace TAO_PEGTL_NAMESPACE::internal
-{
- struct istream_reader
- {
- explicit istream_reader( std::istream& s ) noexcept
- : m_istream( s )
- {}
-
- [[nodiscard]] std::size_t operator()( char* buffer, const std::size_t length )
- {
- m_istream.read( buffer, static_cast< std::streamsize >( length ) );
-
- if( const auto r = m_istream.gcount() ) {
- return static_cast< std::size_t >( r );
- }
- if( m_istream.eof() ) {
- return 0;
- }
-#if defined( __cpp_exceptions )
- const auto ec = errno;
- throw std::system_error( ec, std::system_category(), "std::istream::read() failed" );
-#else
- std::fputs( "std::istream::read() failed\n", stderr );
- std::terminate();
-#endif
- }
-
- std::istream& m_istream;
- };
-
-} // namespace TAO_PEGTL_NAMESPACE::internal
-
-#endif
diff --git a/include/tao/pegtl/internal/istring.hpp b/include/tao/pegtl/internal/istring.hpp
index 3fafca2e9..eccd34dbd 100644
--- a/include/tao/pegtl/internal/istring.hpp
+++ b/include/tao/pegtl/internal/istring.hpp
@@ -7,7 +7,6 @@
#include
-#include "bump_help.hpp"
#include "enable_control.hpp"
#include "one.hpp"
#include "result_on_found.hpp"
@@ -57,23 +56,12 @@ namespace TAO_PEGTL_NAMESPACE::internal
using rule_t = istring;
using subs_t = empty_list;
- [[nodiscard]] static constexpr bool test_one( const char c ) noexcept
- {
- static_assert( sizeof...( Cs ) == 1 );
- return one< result_on_found::success, peek_char, Cs... >::test_one( c );
- }
-
- [[nodiscard]] static constexpr bool test_any( const char c ) noexcept
- {
- return one< result_on_found::success, peek_char, Cs... >::test_one( c );
- }
-
template< typename ParseInput >
- [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( in.size( 0 ) ) )
+ [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( in.size( 42 ) ) )
{
if( in.size( sizeof...( Cs ) ) >= sizeof...( Cs ) ) {
if( istring_equal< Cs... >( in.current() ) ) {
- bump_help< istring >( in, sizeof...( Cs ) );
+ in.template consume< istring >( sizeof...( Cs ) );
return true;
}
}
diff --git a/include/tao/pegtl/internal/lazy_file_input_with_source.hpp b/include/tao/pegtl/internal/lazy_file_input_with_source.hpp
new file mode 100644
index 000000000..1fedb7ec1
--- /dev/null
+++ b/include/tao/pegtl/internal/lazy_file_input_with_source.hpp
@@ -0,0 +1,45 @@
+// Copyright (c) 2021-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_LAZY_FILE_INPUT_WITH_SOURCE_HPP
+#define TAO_PEGTL_INTERNAL_LAZY_FILE_INPUT_WITH_SOURCE_HPP
+
+#include
+#include
+
+#include "../config.hpp"
+#include "../position_with_source.hpp"
+
+#include "file_input.hpp"
+#include "input_with_lines.hpp"
+#include "lazy_input_with_source.hpp"
+
+namespace TAO_PEGTL_NAMESPACE::internal
+{
+ template< typename Eol, typename Input = lazy_input_with_source< Eol, std::filesystem::path, file_input > >
+ class lazy_file_input_with_source
+ : public Input
+ {
+ public:
+ using base_t = Input;
+ using data_t = typename Input::data_t;
+ using error_position_t = typename Input::error_position_t;
+ using rewind_position_t = typename Input::rewind_position_t;
+
+ using eol_rule = Eol;
+
+ template< typename... Ts >
+ explicit lazy_file_input_with_source( std::filesystem::path&& s, Ts&&... ts )
+ : Input( std::move( s ), static_cast< const std::filesystem::path& >( s ), std::forward< Ts >( ts )... )
+ {}
+
+ template< typename... Ts >
+ explicit lazy_file_input_with_source( const std::filesystem::path& s, Ts&&... ts )
+ : Input( s, s, std::forward< Ts >( ts )... )
+ {}
+ };
+
+} // namespace TAO_PEGTL_NAMESPACE::internal
+
+#endif
diff --git a/include/tao/pegtl/internal/lazy_input.hpp b/include/tao/pegtl/internal/lazy_input.hpp
new file mode 100644
index 000000000..bec57af0e
--- /dev/null
+++ b/include/tao/pegtl/internal/lazy_input.hpp
@@ -0,0 +1,53 @@
+// Copyright (c) 2021-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_LAZY_INPUT_HPP
+#define TAO_PEGTL_INTERNAL_LAZY_INPUT_HPP
+
+#include
+
+#include "../apply_mode.hpp"
+#include "../config.hpp"
+#include "../normal.hpp"
+#include "../nothing.hpp"
+#include "../rewind_mode.hpp"
+#include "../text_position.hpp"
+
+#include "input_with_lines.hpp"
+#include "rewind_adapt.hpp"
+#include "text_eol_scan.hpp"
+
+namespace TAO_PEGTL_NAMESPACE::internal
+{
+ template< typename Eol, typename Input >
+ class lazy_input
+ : public input_with_lines< Eol, Input >
+ {
+ public:
+ using base_t = input_with_lines< Eol, Input >;
+ using data_t = typename Input::data_t;
+ using error_position_t = text_position;
+ using rewind_position_t = typename Input::rewind_position_t;
+
+ using eol_rule = Eol;
+
+ using input_with_lines< Eol, Input >::input_with_lines;
+
+ [[nodiscard]] auto current_position() const
+ {
+ return previous_position( this->rewind_position() );
+ }
+
+ [[nodiscard]] auto previous_position( const rewind_position_t saved ) const
+ {
+ error_position_t pos;
+ text_eol_scan< Eol >( pos, this->start(), rewind_adapt( this->start(), saved ) );
+ pos.count = rewind_adapt( this->start(), saved ) - this->start();
+ return pos;
+ }
+ };
+
+} // namespace TAO_PEGTL_NAMESPACE::internal
+
+#endif
diff --git a/include/tao/pegtl/internal/lazy_input_with_source.hpp b/include/tao/pegtl/internal/lazy_input_with_source.hpp
new file mode 100644
index 000000000..81244de41
--- /dev/null
+++ b/include/tao/pegtl/internal/lazy_input_with_source.hpp
@@ -0,0 +1,20 @@
+// Copyright (c) 2021-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_LAZY_INPUT_WITH_SOURCE_HPP
+#define TAO_PEGTL_INTERNAL_LAZY_INPUT_WITH_SOURCE_HPP
+
+#include "../config.hpp"
+
+#include "input_with_source.hpp"
+#include "lazy_input.hpp"
+
+namespace TAO_PEGTL_NAMESPACE::internal
+{
+ template< typename Eol, typename Source, typename Input >
+ using lazy_input_with_source = input_with_source< Source, lazy_input< Eol, Input > >;
+
+} // namespace TAO_PEGTL_NAMESPACE::internal
+
+#endif
diff --git a/include/tao/pegtl/internal/many.hpp b/include/tao/pegtl/internal/many.hpp
new file mode 100644
index 000000000..e242c5681
--- /dev/null
+++ b/include/tao/pegtl/internal/many.hpp
@@ -0,0 +1,74 @@
+// Copyright (c) 2014-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_MANY_HPP
+#define TAO_PEGTL_INTERNAL_MANY_HPP
+
+#include
+
+#include "dependent_false.hpp"
+#include "enable_control.hpp"
+#include "success.hpp"
+
+#include "../config.hpp"
+#include "../type_list.hpp"
+
+namespace TAO_PEGTL_NAMESPACE::internal
+{
+ template< unsigned Count, typename Peek >
+ struct many
+ {
+ using rule_t = many;
+ using subs_t = empty_list;
+
+ template< typename ParseInput >
+ [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( in.size( Count ) ) )
+ {
+ if constexpr( !Peek::allow_bulk ) {
+ std::size_t done = 0;
+
+ for( unsigned i = 0; i < Count; ++i ) {
+ if( const auto t = Peek::peek( in, done ) ) {
+ done += t.size();
+ continue;
+ }
+ return false;
+ }
+ in.template consume< many >( done );
+ return true;
+ }
+ else if constexpr( sizeof( *in.current() ) == 1 ) {
+ static_assert( Peek::fixed_size > 0 );
+ if( in.size( Count * Peek::fixed_size ) >= Count * Peek::fixed_size ) {
+ in.template consume< many >( Count * Peek::fixed_size );
+ return true;
+ }
+ return false;
+ }
+ else if constexpr( sizeof( *in.current() ) == Peek::fixed_size ) {
+ static_assert( Peek::fixed_size > 0 );
+ if( in.size( Count ) >= Count ) {
+ in.template consume< many >( Count );
+ return true;
+ }
+ return false;
+ }
+ else {
+ static_assert( Peek::fixed_size > 0 );
+ static_assert( dependent_false< Peek > );
+ }
+ }
+ };
+
+ template< typename Peek >
+ struct many< 0, Peek >
+ : success
+ {};
+
+ template< unsigned Count, typename Peek >
+ inline constexpr bool enable_control< many< Count, Peek > > = false;
+
+} // namespace TAO_PEGTL_NAMESPACE::internal
+
+#endif
diff --git a/include/tao/pegtl/internal/minus.hpp b/include/tao/pegtl/internal/minus.hpp
index 9536b8217..d32fea45c 100644
--- a/include/tao/pegtl/internal/minus.hpp
+++ b/include/tao/pegtl/internal/minus.hpp
@@ -8,7 +8,6 @@
#include "eof.hpp"
#include "not_at.hpp"
#include "rematch.hpp"
-#include "seq.hpp"
#include "../config.hpp"
diff --git a/include/tao/pegtl/internal/mmap_file.hpp b/include/tao/pegtl/internal/mmap_file_base.hpp
similarity index 55%
rename from include/tao/pegtl/internal/mmap_file.hpp
rename to include/tao/pegtl/internal/mmap_file_base.hpp
index ff9d205fa..7252f1a90 100644
--- a/include/tao/pegtl/internal/mmap_file.hpp
+++ b/include/tao/pegtl/internal/mmap_file_base.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_INTERNAL_MMAP_FILE_HPP
-#define TAO_PEGTL_INTERNAL_MMAP_FILE_HPP
+#ifndef TAO_PEGTL_INTERNAL_MMAP_FILE_BASE_HPP
+#define TAO_PEGTL_INTERNAL_MMAP_FILE_BASE_HPP
#if defined( __unix__ ) || ( defined( __APPLE__ ) && defined( __MACH__ ) )
#include // Required for _POSIX_MAPPED_FILES
@@ -11,34 +11,40 @@
#if defined( _POSIX_MAPPED_FILES )
#include "mmap_file_posix.hpp"
+#define TAO_PEGTL_MMAP_AVAILABLE 1
#elif defined( _WIN32 )
#include "mmap_file_win32.hpp"
+#define TAO_PEGTL_MMAP_AVAILABLE 1
#else
+#undef TAO_PEGTL_MMAP_AVAILABLE
#endif
+#if defined( TAO_PEGTL_MMAP_AVAILABLE )
+
#include
#include "../config.hpp"
namespace TAO_PEGTL_NAMESPACE::internal
{
- struct mmap_file
+ struct mmap_file_base
{
const mmap_file_impl data;
- explicit mmap_file( const std::filesystem::path& path )
+ explicit mmap_file_base( const std::filesystem::path& path )
: data( path )
{}
- mmap_file( const mmap_file& ) = delete;
- mmap_file( mmap_file&& ) = delete;
+ mmap_file_base( mmap_file_base&& ) = delete;
+ mmap_file_base( const mmap_file_base& ) = delete;
- ~mmap_file() = default;
+ ~mmap_file_base() = default;
- mmap_file& operator=( const mmap_file& ) = delete;
- mmap_file& operator=( mmap_file&& ) = delete;
+ void operator=( mmap_file_base&& ) = delete;
+ void operator=( const mmap_file_base& ) = delete;
};
} // namespace TAO_PEGTL_NAMESPACE::internal
#endif
+#endif
diff --git a/include/tao/pegtl/internal/mmap_file_posix.hpp b/include/tao/pegtl/internal/mmap_file_posix.hpp
index fbd86e1eb..6d98fcc25 100644
--- a/include/tao/pegtl/internal/mmap_file_posix.hpp
+++ b/include/tao/pegtl/internal/mmap_file_posix.hpp
@@ -137,16 +137,6 @@ namespace TAO_PEGTL_NAMESPACE::internal
return m_data;
}
- [[nodiscard]] const char* begin() const noexcept
- {
- return m_data;
- }
-
- [[nodiscard]] const char* end() const noexcept
- {
- return m_data + m_size;
- }
-
private:
const std::size_t m_size;
const char* const m_data;
diff --git a/include/tao/pegtl/internal/mmap_file_win32.hpp b/include/tao/pegtl/internal/mmap_file_win32.hpp
index 917d77824..b9cfc6a98 100644
--- a/include/tao/pegtl/internal/mmap_file_win32.hpp
+++ b/include/tao/pegtl/internal/mmap_file_win32.hpp
@@ -222,16 +222,6 @@ namespace TAO_PEGTL_NAMESPACE::internal
return m_data;
}
- [[nodiscard]] const char* begin() const noexcept
- {
- return m_data;
- }
-
- [[nodiscard]] const char* end() const noexcept
- {
- return m_data + m_size;
- }
-
private:
const std::size_t m_size;
const char* const m_data;
diff --git a/include/tao/pegtl/internal/mmap_input.hpp b/include/tao/pegtl/internal/mmap_input.hpp
new file mode 100644
index 000000000..94aac6ea9
--- /dev/null
+++ b/include/tao/pegtl/internal/mmap_input.hpp
@@ -0,0 +1,61 @@
+// Copyright (c) 2014-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_MMAP_INPUT_HPP
+#define TAO_PEGTL_INTERNAL_MMAP_INPUT_HPP
+
+#include
+
+#include "../config.hpp"
+
+#include "mmap_file_base.hpp"
+#include "view_input.hpp"
+
+namespace TAO_PEGTL_NAMESPACE::internal
+{
+ template< typename Data = char >
+ class mmap_input
+ : private mmap_file_base,
+ public view_input< Data >
+ {
+ public:
+ using base_t = view_input< Data >;
+ using data_t = Data;
+ using error_position_t = count_position;
+ using rewind_position_t = pointer_position< data_t >;
+
+ explicit mmap_input( const std::filesystem::path& path )
+ : mmap_file_base( path ),
+ view_input< Data >( data.data(), data.size() )
+ {}
+
+ [[nodiscard]] const data_t* start() const noexcept
+ {
+ return data.data();
+ }
+
+ void restart() noexcept
+ {
+ this->m_current = data.data();
+ }
+
+ [[nodiscard]] auto current_position() const noexcept
+ {
+ return previous_position( this->rewind_position() );
+ }
+
+ [[nodiscard]] auto previous_position( const error_position_t previous ) const noexcept
+ {
+ return previous;
+ }
+
+ [[nodiscard]] auto previous_position( const rewind_position_t previous ) const noexcept
+ {
+ return count_position( previous.data - data.data() );
+ }
+ };
+
+} // namespace TAO_PEGTL_NAMESPACE::internal
+
+#endif
diff --git a/include/tao/pegtl/internal/one.hpp b/include/tao/pegtl/internal/one.hpp
index 94de5ee7a..e77b49747 100644
--- a/include/tao/pegtl/internal/one.hpp
+++ b/include/tao/pegtl/internal/one.hpp
@@ -8,7 +8,6 @@
#include
#include "any.hpp"
-#include "bump_help.hpp"
#include "enable_control.hpp"
#include "failure.hpp"
#include "result_on_found.hpp"
@@ -27,22 +26,17 @@ namespace TAO_PEGTL_NAMESPACE::internal
using rule_t = one;
using subs_t = empty_list;
- [[nodiscard]] static constexpr bool test_one( const data_t c ) noexcept
+ [[nodiscard]] static constexpr bool test( const data_t c ) noexcept
{
return ( ( c == Cs ) || ... ) == static_cast< bool >( R );
}
- [[nodiscard]] static constexpr bool test_any( const data_t c ) noexcept
- {
- return test_one( c );
- }
-
template< typename ParseInput >
[[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( Peek::peek( in ) ) )
{
if( const auto t = Peek::peek( in ) ) {
- if( test_one( t.data ) ) {
- bump_help< one >( in, t.size );
+ if( test( t.data() ) ) {
+ in.template consume< one >( t.size() );
return true;
}
}
diff --git a/include/tao/pegtl/internal/peek_char.hpp b/include/tao/pegtl/internal/peek_char.hpp
deleted file mode 100644
index 603eef878..000000000
--- a/include/tao/pegtl/internal/peek_char.hpp
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright (c) 2014-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_PEEK_CHAR_HPP
-#define TAO_PEGTL_INTERNAL_PEEK_CHAR_HPP
-
-#include
-
-#include "data_and_size.hpp"
-
-#include "../config.hpp"
-
-namespace TAO_PEGTL_NAMESPACE::internal
-{
- struct peek_char
- {
- using data_t = char;
- using pair_t = data_and_size< char >;
-
- template< typename ParseInput >
- [[nodiscard]] static pair_t peek( ParseInput& in ) noexcept( noexcept( in.empty() ) )
- {
- if( in.empty() ) {
- return { 0, 0 };
- }
- return { in.peek_char(), 1 };
- }
- };
-
-} // namespace TAO_PEGTL_NAMESPACE::internal
-
-#endif
diff --git a/include/tao/pegtl/internal/peek_direct.hpp b/include/tao/pegtl/internal/peek_direct.hpp
new file mode 100644
index 000000000..53b479cb7
--- /dev/null
+++ b/include/tao/pegtl/internal/peek_direct.hpp
@@ -0,0 +1,45 @@
+// Copyright (c) 2014-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_PEEK_DIRECT_HPP
+#define TAO_PEGTL_INTERNAL_PEEK_DIRECT_HPP
+
+#include
+#include
+
+#include "data_and_size.hpp"
+
+namespace TAO_PEGTL_NAMESPACE::internal
+{
+ template< typename Data >
+ struct peek_direct
+ {
+ using data_t = Data;
+ using pair_t = data_and_size< Data, std::uint8_t >;
+
+ static constexpr bool allow_bulk = true;
+ static constexpr std::size_t fixed_size = sizeof( Data );
+
+ template< typename ParseInput >
+ [[nodiscard]] static pair_t peek( ParseInput& in, const std::size_t offset = 0 ) noexcept( noexcept( in.size( 42 ) ) )
+ {
+ using peek_t = typename ParseInput::data_t;
+
+ static_assert( sizeof( peek_t ) == sizeof( data_t ) );
+
+ if( in.size( offset + 1 ) > offset ) {
+ return pair_t( Data( *in.current( offset ) ), 1 );
+ }
+ return pair_t();
+ }
+ };
+
+ using peek_char = peek_direct< char >;
+ using peek_int8 = peek_direct< std::int8_t >;
+ using peek_uint8 = peek_direct< std::uint8_t >;
+ using peek_byte = peek_direct< std::byte >;
+
+} // namespace TAO_PEGTL_NAMESPACE::internal
+
+#endif
diff --git a/include/tao/pegtl/internal/peek_endian.hpp b/include/tao/pegtl/internal/peek_endian.hpp
new file mode 100644
index 000000000..db692645e
--- /dev/null
+++ b/include/tao/pegtl/internal/peek_endian.hpp
@@ -0,0 +1,71 @@
+// Copyright (c) 2018-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_PEEK_ENDIAN_HPP
+#define TAO_PEGTL_INTERNAL_PEEK_ENDIAN_HPP
+
+#include
+#include
+
+#include "../config.hpp"
+
+#include "data_and_size.hpp"
+#include "dependent_false.hpp"
+#include "endian.hpp"
+
+namespace TAO_PEGTL_NAMESPACE::internal
+{
+ template< typename Data, typename Endian >
+ struct peek_endian
+ {
+ using data_t = Data;
+ using pair_t = data_and_size< Data >;
+
+ static_assert( sizeof( Data ) > 1 );
+
+ static constexpr bool allow_bulk = true;
+ static constexpr std::size_t fixed_size = sizeof( Data );
+
+ template< typename ParseInput >
+ [[nodiscard]] static pair_t peek( ParseInput& in, const std::size_t offset = 0 ) noexcept( noexcept( in.size( 42 ) ) )
+ {
+ using peek_t = typename ParseInput::data_t;
+
+ if constexpr( sizeof( peek_t ) == 1 ) {
+ if( in.size( sizeof( Data ) + offset ) < sizeof( Data ) + offset ) {
+ return pair_t();
+ }
+ return pair_t( Endian::template from< Data >( in.current( offset ) ), sizeof( Data ) );
+ }
+ else if constexpr( sizeof( peek_t ) == sizeof( Data ) ) {
+ if( in.size( 1 + offset ) < 1 + offset ) {
+ return pair_t();
+ }
+ return pair_t( Endian::template from< Data >( *in.current( offset ) ), 1 );
+ }
+ else {
+ static_assert( dependent_false< peek_endian > );
+ }
+ }
+ };
+
+ using peek_int16_be = peek_endian< std::int16_t, big_endian >;
+ using peek_int32_be = peek_endian< std::int32_t, big_endian >;
+ using peek_int64_be = peek_endian< std::int64_t, big_endian >;
+
+ using peek_int16_le = peek_endian< std::int16_t, little_endian >;
+ using peek_int32_le = peek_endian< std::int32_t, little_endian >;
+ using peek_int64_le = peek_endian< std::int64_t, little_endian >;
+
+ using peek_uint16_be = peek_endian< std::uint16_t, big_endian >;
+ using peek_uint32_be = peek_endian< std::uint32_t, big_endian >;
+ using peek_uint64_be = peek_endian< std::uint64_t, big_endian >;
+
+ using peek_uint16_le = peek_endian< std::uint16_t, little_endian >;
+ using peek_uint32_le = peek_endian< std::uint32_t, little_endian >;
+ using peek_uint64_le = peek_endian< std::uint64_t, little_endian >;
+
+} // namespace TAO_PEGTL_NAMESPACE::internal
+
+#endif
diff --git a/include/tao/pegtl/internal/peek_mask_uint.hpp b/include/tao/pegtl/internal/peek_mask_uint.hpp
new file mode 100644
index 000000000..3025f1491
--- /dev/null
+++ b/include/tao/pegtl/internal/peek_mask_uint.hpp
@@ -0,0 +1,53 @@
+// Copyright (c) 2018-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_PEEK_MASK_UINT_HPP
+#define TAO_PEGTL_INTERNAL_PEEK_MASK_UINT_HPP
+
+#include
+#include
+
+#include "data_and_size.hpp"
+#include "endian.hpp"
+#include "peek_endian.hpp"
+
+namespace TAO_PEGTL_NAMESPACE::internal
+{
+ template< typename Data, Data Mask, typename Endian >
+ struct peek_mask_uint_impl
+ {
+ using data_t = Data;
+ using pair_t = data_and_size< data_t >;
+
+ static_assert( sizeof( Data ) > 1 );
+
+ static constexpr bool allow_bulk = true;
+ static constexpr std::size_t fixed_size = sizeof( Data );
+
+ template< typename ParseInput >
+ [[nodiscard]] static pair_t peek( ParseInput& in, const std::size_t offset = 0 ) noexcept( noexcept( in.size( sizeof( data_t ) ) ) )
+ {
+ pair_t r = peek_endian< Data, Endian >::peek( in, offset );
+ r.mask_with( Mask );
+ return r;
+ }
+ };
+
+ template< std::uint16_t Mask >
+ using peek_mask_uint16_be = peek_mask_uint_impl< std::uint16_t, Mask, big_endian >;
+ template< std::uint32_t Mask >
+ using peek_mask_uint32_be = peek_mask_uint_impl< std::uint32_t, Mask, big_endian >;
+ template< std::uint64_t Mask >
+ using peek_mask_uint64_be = peek_mask_uint_impl< std::uint64_t, Mask, big_endian >;
+
+ template< std::uint16_t Mask >
+ using peek_mask_uint16_le = peek_mask_uint_impl< std::uint16_t, Mask, little_endian >;
+ template< std::uint32_t Mask >
+ using peek_mask_uint32_le = peek_mask_uint_impl< std::uint32_t, Mask, little_endian >;
+ template< std::uint64_t Mask >
+ using peek_mask_uint64_le = peek_mask_uint_impl< std::uint64_t, Mask, little_endian >;
+
+} // namespace TAO_PEGTL_NAMESPACE::internal
+
+#endif
diff --git a/include/tao/pegtl/contrib/internal/peek_mask_uint8.hpp b/include/tao/pegtl/internal/peek_mask_uint8.hpp
similarity index 66%
rename from include/tao/pegtl/contrib/internal/peek_mask_uint8.hpp
rename to include/tao/pegtl/internal/peek_mask_uint8.hpp
index 28c63ced2..580a03078 100644
--- a/include/tao/pegtl/contrib/internal/peek_mask_uint8.hpp
+++ b/include/tao/pegtl/internal/peek_mask_uint8.hpp
@@ -2,13 +2,13 @@
// 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_INTERNAL_PEEK_MASK_UINT8_HPP
-#define TAO_PEGTL_CONTRIB_INTERNAL_PEEK_MASK_UINT8_HPP
+#ifndef TAO_PEGTL_INTERNAL_PEEK_MASK_UINT8_HPP
+#define TAO_PEGTL_INTERNAL_PEEK_MASK_UINT8_HPP
#include
#include
-#include "../../internal/data_and_size.hpp"
+#include "data_and_size.hpp"
namespace TAO_PEGTL_NAMESPACE::internal
{
@@ -18,13 +18,18 @@ namespace TAO_PEGTL_NAMESPACE::internal
using data_t = std::uint8_t;
using pair_t = data_and_size< std::uint8_t >;
+ static constexpr bool allow_bulk = true;
+ static constexpr std::size_t fixed_size = 1;
+
template< typename ParseInput >
[[nodiscard]] static pair_t peek( ParseInput& in ) noexcept( noexcept( in.empty() ) )
{
+ static_assert( sizeof( typename ParseInput::data_t ) == 1 );
+
if( in.empty() ) {
return { 0, 0 };
}
- return { std::uint8_t( in.peek_uint8() & M ), 1 };
+ return { std::uint8_t( std::uint8_t( *in.current() ) & M ), 1 };
}
};
diff --git a/include/tao/pegtl/internal/peek_utf16.hpp b/include/tao/pegtl/internal/peek_utf16.hpp
new file mode 100644
index 000000000..ffab67dc2
--- /dev/null
+++ b/include/tao/pegtl/internal/peek_utf16.hpp
@@ -0,0 +1,53 @@
+// Copyright (c) 2014-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_PEEK_UTF16_HPP
+#define TAO_PEGTL_INTERNAL_PEEK_UTF16_HPP
+
+#include
+
+#include "../config.hpp"
+
+#include "endian.hpp"
+#include "data_and_size.hpp"
+#include "peek_endian.hpp"
+
+namespace TAO_PEGTL_NAMESPACE::internal
+{
+ template< typename Endian >
+ struct peek_utf16_impl
+ {
+ using data_t = char32_t;
+ using pair_t = data_and_size< char32_t >;
+
+ static constexpr std::size_t fixed_size = 0;
+
+ static_assert( sizeof( char16_t ) == 2 );
+ static_assert( sizeof( char32_t ) == 4 );
+
+ template< typename ParseInput >
+ [[nodiscard]] static pair_t peek( ParseInput& in, const std::size_t offset = 0 ) noexcept( noexcept( in.size( 42 ) ) )
+ {
+ if( const auto r = peek_endian< char16_t, Endian >::peek( in, offset ) ) {
+ if( ( r.data() < 0xd800 ) || ( r.data() > 0xdfff ) ) {
+ return pair_t( r.data(), r.size() );
+ }
+ if( r.data() < 0xdc00 ) {
+ if( const auto s = peek_endian< char16_t, Endian >::peek( in, r.size() + offset ) ) {
+ if( ( s.data() >= 0xdc00 ) && ( s.data() <= 0xdfff ) ) {
+ return pair_t( ( ( char32_t( r.data() & 0x03ff ) << 10 ) | char32_t( s.data() & 0x03ff ) ) + 0x10000, std::uint8_t( r.size() + s.size() ) );
+ }
+ }
+ }
+ }
+ return pair_t();
+ }
+ };
+
+ using peek_utf16_be = peek_utf16_impl< big_endian >;
+ using peek_utf16_le = peek_utf16_impl< little_endian >;
+
+} // namespace TAO_PEGTL_NAMESPACE::internal
+
+#endif
diff --git a/include/tao/pegtl/internal/peek_utf32.hpp b/include/tao/pegtl/internal/peek_utf32.hpp
new file mode 100644
index 000000000..981512b6b
--- /dev/null
+++ b/include/tao/pegtl/internal/peek_utf32.hpp
@@ -0,0 +1,46 @@
+// Copyright (c) 2014-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_PEEK_UTF32_HPP
+#define TAO_PEGTL_INTERNAL_PEEK_UTF32_HPP
+
+#include
+
+#include "../config.hpp"
+
+#include "endian.hpp"
+#include "data_and_size.hpp"
+#include "peek_endian.hpp"
+
+namespace TAO_PEGTL_NAMESPACE::internal
+{
+ template< typename Endian >
+ struct peek_utf32_impl
+ {
+ using data_t = char32_t;
+ using pair_t = data_and_size< char32_t >;
+
+ static constexpr bool allow_bulk = true;
+ static constexpr std::size_t fixed_size = 4;
+
+ static_assert( sizeof( char32_t ) == 4 );
+
+ template< typename ParseInput >
+ [[nodiscard]] static pair_t peek( ParseInput& in, const std::size_t offset = 0 ) noexcept( noexcept( in.size( 42 ) ) )
+ {
+ const pair_t r = peek_endian< char32_t, Endian >::peek( in, offset );
+
+ if( ( r.data() <= 0x10ffff ) && !( ( r.data() >= 0xd800 ) && ( r.data() <= 0xdfff ) ) ) {
+ return r;
+ }
+ return pair_t();
+ }
+ };
+
+ using peek_utf32_be = peek_utf32_impl< big_endian >;
+ using peek_utf32_le = peek_utf32_impl< little_endian >;
+
+} // namespace TAO_PEGTL_NAMESPACE::internal
+
+#endif
diff --git a/include/tao/pegtl/internal/peek_utf8.hpp b/include/tao/pegtl/internal/peek_utf8.hpp
index 355537833..454b53cb3 100644
--- a/include/tao/pegtl/internal/peek_utf8.hpp
+++ b/include/tao/pegtl/internal/peek_utf8.hpp
@@ -5,68 +5,74 @@
#ifndef TAO_PEGTL_INTERNAL_PEEK_UTF8_HPP
#define TAO_PEGTL_INTERNAL_PEEK_UTF8_HPP
-#include "data_and_size.hpp"
+#include
#include "../config.hpp"
+#include "data_and_size.hpp"
+
namespace TAO_PEGTL_NAMESPACE::internal
{
struct peek_utf8
{
using data_t = char32_t;
- using pair_t = data_and_size< char32_t >;
+ using pair_t = data_and_size< char32_t, std::uint8_t >;
+
+ static constexpr bool allow_bulk = false;
template< typename ParseInput >
[[nodiscard]] static pair_t peek( ParseInput& in ) noexcept( noexcept( in.empty() ) )
{
+ static_assert( sizeof( decltype( *in.current() ) ) == 1 );
+
if( in.empty() ) {
- return { 0, 0 };
+ return pair_t();
}
- const char32_t c0 = in.peek_uint8();
+ const char32_t c0 = std::uint8_t( *in.current() );
if( ( c0 & 0x80 ) == 0 ) {
- return { c0, 1 };
+ return pair_t( c0, 1 );
}
return peek_impl( in, c0 );
}
private:
template< typename ParseInput >
- [[nodiscard]] static pair_t peek_impl( ParseInput& in, char32_t c0 ) noexcept( noexcept( in.size( 4 ) ) )
+ [[nodiscard]] static pair_t peek_impl( ParseInput& in, char32_t c0 ) noexcept( noexcept( in.size( 42 ) ) )
{
if( ( c0 & 0xE0 ) == 0xC0 ) {
if( in.size( 2 ) >= 2 ) {
- const char32_t c1 = in.peek_uint8( 1 );
+ const char32_t c1 = std::uint8_t( *in.current( 1 ) );
if( ( c1 & 0xC0 ) == 0x80 ) {
c0 &= 0x1F;
c0 <<= 6;
c0 |= ( c1 & 0x3F );
if( c0 >= 0x80 ) {
- return { c0, 2 };
+ return pair_t( c0, 2 );
}
}
}
}
else if( ( c0 & 0xF0 ) == 0xE0 ) {
if( in.size( 3 ) >= 3 ) {
- const char32_t c1 = in.peek_uint8( 1 );
- const char32_t c2 = in.peek_uint8( 2 );
+ const char32_t c1 = std::uint8_t( *in.current( 1 ) );
+ const char32_t c2 = std::uint8_t( *in.current( 2 ) );
if( ( ( c1 & 0xC0 ) == 0x80 ) && ( ( c2 & 0xC0 ) == 0x80 ) ) {
c0 &= 0x0F;
c0 <<= 6;
c0 |= ( c1 & 0x3F );
c0 <<= 6;
c0 |= ( c2 & 0x3F );
- if( c0 >= 0x800 && !( c0 >= 0xD800 && c0 <= 0xDFFF ) ) {
- return { c0, 3 };
+ if( c0 >= 0x800 && !( ( c0 >= 0xD800 ) && ( c0 <= 0xDFFF ) ) ) {
+ return pair_t( c0, 3 );
}
}
}
}
else if( ( c0 & 0xF8 ) == 0xF0 ) {
if( in.size( 4 ) >= 4 ) {
- const char32_t c1 = in.peek_uint8( 1 );
- const char32_t c2 = in.peek_uint8( 2 );
- const char32_t c3 = in.peek_uint8( 3 );
+ const char32_t c1 = std::uint8_t( *in.current( 1 ) );
+ const char32_t c2 = std::uint8_t( *in.current( 2 ) );
+ const char32_t c3 = std::uint8_t( *in.current( 3 ) );
if( ( ( c1 & 0xC0 ) == 0x80 ) && ( ( c2 & 0xC0 ) == 0x80 ) && ( ( c3 & 0xC0 ) == 0x80 ) ) {
c0 &= 0x07;
c0 <<= 6;
@@ -75,8 +81,8 @@ namespace TAO_PEGTL_NAMESPACE::internal
c0 |= ( c2 & 0x3F );
c0 <<= 6;
c0 |= ( c3 & 0x3F );
- if( c0 >= 0x10000 && c0 <= 0x10FFFF ) {
- return { c0, 4 };
+ if( ( c0 >= 0x10000 ) && ( c0 <= 0x10FFFF ) ) {
+ return pair_t( c0, 4 );
}
}
}
diff --git a/include/tao/pegtl/internal/range.hpp b/include/tao/pegtl/internal/range.hpp
index 3245d06c3..9efd5c788 100644
--- a/include/tao/pegtl/internal/range.hpp
+++ b/include/tao/pegtl/internal/range.hpp
@@ -5,7 +5,6 @@
#ifndef TAO_PEGTL_INTERNAL_RANGE_HPP
#define TAO_PEGTL_INTERNAL_RANGE_HPP
-#include "bump_help.hpp"
#include "enable_control.hpp"
#include "one.hpp"
#include "result_on_found.hpp"
@@ -26,22 +25,17 @@ namespace TAO_PEGTL_NAMESPACE::internal
static_assert( Lo < Hi, "invalid range" );
- [[nodiscard]] static constexpr bool test_one( const data_t c ) noexcept
+ [[nodiscard]] static constexpr bool test( const data_t c ) noexcept
{
return ( ( Lo <= c ) && ( c <= Hi ) ) == static_cast< bool >( R );
}
- [[nodiscard]] static constexpr bool test_any( const data_t c ) noexcept
- {
- return test_one( c );
- }
-
template< typename ParseInput >
[[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( Peek::peek( in ) ) )
{
if( const auto t = Peek::peek( in ) ) {
- if( test_one( t.data ) ) {
- bump_help< range >( in, t.size );
+ if( test( t.data() ) ) {
+ in.template consume< range >( t.size() );
return true;
}
}
diff --git a/include/tao/pegtl/internal/ranges.hpp b/include/tao/pegtl/internal/ranges.hpp
index 10de9d082..ec344a442 100644
--- a/include/tao/pegtl/internal/ranges.hpp
+++ b/include/tao/pegtl/internal/ranges.hpp
@@ -7,7 +7,6 @@
#include
-#include "bump_help.hpp"
#include "enable_control.hpp"
#include "failure.hpp"
#include "one.hpp"
@@ -46,12 +45,7 @@ namespace TAO_PEGTL_NAMESPACE::internal
}
}
- [[nodiscard]] static constexpr bool test_one( const data_t c ) noexcept
- {
- return test_impl( std::make_index_sequence< sizeof...( Cs ) / 2 >(), c );
- }
-
- [[nodiscard]] static constexpr bool test_any( const data_t c ) noexcept
+ [[nodiscard]] static constexpr bool test( const data_t c ) noexcept
{
return test_impl( std::make_index_sequence< sizeof...( Cs ) / 2 >(), c );
}
@@ -60,8 +54,8 @@ namespace TAO_PEGTL_NAMESPACE::internal
[[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( Peek::peek( in ) ) )
{
if( const auto t = Peek::peek( in ) ) {
- if( test_one( t.data ) ) {
- bump_help< ranges >( in, t.size );
+ if( test( t.data() ) ) {
+ in.template consume< ranges >( t.size() );
return true;
}
}
diff --git a/include/tao/pegtl/internal/read_input.hpp b/include/tao/pegtl/internal/read_input.hpp
new file mode 100644
index 000000000..9cb3c2cdf
--- /dev/null
+++ b/include/tao/pegtl/internal/read_input.hpp
@@ -0,0 +1,34 @@
+// Copyright (c) 2014-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_READ_INPUT_HPP
+#define TAO_PEGTL_INTERNAL_READ_INPUT_HPP
+
+#include
+#include
+#include
+
+#include "../config.hpp"
+
+#include "copy_input.hpp"
+#include "read_file_stdio.hpp"
+
+namespace TAO_PEGTL_NAMESPACE::internal
+{
+ class read_input
+ : public copy_input< std::string >
+ {
+ public:
+ explicit read_input( const std::filesystem::path& path )
+ : copy_input< std::string >( read_file_stdio( path ).read_string() )
+ {}
+
+ read_input( FILE* file, const std::filesystem::path& path )
+ : copy_input< std::string >( read_file_stdio( file, path ).read_string() )
+ {}
+ };
+
+} // namespace TAO_PEGTL_NAMESPACE::internal
+
+#endif
diff --git a/include/tao/pegtl/internal/rematch.hpp b/include/tao/pegtl/internal/rematch.hpp
index 15ad08fdf..b3f8a4d9b 100644
--- a/include/tao/pegtl/internal/rematch.hpp
+++ b/include/tao/pegtl/internal/rematch.hpp
@@ -5,14 +5,14 @@
#ifndef TAO_PEGTL_INTERNAL_REMATCH_HPP
#define TAO_PEGTL_INTERNAL_REMATCH_HPP
-#include "enable_control.hpp"
-
#include "../apply_mode.hpp"
#include "../config.hpp"
-#include "../memory_input.hpp"
#include "../rewind_mode.hpp"
#include "../type_list.hpp"
+#include "enable_control.hpp"
+#include "rematch_input.hpp"
+
namespace TAO_PEGTL_NAMESPACE::internal
{
template< typename Head, typename... Rules >
@@ -57,8 +57,8 @@ namespace TAO_PEGTL_NAMESPACE::internal
auto m = in.template make_rewind_guard< rewind_mode::required >();
if( Control< Head >::template match< A, rewind_mode::optional, Action, Control >( in, st... ) ) {
- memory_input< ParseInput::tracking_mode_v, typename ParseInput::eol_rule, typename ParseInput::source_t > i2( m.rewind_position(), in.current(), in.source() );
- return m( ( Control< Rule >::template match< A, rewind_mode::optional, Action, Control >( i2, st... ) && ... && ( i2.rewind_position( m.rewind_position() ), Control< Rules >::template match< A, rewind_mode::optional, Action, Control >( i2, st... ) ) ) );
+ rematch_input i2( m, in );
+ return m( ( Control< Rule >::template match< A, rewind_mode::optional, Action, Control >( i2, st... ) && ... && ( i2.private_set_current( m.current() ), Control< Rules >::template match< A, rewind_mode::optional, Action, Control >( i2, st... ) ) ) );
}
return false;
}
diff --git a/include/tao/pegtl/internal/rematch_input.hpp b/include/tao/pegtl/internal/rematch_input.hpp
new file mode 100644
index 000000000..532284185
--- /dev/null
+++ b/include/tao/pegtl/internal/rematch_input.hpp
@@ -0,0 +1,134 @@
+// Copyright (c) 2019-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_REMATCH_INPUT_HPP
+#define TAO_PEGTL_INTERNAL_REMATCH_INPUT_HPP
+
+#include
+
+#include "../config.hpp"
+#include "../pointer_position.hpp"
+
+#include "has_eol_rule.hpp"
+#include "input_with_fakes.hpp"
+#include "input_with_peeks.hpp"
+#include "input_with_start.hpp"
+#include "rewind_guard.hpp"
+
+namespace TAO_PEGTL_NAMESPACE::internal
+{
+ template< typename Guard, typename Input >
+ class rematch_view_input
+ {
+ public:
+ using base_t = input_with_peeks< input_with_fakes< input_with_start< 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 >;
+
+ rematch_view_input( Guard& m, Input& in )
+ : m_guard( m ),
+ m_input( in ),
+ m_current( m.current() )
+ {}
+
+ [[nodiscard]] bool empty() const noexcept
+ {
+ return m_current == m_input.current();
+ }
+
+ [[nodiscard]] std::size_t size() const noexcept
+ {
+ return m_input.current() - m_current;
+ }
+
+ [[nodiscard]] const data_t* start() const noexcept
+ {
+ return m_guard.current();
+ }
+
+ [[nodiscard]] const data_t* current( const std::size_t offset = 0 ) const noexcept
+ {
+ return m_current + offset;
+ }
+
+ [[nodiscard]] const data_t* previous( const rewind_position_t saved ) const noexcept
+ {
+ return m_current + saved.count;
+ }
+
+ [[nodiscard]] const data_t* end() const noexcept
+ {
+ return m_input.current();
+ }
+
+ template< typename Rule >
+ void consume( const std::size_t count ) noexcept
+ {
+ m_current += count;
+ }
+
+ template< rewind_mode M >
+ [[nodiscard]] auto make_rewind_guard() noexcept
+ {
+ return rewind_guard< M, rematch_view_input >( this );
+ }
+
+ [[nodiscard]] auto rewind_position() const noexcept
+ {
+ return rewind_position_t( m_current );
+ }
+
+ void rewind_to_position( const rewind_position_t saved ) noexcept
+ {
+ m_current = saved.data;
+ }
+
+ [[nodiscard]] auto current_position() const
+ {
+ return previous_position( rewind_position_t( m_current ) );
+ }
+
+ [[nodiscard]] auto previous_position( const rewind_position_t saved ) const
+ {
+ return rematch_position( m_guard, m_input, saved );
+ }
+
+ void private_set_current( const data_t* current ) noexcept
+ {
+ m_current = current;
+ }
+
+ protected:
+ const Guard& m_guard;
+ const Input& m_input;
+
+ const data_t* m_current;
+ };
+
+ template< typename Guard, typename Input, bool = has_eol_rule< Input > >
+ struct rematch_input;
+
+ template< typename Guard, typename Input >
+ struct rematch_input< Guard, Input, false >
+ : input_with_peeks< input_with_fakes< rematch_view_input< Guard, Input > > >
+ {
+ using input_with_peeks< input_with_fakes< rematch_view_input< Guard, Input > > >::input_with_peeks;
+ };
+
+ template< typename Guard, typename Input >
+ struct rematch_input< Guard, Input, true >
+ : rematch_input< Guard, Input, false >
+ {
+ using eol_rule = typename Input::eol_rule;
+
+ using rematch_input< Guard, Input, false >::rematch_input;
+ };
+
+ template< typename Guard, typename Input >
+ rematch_input( Guard&, Input& ) -> rematch_input< Guard, Input >;
+
+} // namespace TAO_PEGTL_NAMESPACE::internal
+
+#endif
diff --git a/include/tao/pegtl/internal/rematch_position.hpp b/include/tao/pegtl/internal/rematch_position.hpp
new file mode 100644
index 000000000..9b3027917
--- /dev/null
+++ b/include/tao/pegtl/internal/rematch_position.hpp
@@ -0,0 +1,21 @@
+// 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_REMATCH_POSITION_HPP
+#define TAO_PEGTL_INTERNAL_REMATCH_POSITION_HPP
+
+#include "../config.hpp"
+#include "../pointer_position.hpp"
+
+namespace TAO_PEGTL_NAMESPACE::internal
+{
+ template< typename Guard, typename Input, typename Data >
+ [[nodiscard]] auto rematch_position( Guard&, Input& in, const pointer_position< Data > saved )
+ {
+ return in.previous_position( saved );
+ }
+
+} // namespace TAO_PEGTL_NAMESPACE::internal
+
+#endif
diff --git a/include/tao/pegtl/internal/require.hpp b/include/tao/pegtl/internal/require.hpp
deleted file mode 100644
index f30de0d21..000000000
--- a/include/tao/pegtl/internal/require.hpp
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright (c) 2016-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_REQUIRE_HPP
-#define TAO_PEGTL_INTERNAL_REQUIRE_HPP
-
-#include "enable_control.hpp"
-#include "success.hpp"
-
-#include "../config.hpp"
-#include "../type_list.hpp"
-
-namespace TAO_PEGTL_NAMESPACE::internal
-{
- template< unsigned Amount >
- struct require;
-
- template<>
- struct require< 0 >
- : success
- {};
-
- template< unsigned Amount >
- struct require
- {
- using rule_t = require;
- using subs_t = empty_list;
-
- template< typename ParseInput >
- [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( in.size( 0 ) ) )
- {
- return in.size( Amount ) >= Amount;
- }
- };
-
- template< unsigned Amount >
- inline constexpr bool enable_control< require< Amount > > = false;
-
-} // namespace TAO_PEGTL_NAMESPACE::internal
-
-#endif
diff --git a/include/tao/pegtl/internal/rewind_adapt.hpp b/include/tao/pegtl/internal/rewind_adapt.hpp
new file mode 100644
index 000000000..d62d86bad
--- /dev/null
+++ b/include/tao/pegtl/internal/rewind_adapt.hpp
@@ -0,0 +1,28 @@
+// Copyright (c) 2023-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_REWIND_ADAPT_HPP
+#define TAO_PEGTL_INTERNAL_REWIND_ADAPT_HPP
+
+#include "../config.hpp"
+#include "../count_position.hpp"
+#include "../pointer_position.hpp"
+
+namespace TAO_PEGTL_NAMESPACE::internal
+{
+ template< typename Data >
+ [[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
+ {
+ return p.data;
+ }
+
+} // namespace TAO_PEGTL_NAMESPACE::internal
+
+#endif
diff --git a/include/tao/pegtl/internal/rewind_guard.hpp b/include/tao/pegtl/internal/rewind_guard.hpp
index cd04e2cd5..35fa022b9 100644
--- a/include/tao/pegtl/internal/rewind_guard.hpp
+++ b/include/tao/pegtl/internal/rewind_guard.hpp
@@ -88,12 +88,12 @@ namespace TAO_PEGTL_NAMESPACE::internal
void rewind_restore() const noexcept
{
- m_input->rewind_position( m_saved );
+ m_input->rewind_to_position( m_saved );
}
[[nodiscard]] const auto* current() const noexcept
{
- return m_saved.data;
+ return m_input->previous( m_saved );
}
[[nodiscard]] const auto& rewind_position() const noexcept
diff --git a/include/tao/pegtl/internal/rules.hpp b/include/tao/pegtl/internal/rules.hpp
index aa88e59b7..59fba1d8f 100644
--- a/include/tao/pegtl/internal/rules.hpp
+++ b/include/tao/pegtl/internal/rules.hpp
@@ -12,10 +12,8 @@
#include "at.hpp"
#include "bof.hpp"
#include "bol.hpp"
-#include "bytes.hpp"
#include "control.hpp"
#include "disable.hpp"
-#include "discard.hpp"
#include "enable.hpp"
#include "enable_control.hpp"
#include "eof.hpp"
@@ -30,6 +28,7 @@
#include "list.hpp"
#include "list_tail.hpp"
#include "list_tail_pad.hpp"
+#include "many.hpp"
#include "minus.hpp"
#include "not_at.hpp"
#include "one.hpp"
@@ -45,7 +44,6 @@
#include "rep_min.hpp"
#include "rep_min_max.hpp"
#include "rep_opt.hpp"
-#include "require.hpp"
#include "seq.hpp"
#include "sor.hpp"
#include "star.hpp"
diff --git a/include/tao/pegtl/internal/scan_input.hpp b/include/tao/pegtl/internal/scan_input.hpp
new file mode 100644
index 000000000..7cc8f588e
--- /dev/null
+++ b/include/tao/pegtl/internal/scan_input.hpp
@@ -0,0 +1,21 @@
+// 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_SCAN_INPUT_HPP
+#define TAO_PEGTL_INTERNAL_SCAN_INPUT_HPP
+
+#include "../config.hpp"
+
+#include "input_with_fakes.hpp"
+#include "input_with_peeks.hpp"
+#include "view_input.hpp"
+
+namespace TAO_PEGTL_NAMESPACE::internal
+{
+ template< typename Data >
+ using scan_input = input_with_peeks< input_with_fakes< view_input< Data > > >;
+
+} // namepace TAO_PEGTL_NAMESPACE::internal
+
+#endif
diff --git a/include/tao/pegtl/internal/scan_traits.hpp b/include/tao/pegtl/internal/scan_traits.hpp
new file mode 100644
index 000000000..33da91e07
--- /dev/null
+++ b/include/tao/pegtl/internal/scan_traits.hpp
@@ -0,0 +1,37 @@
+// 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_SCAN_TRAITS_HPP
+#define TAO_PEGTL_INTERNAL_SCAN_TRAITS_HPP
+
+#include "../apply_mode.hpp"
+#include "../config.hpp"
+#include "../normal.hpp"
+#include "../nothing.hpp"
+#include "../rewind_mode.hpp"
+
+namespace TAO_PEGTL_NAMESPACE::internal
+{
+ template< typename Eol, typename = void >
+ struct scan_traits
+ {
+ template< typename Input, typename Position >
+ static void scan( Input& in, Position& pos )
+ {
+ while( !in.empty() ) {
+ if( normal< Eol >::template match< apply_mode::nothing, rewind_mode::required, nothing, normal >( in ) ) {
+ pos.line++;
+ pos.column = 1;
+ }
+ else {
+ pos.column++;
+ in.template consume< void >( 1 );
+ }
+ }
+ }
+ };
+
+} // namespace TAO_PEGTL_NAMESPACE::internal
+
+#endif
diff --git a/include/tao/pegtl/contrib/internal/set_stack_guard.hpp b/include/tao/pegtl/internal/set_stack_guard.hpp
similarity index 83%
rename from include/tao/pegtl/contrib/internal/set_stack_guard.hpp
rename to include/tao/pegtl/internal/set_stack_guard.hpp
index 4e4fb0dc0..b7714d5a2 100644
--- a/include/tao/pegtl/contrib/internal/set_stack_guard.hpp
+++ b/include/tao/pegtl/internal/set_stack_guard.hpp
@@ -2,12 +2,14 @@
// 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_INTERNAL_SET_STACK_GUARD_HPP
-#define TAO_PEGTL_CONTRIB_INTERNAL_SET_STACK_GUARD_HPP
+#ifndef TAO_PEGTL_INTERNAL_SET_STACK_GUARD_HPP
+#define TAO_PEGTL_INTERNAL_SET_STACK_GUARD_HPP
#include
#include
+#include "../config.hpp"
+
namespace TAO_PEGTL_NAMESPACE::internal
{
template< typename... Cs >
@@ -23,8 +25,8 @@ namespace TAO_PEGTL_NAMESPACE::internal
set_stack_guard( set_stack_guard&& ) = delete;
set_stack_guard( const set_stack_guard& ) = delete;
- set_stack_guard& operator=( set_stack_guard&& ) = delete;
- set_stack_guard& operator=( const set_stack_guard& ) = delete;
+ void operator=( set_stack_guard&& ) = delete;
+ void operator=( const set_stack_guard& ) = delete;
~set_stack_guard()
{
diff --git a/include/tao/pegtl/internal/stream_to_string.hpp b/include/tao/pegtl/internal/stream_to_string.hpp
index 79139bde1..38cd77a0a 100644
--- a/include/tao/pegtl/internal/stream_to_string.hpp
+++ b/include/tao/pegtl/internal/stream_to_string.hpp
@@ -13,11 +13,11 @@
namespace TAO_PEGTL_NAMESPACE::internal
{
- template< typename T >
- [[nodiscard]] std::string stream_to_string( const T& t )
+ template< typename... Ts >
+ [[nodiscard]] std::string stream_to_string( const Ts&... ts )
{
std::ostringstream oss;
- oss << t;
+ (void)( oss << ... << ts );
return std::move( oss ).str();
}
diff --git a/include/tao/pegtl/internal/string.hpp b/include/tao/pegtl/internal/string.hpp
index cb9b28250..04c7d8b5d 100644
--- a/include/tao/pegtl/internal/string.hpp
+++ b/include/tao/pegtl/internal/string.hpp
@@ -8,10 +8,9 @@
#include
#include
-#include "bump_help.hpp"
#include "enable_control.hpp"
#include "one.hpp"
-#include "peek_char.hpp"
+#include "peek_direct.hpp"
#include "result_on_found.hpp"
#include "success.hpp"
@@ -44,23 +43,12 @@ namespace TAO_PEGTL_NAMESPACE::internal
using rule_t = string;
using subs_t = empty_list;
- [[nodiscard]] static constexpr bool test_one( const char c ) noexcept
- {
- static_assert( sizeof...( Cs ) == 1 );
- return one< result_on_found::success, peek_char, Cs... >::test_one( c );
- }
-
- [[nodiscard]] static constexpr bool test_any( const char c ) noexcept
- {
- return one< result_on_found::success, peek_char, Cs... >::test_one( c );
- }
-
template< typename ParseInput >
- [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( in.size( 0 ) ) )
+ [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( in.size( 42 ) ) )
{
if( in.size( sizeof...( Cs ) ) >= sizeof...( Cs ) ) {
if( unsafe_equals( in.current(), { Cs... } ) ) {
- bump_help< string >( in, sizeof...( Cs ) );
+ in.template consume< string >( sizeof...( Cs ) );
return true;
}
}
diff --git a/include/tao/pegtl/internal/text_eol_bump.hpp b/include/tao/pegtl/internal/text_eol_bump.hpp
new file mode 100644
index 000000000..628ba45dc
--- /dev/null
+++ b/include/tao/pegtl/internal/text_eol_bump.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_EOL_BUMP_HPP
+#define TAO_PEGTL_INTERNAL_TEXT_EOL_BUMP_HPP
+
+#include "../config.hpp"
+
+#include "bump_traits.hpp"
+#include "text_eol_tags.hpp"
+
+namespace TAO_PEGTL_NAMESPACE::internal
+{
+ template< typename Eol, typename Rule, typename Data, typename Position >
+ void text_eol_bump( Position& pos, const Data* data, const std::size_t count )
+ {
+ bump_traits< Eol, Rule >::bump( pos, data, count );
+ }
+
+} // namespace TAO_PEGTL_NAMESPACE::internal
+
+#endif
diff --git a/include/tao/pegtl/internal/text_eol_scan.hpp b/include/tao/pegtl/internal/text_eol_scan.hpp
new file mode 100644
index 000000000..314a47d49
--- /dev/null
+++ b/include/tao/pegtl/internal/text_eol_scan.hpp
@@ -0,0 +1,25 @@
+// 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_EOL_SCAN_HPP
+#define TAO_PEGTL_INTERNAL_TEXT_EOL_SCAN_HPP
+
+#include "../config.hpp"
+
+#include "scan_input.hpp"
+#include "scan_traits.hpp"
+
+namespace TAO_PEGTL_NAMESPACE::internal
+{
+ template< typename Eol, typename Data, typename Position >
+ void text_eol_scan( Position& pos, const Data* data, const Data* dend )
+ {
+ scan_input< Data > in( data, dend );
+ scan_traits< typename Eol::rule_t >::scan( in, pos );
+ pos.count += dend - data;
+ }
+
+} // namespace TAO_PEGTL_NAMESPACE::internal
+
+#endif
diff --git a/include/tao/pegtl/internal/text_eol_tags.hpp b/include/tao/pegtl/internal/text_eol_tags.hpp
new file mode 100644
index 000000000..9b1d46273
--- /dev/null
+++ b/include/tao/pegtl/internal/text_eol_tags.hpp
@@ -0,0 +1,23 @@
+// Copyright (c) 2021-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_EOL_TAGS_HPP
+#define TAO_PEGTL_INTERNAL_TEXT_EOL_TAGS_HPP
+
+#include "../config.hpp"
+
+namespace TAO_PEGTL_NAMESPACE::internal
+{
+ struct eol_exclude_tag
+ {};
+
+ struct eol_matched_tag
+ {};
+
+ struct eol_unknown_tag
+ {};
+
+} // namespace TAO_PEGTL_NAMESPACE::internal
+
+#endif
diff --git a/include/tao/pegtl/internal/text_file_input_with_source.hpp b/include/tao/pegtl/internal/text_file_input_with_source.hpp
new file mode 100644
index 000000000..e1857d4b2
--- /dev/null
+++ b/include/tao/pegtl/internal/text_file_input_with_source.hpp
@@ -0,0 +1,45 @@
+// Copyright (c) 2021-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_FILE_INPUT_WITH_SOURCE_HPP
+#define TAO_PEGTL_INTERNAL_TEXT_FILE_INPUT_WITH_SOURCE_HPP
+
+#include
+#include
+
+#include "../config.hpp"
+#include "../position_with_source.hpp"
+
+#include "file_input.hpp"
+#include "input_with_lines.hpp"
+#include "text_input_with_source.hpp"
+
+namespace TAO_PEGTL_NAMESPACE::internal
+{
+ template< typename Eol, typename Input = text_input_with_source< Eol, std::filesystem::path, file_input > >
+ class text_file_input_with_source
+ : public Input
+ {
+ public:
+ using base_t = Input;
+ using data_t = typename Input::data_t;
+ using error_position_t = typename Input::error_position_t;
+ using rewind_position_t = typename Input::rewind_position_t;
+
+ using eol_rule = Eol;
+
+ template< typename... Ts >
+ explicit text_file_input_with_source( std::filesystem::path&& s, Ts&&... ts )
+ : Input( std::move( s ), static_cast< const std::filesystem::path& >( s ), std::forward< Ts >( ts )... )
+ {}
+
+ template< typename... Ts >
+ explicit text_file_input_with_source( const std::filesystem::path& s, Ts&&... ts )
+ : Input( s, s, std::forward< Ts >( ts )... )
+ {}
+ };
+
+} // namespace TAO_PEGTL_NAMESPACE::internal
+
+#endif
diff --git a/include/tao/pegtl/internal/text_input.hpp b/include/tao/pegtl/internal/text_input.hpp
new file mode 100644
index 000000000..15439e0e0
--- /dev/null
+++ b/include/tao/pegtl/internal/text_input.hpp
@@ -0,0 +1,125 @@
+// 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)
+
+#ifndef TAO_PEGTL_INTERNAL_TEXT_INPUT_HPP
+#define TAO_PEGTL_INTERNAL_TEXT_INPUT_HPP
+
+#include
+#include
+
+#include "../apply_mode.hpp"
+#include "../config.hpp"
+#include "../normal.hpp"
+#include "../nothing.hpp"
+#include "../pointer_position.hpp"
+#include "../rewind_mode.hpp"
+#include "../text_position.hpp"
+
+#include "input_with_lines.hpp"
+#include "text_eol_bump.hpp"
+
+namespace TAO_PEGTL_NAMESPACE::internal
+{
+ template< typename Eol, typename Input >
+ class text_input
+ : public input_with_lines< Eol, Input >
+ {
+ public:
+ using base_t = input_with_lines< Eol, Input >;
+ using data_t = char;
+ using error_position_t = text_position;
+ using rewind_position_t = text_position;
+
+ using eol_rule = Eol;
+
+ using input_with_lines< Eol, Input >::input_with_lines;
+
+ void restart() noexcept
+ {
+ base_t::restart();
+
+ m_position.count = 0;
+ m_position.line = 1;
+ m_position.column = 1;
+ };
+
+ void restart( const rewind_position_t& initial ) noexcept
+ {
+ base_t::restart();
+
+ m_position = initial;
+ }
+
+ [[nodiscard]] const char* previous( const rewind_position_t& saved ) const noexcept
+ {
+ return this->current() - m_position.count + saved.count;
+ }
+
+ template< typename Rule >
+ void consume( const std::size_t count ) noexcept
+ {
+ text_eol_bump< Eol, Rule >( m_position, this->current(), count );
+ Input::template consume< Rule >( count );
+ }
+
+ template< rewind_mode M >
+ [[nodiscard]] auto make_rewind_guard() noexcept
+ {
+ return rewind_guard< M, text_input >( this );
+ }
+
+ [[nodiscard]] auto rewind_position() const noexcept
+ {
+ return rewind_position_t( m_position );
+ }
+
+ void rewind_to_position( const rewind_position_t& saved ) noexcept
+ {
+ base_t::rewind_to_position( pointer_position< data_t >( previous( saved ) ) );
+
+ m_position = saved;
+ }
+
+ [[nodiscard]] const auto& current_position() const noexcept
+ {
+ return m_position;
+ }
+
+ [[nodiscard]] const auto& previous_position( const rewind_position_t& saved ) const noexcept
+ {
+ return saved;
+ }
+
+ [[nodiscard]] std::size_t direct_count() const noexcept // TODO: Keep?
+ {
+ return m_position.count;
+ }
+
+ [[nodiscard]] std::size_t direct_line() const noexcept // TODO: Keep?
+ {
+ return m_position.line;
+ }
+
+ [[nodiscard]] std::size_t direct_column() const noexcept // TODO: Keep?
+ {
+ return m_position.column;
+ }
+
+ [[nodiscard]] auto& private_position() noexcept
+ {
+ return m_position;
+ }
+
+ [[nodiscard]] const auto& direct_position() const noexcept
+ {
+ return m_position;
+ }
+
+ protected:
+ error_position_t m_position;
+ };
+
+} // namespace TAO_PEGTL_NAMESPACE::internal
+
+#endif
diff --git a/include/tao/pegtl/internal/text_input_with_source.hpp b/include/tao/pegtl/internal/text_input_with_source.hpp
new file mode 100644
index 000000000..d0e3f5fad
--- /dev/null
+++ b/include/tao/pegtl/internal/text_input_with_source.hpp
@@ -0,0 +1,124 @@
+// Copyright (c) 2021-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_INPUT_WITH_SOURCE_HPP
+#define TAO_PEGTL_INTERNAL_TEXT_INPUT_WITH_SOURCE_HPP
+
+#include
+#include
+
+#include "../config.hpp"
+#include "../position_with_source.hpp"
+#include "../text_position.hpp"
+
+#include "input_with_lines.hpp"
+
+namespace TAO_PEGTL_NAMESPACE::internal
+{
+ template< typename Eol, typename Source, typename Input >
+ class text_input_with_source
+ : public input_with_lines< Eol, Input >
+ {
+ public:
+ using base_t = input_with_lines< Eol, Input >;
+ using data_t = typename Input::data_t;
+ using error_position_t = position_with_source< Source, text_position >;
+ using rewind_position_t = text_position;
+
+ using eol_rule = Eol;
+
+ template< typename S, typename... Ts >
+ text_input_with_source( S&& s, Ts&&... ts )
+ : input_with_lines< Eol, Input >( std::forward< Ts >( ts )... ),
+ m_position( std::forward< S >( s ) )
+ {}
+
+ void restart() noexcept
+ {
+ base_t::restart();
+
+ m_position.count = 0;
+ m_position.line = 1;
+ m_position.column = 1;
+ };
+
+ void restart( const rewind_position_t& initial ) noexcept
+ {
+ base_t::restart();
+
+ m_position = initial;
+ }
+
+ [[nodiscard]] const char* previous( const rewind_position_t& saved ) const noexcept
+ {
+ return this->current() - m_position.count + saved.count;
+ }
+
+ template< typename Rule >
+ void consume( const std::size_t count ) noexcept
+ {
+ text_eol_bump< Eol, Rule >( m_position, this->current(), count );
+ Input::template consume< Rule >( count );
+ }
+
+ template< rewind_mode M >
+ [[nodiscard]] auto make_rewind_guard() noexcept
+ {
+ return rewind_guard< M, text_input_with_source >( this );
+ }
+
+ [[nodiscard]] auto rewind_position() const noexcept
+ {
+ return rewind_position_t( m_position );
+ }
+
+ void rewind_to_position( const rewind_position_t& saved ) noexcept
+ {
+ base_t::rewind_to_position( pointer_position< data_t >( previous( saved ) ) );
+
+ m_position.base() = saved;
+ }
+
+ [[nodiscard]] const auto& current_position() const noexcept
+ {
+ return m_position;
+ }
+
+ [[nodiscard]] auto previous_position( const rewind_position_t& saved ) const
+ {
+ return error_position_t( m_position.source, saved );
+ }
+
+ [[nodiscard]] std::size_t direct_count() const noexcept // TODO: Keep?
+ {
+ return m_position.count;
+ }
+
+ [[nodiscard]] std::size_t direct_line() const noexcept // TODO: Keep?
+ {
+ return m_position.line;
+ }
+
+ [[nodiscard]] std::size_t direct_column() const noexcept // TODO: Keep?
+ {
+ return m_position.column;
+ }
+
+ [[nodiscard]] const Source& direct_source() const noexcept // TODO: Keep?
+ {
+ return m_position.source;
+ }
+
+ [[nodiscard]] const auto& direct_position() const noexcept
+ {
+ return m_position;
+ }
+
+ protected:
+ error_position_t m_position;
+ };
+
+} // namespace TAO_PEGTL_NAMESPACE::internal
+
+#endif
diff --git a/include/tao/pegtl/internal/until.hpp b/include/tao/pegtl/internal/until.hpp
index cad3f13b7..4826a13d1 100644
--- a/include/tao/pegtl/internal/until.hpp
+++ b/include/tao/pegtl/internal/until.hpp
@@ -5,7 +5,6 @@
#ifndef TAO_PEGTL_INTERNAL_UNTIL_HPP
#define TAO_PEGTL_INTERNAL_UNTIL_HPP
-#include "bytes.hpp"
#include "enable_control.hpp"
#include "eof.hpp"
#include "not_at.hpp"
@@ -46,7 +45,7 @@ namespace TAO_PEGTL_NAMESPACE::internal
if( in.empty() ) {
return false;
}
- in.bump();
+ in.template consume< until >( 1 );
}
return m( true );
}
diff --git a/include/tao/pegtl/contrib/internal/vector_stack_guard.hpp b/include/tao/pegtl/internal/vector_stack_guard.hpp
similarity index 80%
rename from include/tao/pegtl/contrib/internal/vector_stack_guard.hpp
rename to include/tao/pegtl/internal/vector_stack_guard.hpp
index 1b7c69a8d..14e2e759c 100644
--- a/include/tao/pegtl/contrib/internal/vector_stack_guard.hpp
+++ b/include/tao/pegtl/internal/vector_stack_guard.hpp
@@ -2,12 +2,14 @@
// 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_INTERNAL_VECTOR_STACK_GUARD_HPP
-#define TAO_PEGTL_CONTRIB_INTERNAL_VECTOR_STACK_GUARD_HPP
+#ifndef TAO_PEGTL_INTERNAL_VECTOR_STACK_GUARD_HPP
+#define TAO_PEGTL_INTERNAL_VECTOR_STACK_GUARD_HPP
#include
#include
+#include "../config.hpp"
+
namespace TAO_PEGTL_NAMESPACE::internal
{
template< typename... Cs >
@@ -24,8 +26,8 @@ namespace TAO_PEGTL_NAMESPACE::internal
vector_stack_guard( vector_stack_guard&& ) = delete;
vector_stack_guard( const vector_stack_guard& ) = delete;
- vector_stack_guard& operator=( vector_stack_guard&& ) = delete;
- vector_stack_guard& operator=( const vector_stack_guard& ) = delete;
+ void operator=( vector_stack_guard&& ) = delete;
+ void operator=( const vector_stack_guard& ) = delete;
~vector_stack_guard()
{
diff --git a/include/tao/pegtl/internal/view_input.hpp b/include/tao/pegtl/internal/view_input.hpp
new file mode 100644
index 000000000..18693c860
--- /dev/null
+++ b/include/tao/pegtl/internal/view_input.hpp
@@ -0,0 +1,157 @@
+// Copyright (c) 2014-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_VIEW_INPUT_HPP
+#define TAO_PEGTL_INTERNAL_VIEW_INPUT_HPP
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "../config.hpp"
+#include "../pointer_position.hpp"
+
+#include "rewind_guard.hpp"
+
+namespace TAO_PEGTL_NAMESPACE::internal
+{
+ template< typename Data = char >
+ class view_input
+ {
+ public:
+ using data_t = Data;
+ using error_position_t = pointer_position< data_t >;
+ using rewind_position_t = pointer_position< data_t >;
+
+ view_input( const data_t* in_begin, const data_t* in_end ) noexcept
+ : m_current( in_begin ),
+ m_end( in_end )
+ {}
+
+ view_input( const data_t* in_begin, const std::size_t in_size ) noexcept
+ : view_input( in_begin, in_begin + in_size )
+ {}
+
+ view_input( std::string&& ) = delete;
+ view_input( const std::string&& ) = delete;
+
+ explicit view_input( std::string& data ) noexcept
+ : view_input( const_cast< const std::string& >( data ) )
+ {
+ static_assert( std::is_same_v< data_t, char > ); // TODO: Or reinterpret_cast for sizeof( data_t ) == 1 instead?
+ }
+
+ explicit view_input( const std::string& data ) noexcept
+ : view_input( data.data(), data.size() )
+ {
+ static_assert( std::is_same_v< data_t, char > ); // TODO: Or reinterpret_cast for sizeof( data_t ) == 1 instead?
+ }
+
+ explicit view_input( const std::string_view data ) noexcept
+ : view_input( data.data(), data.size() )
+ {
+ static_assert( std::is_same_v< data_t, char > ); // TODO: Or reinterpret_cast for sizeof( data_t ) == 1 instead?
+ }
+
+ view_input( std::vector< data_t >&& ) = delete;
+ view_input( const std::vector< data_t >&& ) = delete;
+
+ explicit view_input( std::vector< data_t >& data ) noexcept
+ : view_input( const_cast< const std::vector< data_t >& >( data ) )
+ {}
+
+ explicit view_input( const std::vector< data_t >& data ) noexcept
+ : view_input( data.data(), data.size() )
+ {}
+
+ template< std::size_t N >
+ explicit view_input( const char( &in_literal )[ N ] ) noexcept
+ : view_input( in_literal, N - 1 )
+ {
+ static_assert( std::is_same_v< data_t, char > ); // TODO: Or reinterpret_cast for sizeof( data_t ) == 1 instead?
+ }
+
+ template< std::size_t Size >
+ explicit view_input( const std::array< data_t, Size >& in_array ) noexcept
+ : view_input( in_array.data(), in_array.size() )
+ {}
+
+ [[nodiscard]] bool empty() const noexcept
+ {
+ return size() == 0;
+ }
+
+ [[nodiscard]] std::size_t size() const noexcept
+ {
+ return m_end - m_current;
+ }
+
+ [[nodiscard]] const data_t* current( const std::size_t offset = 0 ) const noexcept
+ {
+ return m_current + offset;
+ }
+
+ [[nodiscard]] const data_t* previous( const rewind_position_t saved ) const noexcept
+ {
+ return saved.data;
+ }
+
+ [[nodiscard]] const data_t* end() const noexcept
+ {
+ return m_end;
+ }
+
+ template< typename Rule >
+ void consume( const std::size_t count ) noexcept
+ {
+ m_current += count;
+ }
+
+ template< rewind_mode M >
+ [[nodiscard]] auto make_rewind_guard() noexcept
+ {
+ return rewind_guard< M, view_input >( this ); // TODO: With C++23 "deducing this" we don't need to re-implement this in derived classes that change the rewind position.
+ }
+
+ [[nodiscard]] auto rewind_position() const noexcept
+ {
+ return rewind_position_t( m_current );
+ }
+
+ void rewind_to_position( const rewind_position_t saved ) noexcept
+ {
+ m_current = saved.data;
+ }
+
+ [[nodiscard]] auto current_position() const noexcept
+ {
+ return error_position_t( m_current );
+ }
+
+ [[nodiscard]] auto previous_position( const rewind_position_t saved ) const noexcept
+ {
+ return saved; // error_position_t
+ }
+
+ void private_set_current( const data_t* in_current ) noexcept
+ {
+ m_current = in_current;
+ }
+
+ void private_set_end( const data_t* in_end ) noexcept
+ {
+ m_end = in_end;
+ }
+
+ protected:
+ const data_t* m_current;
+ const data_t* m_end;
+ };
+
+} // namespace TAO_PEGTL_NAMESPACE::internal
+
+#endif
diff --git a/include/tao/pegtl/invert_traits.hpp b/include/tao/pegtl/invert_traits.hpp
new file mode 100644
index 000000000..cbb62eb65
--- /dev/null
+++ b/include/tao/pegtl/invert_traits.hpp
@@ -0,0 +1,46 @@
+// 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_INVERT_TRAITS_HPP
+#define TAO_PEGTL_INVERT_TRAITS_HPP
+
+#include "config.hpp"
+#include "forward.hpp"
+
+#include "internal/any.hpp"
+#include "internal/enum_invert_bool.hpp"
+#include "internal/failure.hpp"
+#include "internal/one.hpp"
+#include "internal/range.hpp"
+#include "internal/result_on_found.hpp"
+
+namespace TAO_PEGTL_NAMESPACE
+{
+ template<>
+ struct invert_traits< internal::failure >
+ {
+ // Unfortunately at this point we don't know what Peek was and have to skip this corner case for the time being.
+ };
+
+ template< typename Peek >
+ struct invert_traits< internal::any< Peek > >
+ {
+ using rule_t = internal::failure;
+ };
+
+ template< internal::result_on_found R, typename Peek, typename Peek::data_t... Cs >
+ struct invert_traits< internal::one< R, Peek, Cs... > >
+ {
+ using rule_t = internal::one< internal::enum_invert_bool( R ), Peek, Cs... >;
+ };
+
+ template< internal::result_on_found R, typename Peek, typename Peek::data_t Lo, typename Peek::data_t Hi >
+ struct invert_traits< internal::range< R, Peek, Lo, Hi > >
+ {
+ using rule_t = internal::range< internal::enum_invert_bool( R ), Peek, Lo, Hi >;
+ };
+
+} // namespace TAO_PEGTL_NAMESPACE
+
+#endif
diff --git a/include/tao/pegtl/istream_input.hpp b/include/tao/pegtl/istream_input.hpp
deleted file mode 100644
index 54697cb56..000000000
--- a/include/tao/pegtl/istream_input.hpp
+++ /dev/null
@@ -1,33 +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)
-
-#ifndef TAO_PEGTL_ISTREAM_INPUT_HPP
-#define TAO_PEGTL_ISTREAM_INPUT_HPP
-
-#include
-
-#include "buffer_input.hpp"
-#include "config.hpp"
-#include "eol.hpp"
-
-#include "internal/istream_reader.hpp"
-
-namespace TAO_PEGTL_NAMESPACE
-{
- template< typename Eol = ascii::lf_crlf, std::size_t Chunk = 64 >
- struct istream_input
- : buffer_input< internal::istream_reader, Eol, std::string, Chunk >
- {
- template< typename T >
- istream_input( std::istream& in_stream, const std::size_t in_maximum, T&& in_source )
- : buffer_input< internal::istream_reader, Eol, std::string, Chunk >( std::forward< T >( in_source ), in_maximum, in_stream )
- {}
- };
-
- template< typename... Ts >
- istream_input( Ts&&... ) -> istream_input<>;
-
-} // namespace TAO_PEGTL_NAMESPACE
-
-#endif
diff --git a/include/tao/pegtl/line_view_at.hpp b/include/tao/pegtl/line_view_at.hpp
index da9e4a4ac..2bdcea245 100644
--- a/include/tao/pegtl/line_view_at.hpp
+++ b/include/tao/pegtl/line_view_at.hpp
@@ -9,36 +9,34 @@
#include "apply_mode.hpp"
#include "config.hpp"
-#include "memory_input.hpp"
#include "normal.hpp"
#include "nothing.hpp"
#include "rewind_mode.hpp"
-#include "tracking_mode.hpp"
#include "internal/at.hpp"
#include "internal/eolf.hpp"
+#include "internal/scan_input.hpp"
#include "internal/until.hpp"
namespace TAO_PEGTL_NAMESPACE
{
- template< typename Input >
- [[nodiscard]] const char* begin_of_line( const Input& in, const TAO_PEGTL_NAMESPACE::position& p ) noexcept
+ template< typename Input, typename Position >
+ [[nodiscard]] const char* begin_of_line( const Input& in, const Position& p ) noexcept
{
return in.at( p ) - ( p.column - 1 );
}
- template< typename Input >
- [[nodiscard]] const char* end_of_line_or_file( const Input& in, const TAO_PEGTL_NAMESPACE::position& p ) noexcept
+ template< typename Input, typename Position >
+ [[nodiscard]] const char* end_of_line_or_file( const Input& in, const Position& p ) noexcept
{
- using input_t = memory_input< tracking_mode::lazy, typename Input::eol_rule, const char* >;
- input_t i2( in.at( p ), in.end(), "" ); // TODO: Start before in.at( p ) to correctly handle the middle of a multi-token EOL.
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 );
return i2.current();
}
- template< typename Input >
- [[nodiscard]] std::string_view line_view_at( const Input& in, const TAO_PEGTL_NAMESPACE::position& p ) noexcept
+ template< typename Input, typename Position >
+ [[nodiscard]] std::string_view line_view_at( const Input& in, const Position& p ) noexcept
{
const char* b = begin_of_line( in, p );
return { b, static_cast< std::size_t >( end_of_line_or_file( in, p ) - b ) };
diff --git a/include/tao/pegtl/match.hpp b/include/tao/pegtl/match.hpp
index ed49d8bd6..6f47f066e 100644
--- a/include/tao/pegtl/match.hpp
+++ b/include/tao/pegtl/match.hpp
@@ -118,6 +118,8 @@ namespace TAO_PEGTL_NAMESPACE
constexpr bool has_apply0_bool = enable_action && internal::has_apply0< Control< Rule >, bool, Action, const ParseInput&, States... >;
constexpr bool has_apply0 = has_apply0_void || has_apply0_bool;
+ static_assert( !( has_apply_void && has_apply_bool ), "both void and bool apply() defined" );
+ static_assert( !( has_apply0_void && has_apply0_bool ), "both void and bool apply0() defined" );
static_assert( !( has_apply && has_apply0 ), "both apply() and apply0() defined" );
constexpr bool is_nothing = std::is_base_of_v< nothing< Rule >, Action< Rule > >;
diff --git a/include/tao/pegtl/memory_input.hpp b/include/tao/pegtl/memory_input.hpp
deleted file mode 100644
index 88a7665fb..000000000
--- a/include/tao/pegtl/memory_input.hpp
+++ /dev/null
@@ -1,365 +0,0 @@
-// Copyright (c) 2014-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_MEMORY_INPUT_HPP
-#define TAO_PEGTL_MEMORY_INPUT_HPP
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include "config.hpp"
-#include "eol.hpp"
-#include "normal.hpp"
-#include "nothing.hpp"
-#include "position.hpp"
-#include "tracking_mode.hpp"
-
-#include "internal/action_input.hpp"
-#include "internal/at.hpp"
-#include "internal/bump.hpp"
-#include "internal/inputerator.hpp"
-#include "internal/rewind_guard.hpp"
-#include "internal/until.hpp"
-
-namespace TAO_PEGTL_NAMESPACE
-{
- namespace internal
- {
- template< tracking_mode, typename Eol, typename Source >
- class memory_input_base;
-
- template< typename Eol, typename Source >
- class memory_input_base< tracking_mode::eager, Eol, Source >
- {
- public:
- using rewind_position_t = large_position;
-
- template< typename T >
- memory_input_base( const large_position& in_begin, const char* in_end, T&& in_source ) noexcept( std::is_nothrow_constructible_v< Source, T&& > )
- : m_begin( in_begin.data ),
- m_current( in_begin ),
- m_end( in_end ),
- m_source( std::forward< T >( in_source ) )
- {}
-
- template< typename T >
- memory_input_base( const char* in_begin, const char* in_end, T&& in_source ) noexcept( std::is_nothrow_constructible_v< Source, T&& > )
- : m_begin( in_begin ),
- m_current( in_begin ),
- m_end( in_end ),
- m_source( std::forward< T >( in_source ) )
- {}
-
- memory_input_base( memory_input_base&& ) = delete;
- memory_input_base( const memory_input_base& ) = delete;
-
- ~memory_input_base() = default;
-
- void operator=( memory_input_base&& ) = delete;
- void operator=( const memory_input_base& ) = delete;
-
- [[nodiscard]] const char* current() const noexcept
- {
- return m_current.data;
- }
-
- [[nodiscard]] const char* begin() const noexcept
- {
- return m_begin;
- }
-
- [[nodiscard]] const char* end( const std::size_t /*unused*/ = 0 ) const noexcept
- {
- return m_end;
- }
-
- [[nodiscard]] std::size_t byte() const noexcept
- {
- return m_current.byte;
- }
-
- [[nodiscard]] std::size_t line() const noexcept
- {
- return m_current.line;
- }
-
- [[nodiscard]] std::size_t column() const noexcept
- {
- return m_current.column;
- }
-
- void bump( const std::size_t in_count = 1 ) noexcept
- {
- internal::bump( m_current, in_count, '\n' );
- }
-
- void bump_in_this_line( const std::size_t in_count = 1 ) noexcept
- {
- internal::bump_in_this_line( m_current, in_count );
- }
-
- void bump_to_next_line( const std::size_t in_count = 1 ) noexcept
- {
- internal::bump_to_next_line( m_current, in_count );
- }
-
- [[nodiscard]] position previous_position( const rewind_position_t& it ) const
- {
- return position( it, m_source );
- }
-
- void restart( const std::size_t in_byte = 0, const std::size_t in_line = 1, const std::size_t in_column = 1 )
- {
- assert( in_line != 0 );
- assert( in_column != 0 );
-
- m_current.data = m_begin;
- m_current.byte = in_byte;
- m_current.line = in_line;
- m_current.column = in_column;
- }
-
- protected:
- const char* const m_begin;
- internal::large_position m_current;
- const char* m_end;
- const Source m_source;
- };
-
- template< typename Eol, typename Source >
- class memory_input_base< tracking_mode::lazy, Eol, Source >
- {
- public:
- using rewind_position_t = small_position;
-
- template< typename P, typename T >
- memory_input_base( const P& in_begin, const char* in_end, T&& in_source ) noexcept( std::is_nothrow_constructible_v< Source, T&& > )
- : m_begin( in_begin ),
- m_current( in_begin.data ),
- m_end( in_end ),
- m_source( std::forward< T >( in_source ) )
- {}
-
- template< typename T >
- memory_input_base( const char* in_begin, const char* in_end, T&& in_source ) noexcept( std::is_nothrow_constructible_v< Source, T&& > )
- : m_begin( in_begin ),
- m_current( in_begin ),
- m_end( in_end ),
- m_source( std::forward< T >( in_source ) )
- {}
-
- memory_input_base( memory_input_base&& ) = delete;
- memory_input_base( const memory_input_base& ) = delete;
-
- ~memory_input_base() = default;
-
- void operator=( memory_input_base&& ) = delete;
- void operator=( const memory_input_base& ) = delete;
-
- [[nodiscard]] const char* current() const noexcept
- {
- return m_current.data;
- }
-
- [[nodiscard]] const char* begin() const noexcept
- {
- return m_begin.data;
- }
-
- [[nodiscard]] const char* end( const std::size_t /*unused*/ = 0 ) const noexcept
- {
- return m_end;
- }
-
- [[nodiscard]] std::size_t byte() const noexcept
- {
- return std::size_t( m_current.data - m_begin.data );
- }
-
- void bump( const std::size_t in_count = 1 ) noexcept
- {
- m_current.data += in_count;
- }
-
- void bump_in_this_line( const std::size_t in_count = 1 ) noexcept
- {
- m_current.data += in_count;
- }
-
- void bump_to_next_line( const std::size_t in_count = 1 ) noexcept
- {
- m_current.data += in_count;
- }
-
- [[nodiscard]] position previous_position( const rewind_position_t& it ) const
- {
- internal::large_position c( m_begin );
- internal::bump( c, static_cast< std::size_t >( it.data - m_begin.data ), '\n' );
- return position( c, m_source );
- }
-
- void restart()
- {
- m_current.data = m_begin.data;
- }
-
- protected:
- const large_position m_begin;
- small_position m_current;
- const char* m_end;
- const Source m_source;
- };
-
- } // namespace internal
-
- template< tracking_mode P = tracking_mode::eager, typename Eol = ascii::lf_crlf, typename Source = std::string >
- class memory_input
- : public internal::memory_input_base< P, Eol, Source >
- {
- public:
- static constexpr tracking_mode tracking_mode_v = P;
-
- using data_t = char;
- using source_t = Source;
- using eol_rule = Eol;
- using typename internal::memory_input_base< P, Eol, Source >::rewind_position_t;
- using action_t = internal::action_input< memory_input >;
-
- using internal::memory_input_base< P, Eol, Source >::memory_input_base;
-
- template< typename T >
- memory_input( const char* in_begin, const std::size_t in_size, T&& in_source ) noexcept( std::is_nothrow_constructible_v< Source, T&& > )
- : memory_input( in_begin, in_begin + in_size, std::forward< T >( in_source ) )
- {}
-
- template< typename T >
- memory_input( const std::string& in_string, T&& in_source ) noexcept( std::is_nothrow_constructible_v< Source, T&& > )
- : memory_input( in_string.data(), in_string.size(), std::forward< T >( in_source ) )
- {}
-
- template< typename T >
- memory_input( const std::string_view in_string, T&& in_source ) noexcept( std::is_nothrow_constructible_v< Source, T&& > )
- : memory_input( in_string.data(), in_string.size(), std::forward< T >( in_source ) )
- {}
-
- template< typename T >
- memory_input( std::string&&, T&& ) = delete;
-
- template< typename T >
- memory_input( const char* in_begin, T&& in_source ) noexcept( std::is_nothrow_constructible_v< Source, T&& > )
- : memory_input( in_begin, std::strlen( in_begin ), std::forward< T >( in_source ) )
- {}
-
- template< typename T >
- memory_input( const char* in_begin, const char* in_end, T&& in_source, const std::size_t in_byte, const std::size_t in_line, const std::size_t in_column ) noexcept( std::is_nothrow_constructible_v< Source, T&& > )
- : memory_input( internal::large_position( in_begin, in_byte, in_line, in_column ), in_end, std::forward< T >( in_source ) )
- {}
-
- memory_input( const memory_input& ) = delete;
- memory_input( memory_input&& ) = delete;
-
- ~memory_input() = default;
-
- memory_input& operator=( const memory_input& ) = delete;
- memory_input& operator=( memory_input&& ) = delete;
-
- [[nodiscard]] const Source& source() const noexcept
- {
- return this->m_source;
- }
-
- [[nodiscard]] bool empty() const noexcept
- {
- return this->current() == this->end();
- }
-
- [[nodiscard]] std::size_t size( const std::size_t /*unused*/ = 0 ) const noexcept
- {
- return std::size_t( this->end() - this->current() );
- }
-
- [[nodiscard]] char peek_char( const std::size_t offset = 0 ) const noexcept
- {
- return this->current()[ offset ];
- }
-
- [[nodiscard]] std::uint8_t peek_uint8( const std::size_t offset = 0 ) const noexcept
- {
- return static_cast< std::uint8_t >( peek_char( offset ) );
- }
-
- // [[nodiscard]] rewind_position_t& rewind_position() noexcept
- // {
- // return this->m_current;
- // }
-
- using internal::memory_input_base< P, Eol, Source >::restart;
-
- [[nodiscard]] position current_position() const
- {
- return this->previous_position( this->m_current );
- }
-
- void discard() const noexcept {}
-
- void require( const std::size_t /*unused*/ ) const noexcept {}
-
- template< rewind_mode M >
- [[nodiscard]] internal::rewind_guard< M, memory_input > make_rewind_guard() noexcept
- {
- return internal::rewind_guard< M, memory_input >( this );
- }
-
- [[nodiscard]] const auto& rewind_position() const noexcept
- {
- return this->m_current;
- }
-
- void rewind_position( const rewind_position_t& data ) noexcept
- {
- this->m_current = data;
- }
-
- [[nodiscard]] const char* at( const position& p ) const noexcept
- {
- return this->begin() + p.byte;
- }
-
- void private_set_end( const char* new_end ) noexcept
- {
- // assert( new_end <= this->m_end );
- // assert( new_end >= this->m_current );
- this->m_end = new_end;
- }
-
- template< apply_mode A,
- rewind_mode M,
- template< typename... >
- class Action,
- template< typename... >
- class Control,
- typename ParseInput,
- typename... States >
- [[nodiscard]] static bool match_eol( ParseInput& in, States&&... st )
- {
- if( Control< typename Eol::rule_t >::template match< A, M, Action, Control >( in, st... ) ) {
- // in.template consume< eol_consume_tag >( 0 );
- return true;
- }
- return false;
- }
- };
-
- template< typename... Ts >
- memory_input( Ts&&... ) -> memory_input<>;
-
-} // namespace TAO_PEGTL_NAMESPACE
-
-#endif
diff --git a/include/tao/pegtl/mmap_input.hpp b/include/tao/pegtl/mmap_input.hpp
deleted file mode 100644
index 73445fdab..000000000
--- a/include/tao/pegtl/mmap_input.hpp
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright (c) 2014-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_MMAP_INPUT_HPP
-#define TAO_PEGTL_MMAP_INPUT_HPP
-
-#include
-#include
-
-#include "config.hpp"
-#include "eol.hpp"
-#include "memory_input.hpp"
-#include "tracking_mode.hpp"
-
-#include "internal/mmap_file.hpp"
-#include "internal/path_to_string.hpp"
-
-namespace TAO_PEGTL_NAMESPACE
-{
- template< tracking_mode P = tracking_mode::eager, typename Eol = ascii::lf_crlf >
- struct mmap_input
- : private internal::mmap_file,
- public memory_input< P, Eol >
- {
- mmap_input( const std::filesystem::path& path, const std::string& source )
- : internal::mmap_file( path ),
- memory_input< P, Eol >( data.begin(), data.end(), source )
- {}
-
- explicit mmap_input( const std::filesystem::path& path )
- : mmap_input( path, internal::path_to_string( path ) )
- {}
-
- mmap_input( const mmap_input& ) = delete;
- mmap_input( mmap_input&& ) = delete;
-
- ~mmap_input() = default;
-
- mmap_input& operator=( const mmap_input& ) = delete;
- mmap_input& operator=( mmap_input&& ) = delete;
- };
-
- template< typename... Ts >
- explicit mmap_input( Ts&&... ) -> mmap_input<>;
-
-} // namespace TAO_PEGTL_NAMESPACE
-
-#endif
diff --git a/include/tao/pegtl/normal.hpp b/include/tao/pegtl/normal.hpp
index ad9896a60..697137497 100644
--- a/include/tao/pegtl/normal.hpp
+++ b/include/tao/pegtl/normal.hpp
@@ -15,6 +15,7 @@
#include "parse_error.hpp"
#include "rewind_mode.hpp"
+#include "internal/action_input.hpp"
#include "internal/enable_control.hpp"
#include "internal/has_error_message.hpp"
#include "internal/has_match.hpp"
@@ -83,11 +84,11 @@ namespace TAO_PEGTL_NAMESPACE
typename RewindPosition,
typename ParseInput,
typename... States >
- static auto apply( const RewindPosition& begin, const ParseInput& in, States&&... st ) noexcept( noexcept( Action< Rule >::apply( std::declval< const typename ParseInput::action_t& >(), st... ) ) )
- -> decltype( Action< Rule >::apply( std::declval< const typename ParseInput::action_t& >(), st... ) )
+ static auto apply( const RewindPosition& begin, const ParseInput& in, States&&... st ) noexcept( noexcept( Action< Rule >::apply( std::declval< const internal::action_input< ParseInput >& >(), st... ) ) )
+ -> decltype( Action< Rule >::apply( std::declval< const internal::action_input< ParseInput >& >(), st... ) )
{
- const typename ParseInput::action_t action_input( begin, in );
- return Action< Rule >::apply( action_input, st... );
+ const internal::action_input< ParseInput > ai( begin, in );
+ return Action< Rule >::apply( ai, st... );
}
template< template< typename... > class Action,
diff --git a/include/tao/pegtl/parse.hpp b/include/tao/pegtl/parse.hpp
index ab34ac2a8..79b357af5 100644
--- a/include/tao/pegtl/parse.hpp
+++ b/include/tao/pegtl/parse.hpp
@@ -12,26 +12,10 @@
#include "normal.hpp"
#include "nothing.hpp"
#include "parse_error.hpp"
-#include "position.hpp"
#include "rewind_mode.hpp"
namespace TAO_PEGTL_NAMESPACE
{
- namespace internal
- {
- [[nodiscard]] inline auto get_position( const position& p ) noexcept( std::is_nothrow_copy_constructible_v< position > )
- {
- return p;
- }
-
- template< typename ParseInput >
- [[nodiscard]] position get_position( const ParseInput& in ) noexcept( noexcept( position( in.position() ) ) )
- {
- return in.position();
- }
-
- } // namespace internal
-
template< typename Rule,
template< typename... > class Action = nothing,
template< typename... > class Control = normal,
diff --git a/include/tao/pegtl/parse_error.hpp b/include/tao/pegtl/parse_error.hpp
index b9ec149c2..b365f6b9e 100644
--- a/include/tao/pegtl/parse_error.hpp
+++ b/include/tao/pegtl/parse_error.hpp
@@ -12,7 +12,6 @@
#include "config.hpp"
#include "parse_error_base.hpp"
-#include "position.hpp"
#include "internal/extract_position.hpp"
#include "internal/stream_to_string.hpp"
@@ -25,15 +24,15 @@ namespace TAO_PEGTL_NAMESPACE
};
template< typename Position >
- class parse_error_template
+ class parse_error
: public parse_error_base
{
public:
using position_t = Position;
template< typename Object >
- parse_error_template( const std::string& msg, const Object& obj )
- : parse_error_template( msg, internal::extract_position( obj ), disambiguate_t() )
+ parse_error( const std::string& msg, const Object& obj )
+ : parse_error( msg, internal::extract_position( obj ), disambiguate_t() )
{}
[[nodiscard]] const position_t& position_object() const noexcept
@@ -44,16 +43,14 @@ namespace TAO_PEGTL_NAMESPACE
protected:
const position_t m_position;
- parse_error_template( const std::string& msg, const Position& pos, const disambiguate_t /*unused*/ )
+ parse_error( 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_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.
+ parse_error( const std::string&, const Object& ) -> parse_error< std::decay_t< decltype( internal::extract_position( std::declval< Object >() ) ) > >;
} // namespace TAO_PEGTL_NAMESPACE
diff --git a/include/tao/pegtl/parse_error_base.hpp b/include/tao/pegtl/parse_error_base.hpp
index 889f2efb2..586de6fb2 100644
--- a/include/tao/pegtl/parse_error_base.hpp
+++ b/include/tao/pegtl/parse_error_base.hpp
@@ -9,7 +9,6 @@
#include
#include
#include
-#include
#include "config.hpp"
diff --git a/include/tao/pegtl/pointer_position.hpp b/include/tao/pegtl/pointer_position.hpp
new file mode 100644
index 000000000..6e78fc324
--- /dev/null
+++ b/include/tao/pegtl/pointer_position.hpp
@@ -0,0 +1,49 @@
+// Copyright (c) 2021-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_POINTER_POSITION_HPP
+#define TAO_PEGTL_POINTER_POSITION_HPP
+
+#include
+
+#include "config.hpp"
+
+namespace TAO_PEGTL_NAMESPACE
+{
+ template< typename Data >
+ struct pointer_position
+ {
+ const Data* data = nullptr;
+
+ pointer_position() noexcept = default;
+
+ explicit pointer_position( const Data* in_data ) noexcept
+ : data( in_data )
+ {}
+ };
+
+ template< typename Data >
+ pointer_position( const Data* ) -> pointer_position< Data >;
+
+ template< typename Data >
+ [[nodiscard]] bool operator==( const pointer_position< Data > l, const pointer_position< Data > r ) noexcept
+ {
+ return l.current == r.current;
+ }
+
+ template< typename Data >
+ [[nodiscard]] bool operator!=( const pointer_position< Data > l, const pointer_position< Data > r ) noexcept
+ {
+ return !( l == r );
+ }
+
+ template< typename Data >
+ std::ostream& operator<<( std::ostream& os, const pointer_position< Data > p )
+ {
+ return os << static_cast< const volatile void* >( p.data );
+ }
+
+} // namespace TAO_PEGTL_NAMESPACE
+
+#endif
diff --git a/include/tao/pegtl/position.hpp b/include/tao/pegtl/position.hpp
deleted file mode 100644
index 1015fbb69..000000000
--- a/include/tao/pegtl/position.hpp
+++ /dev/null
@@ -1,69 +0,0 @@
-// Copyright (c) 2014-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_POSITION_HPP
-#define TAO_PEGTL_POSITION_HPP
-
-#include
-#include
-#include
-
-#include "config.hpp"
-
-#include "internal/inputerator.hpp"
-
-namespace TAO_PEGTL_NAMESPACE
-{
- struct position
- {
- position() = delete;
-
- position( position&& ) noexcept = default;
- position( const position& ) = default;
-
- position& operator=( position&& p ) noexcept = default;
- position& operator=( const position& ) = default;
-
- template< typename T >
- position( const internal::large_position& in_iter, T&& in_source )
- : byte( in_iter.byte ),
- line( in_iter.line ),
- column( in_iter.column ),
- source( std::forward< T >( in_source ) )
- {}
-
- template< typename T >
- position( const std::size_t in_byte, const std::size_t in_line, const std::size_t in_column, T&& in_source )
- : byte( in_byte ),
- line( in_line ),
- column( in_column ),
- source( std::forward< T >( in_source ) )
- {}
-
- ~position() = default;
-
- std::size_t byte;
- std::size_t line;
- std::size_t column;
- std::string source;
- };
-
- [[nodiscard]] inline bool operator==( const position& lhs, const position& rhs ) noexcept
- {
- return ( lhs.byte == rhs.byte ) && ( lhs.source == rhs.source );
- }
-
- [[nodiscard]] inline bool operator!=( const position& lhs, const position& rhs ) noexcept
- {
- return !( lhs == rhs );
- }
-
- inline std::ostream& operator<<( std::ostream& os, const position& p )
- {
- return os << p.source << ':' << p.line << ':' << p.column;
- }
-
-} // namespace TAO_PEGTL_NAMESPACE
-
-#endif
diff --git a/include/tao/pegtl/position_with_source.hpp b/include/tao/pegtl/position_with_source.hpp
new file mode 100644
index 000000000..396545b21
--- /dev/null
+++ b/include/tao/pegtl/position_with_source.hpp
@@ -0,0 +1,58 @@
+// Copyright (c) 2021-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_POSITION_WITH_SOURCE_HPP
+#define TAO_PEGTL_INTERNAL_POSITION_WITH_SOURCE_HPP
+
+#include
+#include
+
+#include "config.hpp"
+
+namespace TAO_PEGTL_NAMESPACE::internal
+{
+ template< typename Source, typename Position >
+ struct position_with_source
+ : Position
+ {
+ Source source;
+
+ template< typename S, typename... Ps >
+ explicit position_with_source( S&& s, Ps&&... ps )
+ : Position( std::forward< Ps >( ps )... ),
+ source( std::forward< S >( s ) )
+ {}
+
+ [[nodiscard]] Position& base() noexcept
+ {
+ return *this;
+ }
+
+ [[nodiscard]] const Position& base() const noexcept
+ {
+ return *this;
+ }
+ };
+
+ template< typename Source, typename Position >
+ [[nodiscard]] bool operator==( const position_with_source< Source, Position >& l, const position_with_source< Source, Position >& r ) noexcept
+ {
+ return ( l.source == r.source ) && ( l.base() == r.base() );
+ }
+
+ template< typename Source, typename Position >
+ [[nodiscard]] bool operator!=( const position_with_source< Source, Position >& l, const position_with_source< Source, Position >& r ) noexcept
+ {
+ return !( l == r );
+ }
+
+ template< typename Source, typename Position >
+ std::ostream& operator<<( std::ostream& os, const position_with_source< Source, Position >& p )
+ {
+ return os << p.source << '@' << p.base();
+ }
+
+} // namespace TAO_PEGTL_NAMESPACE::internal
+
+#endif
diff --git a/include/tao/pegtl/contrib/print.hpp b/include/tao/pegtl/print.hpp
similarity index 90%
rename from include/tao/pegtl/contrib/print.hpp
rename to include/tao/pegtl/print.hpp
index 6e079e9dd..fc42a9e11 100644
--- a/include/tao/pegtl/contrib/print.hpp
+++ b/include/tao/pegtl/print.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_CONTRIB_PRINT_HPP
-#define TAO_PEGTL_CONTRIB_PRINT_HPP
+#ifndef TAO_PEGTL_PRINT_HPP
+#define TAO_PEGTL_PRINT_HPP
#include
-#include "../config.hpp"
-#include "../demangle.hpp"
-#include "../type_list.hpp"
-#include "../visit.hpp"
+#include "config.hpp"
+#include "demangle.hpp"
+#include "type_list.hpp"
+#include "visit.hpp"
namespace TAO_PEGTL_NAMESPACE
{
diff --git a/include/tao/pegtl/read_input.hpp b/include/tao/pegtl/read_input.hpp
deleted file mode 100644
index 2b1bd9706..000000000
--- a/include/tao/pegtl/read_input.hpp
+++ /dev/null
@@ -1,55 +0,0 @@
-// Copyright (c) 2014-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_READ_INPUT_HPP
-#define TAO_PEGTL_READ_INPUT_HPP
-
-#include
-#include
-
-#include "config.hpp"
-#include "eol.hpp"
-#include "string_input.hpp"
-#include "tracking_mode.hpp"
-
-#include "internal/path_to_string.hpp"
-#include "internal/read_file_stdio.hpp"
-
-namespace TAO_PEGTL_NAMESPACE
-{
- template< tracking_mode P = tracking_mode::eager, typename Eol = ascii::lf_crlf >
- struct read_input
- : string_input< P, Eol >
- {
- read_input( const std::filesystem::path& path, const std::string& source )
- : string_input< P, Eol >( internal::read_file_stdio( path ).read_string(), source )
- {}
-
- explicit read_input( const std::filesystem::path& path )
- : read_input( path, internal::path_to_string( path ) )
- {}
-
- read_input( FILE* file, const std::filesystem::path& path, const std::string& source )
- : string_input< P, Eol >( internal::read_file_stdio( file, path ).read_string(), source )
- {}
-
- read_input( FILE* file, const std::filesystem::path& path )
- : read_input( file, path, internal::path_to_string( path ) )
- {}
-
- read_input( const read_input& ) = delete;
- read_input( read_input&& ) = delete;
-
- ~read_input() = default;
-
- read_input& operator=( const read_input& ) = delete;
- read_input& operator=( read_input&& ) = delete;
- };
-
- template< typename... Ts >
- explicit read_input( Ts&&... ) -> read_input<>;
-
-} // namespace TAO_PEGTL_NAMESPACE
-
-#endif
diff --git a/include/tao/pegtl/contrib/remove_first_state.hpp b/include/tao/pegtl/remove_first_state.hpp
similarity index 95%
rename from include/tao/pegtl/contrib/remove_first_state.hpp
rename to include/tao/pegtl/remove_first_state.hpp
index 192ea91f7..fdbaef6f4 100644
--- a/include/tao/pegtl/contrib/remove_first_state.hpp
+++ b/include/tao/pegtl/remove_first_state.hpp
@@ -2,14 +2,14 @@
// 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_REMOVE_FIRST_STATE_HPP
-#define TAO_PEGTL_CONTRIB_REMOVE_FIRST_STATE_HPP
+#ifndef TAO_PEGTL_REMOVE_FIRST_STATE_HPP
+#define TAO_PEGTL_REMOVE_FIRST_STATE_HPP
#include
-#include "../config.hpp"
+#include "config.hpp"
-#include "../internal/has_unwind.hpp"
+#include "internal/has_unwind.hpp"
namespace TAO_PEGTL_NAMESPACE
{
diff --git a/include/tao/pegtl/contrib/remove_last_states.hpp b/include/tao/pegtl/remove_last_states.hpp
similarity index 97%
rename from include/tao/pegtl/contrib/remove_last_states.hpp
rename to include/tao/pegtl/remove_last_states.hpp
index 80472adbf..904e048e5 100644
--- a/include/tao/pegtl/contrib/remove_last_states.hpp
+++ b/include/tao/pegtl/remove_last_states.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_CONTRIB_REMOVE_LAST_STATES_HPP
-#define TAO_PEGTL_CONTRIB_REMOVE_LAST_STATES_HPP
+#ifndef TAO_PEGTL_REMOVE_LAST_STATES_HPP
+#define TAO_PEGTL_REMOVE_LAST_STATES_HPP
#include
#include
-#include "../config.hpp"
+#include "config.hpp"
-#include "../internal/has_unwind.hpp"
+#include "internal/has_unwind.hpp"
namespace TAO_PEGTL_NAMESPACE
{
diff --git a/include/tao/pegtl/rules.hpp b/include/tao/pegtl/rules.hpp
index 344314dbe..11845155f 100644
--- a/include/tao/pegtl/rules.hpp
+++ b/include/tao/pegtl/rules.hpp
@@ -8,8 +8,8 @@
#include
#include "config.hpp"
+#include "invert_traits.hpp"
#include "parse_error.hpp"
-#include "position.hpp"
#include "internal/rules.hpp"
@@ -22,10 +22,8 @@ namespace TAO_PEGTL_NAMESPACE
template< typename... Rules > struct at : internal::at< Rules... > {};
struct bof : internal::bof {};
struct bol : internal::bol {};
- template< unsigned Num > struct bytes : internal::bytes< Num > {};
template< template< typename... > class Control, typename... Rules > struct control : internal::control< Control, Rules... > {};
template< typename... Rules > struct disable : internal::disable< Rules... > {};
- struct discard : internal::discard {};
template< typename... Rules > struct enable : internal::enable< Rules... > {};
struct eof : internal::eof {};
struct eol : internal::eol {};
@@ -34,6 +32,7 @@ namespace TAO_PEGTL_NAMESPACE
struct failure : internal::failure {};
template< typename Rule, typename... Actions > struct if_apply : internal::if_apply< Rule, Actions... > {};
template< typename Cond, typename Then, typename Else > struct if_then_else : internal::if_then_else< Cond, Then, Else > {};
+ template< typename Rule > struct invert : invert_traits< typename Rule::rule_t >::rule_t {};
template< typename Rule, typename Sep, typename Pad = void > struct list : internal::list< Rule, internal::pad< Sep, Pad > > {};
template< typename Rule, typename Sep > struct list< Rule, Sep, void > : internal::list< Rule, Sep > {};
template< typename Rule, typename Sep, typename Pad = void > struct list_tail : internal::list_tail_pad< Rule, Sep, Pad > {};
@@ -51,7 +50,6 @@ namespace TAO_PEGTL_NAMESPACE
template< unsigned Min, typename Rule, typename... Rules > struct rep_min : internal::rep_min< Min, Rule, Rules... > {};
template< unsigned Min, unsigned Max, typename... Rules > struct rep_min_max : internal::rep_min_max< Min, Max, Rules... > {};
template< unsigned Max, typename... Rules > struct rep_opt : internal::rep_opt< Max, Rules... > {};
- template< unsigned Amount > struct require : internal::require< Amount > {};
template< typename... Rules > struct seq : internal::seq< Rules... > {};
template< typename... Rules > struct sor : internal::sor< Rules... > {};
template< typename Rule, typename... Rules > struct star : internal::star< Rule, Rules... > {};
diff --git a/include/tao/pegtl/string_input.hpp b/include/tao/pegtl/string_input.hpp
deleted file mode 100644
index 3bfd9fb1c..000000000
--- a/include/tao/pegtl/string_input.hpp
+++ /dev/null
@@ -1,65 +0,0 @@
-// Copyright (c) 2014-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_STRING_INPUT_HPP
-#define TAO_PEGTL_STRING_INPUT_HPP
-
-#include
-#include
-
-#include "config.hpp"
-#include "eol.hpp"
-#include "memory_input.hpp"
-#include "tracking_mode.hpp"
-
-namespace TAO_PEGTL_NAMESPACE
-{
- namespace internal
- {
- struct string_holder
- {
- const std::string data;
-
- template< typename T >
- explicit string_holder( T&& in_data )
- : data( std::forward< T >( in_data ) )
- {}
-
- string_holder( const string_holder& ) = delete;
- string_holder( string_holder&& ) = delete;
-
- ~string_holder() = default;
-
- string_holder& operator=( const string_holder& ) = delete;
- string_holder& operator=( string_holder&& ) = delete;
- };
-
- } // namespace internal
-
- template< tracking_mode P = tracking_mode::eager, typename Eol = ascii::lf_crlf, typename Source = std::string >
- struct string_input
- : private internal::string_holder,
- public memory_input< P, Eol, Source >
- {
- template< typename V, typename T, typename... Ts >
- explicit string_input( V&& in_data, T&& in_source, Ts&&... ts )
- : internal::string_holder( std::forward< V >( in_data ) ),
- memory_input< P, Eol, Source >( data.data(), data.size(), std::forward< T >( in_source ), std::forward< Ts >( ts )... )
- {}
-
- string_input( const string_input& ) = delete;
- string_input( string_input&& ) = delete;
-
- ~string_input() = default;
-
- string_input& operator=( const string_input& ) = delete;
- string_input& operator=( string_input&& ) = delete;
- };
-
- template< typename... Ts >
- explicit string_input( Ts&&... ) -> string_input<>;
-
-} // namespace TAO_PEGTL_NAMESPACE
-
-#endif
diff --git a/include/tao/pegtl/text_position.hpp b/include/tao/pegtl/text_position.hpp
new file mode 100644
index 000000000..5b241c467
--- /dev/null
+++ b/include/tao/pegtl/text_position.hpp
@@ -0,0 +1,71 @@
+// Copyright (c) 2021-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_TEXT_POSITION_HPP
+#define TAO_PEGTL_TEXT_POSITION_HPP
+
+#include
+#include
+#include
+
+#include "config.hpp"
+
+namespace TAO_PEGTL_NAMESPACE
+{
+ struct text_position
+ {
+ std::size_t count = 0;
+ std::size_t line = 1;
+ std::size_t column = 1;
+
+ text_position() = default;
+
+ text_position( const std::size_t in_count, const std::size_t in_line, const std::size_t in_column ) noexcept
+ : count( in_count ),
+ line( in_line ),
+ column( in_column )
+ {}
+ };
+
+ [[nodiscard]] inline bool operator==( const text_position l, const text_position r ) noexcept
+ {
+ return ( l.count == r.count ) && ( l.line == r.line ) && ( l.column == r.column );
+ }
+
+ [[nodiscard]] inline bool operator!=( const text_position l, const text_position r ) noexcept
+ {
+ return !( l == r );
+ }
+
+ inline std::ostream& operator<<( std::ostream& os, const text_position p )
+ {
+ return os << p.line << ':' << p.column << '(' << p.count << ')';
+ }
+
+ inline text_position& operator+=( text_position& l, const text_position& r ) noexcept
+ {
+ if( r.line == 1 ) {
+ l.column += r.column - 1;
+ }
+ else {
+ l.line += r.line - 1;
+ l.column = r.column;
+ }
+ l.count += r.count;
+ return l;
+ }
+
+ [[nodiscard]] inline text_position operator+( const text_position& l, const text_position& r ) noexcept
+ {
+ if( r.line == 1 ) {
+ return text_position( l.count + r.count, l.line, l.column + r.column - 1 );
+ }
+ else {
+ return text_position( l.count + r.count, l.line + r.line - 1, r.column );
+ }
+ }
+
+} // namespace TAO_PEGTL_NAMESPACE
+
+#endif
diff --git a/include/tao/pegtl/tracking_mode.hpp b/include/tao/pegtl/tracking_mode.hpp
deleted file mode 100644
index a15e58d43..000000000
--- a/include/tao/pegtl/tracking_mode.hpp
+++ /dev/null
@@ -1,20 +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)
-
-#ifndef TAO_PEGTL_TRACKING_MODE_HPP
-#define TAO_PEGTL_TRACKING_MODE_HPP
-
-#include "config.hpp"
-
-namespace TAO_PEGTL_NAMESPACE
-{
- enum class tracking_mode : bool
- {
- eager,
- lazy
- };
-
-} // namespace TAO_PEGTL_NAMESPACE
-
-#endif
diff --git a/include/tao/pegtl/contrib/uint16.hpp b/include/tao/pegtl/uint16.hpp
similarity index 92%
rename from include/tao/pegtl/contrib/uint16.hpp
rename to include/tao/pegtl/uint16.hpp
index 412686236..8924a6840 100644
--- a/include/tao/pegtl/contrib/uint16.hpp
+++ b/include/tao/pegtl/uint16.hpp
@@ -2,16 +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_CONTRIB_UINT16_HPP
-#define TAO_PEGTL_CONTRIB_UINT16_HPP
+#ifndef TAO_PEGTL_UINT16_HPP
+#define TAO_PEGTL_UINT16_HPP
-#include "../config.hpp"
-
-#include "../internal/result_on_found.hpp"
-#include "../internal/rules.hpp"
+#include "config.hpp"
#include "internal/peek_mask_uint.hpp"
-#include "internal/peek_uint.hpp"
+#include "internal/peek_endian.hpp"
+#include "internal/result_on_found.hpp"
+#include "internal/rules.hpp"
namespace TAO_PEGTL_NAMESPACE
{
@@ -19,7 +18,7 @@ namespace TAO_PEGTL_NAMESPACE
{
// clang-format off
struct any : internal::any< internal::peek_uint16_be > {};
-
+ template< unsigned Count > struct many : internal::many< Count, internal::peek_uint16_be > {};
template< std::uint16_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_uint16_be, Cs... > {};
template< std::uint16_t Lo, std::uint16_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_uint16_be, Lo, Hi > {};
template< std::uint16_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_uint16_be, Cs... > {};
@@ -41,7 +40,7 @@ namespace TAO_PEGTL_NAMESPACE
{
// clang-format off
struct any : internal::any< internal::peek_uint16_le > {};
-
+ template< unsigned Count > struct many : internal::many< Count, internal::peek_uint16_le > {};
template< std::uint16_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_uint16_le, Cs... > {};
template< std::uint16_t Lo, std::uint16_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_uint16_le, Lo, Hi > {};
template< std::uint16_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_uint16_le, Cs... > {};
diff --git a/include/tao/pegtl/contrib/uint32.hpp b/include/tao/pegtl/uint32.hpp
similarity index 92%
rename from include/tao/pegtl/contrib/uint32.hpp
rename to include/tao/pegtl/uint32.hpp
index 05dfa6f6c..7f0c20d85 100644
--- a/include/tao/pegtl/contrib/uint32.hpp
+++ b/include/tao/pegtl/uint32.hpp
@@ -2,16 +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_CONTRIB_UINT32_HPP
-#define TAO_PEGTL_CONTRIB_UINT32_HPP
+#ifndef TAO_PEGTL_UINT32_HPP
+#define TAO_PEGTL_UINT32_HPP
-#include "../config.hpp"
-
-#include "../internal/result_on_found.hpp"
-#include "../internal/rules.hpp"
+#include "config.hpp"
#include "internal/peek_mask_uint.hpp"
-#include "internal/peek_uint.hpp"
+#include "internal/peek_endian.hpp"
+#include "internal/result_on_found.hpp"
+#include "internal/rules.hpp"
namespace TAO_PEGTL_NAMESPACE
{
@@ -19,7 +18,7 @@ namespace TAO_PEGTL_NAMESPACE
{
// clang-format off
struct any : internal::any< internal::peek_uint32_be > {};
-
+ template< unsigned Count > struct many : internal::many< Count, internal::peek_uint32_be > {};
template< std::uint32_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_uint32_be, Cs... > {};
template< std::uint32_t Lo, std::uint32_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_uint32_be, Lo, Hi > {};
template< std::uint32_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_uint32_be, Cs... > {};
@@ -41,7 +40,7 @@ namespace TAO_PEGTL_NAMESPACE
{
// clang-format off
struct any : internal::any< internal::peek_uint32_le > {};
-
+ template< unsigned Count > struct many : internal::many< Count, internal::peek_uint32_le > {};
template< std::uint32_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_uint32_le, Cs... > {};
template< std::uint32_t Lo, std::uint32_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_uint32_le, Lo, Hi > {};
template< std::uint32_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_uint32_le, Cs... > {};
diff --git a/include/tao/pegtl/contrib/uint64.hpp b/include/tao/pegtl/uint64.hpp
similarity index 92%
rename from include/tao/pegtl/contrib/uint64.hpp
rename to include/tao/pegtl/uint64.hpp
index e1cdb864e..b8c996579 100644
--- a/include/tao/pegtl/contrib/uint64.hpp
+++ b/include/tao/pegtl/uint64.hpp
@@ -2,16 +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_CONTRIB_UINT64_HPP
-#define TAO_PEGTL_CONTRIB_UINT64_HPP
+#ifndef TAO_PEGTL_UINT64_HPP
+#define TAO_PEGTL_UINT64_HPP
-#include "../config.hpp"
-
-#include "../internal/result_on_found.hpp"
-#include "../internal/rules.hpp"
+#include "config.hpp"
#include "internal/peek_mask_uint.hpp"
-#include "internal/peek_uint.hpp"
+#include "internal/peek_endian.hpp"
+#include "internal/result_on_found.hpp"
+#include "internal/rules.hpp"
namespace TAO_PEGTL_NAMESPACE
{
@@ -19,7 +18,7 @@ namespace TAO_PEGTL_NAMESPACE
{
// clang-format off
struct any : internal::any< internal::peek_uint64_be > {};
-
+ template< unsigned Count > struct many : internal::many< Count, internal::peek_uint64_be > {};
template< std::uint64_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_uint64_be, Cs... > {};
template< std::uint64_t Lo, std::uint64_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_uint64_be, Lo, Hi > {};
template< std::uint64_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_uint64_be, Cs... > {};
@@ -27,7 +26,6 @@ namespace TAO_PEGTL_NAMESPACE
template< std::uint64_t... Cs > struct ranges : internal::ranges< internal::peek_uint64_be, Cs... > {};
template< std::uint64_t... Cs > struct string : internal::seq< internal::one< internal::result_on_found::success, internal::peek_uint64_be, Cs >... > {};
-
template< std::uint64_t M, std::uint64_t... Cs > struct mask_not_one : internal::one< internal::result_on_found::failure, internal::peek_mask_uint64_be< M >, Cs... > {};
template< std::uint64_t M, std::uint64_t Lo, std::uint64_t Hi > struct mask_not_range : internal::range< internal::result_on_found::failure, internal::peek_mask_uint64_be< M >, Lo, Hi > {};
template< std::uint64_t M, std::uint64_t... Cs > struct mask_one : internal::one< internal::result_on_found::success, internal::peek_mask_uint64_be< M >, Cs... > {};
@@ -42,7 +40,7 @@ namespace TAO_PEGTL_NAMESPACE
{
// clang-format off
struct any : internal::any< internal::peek_uint64_le > {};
-
+ template< unsigned Count > struct many : internal::many< Count, internal::peek_uint64_le > {};
template< std::uint64_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_uint64_le, Cs... > {};
template< std::uint64_t Lo, std::uint64_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_uint64_le, Lo, Hi > {};
template< std::uint64_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_uint64_le, Cs... > {};
diff --git a/include/tao/pegtl/contrib/uint8.hpp b/include/tao/pegtl/uint8.hpp
similarity index 89%
rename from include/tao/pegtl/contrib/uint8.hpp
rename to include/tao/pegtl/uint8.hpp
index 1b0a7c5f5..1bc59872a 100644
--- a/include/tao/pegtl/contrib/uint8.hpp
+++ b/include/tao/pegtl/uint8.hpp
@@ -2,22 +2,21 @@
// 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_UINT8_HPP
-#define TAO_PEGTL_CONTRIB_UINT8_HPP
+#ifndef TAO_PEGTL_UINT8_HPP
+#define TAO_PEGTL_UINT8_HPP
-#include "../config.hpp"
-
-#include "../internal/result_on_found.hpp"
-#include "../internal/rules.hpp"
+#include "config.hpp"
+#include "internal/result_on_found.hpp"
+#include "internal/peek_direct.hpp"
#include "internal/peek_mask_uint8.hpp"
-#include "internal/peek_uint8.hpp"
+#include "internal/rules.hpp"
namespace TAO_PEGTL_NAMESPACE::uint8
{
// clang-format off
struct any : internal::any< internal::peek_uint8 > {};
-
+ template< unsigned Count > struct many : internal::many< Count, internal::peek_uint8 > {};
template< std::uint8_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_uint8, Cs... > {};
template< std::uint8_t Lo, std::uint8_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_uint8, Lo, Hi > {};
template< std::uint8_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_uint8, Cs... > {};
diff --git a/include/tao/pegtl/contrib/utf16.hpp b/include/tao/pegtl/utf16.hpp
similarity index 84%
rename from include/tao/pegtl/contrib/utf16.hpp
rename to include/tao/pegtl/utf16.hpp
index dabac9f70..e9a782c83 100644
--- a/include/tao/pegtl/contrib/utf16.hpp
+++ b/include/tao/pegtl/utf16.hpp
@@ -2,15 +2,14 @@
// 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_UTF16_HPP
-#define TAO_PEGTL_CONTRIB_UTF16_HPP
+#ifndef TAO_PEGTL_UTF16_HPP
+#define TAO_PEGTL_UTF16_HPP
-#include "../config.hpp"
-
-#include "../internal/result_on_found.hpp"
-#include "../internal/rules.hpp"
+#include "config.hpp"
#include "internal/peek_utf16.hpp"
+#include "internal/result_on_found.hpp"
+#include "internal/rules.hpp"
namespace TAO_PEGTL_NAMESPACE
{
@@ -19,6 +18,7 @@ namespace TAO_PEGTL_NAMESPACE
// clang-format off
struct any : internal::any< internal::peek_utf16_be > {};
struct bom : internal::one< internal::result_on_found::success, internal::peek_utf16_be, 0xfeff > {};
+ template< unsigned Count > struct many : internal::many< Count, internal::peek_utf16_be > {};
template< char32_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_utf16_be, Cs... > {};
template< char32_t Lo, char32_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_utf16_be, Lo, Hi > {};
template< char32_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_utf16_be, Cs... > {};
@@ -34,6 +34,7 @@ namespace TAO_PEGTL_NAMESPACE
// clang-format off
struct any : internal::any< internal::peek_utf16_le > {};
struct bom : internal::one< internal::result_on_found::success, internal::peek_utf16_le, 0xfeff > {};
+ template< unsigned Count > struct many : internal::many< Count, internal::peek_utf16_le > {};
template< char32_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_utf16_le, Cs... > {};
template< char32_t Lo, char32_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_utf16_le, Lo, Hi > {};
template< char32_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_utf16_le, Cs... > {};
@@ -44,15 +45,7 @@ namespace TAO_PEGTL_NAMESPACE
} // namespace utf16_le
-#if defined( _WIN32 ) && !defined( __MINGW32__ ) && !defined( __CYGWIN__ )
- namespace utf16 = utf16_le;
-#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
- namespace utf16 = utf16_le;
-#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
- namespace utf16 = utf16_be;
-#else
-#error Unknown endianness.
-#endif
+ namespace utf16 = TAO_PEGTL_ENDIAN_SUFFIXED( utf16_ );
} // namespace TAO_PEGTL_NAMESPACE
diff --git a/include/tao/pegtl/contrib/utf32.hpp b/include/tao/pegtl/utf32.hpp
similarity index 84%
rename from include/tao/pegtl/contrib/utf32.hpp
rename to include/tao/pegtl/utf32.hpp
index 84f3cb04b..0a4181105 100644
--- a/include/tao/pegtl/contrib/utf32.hpp
+++ b/include/tao/pegtl/utf32.hpp
@@ -2,15 +2,14 @@
// 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_UTF32_HPP
-#define TAO_PEGTL_CONTRIB_UTF32_HPP
+#ifndef TAO_PEGTL_UTF32_HPP
+#define TAO_PEGTL_UTF32_HPP
-#include "../config.hpp"
-
-#include "../internal/result_on_found.hpp"
-#include "../internal/rules.hpp"
+#include "config.hpp"
#include "internal/peek_utf32.hpp"
+#include "internal/result_on_found.hpp"
+#include "internal/rules.hpp"
namespace TAO_PEGTL_NAMESPACE
{
@@ -19,6 +18,7 @@ namespace TAO_PEGTL_NAMESPACE
// clang-format off
struct any : internal::any< internal::peek_utf32_be > {};
struct bom : internal::one< internal::result_on_found::success, internal::peek_utf32_be, 0xfeff > {};
+ template< unsigned Count > struct many : internal::many< Count, internal::peek_utf32_be > {};
template< char32_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_utf32_be, Cs... > {};
template< char32_t Lo, char32_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_utf32_be, Lo, Hi > {};
template< char32_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_utf32_be, Cs... > {};
@@ -34,6 +34,7 @@ namespace TAO_PEGTL_NAMESPACE
// clang-format off
struct any : internal::any< internal::peek_utf32_le > {};
struct bom : internal::one< internal::result_on_found::success, internal::peek_utf32_le, 0xfeff > {};
+ template< unsigned Count > struct many : internal::many< Count, internal::peek_utf32_le > {};
template< char32_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_utf32_le, Cs... > {};
template< char32_t Lo, char32_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_utf32_le, Lo, Hi > {};
template< char32_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_utf32_le, Cs... > {};
@@ -44,15 +45,7 @@ namespace TAO_PEGTL_NAMESPACE
} // namespace utf32_le
-#if defined( _WIN32 ) && !defined( __MINGW32__ ) && !defined( __CYGWIN__ )
- namespace utf32 = utf32_le;
-#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
- namespace utf32 = utf32_le;
-#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
- namespace utf32 = utf32_be;
-#else
-#error Unknown endianness.
-#endif
+ namespace utf32 = TAO_PEGTL_ENDIAN_SUFFIXED( utf32_ );
} // namespace TAO_PEGTL_NAMESPACE
diff --git a/include/tao/pegtl/utf8.hpp b/include/tao/pegtl/utf8.hpp
index 302b4b0ca..2a47b56be 100644
--- a/include/tao/pegtl/utf8.hpp
+++ b/include/tao/pegtl/utf8.hpp
@@ -16,6 +16,7 @@ namespace TAO_PEGTL_NAMESPACE::utf8
// clang-format off
struct any : internal::any< internal::peek_utf8 > {};
struct bom : internal::one< internal::result_on_found::success, internal::peek_utf8, 0xfeff > {}; // Lemon curry?
+ template< unsigned Count > struct many : internal::many< Count, internal::peek_utf8 > {};
template< char32_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_utf8, Cs... > {};
template< char32_t Lo, char32_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_utf8, Lo, Hi > {};
template< char32_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_utf8, Cs... > {};
diff --git a/src/example/pegtl/abnf2pegtl.cpp b/src/example/pegtl/abnf2pegtl.cc
similarity index 100%
rename from src/example/pegtl/abnf2pegtl.cpp
rename to src/example/pegtl/abnf2pegtl.cc
diff --git a/src/example/pegtl/analyze.cpp b/src/example/pegtl/analyze.cc
similarity index 100%
rename from src/example/pegtl/analyze.cpp
rename to src/example/pegtl/analyze.cc
diff --git a/src/example/pegtl/calculator.cpp b/src/example/pegtl/calculator.cc
similarity index 100%
rename from src/example/pegtl/calculator.cpp
rename to src/example/pegtl/calculator.cc
diff --git a/src/example/pegtl/chomsky_hierarchy.cpp b/src/example/pegtl/chomsky_hierarchy.cc
similarity index 100%
rename from src/example/pegtl/chomsky_hierarchy.cpp
rename to src/example/pegtl/chomsky_hierarchy.cc
diff --git a/src/example/pegtl/csv1.cpp b/src/example/pegtl/csv1.cc
similarity index 100%
rename from src/example/pegtl/csv1.cpp
rename to src/example/pegtl/csv1.cc
diff --git a/src/example/pegtl/csv2.cpp b/src/example/pegtl/csv2.cc
similarity index 100%
rename from src/example/pegtl/csv2.cpp
rename to src/example/pegtl/csv2.cc
diff --git a/src/example/pegtl/dynamic_match.cpp b/src/example/pegtl/dynamic_match.cc
similarity index 100%
rename from src/example/pegtl/dynamic_match.cpp
rename to src/example/pegtl/dynamic_match.cc
diff --git a/src/example/pegtl/expression.cpp b/src/example/pegtl/expression.cc
similarity index 100%
rename from src/example/pegtl/expression.cpp
rename to src/example/pegtl/expression.cc
diff --git a/src/example/pegtl/hello_world.cpp b/src/example/pegtl/hello_world.cc
similarity index 100%
rename from src/example/pegtl/hello_world.cpp
rename to src/example/pegtl/hello_world.cc
diff --git a/src/example/pegtl/indent_aware.cpp b/src/example/pegtl/indent_aware.cc
similarity index 100%
rename from src/example/pegtl/indent_aware.cpp
rename to src/example/pegtl/indent_aware.cc
diff --git a/src/example/pegtl/iri.cpp b/src/example/pegtl/iri.cc
similarity index 100%
rename from src/example/pegtl/iri.cpp
rename to src/example/pegtl/iri.cc
diff --git a/src/example/pegtl/json_analyze.cpp b/src/example/pegtl/json_analyze.cc
similarity index 100%
rename from src/example/pegtl/json_analyze.cpp
rename to src/example/pegtl/json_analyze.cc
diff --git a/src/example/pegtl/json_ast.cpp b/src/example/pegtl/json_ast.cc
similarity index 100%
rename from src/example/pegtl/json_ast.cpp
rename to src/example/pegtl/json_ast.cc
diff --git a/src/example/pegtl/json_build.cpp b/src/example/pegtl/json_build.cc
similarity index 100%
rename from src/example/pegtl/json_build.cpp
rename to src/example/pegtl/json_build.cc
diff --git a/src/example/pegtl/json_count.cpp b/src/example/pegtl/json_count.cc
similarity index 100%
rename from src/example/pegtl/json_count.cpp
rename to src/example/pegtl/json_count.cc
diff --git a/src/example/pegtl/json_coverage.cpp b/src/example/pegtl/json_coverage.cc
similarity index 100%
rename from src/example/pegtl/json_coverage.cpp
rename to src/example/pegtl/json_coverage.cc
diff --git a/src/example/pegtl/json_parse.cpp b/src/example/pegtl/json_parse.cc
similarity index 100%
rename from src/example/pegtl/json_parse.cpp
rename to src/example/pegtl/json_parse.cc
diff --git a/src/example/pegtl/json_print_debug.cpp b/src/example/pegtl/json_print_debug.cc
similarity index 100%
rename from src/example/pegtl/json_print_debug.cpp
rename to src/example/pegtl/json_print_debug.cc
diff --git a/src/example/pegtl/json_print_names.cpp b/src/example/pegtl/json_print_names.cc
similarity index 100%
rename from src/example/pegtl/json_print_names.cpp
rename to src/example/pegtl/json_print_names.cc
diff --git a/src/example/pegtl/json_trace.cpp b/src/example/pegtl/json_trace.cc
similarity index 100%
rename from src/example/pegtl/json_trace.cpp
rename to src/example/pegtl/json_trace.cc
diff --git a/src/example/pegtl/lua53_analyze.cpp b/src/example/pegtl/lua53_analyze.cc
similarity index 100%
rename from src/example/pegtl/lua53_analyze.cpp
rename to src/example/pegtl/lua53_analyze.cc
diff --git a/src/example/pegtl/lua53_parse.cpp b/src/example/pegtl/lua53_parse.cc
similarity index 100%
rename from src/example/pegtl/lua53_parse.cpp
rename to src/example/pegtl/lua53_parse.cc
diff --git a/src/example/pegtl/modulus_match.cpp b/src/example/pegtl/modulus_match.cc
similarity index 100%
rename from src/example/pegtl/modulus_match.cpp
rename to src/example/pegtl/modulus_match.cc
diff --git a/src/example/pegtl/parse_tree.cpp b/src/example/pegtl/parse_tree.cc
similarity index 100%
rename from src/example/pegtl/parse_tree.cpp
rename to src/example/pegtl/parse_tree.cc
diff --git a/src/example/pegtl/parse_tree_user_state.cpp b/src/example/pegtl/parse_tree_user_state.cc
similarity index 100%
rename from src/example/pegtl/parse_tree_user_state.cpp
rename to src/example/pegtl/parse_tree_user_state.cc
diff --git a/src/example/pegtl/proto3.cpp b/src/example/pegtl/proto3.cc
similarity index 100%
rename from src/example/pegtl/proto3.cpp
rename to src/example/pegtl/proto3.cc
diff --git a/src/example/pegtl/random_order.cpp b/src/example/pegtl/random_order.cc
similarity index 100%
rename from src/example/pegtl/random_order.cpp
rename to src/example/pegtl/random_order.cc
diff --git a/src/example/pegtl/recover.cpp b/src/example/pegtl/recover.cc
similarity index 100%
rename from src/example/pegtl/recover.cpp
rename to src/example/pegtl/recover.cc
diff --git a/src/example/pegtl/s_expression.cpp b/src/example/pegtl/s_expression.cc
similarity index 100%
rename from src/example/pegtl/s_expression.cpp
rename to src/example/pegtl/s_expression.cc
diff --git a/src/example/pegtl/sum.cpp b/src/example/pegtl/sum.cc
similarity index 100%
rename from src/example/pegtl/sum.cpp
rename to src/example/pegtl/sum.cc
diff --git a/src/example/pegtl/symbol_table.cpp b/src/example/pegtl/symbol_table.cc
similarity index 100%
rename from src/example/pegtl/symbol_table.cpp
rename to src/example/pegtl/symbol_table.cc
diff --git a/src/example/pegtl/temporary.cc b/src/example/pegtl/temporary.cc
new file mode 100644
index 000000000..009891984
--- /dev/null
+++ b/src/example/pegtl/temporary.cc
@@ -0,0 +1,6 @@
+#include
+
+int main()
+{
+ return 0;
+}
diff --git a/src/example/pegtl/token_input.cpp b/src/example/pegtl/token_input.cc
similarity index 98%
rename from src/example/pegtl/token_input.cpp
rename to src/example/pegtl/token_input.cc
index 26db2ac9e..953c7593c 100644
--- a/src/example/pegtl/token_input.cpp
+++ b/src/example/pegtl/token_input.cc
@@ -140,7 +140,7 @@ namespace TAO_PEGTL_NAMESPACE
return rewind_position_t( m_current );
}
- void rewind_position( const rewind_position_t& data ) noexcept
+ void rewind_to_position( const rewind_position_t& data ) noexcept
{
m_current = data.data;
}
diff --git a/src/example/pegtl/unescape.cpp b/src/example/pegtl/unescape.cc
similarity index 100%
rename from src/example/pegtl/unescape.cpp
rename to src/example/pegtl/unescape.cc
diff --git a/src/example/pegtl/uri.cpp b/src/example/pegtl/uri.cc
similarity index 100%
rename from src/example/pegtl/uri.cpp
rename to src/example/pegtl/uri.cc
diff --git a/src/example/pegtl/uri_print_debug.cpp b/src/example/pegtl/uri_print_debug.cc
similarity index 100%
rename from src/example/pegtl/uri_print_debug.cpp
rename to src/example/pegtl/uri_print_debug.cc
diff --git a/src/example/pegtl/uri_print_names.cpp b/src/example/pegtl/uri_print_names.cc
similarity index 100%
rename from src/example/pegtl/uri_print_names.cpp
rename to src/example/pegtl/uri_print_names.cc
diff --git a/src/example/pegtl/uri_trace.cpp b/src/example/pegtl/uri_trace.cc
similarity index 100%
rename from src/example/pegtl/uri_trace.cpp
rename to src/example/pegtl/uri_trace.cc
diff --git a/src/test/pegtl/CMakeLists.txt b/src/test/pegtl/CMakeLists.txt
index 8c8adcbe8..b6172e396 100644
--- a/src/test/pegtl/CMakeLists.txt
+++ b/src/test/pegtl/CMakeLists.txt
@@ -83,7 +83,6 @@ set(test_sources
rule_at.cpp
rule_bof.cpp
rule_bol.cpp
- rule_bytes.cpp
rule_control.cpp
rule_disable.cpp
rule_discard.cpp
@@ -98,6 +97,7 @@ set(test_sources
rule_list.cpp
rule_list_must.cpp
rule_list_tail.cpp
+ rule_many.cpp
rule_minus.cpp
rule_must.cpp
rule_not_at.cpp
diff --git a/src/test/pegtl/action_enable.cpp b/src/test/pegtl/action_enable.cpp
index 89118e275..eb74a4841 100644
--- a/src/test/pegtl/action_enable.cpp
+++ b/src/test/pegtl/action_enable.cpp
@@ -3,6 +3,14 @@
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
#include "test.hpp"
+#include "test_inputs.hpp"
+
+#include
+#include
+#include
+#include
+#include
+#include
namespace TAO_PEGTL_NAMESPACE
{
@@ -49,7 +57,7 @@ namespace TAO_PEGTL_NAMESPACE
void unit_test()
{
- memory_input<> in( "abcba", "" );
+ test::text_input< ascii::lf > in( "abcba" );
int a = 0;
int b = 0;
int c = 0;
diff --git a/src/test/pegtl/action_match.cpp b/src/test/pegtl/action_match_lazy.cpp
similarity index 60%
rename from src/test/pegtl/action_match.cpp
rename to src/test/pegtl/action_match_lazy.cpp
index 29446bc6c..81326adb0 100644
--- a/src/test/pegtl/action_match.cpp
+++ b/src/test/pegtl/action_match_lazy.cpp
@@ -3,6 +3,13 @@
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
#include "test.hpp"
+#include "test_inputs.hpp"
+
+#include
+#include
+#include
+#include
+#include
namespace TAO_PEGTL_NAMESPACE
{
@@ -33,11 +40,12 @@ namespace TAO_PEGTL_NAMESPACE
// - ...
std::size_t global_state = 0;
+ const char* global_start = nullptr;
struct state_one
{
- std::size_t byte_in_line_a;
- std::size_t byte_in_line_b;
+ std::size_t applications_a = 0;
+ std::size_t applications_b = 0;
};
// clang-format off
@@ -78,7 +86,14 @@ namespace TAO_PEGTL_NAMESPACE
template< typename ActionInput >
static void apply( const ActionInput& in, state_one& state )
{
- state.byte_in_line_b += in.input().byte();
+ ++state.applications_b;
+ TAO_PEGTL_TEST_ASSERT( in.current_position().count == 1 );
+ TAO_PEGTL_TEST_ASSERT( in.current_position().line == 1 );
+ TAO_PEGTL_TEST_ASSERT( in.current_position().column == 2 );
+ TAO_PEGTL_TEST_ASSERT( in.input().current_position().count == 2 );
+ TAO_PEGTL_TEST_ASSERT( in.input().current_position().line == 1 );
+ TAO_PEGTL_TEST_ASSERT( in.input().current_position().column == 3 );
+ TAO_PEGTL_TEST_ASSERT( in.current() == global_start + 1 );
}
};
@@ -98,17 +113,26 @@ namespace TAO_PEGTL_NAMESPACE
template< typename ActionInput >
static void apply( const ActionInput& in, state_one& state )
{
- state.byte_in_line_a += in.input().byte();
+ ++state.applications_a;
+ TAO_PEGTL_TEST_ASSERT( in.current_position().count == 0 );
+ TAO_PEGTL_TEST_ASSERT( in.current_position().line == 1 );
+ TAO_PEGTL_TEST_ASSERT( in.current_position().column == 1 );
+ TAO_PEGTL_TEST_ASSERT( in.input().current_position().count == 1 );
+ TAO_PEGTL_TEST_ASSERT( in.input().current_position().line == 1 );
+ TAO_PEGTL_TEST_ASSERT( in.input().current_position().column == 2 );
+ TAO_PEGTL_TEST_ASSERT( in.current() == global_start );
}
};
void unit_test()
{
- state_one state{ 0, 0 };
- bool parse_result = parse< grammar_one_a, action_one_a >( memory_input( "aaa", __FUNCTION__ ), state );
+ state_one state;
+ test::lazy_input< ascii::lf >in( "aaa" );
+ global_start = in.current();
+ const bool parse_result = parse< grammar_one_a, action_one_a >( in, state );
TAO_PEGTL_TEST_ASSERT( parse_result );
- TAO_PEGTL_TEST_ASSERT( state.byte_in_line_a == 1 );
- TAO_PEGTL_TEST_ASSERT( state.byte_in_line_b == 2 );
+ TAO_PEGTL_TEST_ASSERT( state.applications_a == 1 );
+ TAO_PEGTL_TEST_ASSERT( state.applications_b == 1 );
TAO_PEGTL_TEST_ASSERT( global_state == 1 );
}
diff --git a/src/test/pegtl/action_match_text.cpp b/src/test/pegtl/action_match_text.cpp
new file mode 100644
index 000000000..a86c70254
--- /dev/null
+++ b/src/test/pegtl/action_match_text.cpp
@@ -0,0 +1,147 @@
+// Copyright (c) 2019-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 "test.hpp"
+#include "test_inputs.hpp"
+
+#include
+#include
+#include
+#include
+#include
+
+namespace TAO_PEGTL_NAMESPACE
+{
+ struct remove_state
+ {
+ template< typename Rule,
+ 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&&... /*unused*/ )
+ {
+ return TAO_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in );
+ }
+ };
+
+ // further generic helpers could be build, e.g.
+ //
+ // - change_control
+ // - remove prefix/suffix from input (e.g. remove surrounding quotes)
+ // - replace the input completely?
+ // - append states
+ // - prepend states
+ // - ...
+
+ std::size_t global_state = 0;
+ const char* global_start = nullptr;
+
+ struct state_one
+ {
+ std::size_t applications_a = 0;
+ std::size_t applications_b = 0;
+ };
+
+ // clang-format off
+ struct grammar_inner : one< 'a' > {};
+ struct grammar_one_c : seq< grammar_inner > {};
+ struct grammar_one_b : seq< grammar_inner, grammar_one_c > {};
+ struct grammar_one_a : seq< grammar_inner, grammar_one_b, eof > {};
+ // clang-format on
+
+ template< typename Rule >
+ struct action_one_b
+ {};
+
+ template< typename Rule >
+ struct action_one_t
+ {};
+
+ template< typename Rule >
+ struct action_one_a
+ {};
+
+ template<>
+ struct action_one_b< grammar_one_c >
+ : remove_state
+ {};
+
+ template<>
+ struct action_one_b< grammar_inner >
+ {
+ // used inside of remove_state
+ template< typename ActionInput >
+ static void apply( const ActionInput& /*unused*/ )
+ {
+ ++global_state;
+ }
+
+ // used outside of remove_state
+ template< typename ActionInput >
+ static void apply( const ActionInput& in, state_one& state )
+ {
+ ++state.applications_b;
+ TAO_PEGTL_TEST_ASSERT( in.current_position().count == 1 );
+ TAO_PEGTL_TEST_ASSERT( in.current_position().line == 1 );
+ TAO_PEGTL_TEST_ASSERT( in.current_position().column == 2 );
+ TAO_PEGTL_TEST_ASSERT( in.input().current_position().count == 2 );
+ TAO_PEGTL_TEST_ASSERT( in.input().current_position().line == 1 );
+ TAO_PEGTL_TEST_ASSERT( in.input().current_position().column == 3 );
+ TAO_PEGTL_TEST_ASSERT( in.input().direct_position().count == 2 );
+ TAO_PEGTL_TEST_ASSERT( in.input().direct_position().line == 1 );
+ TAO_PEGTL_TEST_ASSERT( in.input().direct_position().column == 3 );
+ TAO_PEGTL_TEST_ASSERT( in.current() == global_start + 1 );
+ }
+ };
+
+ template<>
+ struct action_one_t< grammar_one_b >
+ : change_action< action_one_b >
+ {};
+
+ template<>
+ struct action_one_a< grammar_one_b >
+ : change_action< action_one_t >
+ {};
+
+ template<>
+ struct action_one_a< grammar_inner >
+ {
+ template< typename ActionInput >
+ static void apply( const ActionInput& in, state_one& state )
+ {
+ ++state.applications_a;
+ TAO_PEGTL_TEST_ASSERT( in.current_position().count == 0 );
+ TAO_PEGTL_TEST_ASSERT( in.current_position().line == 1 );
+ TAO_PEGTL_TEST_ASSERT( in.current_position().column == 1 );
+ TAO_PEGTL_TEST_ASSERT( in.input().current_position().count == 1 );
+ TAO_PEGTL_TEST_ASSERT( in.input().current_position().line == 1 );
+ TAO_PEGTL_TEST_ASSERT( in.input().current_position().column == 2 );
+ TAO_PEGTL_TEST_ASSERT( in.input().direct_position().count == 1 );
+ TAO_PEGTL_TEST_ASSERT( in.input().direct_position().line == 1 );
+ TAO_PEGTL_TEST_ASSERT( in.input().direct_position().column == 2 );
+ TAO_PEGTL_TEST_ASSERT( in.current() == global_start );
+ }
+ };
+
+ void unit_test()
+ {
+ state_one state;
+ test::text_input< ascii::lf >in( "aaa" );
+ global_start = in.current();
+ const bool parse_result = parse< grammar_one_a, action_one_a >( in, state );
+ TAO_PEGTL_TEST_ASSERT( parse_result );
+ TAO_PEGTL_TEST_ASSERT( state.applications_a == 1 );
+ TAO_PEGTL_TEST_ASSERT( state.applications_b == 1 );
+ TAO_PEGTL_TEST_ASSERT( global_state == 1 );
+ }
+
+} // namespace TAO_PEGTL_NAMESPACE
+
+#include "main.hpp"
diff --git a/src/test/pegtl/actions_one.cpp b/src/test/pegtl/actions_1.cpp
similarity index 82%
rename from src/test/pegtl/actions_one.cpp
rename to src/test/pegtl/actions_1.cpp
index 5e6172986..bbb63e61e 100644
--- a/src/test/pegtl/actions_one.cpp
+++ b/src/test/pegtl/actions_1.cpp
@@ -2,12 +2,18 @@
// 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 "test.hpp"
-
#include
#include
#include
+#include "test.hpp"
+#include "test_inputs.hpp"
+
+#include
+#include
+#include
+#include
+
namespace TAO_PEGTL_NAMESPACE
{
std::vector< std::pair< std::string, std::string > > applied;
@@ -67,7 +73,8 @@ namespace TAO_PEGTL_NAMESPACE
void unit_test()
{
- parse< disable< test1::bar >, test_action >( memory_input( "baab", __FUNCTION__ ) );
+ const auto result = parse< disable< test1::bar >, test_action >( test::text_input< ascii::lf >( "baab" ) );
+ TAO_PEGTL_TEST_ASSERT( result );
TAO_PEGTL_TEST_ASSERT( applied.size() == 1 );
TAO_PEGTL_TEST_ASSERT( applied[ 0 ].first == demangle< disable< test1::bar > >() );
@@ -75,25 +82,25 @@ namespace TAO_PEGTL_NAMESPACE
applied.clear();
- parse< at< action< test_action, test1::bar > > >( memory_input( "baab", __FUNCTION__ ) );
+ parse< at< action< test_action, test1::bar > > >( test::text_input< ascii::lf >( "baab" ) );
TAO_PEGTL_TEST_ASSERT( applied.empty() );
applied.clear();
- parse< test1::bar, test_action >( memory_input( "baab", __FUNCTION__ ) );
+ parse< test1::bar, test_action >( test::text_input< ascii::lf >( "baab" ) );
test1::test_result();
applied.clear();
- parse< action< test_action, test1::bar > >( memory_input( "baab", __FUNCTION__ ) );
+ parse< action< test_action, test1::bar > >( test::text_input< ascii::lf >( "baab" ) );
test1::test_result();
applied.clear();
- parse< disable< enable< action< test_action, test1::bar > > > >( memory_input( "baab", __FUNCTION__ ) );
+ parse< disable< enable< action< test_action, test1::bar > > > >( test::text_input< ascii::lf >( "baab" ) );
test1::test_result();
}
diff --git a/src/test/pegtl/actions_two.cpp b/src/test/pegtl/actions_2.cpp
similarity index 78%
rename from src/test/pegtl/actions_two.cpp
rename to src/test/pegtl/actions_2.cpp
index d14380a44..318181975 100644
--- a/src/test/pegtl/actions_two.cpp
+++ b/src/test/pegtl/actions_2.cpp
@@ -3,6 +3,12 @@
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
#include "test.hpp"
+#include "test_inputs.hpp"
+
+#include
+#include
+#include
+#include
namespace TAO_PEGTL_NAMESPACE
{
@@ -41,7 +47,7 @@ namespace TAO_PEGTL_NAMESPACE
template< typename ActionInput >
static void apply( const ActionInput& in, state1& s )
{
- assert( in.size() == 1 );
+ TAO_PEGTL_TEST_ASSERT( in.size() == 1 );
s.c = in.begin()[ 0 ];
}
};
@@ -49,7 +55,7 @@ namespace TAO_PEGTL_NAMESPACE
void state_test()
{
std::string result;
- memory_input in( "dk41sk41xk3", __FUNCTION__ );
+ test::text_input< ascii::lf > in( "dk41sk41xk3" );
parse< fibble, action1 >( in, result );
TAO_PEGTL_TEST_ASSERT( result == "dkskxk" );
}
@@ -80,11 +86,11 @@ namespace TAO_PEGTL_NAMESPACE
void apply0_test()
{
- memory_input ina( "abcdefgh", __FUNCTION__ );
+ test::text_input< ascii::lf > ina( "abcdefgh" );
parse< star< alpha >, action0 >( ina );
TAO_PEGTL_TEST_ASSERT( i0 == 8 );
std::string s0;
- memory_input ind( "12345678", __FUNCTION__ );
+ test::text_input< ascii::lf > ind( "12345678" );
parse< star< digit >, action0 >( ind, s0 );
TAO_PEGTL_TEST_ASSERT( s0 == "00000000" );
}
@@ -93,7 +99,7 @@ namespace TAO_PEGTL_NAMESPACE
const std::size_t count_line = 42;
const std::size_t count_column = 12;
- const char* count_source = "count_source";
+ // const char* count_source = "count_source";
template< typename Rule >
struct count_action
@@ -101,10 +107,10 @@ namespace TAO_PEGTL_NAMESPACE
template< typename ActionInput >
static void apply( const ActionInput& in )
{
- TAO_PEGTL_TEST_ASSERT( in.rewind_position().byte == count_byte );
+ TAO_PEGTL_TEST_ASSERT( in.rewind_position().count == count_byte );
TAO_PEGTL_TEST_ASSERT( in.rewind_position().line == count_line );
TAO_PEGTL_TEST_ASSERT( in.rewind_position().column == count_column );
- TAO_PEGTL_TEST_ASSERT( in.input().source() == count_source );
+ // TAO_PEGTL_TEST_ASSERT( in.input().current_position().source == count_source );
TAO_PEGTL_TEST_ASSERT( in.size() == 1 );
TAO_PEGTL_TEST_ASSERT( in.begin() + 1 == in.end() );
TAO_PEGTL_TEST_ASSERT( in.peek_char() == 'f' );
@@ -115,7 +121,10 @@ namespace TAO_PEGTL_NAMESPACE
void count_test()
{
const char* foo = "f";
- memory_input in( foo, foo + 1, count_source, count_byte, count_line, count_column );
+ test::text_input< ascii::lf > in( foo, foo + 1 );
+ in.private_position().count = count_byte;
+ in.private_position().line = count_line;
+ in.private_position().column = count_column;
TAO_PEGTL_TEST_ASSERT( parse< alpha, count_action >( in ) );
}
diff --git a/src/test/pegtl/actions_three.cpp b/src/test/pegtl/actions_3.cpp
similarity index 89%
rename from src/test/pegtl/actions_three.cpp
rename to src/test/pegtl/actions_3.cpp
index 5185274d4..b8b88140e 100644
--- a/src/test/pegtl/actions_three.cpp
+++ b/src/test/pegtl/actions_3.cpp
@@ -3,6 +3,12 @@
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
#include "test.hpp"
+#include "test_inputs.hpp"
+
+#include
+#include
+#include
+#include
namespace TAO_PEGTL_NAMESPACE
{
@@ -53,7 +59,7 @@ namespace TAO_PEGTL_NAMESPACE
void apply_bool_true()
{
apply_result = true;
- memory_input in( "ab", __FUNCTION__ );
+ test::text_input< ascii::lf > in( "ab" );
const auto result = parse< grammar, apply_bool_action >( in );
TAO_PEGTL_TEST_ASSERT( result );
TAO_PEGTL_TEST_ASSERT( in.size() == 1 );
@@ -63,7 +69,7 @@ namespace TAO_PEGTL_NAMESPACE
void apply_bool_false()
{
apply_result = false;
- memory_input in( "ab", __FUNCTION__ );
+ test::text_input< ascii::lf > in( "ab" );
const auto result = parse< grammar, apply_bool_action >( in );
TAO_PEGTL_TEST_ASSERT( !result );
TAO_PEGTL_TEST_ASSERT( in.size() == 2 );
@@ -86,7 +92,7 @@ namespace TAO_PEGTL_NAMESPACE
void apply0_bool_true()
{
apply_result = true;
- memory_input in( "ab", __FUNCTION__ );
+ test::text_input< ascii::lf > in( "ab" );
const auto result = parse< grammar, apply0_bool_action >( in );
TAO_PEGTL_TEST_ASSERT( result );
TAO_PEGTL_TEST_ASSERT( in.size() == 1 );
@@ -96,7 +102,7 @@ namespace TAO_PEGTL_NAMESPACE
void apply0_bool_false()
{
apply_result = false;
- memory_input in( "ab", __FUNCTION__ );
+ test::text_input< ascii::lf > in( "ab" );
const auto result = parse< grammar, apply0_bool_action >( in );
TAO_PEGTL_TEST_ASSERT( !result );
TAO_PEGTL_TEST_ASSERT( in.size() == 2 );
diff --git a/src/test/pegtl/contrib_instantiate.cpp b/src/test/pegtl/add_guard.cpp
similarity index 85%
rename from src/test/pegtl/contrib_instantiate.cpp
rename to src/test/pegtl/add_guard.cpp
index a8257c72c..a2c99aff4 100644
--- a/src/test/pegtl/contrib_instantiate.cpp
+++ b/src/test/pegtl/add_guard.cpp
@@ -3,8 +3,13 @@
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
#include "test.hpp"
+#include "test_inputs.hpp"
-#include
+#include
+#include
+#include
+#include
+#include
namespace TAO_PEGTL_NAMESPACE
{
@@ -56,12 +61,12 @@ namespace TAO_PEGTL_NAMESPACE
template<>
struct test_action< sor< alpha, digit > >
- : instantiate< test_class >
+ : add_guard< test_class >
{};
void unit_test()
{
- memory_input in( "a", __FUNCTION__ );
+ test::text_input< ascii::lf > in( "a" );
TAO_PEGTL_TEST_ASSERT( parse< test_grammar, test_action >( in ) );
TAO_PEGTL_TEST_ASSERT( ctor == true );
diff --git a/src/test/pegtl/contrib_analyze.cpp b/src/test/pegtl/analyze.cpp
similarity index 100%
rename from src/test/pegtl/contrib_analyze.cpp
rename to src/test/pegtl/analyze.cpp
diff --git a/src/test/pegtl/argv_input.cpp b/src/test/pegtl/argv_input.cc
similarity index 100%
rename from src/test/pegtl/argv_input.cpp
rename to src/test/pegtl/argv_input.cc
diff --git a/src/test/pegtl/ascii_chars.cpp b/src/test/pegtl/ascii_chars.cpp
index 65566bdf9..fb3fbafb5 100644
--- a/src/test/pegtl/ascii_chars.cpp
+++ b/src/test/pegtl/ascii_chars.cpp
@@ -2,8 +2,6 @@
// 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 "verify_char.hpp"
#include "verify_meta.hpp"
diff --git a/src/test/pegtl/ascii_not_one.cpp b/src/test/pegtl/ascii_not_one.cpp
new file mode 100644
index 000000000..385425b5d
--- /dev/null
+++ b/src/test/pegtl/ascii_not_one.cpp
@@ -0,0 +1,28 @@
+// 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)
+
+#include "test.hpp"
+#include "verify_char.hpp"
+#include "verify_meta.hpp"
+
+namespace TAO_PEGTL_NAMESPACE
+{
+ void unit_test()
+ {
+ verify_analyze< not_one<> >( __LINE__, __FILE__, true, false );
+ verify_analyze< not_one< 'a' > >( __LINE__, __FILE__, true, false );
+ verify_analyze< not_one< 'a', 'c', 'z' > >( __LINE__, __FILE__, true, false );
+
+ for( int i = -100; i < 200; ++i ) {
+ const auto c = char( i );
+
+ verify_char< not_one<> >( __LINE__, __FILE__, c, true );
+ verify_char< not_one< 'a' > >( __LINE__, __FILE__, c, c != 'a' );
+ verify_char< not_one< 'a', 'c', 'z' > >( __LINE__, __FILE__, c, ( c != 'a' ) && ( c != 'c' ) && ( c != 'z' ) );
+ }
+ }
+
+} // namespace TAO_PEGTL_NAMESPACE
+
+#include "main.hpp"
diff --git a/src/test/pegtl/ascii_not_range.cpp b/src/test/pegtl/ascii_not_range.cpp
new file mode 100644
index 000000000..0c71a22ca
--- /dev/null
+++ b/src/test/pegtl/ascii_not_range.cpp
@@ -0,0 +1,24 @@
+// 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)
+
+#include "test.hpp"
+#include "verify_char.hpp"
+#include "verify_meta.hpp"
+
+namespace TAO_PEGTL_NAMESPACE
+{
+ void unit_test()
+ {
+ verify_analyze< not_range< 'a', 'f' > >( __LINE__, __FILE__, true, false );
+
+ for( int i = -100; i < 200; ++i ) {
+ const auto c = char( i );
+
+ verify_char< not_range< 'a', 'f' > >( __LINE__, __FILE__, c, ( c < 'a' ) || ( 'f' < c ) );
+ }
+ }
+
+} // namespace TAO_PEGTL_NAMESPACE
+
+#include "main.hpp"
diff --git a/src/test/pegtl/ascii_one.cpp b/src/test/pegtl/ascii_one.cpp
new file mode 100644
index 000000000..64829c1ed
--- /dev/null
+++ b/src/test/pegtl/ascii_one.cpp
@@ -0,0 +1,28 @@
+// 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)
+
+#include "test.hpp"
+#include "verify_char.hpp"
+#include "verify_meta.hpp"
+
+namespace TAO_PEGTL_NAMESPACE
+{
+ void unit_test()
+ {
+ verify_analyze< one<> >( __LINE__, __FILE__, true, false );
+ verify_analyze< one< 'a' > >( __LINE__, __FILE__, true, false );
+ verify_analyze< one< 'a', 'c', 'z' > >( __LINE__, __FILE__, true, false );
+
+ for( int i = -100; i < 200; ++i ) {
+ const auto c = char( i );
+
+ verify_char< one<> >( __LINE__, __FILE__, c, false );
+ verify_char< one< 'a' > >( __LINE__, __FILE__, c, c == 'a' );
+ verify_char< one< 'a', 'c', 'z' > >( __LINE__, __FILE__, c, ( c == 'a' ) || ( c == 'c' ) || ( c == 'z' ) );
+ }
+ }
+
+} // namespace TAO_PEGTL_NAMESPACE
+
+#include "main.hpp"
diff --git a/src/test/pegtl/ascii_range.cpp b/src/test/pegtl/ascii_range.cpp
new file mode 100644
index 000000000..f5f46e39e
--- /dev/null
+++ b/src/test/pegtl/ascii_range.cpp
@@ -0,0 +1,24 @@
+// 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)
+
+#include "test.hpp"
+#include "verify_char.hpp"
+#include "verify_meta.hpp"
+
+namespace TAO_PEGTL_NAMESPACE
+{
+ void unit_test()
+ {
+ verify_analyze< range< 'a', 'f' > >( __LINE__, __FILE__, true, false );
+
+ for( int i = -100; i < 200; ++i ) {
+ const auto c = char( i );
+
+ verify_char< range< 'a', 'f' > >( __LINE__, __FILE__, c, ( 'a' <= c ) && ( c <= 'f' ) );
+ }
+ }
+
+} // namespace TAO_PEGTL_NAMESPACE
+
+#include "main.hpp"
diff --git a/src/test/pegtl/buffer_input.cpp b/src/test/pegtl/buffer_input.cpp
deleted file mode 100644
index 74ec6173b..000000000
--- a/src/test/pegtl/buffer_input.cpp
+++ /dev/null
@@ -1,46 +0,0 @@
-// Copyright (c) 2019-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 "test.hpp"
-
-#include
-
-namespace TAO_PEGTL_NAMESPACE
-{
- template< typename Rule, template< typename... > class Action = nothing >
- bool parse_cstring( const char* string, const char* source, const std::size_t maximum )
- {
- buffer_input< internal::cstring_reader > in( source, maximum, string );
- return parse< Rule, Action >( in );
- }
-
- void unit_test()
- {
- static constexpr std::size_t chunk_size = buffer_input< internal::cstring_reader >::chunk_size;
-
- static_assert( chunk_size >= 2 );
- TAO_PEGTL_TEST_ASSERT( parse_cstring< seq< string< 'a', 'b', 'c' >, eof > >( "abc", TAO_TEST_LINE, 1 ) );
- TAO_PEGTL_TEST_ASSERT( parse_cstring< seq< string< 'a', 'b', 'c' >, eof > >( "abc", TAO_TEST_LINE, 128 ) );
-
- // We need one extra byte in the buffer so that eof calling in.empty() calling in.require( 1 ) does not throw a "require beyond end of buffer" exception.
-#if defined( __cpp_exceptions )
- TAO_PEGTL_TEST_THROWS( parse_cstring< seq< rep< chunk_size + 2, one< 'a' > >, eof > >( std::string( std::size_t( chunk_size + 2 ), 'a' ).c_str(), TAO_TEST_LINE, 2 ) );
-#endif
- TAO_PEGTL_TEST_ASSERT( parse_cstring< seq< rep< chunk_size + 2, one< 'a' > >, eof > >( std::string( std::size_t( chunk_size + 2 ), 'a' ).c_str(), TAO_TEST_LINE, 3 ) );
-
- TAO_PEGTL_TEST_ASSERT( parse_cstring< rep< chunk_size + 9, one< 'a' > > >( std::string( std::size_t( chunk_size + 9 ), 'a' ).c_str(), TAO_TEST_LINE, 9 ) );
- TAO_PEGTL_TEST_ASSERT( parse_cstring< rep< chunk_size + 9, one< 'a' > > >( std::string( std::size_t( chunk_size + 10 ), 'a' ).c_str(), TAO_TEST_LINE, 9 ) );
-#if defined( __cpp_exceptions )
- TAO_PEGTL_TEST_THROWS( parse_cstring< rep< chunk_size + 10, one< 'a' > > >( std::string( std::size_t( chunk_size + 10 ), 'a' ).c_str(), TAO_TEST_LINE, 9 ) );
- TAO_PEGTL_TEST_THROWS( parse_cstring< rep< chunk_size + 10, one< 'a' > > >( std::string( std::size_t( chunk_size + 11 ), 'a' ).c_str(), TAO_TEST_LINE, 9 ) );
- TAO_PEGTL_TEST_THROWS( parse_cstring< seq< rep< chunk_size + 10, one< 'a' > >, eof > >( std::string( std::size_t( chunk_size + 10 ), 'a' ).c_str(), TAO_TEST_LINE, 9 ) );
- TAO_PEGTL_TEST_THROWS( parse_cstring< seq< rep< chunk_size + 10, one< 'a' > >, eof > >( std::string( std::size_t( chunk_size + 10 ), 'a' ).c_str(), TAO_TEST_LINE, 10 ) );
-#endif
- }
-
-} // namespace TAO_PEGTL_NAMESPACE
-
-#include "main.hpp"
diff --git a/src/test/pegtl/change_action_and_state.cpp b/src/test/pegtl/change_action_and_state.cpp
index 4f2039a13..e2dc73d7f 100644
--- a/src/test/pegtl/change_action_and_state.cpp
+++ b/src/test/pegtl/change_action_and_state.cpp
@@ -3,6 +3,12 @@
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
#include "test.hpp"
+#include "test_inputs.hpp"
+
+#include
+#include
+#include
+#include
namespace TAO_PEGTL_NAMESPACE
{
@@ -81,28 +87,28 @@ namespace TAO_PEGTL_NAMESPACE
void unit_test()
{
{
- memory_input in( "ab", "" );
+ test::text_input< ascii::lf > in( "ab" );
int c = 0;
const auto result = parse< AB, my_action_1 >( in, c );
TAO_PEGTL_TEST_ASSERT( result );
TAO_PEGTL_TEST_ASSERT( c == 4 );
}
{
- memory_input in( "a", "" );
+ test::text_input< ascii::lf > in( "a" );
int c = 0;
const auto result = parse< AB, my_action_1 >( in, c );
TAO_PEGTL_TEST_ASSERT( !result );
TAO_PEGTL_TEST_ASSERT( c == 1 );
}
{
- memory_input in( "b", "" );
+ test::text_input< ascii::lf > in( "b" );
int c = 0;
const auto result = parse< AB, my_action_1 >( in, c );
TAO_PEGTL_TEST_ASSERT( !result );
TAO_PEGTL_TEST_ASSERT( c == 0 );
}
{
- memory_input in( "ab", "" );
+ test::text_input< ascii::lf > in( "ab" );
int c = 5;
const auto result = parse< disable< AB >, my_action_1 >( in, c );
TAO_PEGTL_TEST_ASSERT( result );
diff --git a/src/test/pegtl/change_action_and_states.cpp b/src/test/pegtl/change_action_and_states.cpp
index e03eca895..9d9317268 100644
--- a/src/test/pegtl/change_action_and_states.cpp
+++ b/src/test/pegtl/change_action_and_states.cpp
@@ -3,6 +3,12 @@
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
#include "test.hpp"
+#include "test_inputs.hpp"
+
+#include
+#include
+#include
+#include
namespace TAO_PEGTL_NAMESPACE
{
@@ -71,28 +77,28 @@ namespace TAO_PEGTL_NAMESPACE
void unit_test()
{
{
- memory_input in( "ab", "" );
+ test::text_input< ascii::lf > in( "ab" );
int c = 0;
const auto result = parse< AB, my_action_1 >( in, c );
TAO_PEGTL_TEST_ASSERT( result );
TAO_PEGTL_TEST_ASSERT( c == 3 );
}
{
- memory_input in( "a", "" );
+ test::text_input< ascii::lf > in( "a" );
int c = 0;
const auto result = parse< AB, my_action_1 >( in, c );
TAO_PEGTL_TEST_ASSERT( !result );
TAO_PEGTL_TEST_ASSERT( c == 1 );
}
{
- memory_input in( "b", "" );
+ test::text_input< ascii::lf > in( "b" );
int c = 0;
const auto result = parse< AB, my_action_1 >( in, c );
TAO_PEGTL_TEST_ASSERT( !result );
TAO_PEGTL_TEST_ASSERT( c == 0 );
}
{
- memory_input in( "ab", "" );
+ test::text_input< ascii::lf > in( "ab" );
int c = 5;
const auto result = parse< disable< AB >, my_action_1 >( in, c );
TAO_PEGTL_TEST_ASSERT( result );
diff --git a/src/test/pegtl/change_state.cpp b/src/test/pegtl/change_state.cpp
index d52302a23..f9f892069 100644
--- a/src/test/pegtl/change_state.cpp
+++ b/src/test/pegtl/change_state.cpp
@@ -3,6 +3,12 @@
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
#include "test.hpp"
+#include "test_inputs.hpp"
+
+#include
+#include
+#include
+#include
namespace TAO_PEGTL_NAMESPACE
{
@@ -64,28 +70,28 @@ namespace TAO_PEGTL_NAMESPACE
void unit_test()
{
{
- memory_input in( "ab", "" );
+ test::text_input< ascii::lf > in( "ab" );
int c = 0;
const auto result = parse< AB, my_action >( in, c );
TAO_PEGTL_TEST_ASSERT( result );
TAO_PEGTL_TEST_ASSERT( c == 4 );
}
{
- memory_input in( "a", "" );
+ test::text_input< ascii::lf > in( "a" );
int c = 0;
const auto result = parse< AB, my_action >( in, c );
TAO_PEGTL_TEST_ASSERT( !result );
TAO_PEGTL_TEST_ASSERT( c == 1 );
}
{
- memory_input in( "b", "" );
+ test::text_input< ascii::lf > in( "b" );
int c = 0;
const auto result = parse< AB, my_action >( in, c );
TAO_PEGTL_TEST_ASSERT( !result );
TAO_PEGTL_TEST_ASSERT( c == 0 );
}
{
- memory_input in( "ab", "" );
+ test::text_input< ascii::lf > in( "ab" );
int c = 5;
const auto result = parse< disable< AB >, my_action >( in, c );
TAO_PEGTL_TEST_ASSERT( result );
diff --git a/src/test/pegtl/change_states.cpp b/src/test/pegtl/change_states.cpp
index b40133271..03589d863 100644
--- a/src/test/pegtl/change_states.cpp
+++ b/src/test/pegtl/change_states.cpp
@@ -3,6 +3,12 @@
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
#include "test.hpp"
+#include "test_inputs.hpp"
+
+#include
+#include
+#include
+#include
namespace TAO_PEGTL_NAMESPACE
{
@@ -48,28 +54,28 @@ namespace TAO_PEGTL_NAMESPACE
void unit_test()
{
{
- memory_input in( "ab", "" );
+ test::text_input< ascii::lf > in( "ab" );
int c = 0;
const auto result = parse< AB, my_action >( in, c );
TAO_PEGTL_TEST_ASSERT( result );
TAO_PEGTL_TEST_ASSERT( c == 3 );
}
{
- memory_input in( "a", "" );
+ test::text_input< ascii::lf > in( "a" );
int c = 0;
const auto result = parse< AB, my_action >( in, c );
TAO_PEGTL_TEST_ASSERT( !result );
TAO_PEGTL_TEST_ASSERT( c == 1 );
}
{
- memory_input in( "b", "" );
+ test::text_input< ascii::lf > in( "b" );
int c = 0;
const auto result = parse< AB, my_action >( in, c );
TAO_PEGTL_TEST_ASSERT( !result );
TAO_PEGTL_TEST_ASSERT( c == 0 );
}
{
- memory_input in( "ab", "" );
+ test::text_input< ascii::lf > in( "ab" );
int c = 5;
const auto result = parse< disable< AB >, my_action >( in, c );
TAO_PEGTL_TEST_ASSERT( result );
diff --git a/src/test/pegtl/check_bytes.cpp b/src/test/pegtl/check_bytes.cc
similarity index 83%
rename from src/test/pegtl/check_bytes.cpp
rename to src/test/pegtl/check_bytes.cc
index c02e91a47..32ac3a42b 100644
--- a/src/test/pegtl/check_bytes.cpp
+++ b/src/test/pegtl/check_bytes.cc
@@ -28,20 +28,20 @@ namespace TAO_PEGTL_NAMESPACE
void unit_test()
{
- memory_input<> i1( "aaa", __FUNCTION__ );
+ memory_input<> i1( __FUNCTION__, "aaa" );
const auto r1 = parse< test_grammar >( i1 );
TAO_PEGTL_TEST_ASSERT( r1 );
- memory_input<> i2( "aaaaaaaaaaa", __FUNCTION__ );
+ memory_input<> i2( __FUNCTION__, "aaaaaaaaaaa" );
const auto r2 = parse< test_grammar >( i2 );
TAO_PEGTL_TEST_ASSERT( r2 );
- memory_input<> i3( "aaa", __FUNCTION__ );
+ memory_input<> i3( __FUNCTION__, "aaa" );
const auto r3 = parse< test_grammar, test_action >( i3 );
TAO_PEGTL_TEST_ASSERT( r3 );
#if defined( __cpp_exceptions )
- memory_input<> i4( "aaaaaaaaaaa", __FUNCTION__ );
+ memory_input<> i4( __FUNCTION__, "aaaaaaaaaaa" );
TAO_PEGTL_TEST_THROWS( parse< test_grammar, test_action >( i4 ) );
#endif
}
diff --git a/src/test/pegtl/contains.cpp b/src/test/pegtl/contains.cpp
index 764b0d152..7d3a286ec 100644
--- a/src/test/pegtl/contains.cpp
+++ b/src/test/pegtl/contains.cpp
@@ -2,10 +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)
-#include
-
#include "test.hpp"
+#include
+#include
+#include
+
namespace TAO_PEGTL_NAMESPACE
{
// clang-format off
diff --git a/src/test/pegtl/contrib_coverage.cpp b/src/test/pegtl/contrib_coverage.cc
similarity index 100%
rename from src/test/pegtl/contrib_coverage.cpp
rename to src/test/pegtl/contrib_coverage.cc
diff --git a/src/test/pegtl/contrib_function.cpp b/src/test/pegtl/contrib_function.cpp
index eca901aab..9c1769711 100644
--- a/src/test/pegtl/contrib_function.cpp
+++ b/src/test/pegtl/contrib_function.cpp
@@ -3,20 +3,23 @@
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
#include "test.hpp"
+#include "test_inputs.hpp"
#include
+#include
namespace TAO_PEGTL_NAMESPACE
{
bool call1 = false;
- [[nodiscard]] bool func1( memory_input<>& /*unused*/, int /*unused*/, char*& /*unused*/, const double& /*unused*/ )
+ [[nodiscard]] bool func1( test::text_input< ascii::lf >& /*unused*/, int /*unused*/, char*& /*unused*/, const double& /*unused*/ )
{
call1 = true;
return true;
}
- struct rule1 : TAO_PEGTL_NAMESPACE::function< func1 >
+ struct rule1
+ : TAO_PEGTL_NAMESPACE::function< func1 >
{};
void unit_test()
@@ -24,7 +27,7 @@ namespace TAO_PEGTL_NAMESPACE
int i = 42;
char c = 'a';
double d = 42.0;
- memory_input in( "foo", __FUNCTION__ );
+ test::text_input< ascii::lf > in( "foo" );
TAO_PEGTL_TEST_ASSERT( parse< rule1 >( in, i, &c, d ) );
TAO_PEGTL_TEST_ASSERT( call1 );
}
diff --git a/src/test/pegtl/contrib_http.cpp b/src/test/pegtl/contrib_http.cc
similarity index 100%
rename from src/test/pegtl/contrib_http.cpp
rename to src/test/pegtl/contrib_http.cc
diff --git a/src/test/pegtl/contrib_if_then.cpp b/src/test/pegtl/contrib_if_then.cc
similarity index 100%
rename from src/test/pegtl/contrib_if_then.cpp
rename to src/test/pegtl/contrib_if_then.cc
diff --git a/src/test/pegtl/contrib_integer.cpp b/src/test/pegtl/contrib_integer.cpp
index 1421cd8f9..af966cd0f 100644
--- a/src/test/pegtl/contrib_integer.cpp
+++ b/src/test/pegtl/contrib_integer.cpp
@@ -15,11 +15,13 @@ int main()
#include
#include "test.hpp"
-
+#include "test_inputs.hpp"
#include "verify_meta.hpp"
#include "verify_rule.hpp"
#include
+#include
+#include
namespace TAO_PEGTL_NAMESPACE
{
@@ -43,13 +45,13 @@ namespace TAO_PEGTL_NAMESPACE
{
{
S st = -123;
- memory_input in( i, __FUNCTION__ );
+ test::text_input< ascii::lf > in( i );
parse< must< signed_rule, eof >, int_action >( in, st );
TAO_PEGTL_TEST_ASSERT( st == s );
}
{
S st = -123;
- memory_input in( i, __FUNCTION__ );
+ test::text_input< ascii::lf > in( i );
parse< must< signed_rule_with_action, eof > >( in, st );
TAO_PEGTL_TEST_ASSERT( st == s );
}
@@ -59,7 +61,7 @@ namespace TAO_PEGTL_NAMESPACE
void test_signed( const std::string& i )
{
S st;
- memory_input in( i, __FUNCTION__ );
+ test::text_input< ascii::lf > in( i );
TAO_PEGTL_TEST_THROWS( parse< must< signed_rule, eof >, int_action >( in, st ) );
}
@@ -76,7 +78,7 @@ namespace TAO_PEGTL_NAMESPACE
{
S st;
const auto i = lexical_cast( s );
- memory_input in( i, __FUNCTION__ );
+ test::text_input< ascii::lf > in( i );
parse< must< signed_rule, eof >, int_action >( in, st );
TAO_PEGTL_TEST_ASSERT( st == s );
}
@@ -86,13 +88,13 @@ namespace TAO_PEGTL_NAMESPACE
{
{
S st = 123;
- memory_input in( i, __FUNCTION__ );
+ test::text_input< ascii::lf > in( i );
parse< must< unsigned_rule, eof >, int_action >( in, st );
TAO_PEGTL_TEST_ASSERT( st == s );
}
{
S st = 123;
- memory_input in( i, __FUNCTION__ );
+ test::text_input< ascii::lf > in( i );
parse< must< unsigned_rule_with_action, eof > >( in, st );
TAO_PEGTL_TEST_ASSERT( st == s );
}
@@ -102,7 +104,7 @@ namespace TAO_PEGTL_NAMESPACE
void test_unsigned( const std::string& i )
{
S st = 123;
- memory_input in( i, __FUNCTION__ );
+ test::text_input< ascii::lf > in( i );
TAO_PEGTL_TEST_THROWS( parse< must< unsigned_rule, eof >, int_action >( in, st ) );
}
@@ -111,7 +113,7 @@ namespace TAO_PEGTL_NAMESPACE
{
S st = 123;
const auto i = lexical_cast( s );
- memory_input in( i, __FUNCTION__ );
+ test::text_input< ascii::lf > in( i );
parse< must< unsigned_rule, eof >, int_action >( in, st );
TAO_PEGTL_TEST_ASSERT( st == s );
}
diff --git a/src/test/pegtl/contrib_iri.cpp b/src/test/pegtl/contrib_iri.cpp
index 84440b486..e6d066532 100644
--- a/src/test/pegtl/contrib_iri.cpp
+++ b/src/test/pegtl/contrib_iri.cpp
@@ -12,9 +12,14 @@ int main()
#else
#include "test.hpp"
+#include "test_inputs.hpp"
#include "verify_meta.hpp"
#include "verify_rule.hpp"
+#include
+#include
+#include
+
#include
namespace TAO_PEGTL_NAMESPACE
@@ -48,7 +53,7 @@ namespace TAO_PEGTL_NAMESPACE
verify_rule< GRAMMAR >( __LINE__, __FILE__, "quake://480fps.com:26000/", result_type::success );
verify_rule< GRAMMAR >( __LINE__, __FILE__, "ftp://300.300.300.300/foo", result_type::success ); // 300.300.300.300 is a valid hostname!
- TAO_PEGTL_TEST_THROWS( parse< GRAMMAR >( memory_input( "", "" ) ) );
+ TAO_PEGTL_TEST_THROWS( parse< GRAMMAR >( test::text_input< ascii::lf >( "" ) ) );
}
} // namespace TAO_PEGTL_NAMESPACE
diff --git a/src/test/pegtl/contrib_json.cpp b/src/test/pegtl/contrib_json.cpp
index d57adc486..c87ba2f45 100644
--- a/src/test/pegtl/contrib_json.cpp
+++ b/src/test/pegtl/contrib_json.cpp
@@ -3,15 +3,57 @@
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
#include "test.hpp"
+#include "test_inputs.hpp"
#include "verify_meta.hpp"
#include "verify_rule.hpp"
#include
+#include
namespace TAO_PEGTL_NAMESPACE
{
using GRAMMAR = seq< json::text, eof >;
+ [[nodiscard]] bool json_pass( const std::filesystem::path& path )
+ {
+ test::file_input< ascii::lf_crlf > in( path );
+ const auto s = in.string();
+ test::text_input< ascii::lf_crlf > ti( s );
+ test::lazy_input< ascii::lf_crlf > li( s );
+ const auto f = failed;
+ TAO_PEGTL_TEST_ASSERT( in.size() == ti.size() );
+ TAO_PEGTL_TEST_ASSERT( in.size() == li.size() );
+ TAO_PEGTL_TEST_ASSERT( parse< GRAMMAR >( ti ) );
+ TAO_PEGTL_TEST_ASSERT( parse< GRAMMAR >( li ) );
+ TAO_PEGTL_TEST_ASSERT( parse< GRAMMAR >( in ) );
+ TAO_PEGTL_TEST_ASSERT( in.size() == ti.size() );
+ TAO_PEGTL_TEST_ASSERT( in.size() == li.size() );
+ TAO_PEGTL_TEST_ASSERT( ti.direct_position() == ti.current_position() );
+ TAO_PEGTL_TEST_ASSERT( ti.direct_position() == li.current_position() );
+ TAO_PEGTL_TEST_ASSERT( ti.direct_position() == in.current_position().base() );
+ return failed == f;
+ }
+
+ [[nodiscard]] bool json_fail( const std::filesystem::path& path )
+ {
+ test::file_input< ascii::lf_crlf > in( path );
+ const auto s = in.string();
+ test::text_input< ascii::lf_crlf > ti( s );
+ test::lazy_input< ascii::lf_crlf > li( s );
+ const auto f = failed;
+ TAO_PEGTL_TEST_ASSERT( in.size() == ti.size() );
+ TAO_PEGTL_TEST_ASSERT( in.size() == li.size() );
+ TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( ti ) );
+ TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( li ) );
+ TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( in ) );
+ TAO_PEGTL_TEST_ASSERT( in.size() == ti.size() );
+ TAO_PEGTL_TEST_ASSERT( in.size() == li.size() );
+ TAO_PEGTL_TEST_ASSERT( ti.direct_position() == ti.current_position() );
+ TAO_PEGTL_TEST_ASSERT( ti.direct_position() == li.current_position() );
+ TAO_PEGTL_TEST_ASSERT( ti.direct_position() == in.current_position().base() );
+ return failed == f;
+ }
+
void unit_test()
{
verify_analyze< GRAMMAR >( __LINE__, __FILE__, true, false );
@@ -43,80 +85,80 @@ namespace TAO_PEGTL_NAMESPACE
verify_rule< GRAMMAR >( __LINE__, __FILE__, "[\"\xF4\x8F\xBF\xBF\"]", result_type::success, 0 ); // largest allowed codepoint U+10FFFF
verify_rule< GRAMMAR >( __LINE__, __FILE__, "[\"\U0010FFFF\"]", result_type::success, 0 ); // largest allowed codepoint U+10FFFF
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( "", "" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( " ", "" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( " ", "" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( "[", "" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( "]", "" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( " [", "" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( " ]", "" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( "[ ", "" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( "] ", "" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( " [ ", "" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( " ] ", "" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( "[\"\\a\"]", "" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( "[\"\\c\"]", "" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( "[\"\\d\"]", "" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( "[\"\\e\"]", "" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( "[\"\\v\"]", "" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( "[\"\\'\"]", "" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( "[\"\b\"]", "" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( "[\"\f\"]", "" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( "[\"\n\"]", "" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( "[\"\r\"]", "" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( "[\"\t\"]", "" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( "[\"\\\"]", "" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( "[\"\\\\\\\"]", "" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( "[\"\\u12\"]", "" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( "[\"\xFF\"]", "" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( "[\"\xF4\x90\x80\x80\"]", "" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( "[\"\xF7\xBF\xBF\xBF\"]", "" ) ) );
+ TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( test::text_input< ascii::lf_crlf >( "", "" ) ) );
+ TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( test::text_input< ascii::lf_crlf >( " ", "" ) ) );
+ TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( test::text_input< ascii::lf_crlf >( " ", "" ) ) );
+ TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( test::text_input< ascii::lf_crlf >( "[", "" ) ) );
+ TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( test::text_input< ascii::lf_crlf >( "]", "" ) ) );
+ TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( test::text_input< ascii::lf_crlf >( " [", "" ) ) );
+ TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( test::text_input< ascii::lf_crlf >( " ]", "" ) ) );
+ TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( test::text_input< ascii::lf_crlf >( "[ ", "" ) ) );
+ TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( test::text_input< ascii::lf_crlf >( "] ", "" ) ) );
+ TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( test::text_input< ascii::lf_crlf >( " [ ", "" ) ) );
+ TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( test::text_input< ascii::lf_crlf >( " ] ", "" ) ) );
+ TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( test::text_input< ascii::lf_crlf >( "[\"\\a\"]", "" ) ) );
+ TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( test::text_input< ascii::lf_crlf >( "[\"\\c\"]", "" ) ) );
+ TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( test::text_input< ascii::lf_crlf >( "[\"\\d\"]", "" ) ) );
+ TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( test::text_input< ascii::lf_crlf >( "[\"\\e\"]", "" ) ) );
+ TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( test::text_input< ascii::lf_crlf >( "[\"\\v\"]", "" ) ) );
+ TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( test::text_input< ascii::lf_crlf >( "[\"\\'\"]", "" ) ) );
+ TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( test::text_input< ascii::lf_crlf >( "[\"\b\"]", "" ) ) );
+ TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( test::text_input< ascii::lf_crlf >( "[\"\f\"]", "" ) ) );
+ TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( test::text_input< ascii::lf_crlf >( "[\"\n\"]", "" ) ) );
+ TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( test::text_input< ascii::lf_crlf >( "[\"\r\"]", "" ) ) );
+ TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( test::text_input< ascii::lf_crlf >( "[\"\t\"]", "" ) ) );
+ TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( test::text_input< ascii::lf_crlf >( "[\"\\\"]", "" ) ) );
+ TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( test::text_input< ascii::lf_crlf >( "[\"\\\\\\\"]", "" ) ) );
+ TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( test::text_input< ascii::lf_crlf >( "[\"\\u12\"]", "" ) ) );
+ TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( test::text_input< ascii::lf_crlf >( "[\"\xFF\"]", "" ) ) );
+ TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( test::text_input< ascii::lf_crlf >( "[\"\xF4\x90\x80\x80\"]", "" ) ) );
+ TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( test::text_input< ascii::lf_crlf >( "[\"\xF7\xBF\xBF\xBF\"]", "" ) ) );
- TAO_PEGTL_TEST_ASSERT( parse< GRAMMAR >( file_input( "src/test/pegtl/data/pass1.json" ) ) );
- TAO_PEGTL_TEST_ASSERT( parse< GRAMMAR >( file_input( "src/test/pegtl/data/pass2.json" ) ) );
- TAO_PEGTL_TEST_ASSERT( parse< GRAMMAR >( file_input( "src/test/pegtl/data/pass3.json" ) ) );
+ TAO_PEGTL_TEST_ASSERT( json_pass( "src/test/pegtl/data/pass1.json" ) );
+ TAO_PEGTL_TEST_ASSERT( json_pass( "src/test/pegtl/data/pass2.json" ) );
+ TAO_PEGTL_TEST_ASSERT( json_pass( "src/test/pegtl/data/pass3.json" ) );
- TAO_PEGTL_TEST_ASSERT( parse< GRAMMAR >( file_input( "src/test/pegtl/data/blns.json" ) ) );
+ TAO_PEGTL_TEST_ASSERT( parse< GRAMMAR >( test::file_input< ascii::lf_crlf >( "src/test/pegtl/data/blns.json" ) ) );
- // TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail1.json" ) )); // disabled as it is valid now
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail2.json" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail3.json" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail4.json" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail5.json" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail6.json" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail7.json" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail8.json" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail9.json" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail10.json" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail11.json" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail12.json" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail13.json" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail14.json" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail15.json" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail16.json" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail17.json" ) ) );
- // TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail18.json" ) )); // disabled as deep nesting is allowed
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail19.json" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail20.json" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail21.json" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail22.json" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail23.json" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail24.json" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail25.json" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail26.json" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail27.json" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail28.json" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail29.json" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail30.json" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail31.json" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail32.json" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail33.json" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail34.json" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail35.json" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail36.json" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail37.json" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail38.json" ) ) );
- TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail39.json" ) ) );
+ // TAO_PEGTL_TEST_ASSERT( json_fail( "src/test/pegtl/data/fail1.json" ) ); // disabled as it is valid now
+ TAO_PEGTL_TEST_ASSERT( json_fail( "src/test/pegtl/data/fail2.json" ) );
+ TAO_PEGTL_TEST_ASSERT( json_fail( "src/test/pegtl/data/fail3.json" ) );
+ TAO_PEGTL_TEST_ASSERT( json_fail( "src/test/pegtl/data/fail4.json" ) );
+ TAO_PEGTL_TEST_ASSERT( json_fail( "src/test/pegtl/data/fail5.json" ) );
+ TAO_PEGTL_TEST_ASSERT( json_fail( "src/test/pegtl/data/fail6.json" ) );
+ TAO_PEGTL_TEST_ASSERT( json_fail( "src/test/pegtl/data/fail7.json" ) );
+ TAO_PEGTL_TEST_ASSERT( json_fail( "src/test/pegtl/data/fail8.json" ) );
+ TAO_PEGTL_TEST_ASSERT( json_fail( "src/test/pegtl/data/fail9.json" ) );
+ TAO_PEGTL_TEST_ASSERT( json_fail( "src/test/pegtl/data/fail10.json" ) );
+ TAO_PEGTL_TEST_ASSERT( json_fail( "src/test/pegtl/data/fail11.json" ) );
+ TAO_PEGTL_TEST_ASSERT( json_fail( "src/test/pegtl/data/fail12.json" ) );
+ TAO_PEGTL_TEST_ASSERT( json_fail( "src/test/pegtl/data/fail13.json" ) );
+ TAO_PEGTL_TEST_ASSERT( json_fail( "src/test/pegtl/data/fail14.json" ) );
+ TAO_PEGTL_TEST_ASSERT( json_fail( "src/test/pegtl/data/fail15.json" ) );
+ TAO_PEGTL_TEST_ASSERT( json_fail( "src/test/pegtl/data/fail16.json" ) );
+ TAO_PEGTL_TEST_ASSERT( json_fail( "src/test/pegtl/data/fail17.json" ) );
+ // TAO_PEGTL_TEST_ASSERT( json_fail( "src/test/pegtl/data/fail18.json" ) ); // disabled as deep nesting is allowed
+ TAO_PEGTL_TEST_ASSERT( json_fail( "src/test/pegtl/data/fail19.json" ) );
+ TAO_PEGTL_TEST_ASSERT( json_fail( "src/test/pegtl/data/fail20.json" ) );
+ TAO_PEGTL_TEST_ASSERT( json_fail( "src/test/pegtl/data/fail21.json" ) );
+ TAO_PEGTL_TEST_ASSERT( json_fail( "src/test/pegtl/data/fail22.json" ) );
+ TAO_PEGTL_TEST_ASSERT( json_fail( "src/test/pegtl/data/fail23.json" ) );
+ TAO_PEGTL_TEST_ASSERT( json_fail( "src/test/pegtl/data/fail24.json" ) );
+ TAO_PEGTL_TEST_ASSERT( json_fail( "src/test/pegtl/data/fail25.json" ) );
+ TAO_PEGTL_TEST_ASSERT( json_fail( "src/test/pegtl/data/fail26.json" ) );
+ TAO_PEGTL_TEST_ASSERT( json_fail( "src/test/pegtl/data/fail27.json" ) );
+ TAO_PEGTL_TEST_ASSERT( json_fail( "src/test/pegtl/data/fail28.json" ) );
+ TAO_PEGTL_TEST_ASSERT( json_fail( "src/test/pegtl/data/fail29.json" ) );
+ TAO_PEGTL_TEST_ASSERT( json_fail( "src/test/pegtl/data/fail30.json" ) );
+ TAO_PEGTL_TEST_ASSERT( json_fail( "src/test/pegtl/data/fail31.json" ) );
+ TAO_PEGTL_TEST_ASSERT( json_fail( "src/test/pegtl/data/fail32.json" ) );
+ TAO_PEGTL_TEST_ASSERT( json_fail( "src/test/pegtl/data/fail33.json" ) );
+ TAO_PEGTL_TEST_ASSERT( json_fail( "src/test/pegtl/data/fail34.json" ) );
+ TAO_PEGTL_TEST_ASSERT( json_fail( "src/test/pegtl/data/fail35.json" ) );
+ TAO_PEGTL_TEST_ASSERT( json_fail( "src/test/pegtl/data/fail36.json" ) );
+ TAO_PEGTL_TEST_ASSERT( json_fail( "src/test/pegtl/data/fail37.json" ) );
+ TAO_PEGTL_TEST_ASSERT( json_fail( "src/test/pegtl/data/fail38.json" ) );
+ TAO_PEGTL_TEST_ASSERT( json_fail( "src/test/pegtl/data/fail39.json" ) );
}
} // namespace TAO_PEGTL_NAMESPACE
diff --git a/src/test/pegtl/contrib_limit_depth.cpp b/src/test/pegtl/contrib_limit_depth.cc
similarity index 100%
rename from src/test/pegtl/contrib_limit_depth.cpp
rename to src/test/pegtl/contrib_limit_depth.cc
diff --git a/src/test/pegtl/contrib_parse_tree.cpp b/src/test/pegtl/contrib_parse_tree.cc
similarity index 100%
rename from src/test/pegtl/contrib_parse_tree.cpp
rename to src/test/pegtl/contrib_parse_tree.cc
diff --git a/src/test/pegtl/contrib_parse_tree_to_dot.cpp b/src/test/pegtl/contrib_parse_tree_to_dot.cc
similarity index 100%
rename from src/test/pegtl/contrib_parse_tree_to_dot.cpp
rename to src/test/pegtl/contrib_parse_tree_to_dot.cc
diff --git a/src/test/pegtl/contrib_partial_trace.cpp b/src/test/pegtl/contrib_partial_trace.cc
similarity index 100%
rename from src/test/pegtl/contrib_partial_trace.cpp
rename to src/test/pegtl/contrib_partial_trace.cc
diff --git a/src/test/pegtl/contrib_predicates.cpp b/src/test/pegtl/contrib_predicates.cpp
deleted file mode 100644
index 548a5447e..000000000
--- a/src/test/pegtl/contrib_predicates.cpp
+++ /dev/null
@@ -1,102 +0,0 @@
-// Copyright (c) 2020-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 "test.hpp"
-#include "verify_meta.hpp"
-#include "verify_rule.hpp"
-
-#include
-
-namespace TAO_PEGTL_NAMESPACE
-{
- void unit_test()
- {
- verify_analyze< predicates_or< one< ' ' > > >( __LINE__, __FILE__, true, false );
- verify_analyze< predicates_or< one< ' ' >, range< 'a', 'z' > > >( __LINE__, __FILE__, true, false );
-
- verify_rule< predicates_or< one< 'a' > > >( __LINE__, __FILE__, "a", result_type::success, 0 );
-
- for( char i = 1; i < 'a'; ++i ) {
- char t[] = { i, 0 };
- verify_rule< predicates_or< one< 'a' > > >( __LINE__, __FILE__, std::string( t ), result_type::local_failure, 1 );
- }
- for( char i = 'b'; i < 127; ++i ) {
- char t[] = { i, 0 };
- verify_rule< predicates_or< one< 'a' > > >( __LINE__, __FILE__, std::string( t ), result_type::local_failure, 1 );
- }
-
- verify_rule< predicates_or< one< 'a', 'b' > > >( __LINE__, __FILE__, "a", result_type::success, 0 );
- verify_rule< predicates_or< one< 'a', 'b' > > >( __LINE__, __FILE__, "b", result_type::success, 0 );
-
- for( char i = 1; i < 'a'; ++i ) {
- char t[] = { i, 0 };
- verify_rule< predicates_or< one< 'a', 'b' > > >( __LINE__, __FILE__, std::string( t ), result_type::local_failure, 1 );
- }
- for( char i = 'c'; i < 127; ++i ) {
- char t[] = { i, 0 };
- verify_rule< predicates_or< one< 'a', 'b' > > >( __LINE__, __FILE__, std::string( t ), result_type::local_failure, 1 );
- }
-
- verify_rule< predicates_or< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "a", result_type::success, 0 );
- verify_rule< predicates_or< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "b", result_type::success, 0 );
-
- for( char i = 1; i < 'a'; ++i ) {
- char t[] = { i, 0 };
- verify_rule< predicates_or< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, std::string( t ), result_type::local_failure, 1 );
- }
- for( char i = 'c'; i < 127; ++i ) {
- char t[] = { i, 0 };
- verify_rule< predicates_or< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, std::string( t ), result_type::local_failure, 1 );
- }
-
- verify_rule< predicates_or< range< 'a', 'b' > > >( __LINE__, __FILE__, "a", result_type::success, 0 );
- verify_rule< predicates_or< range< 'a', 'b' > > >( __LINE__, __FILE__, "b", result_type::success, 0 );
-
- for( char i = 1; i < 'a'; ++i ) {
- char t[] = { i, 0 };
- verify_rule< predicates_or< range< 'a', 'b' > > >( __LINE__, __FILE__, std::string( t ), result_type::local_failure, 1 );
- }
- for( char i = 'c'; i < 127; ++i ) {
- char t[] = { i, 0 };
- verify_rule< predicates_or< range< 'a', 'b' > > >( __LINE__, __FILE__, std::string( t ), result_type::local_failure, 1 );
- }
-
- using rule_t = predicates_or< one< 'f' >, range< 'b', 'd' >, range< 'm', 'n' >, one< 'x', 'y' > >;
-
- verify_rule< rule_t >( __LINE__, __FILE__, "b", result_type::success, 0 );
- verify_rule< rule_t >( __LINE__, __FILE__, "c", result_type::success, 0 );
- verify_rule< rule_t >( __LINE__, __FILE__, "d", result_type::success, 0 );
- verify_rule< rule_t >( __LINE__, __FILE__, "m", result_type::success, 0 );
- verify_rule< rule_t >( __LINE__, __FILE__, "n", result_type::success, 0 );
- verify_rule< rule_t >( __LINE__, __FILE__, "x", result_type::success, 0 );
- verify_rule< rule_t >( __LINE__, __FILE__, "y", result_type::success, 0 );
- verify_rule< rule_t >( __LINE__, __FILE__, "f", result_type::success, 0 );
-
- verify_rule< rule_t >( __LINE__, __FILE__, "a", result_type::local_failure, 1 );
- verify_rule< rule_t >( __LINE__, __FILE__, "e", result_type::local_failure, 1 );
- verify_rule< rule_t >( __LINE__, __FILE__, "g", result_type::local_failure, 1 );
- verify_rule< rule_t >( __LINE__, __FILE__, "l", result_type::local_failure, 1 );
- verify_rule< rule_t >( __LINE__, __FILE__, "w", result_type::local_failure, 1 );
- verify_rule< rule_t >( __LINE__, __FILE__, "z", result_type::local_failure, 1 );
- verify_rule< rule_t >( __LINE__, __FILE__, "k", result_type::local_failure, 1 );
- verify_rule< rule_t >( __LINE__, __FILE__, "r", result_type::local_failure, 1 );
-
- using pred_t = predicates_or< one< 'a' >, predicates_or< one< 'b' > > >;
-
- verify_rule< predicates_or< pred_t > >( __LINE__, __FILE__, "a", result_type::success, 0 );
- verify_rule< predicates_or< pred_t > >( __LINE__, __FILE__, "b", result_type::success, 0 );
-
- for( char i = 1; i < 'a'; ++i ) {
- char t[] = { i, 0 };
- verify_rule< predicates_or< pred_t > >( __LINE__, __FILE__, std::string( t ), result_type::local_failure, 1 );
- }
- for( char i = 'c'; i < 127; ++i ) {
- char t[] = { i, 0 };
- verify_rule< predicates_or< pred_t > >( __LINE__, __FILE__, std::string( t ), result_type::local_failure, 1 );
- }
- }
-
-} // namespace TAO_PEGTL_NAMESPACE
-
-#include "main.hpp"
diff --git a/src/test/pegtl/contrib_raw_string.cpp b/src/test/pegtl/contrib_raw_string.cpp
index b2a95a4d4..66f86f2f9 100644
--- a/src/test/pegtl/contrib_raw_string.cpp
+++ b/src/test/pegtl/contrib_raw_string.cpp
@@ -3,9 +3,14 @@
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
#include "test.hpp"
+#include "test_inputs.hpp"
#include "verify_meta.hpp"
+#include
+#include
#include
+#include
+#include
namespace TAO_PEGTL_NAMESPACE
{
@@ -54,13 +59,13 @@ namespace TAO_PEGTL_NAMESPACE
void verify_data( const std::size_t line, const char* file, const char ( &m )[ M ], const char ( &n )[ N ] )
{
content.clear();
- memory_input in( m, m + M - 1, file, 0, line, 1 );
+ test::text_input< ascii::lf_crlf > in( m, m + M - 1 );
const auto r = parse< Rule, Action >( in );
if( ( !r ) || ( content != std::string_view( n, N - 1 ) ) ) {
TAO_PEGTL_TEST_FAILED( "input data [ '" << m << "' ] expected success with [ '" << n << "' ] but got [ '" << content << "' ] result [ " << r << " ]" ); // LCOV_EXCL_LINE
}
content.clear();
- memory_input< tracking_mode::lazy > in2( m, m + M - 1, file, 0, line, 1 );
+ test::lazy_input< ascii::lf_crlf > in2( m, m + M - 1 );
const auto r2 = parse< Rule, Action >( in2 );
if( ( !r2 ) || ( content != std::string_view( n, N - 1 ) ) ) {
TAO_PEGTL_TEST_FAILED( "input data [ '" << m << "' ] with tracking_mode::lazy expected success with [ '" << n << "' ] but got [ '" << content << "' ] result [ " << r2 << " ]" ); // LCOV_EXCL_LINE
@@ -70,7 +75,7 @@ namespace TAO_PEGTL_NAMESPACE
template< typename Rule >
void verify_fail( const std::size_t line, const char* file, const std::string& s )
{
- memory_input in( s, "expect exception" );
+ test::text_input< ascii::lf_crlf > in( s );
if( parse< Rule >( in ) ) {
TAO_PEGTL_TEST_FAILED( "expected exception" ); // LCOV_EXCL_LINE
}
diff --git a/src/test/pegtl/contrib_separated_seq.cpp b/src/test/pegtl/contrib_separated_seq.cc
similarity index 100%
rename from src/test/pegtl/contrib_separated_seq.cpp
rename to src/test/pegtl/contrib_separated_seq.cc
diff --git a/src/test/pegtl/contrib_state_control.cpp b/src/test/pegtl/contrib_state_control.cc
similarity index 100%
rename from src/test/pegtl/contrib_state_control.cpp
rename to src/test/pegtl/contrib_state_control.cc
diff --git a/src/test/pegtl/contrib_to_string.cpp b/src/test/pegtl/contrib_to_string.cc
similarity index 100%
rename from src/test/pegtl/contrib_to_string.cpp
rename to src/test/pegtl/contrib_to_string.cc
diff --git a/src/test/pegtl/contrib_trace1.cpp b/src/test/pegtl/contrib_trace1.cc
similarity index 100%
rename from src/test/pegtl/contrib_trace1.cpp
rename to src/test/pegtl/contrib_trace1.cc
diff --git a/src/test/pegtl/contrib_trace2.cpp b/src/test/pegtl/contrib_trace2.cc
similarity index 100%
rename from src/test/pegtl/contrib_trace2.cpp
rename to src/test/pegtl/contrib_trace2.cc
diff --git a/src/test/pegtl/contrib_unescape.cpp b/src/test/pegtl/contrib_unescape.cpp
index 6a21ff9f1..8bf467f8f 100644
--- a/src/test/pegtl/contrib_unescape.cpp
+++ b/src/test/pegtl/contrib_unescape.cpp
@@ -3,8 +3,11 @@
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
#include "test.hpp"
+#include "test_inputs.hpp"
#include
+#include
+#include
namespace TAO_PEGTL_NAMESPACE
{
@@ -29,25 +32,30 @@ namespace TAO_PEGTL_NAMESPACE
// clang-format on
template< unsigned M, unsigned N >
- bool verify_data( const char ( &m )[ M ], const char ( &n )[ N ] )
+ [[nodiscard]] bool verify_data( const char ( &m )[ M ], const char ( &n )[ N ] )
{
std::string s;
- memory_input in( m, M - 1, __FUNCTION__ );
+ test::text_input< ascii::lf > in( m );
+ std::cerr << __LINE__ << " : " << m << std::endl;
+ std::cerr << __LINE__ << " : " << in.string_view() << std::endl;
+ std::cerr << __LINE__ << " : " << n << std::endl;
if( !parse< unstring, unaction >( in, s ) ) {
+ std::cerr << __LINE__ << " : " << s << std::endl;
return false; // LCOV_EXCL_LINE
}
+ std::cerr << __LINE__ << " : " << s << std::endl;
return s == std::string( n, N - 1 );
}
- bool verify_fail( const std::string& m )
+ [[nodiscard]] bool verify_fail( const std::string& m )
{
std::string s;
- memory_input in( m, __FUNCTION__ );
+ test::text_input< ascii::lf > in( m );
#if defined( __cpp_exceptions )
try {
return !parse< unstring, unaction >( in, s );
}
- catch( const parse_error& ) {
+ catch( const parse_error_base& ) {
}
return true;
#else
diff --git a/src/test/pegtl/contrib_uri.cpp b/src/test/pegtl/contrib_uri.cpp
index 9121b7f9e..f41368b0c 100644
--- a/src/test/pegtl/contrib_uri.cpp
+++ b/src/test/pegtl/contrib_uri.cpp
@@ -11,9 +11,14 @@ int main()
#else
#include "test.hpp"
+#include "test_inputs.hpp"
#include "verify_meta.hpp"
#include "verify_rule.hpp"
+#include
+#include