Skip to content

Commit

Permalink
Input refactoring in progress.
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinH committed Dec 17, 2023
1 parent 4c3aaa3 commit 3802054
Show file tree
Hide file tree
Showing 72 changed files with 304 additions and 209 deletions.
3 changes: 3 additions & 0 deletions doc/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
* Moved `end_of_line()` from input member function to global function of same name.
* Makefile generates binaries in `build/bin/` instead of `build/src/`.
* Makefile generates dependencies in `build/dep/` instead of `build/src/`.
* Renamed contrib "limit_depth" functionality to "check_depth".
* Renamed contrib "check_bytes" functionality to "check_count".
* Renamed contrib "limit_bytes" functionality to "limit_count".
* Removed rule `bytes` and replaced with `many` for different data types.
* Removed support for `boost::filesystem` and `std::experimental::filesystem`.
* Removed support for building an amalgamated header.
Expand Down
7 changes: 7 additions & 0 deletions include/tao/pegtl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "pegtl/parse.hpp"
#include "pegtl/print.hpp"
#include "pegtl/rules.hpp"
#include "pegtl/tags.hpp"
#include "pegtl/utf8.hpp"
#include "pegtl/version.hpp"
#include "pegtl/visit.hpp"
Expand All @@ -40,4 +41,10 @@

#include "pegtl/line_view_at.hpp"

#include "pegtl/count_position.hpp"
#include "pegtl/pointer_position.hpp"
#include "pegtl/position_with_source.hpp"
#include "pegtl/text_position.hpp"
#include "pegtl/text_position_with_source.hpp"

#endif
8 changes: 4 additions & 4 deletions include/tao/pegtl/analyze_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ namespace TAO_PEGTL_NAMESPACE
: analyze_opt_traits<>
{};

template< typename Name >
struct analyze_traits< Name, internal::eol >
template< typename Name, typename Eol >
struct analyze_traits< Name, internal::eol< Eol > >
: analyze_any_traits<>
{};

template< typename Name >
struct analyze_traits< Name, internal::eolf >
template< typename Name, typename Eol >
struct analyze_traits< Name, internal::eolf< Eol > >
: analyze_opt_traits<>
{};

Expand Down
2 changes: 1 addition & 1 deletion include/tao/pegtl/ascii.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace TAO_PEGTL_NAMESPACE
template< char Lo, char Hi > struct range : internal::range< internal::result_on_found::success, internal::peek_char, Lo, Hi > {};
template< char... Cs > struct ranges : internal::ranges< internal::peek_char, Cs... > {};
struct seven : internal::range< internal::result_on_found::success, internal::peek_char, static_cast< char >( 0 ), static_cast< char >( 127 ) > {};
struct shebang : internal::seq< internal::string< '#', '!' >, internal::until< internal::eolf > > {};
struct shebang : internal::seq< internal::string< '#', '!' >, internal::until< internal::eolf< void > > > {};
struct sp : internal::one< internal::result_on_found::success, internal::peek_char, ' ' > {};
struct space : internal::one< internal::result_on_found::success, internal::peek_char, ' ', '\n', '\r', '\t', '\v', '\f' > {};
template< char... Cs > struct string : internal::string< Cs... > {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)

#ifndef TAO_PEGTL_CONTRIB_CHECK_BYTES_HPP
#define TAO_PEGTL_CONTRIB_CHECK_BYTES_HPP
#ifndef TAO_PEGTL_CONTRIB_CHECK_COUNT_HPP
#define TAO_PEGTL_CONTRIB_CHECK_COUNT_HPP

