Skip to content

Commit

Permalink
Fiddle with details.
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinH committed Feb 17, 2024
1 parent 86b4d34 commit 804fe5d
Show file tree
Hide file tree
Showing 25 changed files with 57 additions and 38 deletions.
2 changes: 1 addition & 1 deletion include/tao/pegtl/analyze.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ namespace TAO_PEGTL_NAMESPACE
{
using Traits = analyze_traits< Name, typename Name::rule_t >;

const auto [ i, b ] = entry.try_emplace( demangle< Name >(), Traits::type_v );
const auto [ i, b ] = entry.try_emplace( demangle< Name >(), Traits::enum_v );
if( b ) {
analyze_insert_impl( typename Traits::subs_t(), i->second.subs, entry );
}
Expand Down
8 changes: 4 additions & 4 deletions include/tao/pegtl/analyze_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,31 @@ namespace TAO_PEGTL_NAMESPACE
struct analyze_any_traits
{
// Consumption-on-success is always true; assumes bounded repetition of conjunction of sub-rules.
static constexpr internal::analyze_enum type_v = internal::analyze_enum::any;
static constexpr internal::analyze_enum enum_v = internal::analyze_enum::any;
using subs_t = type_list< Rules... >;
};

template< typename... Rules >
struct analyze_opt_traits
{
// Consumption-on-success not necessarily true; assumes bounded repetition of conjunction of sub-rules.
static constexpr internal::analyze_enum type_v = internal::analyze_enum::opt;
static constexpr internal::analyze_enum enum_v = internal::analyze_enum::opt;
using subs_t = type_list< Rules... >;
};

template< typename... Rules >
struct analyze_seq_traits
{
// Consumption-on-success depends on consumption of (non-zero bounded repetition of) conjunction of sub-rules.
static constexpr internal::analyze_enum type_v = internal::analyze_enum::seq;
static constexpr internal::analyze_enum enum_v = internal::analyze_enum::seq;
using subs_t = type_list< Rules... >;
};

template< typename... Rules >
struct analyze_sor_traits
{
// Consumption-on-success depends on consumption of (non-zero bounded repetition of) disjunction of sub-rules.
static constexpr internal::analyze_enum type_v = internal::analyze_enum::sor;
static constexpr internal::analyze_enum enum_v = internal::analyze_enum::sor;
using subs_t = type_list< Rules... >;
};

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 @@ -94,7 +94,7 @@ namespace TAO_PEGTL_NAMESPACE
struct lf_crlf : ascii::lf_crlf { using eol_lazy_peek = internal::peek_char; };
struct cr_lf_crlf : ascii::cr_lf_crlf { using eol_lazy_peek = internal::peek_char; };
// clang-format on
} // namespace rule
} // namespace lazy

} // namespace ascii

Expand Down
2 changes: 1 addition & 1 deletion include/tao/pegtl/buffer/discard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ namespace TAO_PEGTL_NAMESPACE
}
};

} // namespace TAO_PEGTL_NAMESPACE::internal
} // namespace TAO_PEGTL_NAMESPACE

#endif
2 changes: 1 addition & 1 deletion include/tao/pegtl/buffer/require.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ namespace TAO_PEGTL_NAMESPACE
: internal::success
{};

} // namespace TAO_PEGTL_NAMESPACE::internal
} // namespace TAO_PEGTL_NAMESPACE

#endif
2 changes: 1 addition & 1 deletion include/tao/pegtl/contrib/dispatch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

#include "../apply_mode.hpp"
#include "../config.hpp"
#include "../match.hpp"
#include "../normal.hpp"
#include "../nothing.hpp"
#include "../match.hpp"
#include "../rewind_mode.hpp"

#include "../internal/dependent_false.hpp"
Expand Down
2 changes: 1 addition & 1 deletion include/tao/pegtl/contrib/trace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
#include <type_traits>

#include "../config.hpp"
#include "../parse.hpp"
#include "../normal.hpp"
#include "../nothing.hpp"
#include "../parse.hpp"

#include "../control/state_control.hpp"

Expand Down
2 changes: 1 addition & 1 deletion include/tao/pegtl/internal/analyze_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace TAO_PEGTL_NAMESPACE

template< typename Name, typename... Actions >
struct analyze_traits< Name, internal::apply< Actions... > >
: analyze_opt_traits<>
: analyze_opt_traits<>
{};

template< typename Name, typename... Actions >
Expand Down
2 changes: 1 addition & 1 deletion include/tao/pegtl/internal/choose_lazy_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace TAO_PEGTL_NAMESPACE::internal
{
static_assert( !std::is_same_v< Eol, void > );

if constexpr( get_eol_rule_char_v< Eol > ) {
if constexpr( int( get_eol_rule_char_v< Eol > ) != 0 ) {
char_scan_traits< Eol >::scan( pos, in );
}
else if constexpr( has_eol_char_rule< Eol > ) {
Expand Down
1 change: 1 addition & 0 deletions include/tao/pegtl/internal/input_with_funcs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define TAO_PEGTL_INTERNAL_INPUT_WITH_FUNCS_HPP

#include <cstddef>
#include <cstdint>
#include <string>
#include <string_view>
#include <vector>
Expand Down
6 changes: 3 additions & 3 deletions include/tao/pegtl/internal/inputs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ namespace TAO_PEGTL_NAMESPACE::internal
template< typename Eol, typename Input >
using base_short = input_with_fakes< input_with_funcs< input_with_lines< Eol, Input > > >;

template< typename Eol, typename Input >
using text_short = input_double_path< text_input_with_source< Eol, std::filesystem::path, std::filesystem::path, Input > >;

template< typename Input >
using path_short = input_double_path< input_with_source< std::filesystem::path, std::filesystem::path, Input > >;

template< typename Eol, typename Input >
using text_short = input_double_path< text_input_with_source< Eol, std::filesystem::path, std::filesystem::path, Input > >;

template< typename Eol, typename Data >
using base_alias = base_short< Eol, view_input< Data > >;

Expand Down
2 changes: 1 addition & 1 deletion include/tao/pegtl/internal/integer_size.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace TAO_PEGTL_NAMESPACE::internal
}
}

template< typename Type, typename Input>
template< typename Type, typename Input >
[[nodiscard]] constexpr std::size_t integer_input_size() noexcept
{
using Data = typename Input::data_t;
Expand Down
2 changes: 1 addition & 1 deletion include/tao/pegtl/internal/utf32_to_utf8.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace TAO_PEGTL_NAMESPACE::internal
using type = String<>;
};

template< char32_t... Cs >
template< char32_t... Cs >
using utf32_to_utf8_t = typename utf32_to_utf8_list< ascii_string, Cs... >::type;

} // namespace TAO_PEGTL_NAMESPACE::internal
Expand Down
2 changes: 1 addition & 1 deletion include/tao/pegtl/internal/utf_rules.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ namespace TAO_PEGTL_NAMESPACE::TAO_PEGTL_UTF_NAME
struct ps : TAO_PEGTL_UTF_NAME::ps { using eol_lazy_peek = TAO_PEGTL_UTF_PEEK; };
struct eolu : TAO_PEGTL_UTF_NAME::eolu { using eol_lazy_peek = TAO_PEGTL_UTF_PEEK; };
// clang-format on
} // namespace rule
} // namespace lazy

} // namespace TAO_PEGTL_NAMESPACE::TAO_PEGTL_UTF_NAME

Expand Down
2 changes: 1 addition & 1 deletion include/tao/pegtl/internal/utf_string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace TAO_PEGTL_NAMESPACE::internal
};

template< typename Peek, char32_t... Cs >
using utf_string_t = typename utf_string< Peek, Cs...>::type;
using utf_string_t = typename utf_string< Peek, Cs... >::type;

} // namespace TAO_PEGTL_NAMESPACE::internal

Expand Down
9 changes: 5 additions & 4 deletions include/tao/pegtl/parse_error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,19 @@ namespace TAO_PEGTL_NAMESPACE
const position_t m_position;
};

template< typename Position >
parse_error( const std::string&, Position ) -> parse_error< std::decay_t< Position > >;

template< typename Object >
[[noreturn]] void throw_parse_error( const std::string& msg, const Object& obj )
{
auto pos = internal::extract_position( obj );
throw parse_error< std::decay_t< decltype( pos ) > >( msg, std::move( pos ) );
throw parse_error( msg, internal::extract_position( obj ) );
}