#include "../apply_mode.hpp"
#include "../config.hpp"
Expand All @@ -21,7 +21,7 @@
namespace TAO_PEGTL_NAMESPACE
{
template< std::size_t Maximum >
struct check_bytes
struct check_count
: maybe_nothing
{
template< typename Rule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)

#ifndef TAO_PEGTL_CONTRIB_LIMIT_DEPTH_HPP
#define TAO_PEGTL_CONTRIB_LIMIT_DEPTH_HPP
#ifndef TAO_PEGTL_CONTRIB_CHECK_DEPTH_HPP
#define TAO_PEGTL_CONTRIB_CHECK_DEPTH_HPP

#include "../apply_mode.hpp"
#include "../config.hpp"
Expand All @@ -21,7 +21,7 @@
namespace TAO_PEGTL_NAMESPACE
{
template< std::size_t Maximum >
struct limit_depth
struct check_depth
: maybe_nothing
{
static constexpr const char* error_message = "maximum parser rule nesting depth exceeded";
Expand All @@ -41,7 +41,7 @@ namespace TAO_PEGTL_NAMESPACE
const auto dg( in.make_depth_guard() );
if( dg.current_depth() > Maximum ) {
#if defined( __cpp_exceptions )
Control< limit_depth >::raise( in );
Control< check_depth >::raise( in );
#else
std::fputs( "maximum parser rule nesting depth exceeded\n", stderr );
std::terminate();
Expand Down
5 changes: 3 additions & 2 deletions include/tao/pegtl/contrib/http.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "../nothing.hpp"
#include "../remove_first_state.hpp"
#include "../rules.hpp"
#include "../tags.hpp"
#include "../utf8.hpp"

#include "abnf.hpp"
Expand Down Expand Up @@ -166,7 +167,7 @@ namespace TAO_PEGTL_NAMESPACE::http
}
break;
}
in.template consume< internal::eol_exclude_tag >( i );
in.template consume< eol_exclude_tag >( i );
return i > 0;
}
};
Expand All @@ -192,7 +193,7 @@ namespace TAO_PEGTL_NAMESPACE::http
[[nodiscard]] static bool match( ParseInput& in, const std::size_t size, States&&... /*unused*/ )
{
if( in.size( size ) >= size ) {
in.template consume< internal::eol_unknown_tag >( size );
in.template consume< eol_unknown_tag >( size );
return true;
}
return false;
Expand Down
3 changes: 1 addition & 2 deletions include/tao/pegtl/contrib/integer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
#include "../parse.hpp"
#include "../parse_error.hpp"
#include "../rules.hpp"

#include "../internal/text_eol_tags.hpp"
#include "../tags.hpp"

namespace TAO_PEGTL_NAMESPACE
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)

#ifndef TAO_PEGTL_CONTRIB_LIMIT_BYTES_HPP
#define TAO_PEGTL_CONTRIB_LIMIT_BYTES_HPP
#ifndef TAO_PEGTL_CONTRIB_LIMIT_COUNT_HPP
#define TAO_PEGTL_CONTRIB_LIMIT_COUNT_HPP

#include <algorithm>

Expand All @@ -30,11 +30,11 @@ namespace TAO_PEGTL_NAMESPACE
MemoryInput& m_in;
const char* m_end;

explicit bytes_guard( MemoryInput& in_in ) noexcept
: m_in( in_in ),
m_end( in_in.end() )
explicit bytes_guard( MemoryInput& in ) noexcept
: m_in( in ),
m_end( in.end() )
{
m_in.private_set_end( m_in.begin() + std::min( m_in.size(), Maximum ) );
m_in.private_set_end( m_in.start() + ( std::min )( m_in.size(), Maximum ) );
}

bytes_guard( bytes_guard&& ) = delete;
Expand All @@ -45,16 +45,16 @@ namespace TAO_PEGTL_NAMESPACE
m_in.private_set_end( m_end );
}

bytes_guard& operator=( bytes_guard&& ) = delete;
bytes_guard& operator=( const bytes_guard& ) = delete;
void operator=( bytes_guard&& ) = delete;
void operator=( const bytes_guard& ) = delete;
};

// C++17 does not allow for partial deduction guides.

} // namespace internal