template< typename Object >
[[noreturn]] void throw_with_nested_parse_error( const std::string& msg, const Object& obj )
{
auto pos = internal::extract_position( obj );
std::throw_with_nested( parse_error< std::decay_t< decltype( pos ) > >( msg, std::move( pos ) ) );
std::throw_with_nested( parse_error( msg, internal::extract_position( obj ) ) );
}

} // namespace TAO_PEGTL_NAMESPACE
Expand Down
6 changes: 6 additions & 0 deletions include/tao/pegtl/position_with_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ namespace TAO_PEGTL_NAMESPACE
{
Source source;

position_with_source( position_with_source&& ) = default;
position_with_source( const position_with_source& ) = default;

position_with_source& operator=( position_with_source&& ) = default;
position_with_source& operator=( const position_with_source& ) = default;

template< typename S, typename... Ps >
explicit position_with_source( S&& s, Ps&&... ps )
: Position( std::forward< Ps >( ps )... ),
Expand Down
4 changes: 2 additions & 2 deletions include/tao/pegtl/text_position_with_source.hpp
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_INTERNAL_TEXT_POSITION_WITH_SOURCE_HPP
#define TAO_PEGTL_INTERNAL_TEXT_POSITION_WITH_SOURCE_HPP
#ifndef TAO_PEGTL_TEXT_POSITION_WITH_SOURCE_HPP
#define TAO_PEGTL_TEXT_POSITION_WITH_SOURCE_HPP

#include <filesystem>
#include <string>
Expand Down
2 changes: 1 addition & 1 deletion src/test/pegtl/action_match_lazy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ namespace TAO_PEGTL_NAMESPACE
void unit_test()
{
state_one state;
text_view_input< lazy::lf >in( "aaa" );
text_view_input< lazy::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 );
Expand Down
2 changes: 1 addition & 1 deletion src/test/pegtl/action_match_text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ namespace TAO_PEGTL_NAMESPACE
void unit_test()
{
state_one state;
text_view_input< scan::lf >in( "aaa" );
text_view_input< scan::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 );
Expand Down
2 changes: 1 addition & 1 deletion src/test/pegtl/internal_get_eol_rule_char.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include <type_traits>

#include <tao/pegtl/ascii.hpp>
#include <tao/pegtl/utf8.hpp>
#include <tao/pegtl/utf32.hpp>
#include <tao/pegtl/utf8.hpp>

#include <tao/pegtl/internal/get_eol_rule_char.hpp>

Expand Down
1 change: 1 addition & 0 deletions src/test/pegtl/internal_lazy_scan_traits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "test_utility.hpp"

#include <tao/pegtl/text_position.hpp>

#include <tao/pegtl/internal/data_and_size.hpp>
#include <tao/pegtl/internal/dependent_false.hpp>
#include <tao/pegtl/internal/lazy_scan_traits.hpp>
Expand Down
1 change: 1 addition & 0 deletions src/test/pegtl/internal_text_scan_traits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "test_utility.hpp"

#include <tao/pegtl/text_position.hpp>

#include <tao/pegtl/internal/text_scan_traits.hpp>

namespace TAO_PEGTL_NAMESPACE
Expand Down
19 changes: 15 additions & 4 deletions src/test/pegtl/test_endian.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ namespace TAO_PEGTL_NAMESPACE::test
// the one in tao/pegtl/include/endian.hpp etc. for the tests to be useful...
// TODO: When can we finally switch to the C++20 and C++23 endian facilities?

[[nodiscard]] inline bool is_be() noexcept
{
union {
std::uint8_t a[ 2 ];
std::uint16_t i;
} u;
static_assert( sizeof( u ) == 2 );
u.i = 0x1af3;
return u.a[ 0 ] == 0x1a;
}

[[nodiscard]] inline std::uint16_t b_swap( const std::uint16_t value ) noexcept
{
return ( ( value & 0x00ff ) << 8 ) | ( ( value & 0xff00 ) >> 8 );
Expand All @@ -28,31 +39,31 @@ namespace TAO_PEGTL_NAMESPACE::test

[[nodiscard]] inline std::uint16_t h_to_be( const std::uint16_t value ) noexcept
{
if( htons( value ) == value ) {
if( is_be() ) {
return value;
}
return b_swap( value );
}

[[nodiscard]] inline std::uint16_t h_to_le( const std::uint16_t value ) noexcept
{
if( htons( value ) == value ) {
if( is_be() ) {
return b_swap( value );
}
return value;
}

[[nodiscard]] inline std::uint32_t h_to_be( const std::uint32_t value ) noexcept
{
if( htonl( value ) == value ) {
if( is_be() ) {
return value;
}
return b_swap( value );
}

[[nodiscard]] inline std::uint32_t h_to_le( const std::uint32_t value ) noexcept
{
if( htonl( value ) == value ) {
if( is_be() ) {
return b_swap( value );
}
return value;
Expand Down
10 changes: 4 additions & 6 deletions src/test/pegtl/test_result.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <sstream>

#include "test.hpp"

#include "result_type.hpp"

namespace TAO_PEGTL_NAMESPACE
Expand All @@ -15,18 +16,15 @@ namespace TAO_PEGTL_NAMESPACE
std::ostringstream oss;
oss << result_type::success;
TAO_PEGTL_TEST_ASSERT( oss.str() == "success" );
}
{
} {
std::ostringstream oss;
oss << result_type::local_failure;
TAO_PEGTL_TEST_ASSERT( oss.str() == "local_failure" );
}
{
} {
std::ostringstream oss;
oss << result_type::global_failure;
TAO_PEGTL_TEST_ASSERT( oss.str() == "global_failure" );
}
{
} {
std::ostringstream oss;
oss << static_cast< result_type >( 1764 );
TAO_PEGTL_TEST_ASSERT( oss.str() == "1764" );
Expand Down

0 comments on commit 804fe5d

Please sign in to comment.