template< std::size_t Maximum >
struct limit_bytes
struct limit_count
: maybe_nothing
{
static constexpr const char* error_message = "maximum allowed rule consumption reached";
Expand All @@ -74,7 +74,7 @@ namespace TAO_PEGTL_NAMESPACE
if( TAO_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, st... ) ) {
if( in.empty() && ( bg.m_end != in.current() ) ) {
#if defined( __cpp_exceptions )
Control< limit_bytes >::raise( in );
Control< limit_count >::raise( in );
#else
std::fputs( "maximum allowed rule consumption reached\n", stderr );
std::terminate();
Expand Down
6 changes: 3 additions & 3 deletions include/tao/pegtl/contrib/parse_tree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include <utility>
#include <vector>

#include "remove_first_state.hpp"
#include "shuffle_states.hpp"

#include "../apply_mode.hpp"
Expand All @@ -26,6 +25,7 @@
#include "../normal.hpp"
#include "../nothing.hpp"
#include "../parse.hpp"
#include "../remove_first_state.hpp"
#include "../rewind_mode.hpp"

#include "../internal/enable_control.hpp"
Expand Down Expand Up @@ -57,8 +57,8 @@ namespace TAO_PEGTL_NAMESPACE::parse_tree
~basic_node() = default;

// no assignment either
basic_node& operator=( const basic_node& ) = delete;
basic_node& operator=( basic_node&& ) = delete;
void operator=( const basic_node& ) = delete;
void operator=( basic_node&& ) = delete;

[[nodiscard]] bool is_root() const noexcept
{
Expand Down
7 changes: 3 additions & 4 deletions include/tao/pegtl/contrib/raw_string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
#include "../eol.hpp"
#include "../rewind_mode.hpp"
#include "../rules.hpp"

#include "../internal/text_eol_tags.hpp"
#include "../tags.hpp"

namespace TAO_PEGTL_NAMESPACE
{
Expand Down Expand Up @@ -45,7 +44,7 @@ namespace TAO_PEGTL_NAMESPACE
case Open:
marker_size = i + 1;
in.template consume< eol_exclude_tag >( marker_size );
(void)Control< eol >::template match< A, M, Action, Control >( in );
(void)Control< eol< void > >::template match< A, M, Action, Control >( in );
return true;
case Marker:
break;
Expand Down Expand Up @@ -211,7 +210,7 @@ namespace TAO_PEGTL_NAMESPACE
std::size_t marker_size;
if( Control< internal::raw_string_open< Open, Marker > >::template match< A, M, Action, Control >( in, marker_size ) ) {
if( Control< content >::template match< A, M, Action, Control >( in, marker_size, st... ) ) {
in.template consume< internal::eol_exclude_tag >( marker_size );
in.template consume< eol_exclude_tag >( marker_size );
return true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions include/tao/pegtl/count_position.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ namespace TAO_PEGTL_NAMESPACE
{}
};

[[nodiscard]] inline bool operator==( const count_position& l, const count_position& r ) noexcept
[[nodiscard]] inline bool operator==( const count_position l, const count_position r ) noexcept
{
return l.count == r.count;
}

[[nodiscard]] inline bool operator!=( const count_position& l, const count_position& r ) noexcept
[[nodiscard]] inline bool operator!=( const count_position l, const count_position r ) noexcept
{
return !( l == r );
}
Expand Down
5 changes: 3 additions & 2 deletions include/tao/pegtl/inputs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@
#include <string>

#include "config.hpp"
#include "eol.hpp"

#include "internal/inputs.hpp"

namespace TAO_PEGTL_NAMESPACE
{
using argv_input = internal::input_with_fakes< internal::input_with_peeks< internal::argv_input > >; // TODO: Add input_with_start?
using argv_input = internal::input_with_fakes< internal::input_with_peeks< internal::input_with_start< internal::input_with_lines< ascii::lf, internal::argv_input > > > >;
template< typename Container >
using copy_input = internal::input_with_fakes< internal::input_with_peeks< internal::copy_input< Container > > >;
using file_input = internal::input_with_fakes< internal::input_with_peeks< internal::file_input > >;
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?
using argv_input_with_source = internal::input_with_fakes< internal::input_with_peeks< internal::input_with_start< internal::input_with_lines< ascii::lf, internal::argv_input_with_source > > > >;
template< typename Container >
using copy_input_with_source = internal::input_with_fakes< internal::input_with_peeks< internal::input_with_source< std::string, internal::copy_input< Container > > > >;
using file_input_with_source = internal::input_with_fakes< internal::input_with_peeks< internal::file_input_with_source< file_input > > >;
Expand Down
5 changes: 5 additions & 0 deletions include/tao/pegtl/internal/buffer_input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ namespace TAO_PEGTL_NAMESPACE::internal
return m_current + offset;
}

[[nodiscard]] const data_t* previous( const error_position_t saved ) const noexcept
{
return m_current - m_position.count + saved.count;
}

[[nodiscard]] const data_t* previous( const rewind_position_t saved ) const noexcept
{
return saved.data;
Expand Down
6 changes: 3 additions & 3 deletions include/tao/pegtl/internal/bump_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <type_traits>

#include "../config.hpp"
#include "../tags.hpp"

#include "any.hpp"
#include "at.hpp"
Expand All @@ -17,7 +18,6 @@
#include "eolf.hpp"
#include "everything.hpp"
#include "many.hpp"
#include "text_eol_tags.hpp"
#include "until.hpp"

namespace TAO_PEGTL_NAMESPACE::internal
Expand Down Expand Up @@ -91,12 +91,12 @@ namespace TAO_PEGTL_NAMESPACE::internal
{};

template< typename Eol >
struct bump_traits< Eol, until< eol > >
struct bump_traits< Eol, until< eol< void > > >
: bump_traits< Eol, eol_exclude_tag >
{};

template< typename Eol >
struct bump_traits< Eol, until< eolf > >
struct bump_traits< Eol, until< eolf< void > > >
: bump_traits< Eol, eol_exclude_tag >
{};

Expand Down
5 changes: 5 additions & 0 deletions include/tao/pegtl/internal/copy_input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ namespace TAO_PEGTL_NAMESPACE::internal
return m_current + offset;
}

[[nodiscard]] const data_t* previous( const error_position_t saved ) const noexcept
{
return start() + saved.count;
}

[[nodiscard]] const data_t* previous( const rewind_position_t saved ) const noexcept
{
return saved.data;
Expand Down
29 changes: 25 additions & 4 deletions include/tao/pegtl/internal/eol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,35 @@
#include "../type_list.hpp"

#include "enable_control.hpp"
#include "text_eol_tags.hpp"

namespace TAO_PEGTL_NAMESPACE::internal
{
template< typename Eol >
struct eol
{
using rule_t = eol;
using subs_t = empty_list; // Not quite true, but good enough and we can't really do better.
using subs_t = empty_list; // TODO?

template< apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control,
typename ParseInput,
typename... States >
[[nodiscard]] static bool match( ParseInput& in, States&&... st )
{
using eol_impl = typename Eol::rule_t;
return Control< eol_impl >::template match< apply_mode::nothing, M, Action, Control >( in, st... );
}
};

template<>
struct eol< void >
{
using rule_t = eol;
using subs_t = empty_list;

template< apply_mode A,
rewind_mode M,
Expand All @@ -36,8 +57,8 @@ namespace TAO_PEGTL_NAMESPACE::internal
}
};

template<>
inline constexpr bool enable_control< eol > = false;
template< typename Eol >
inline constexpr bool enable_control< eol< Eol > > = false;

} // namespace TAO_PEGTL_NAMESPACE::internal

Expand Down
Loading

0 comments on commit 3802054

Please sign in to comment.