Skip to content

Commit cbdf49d

Browse files
committed
Update embedded PEGTL
1 parent 831894a commit cbdf49d

File tree

8 files changed

+130
-50
lines changed

8 files changed

+130
-50
lines changed

include/tao/json/external/pegtl/ascii.hpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace tao
2727
struct identifier_other : internal::identifier_other {};
2828
struct identifier : internal::identifier {};
2929
template< char... Cs > struct istring : internal::istring< Cs... > {};
30-
template< char C, char... Cs > struct keyword : internal::seq< internal::string< C, Cs... >, internal::not_at< internal::identifier_other > > {};
30+
template< char... Cs > struct keyword : internal::seq< internal::string< Cs... >, internal::not_at< internal::identifier_other > > {};
3131
struct lower : internal::range< internal::result_on_found::SUCCESS, internal::peek_char, 'a', 'z' > {};
3232
template< char... Cs > struct not_one : internal::one< internal::result_on_found::FAILURE, internal::peek_char, Cs... > {};
3333
template< char Lo, char Hi > struct not_range : internal::range< internal::result_on_found::FAILURE, internal::peek_char, Lo, Hi > {};
@@ -45,6 +45,17 @@ namespace tao
4545
struct xdigit : internal::ranges< internal::peek_char, '0', '9', 'a', 'f', 'A', 'F' > {};
4646
// clang-format on
4747

48+
template<>
49+
struct keyword<>
50+
{
51+
template< typename Input >
52+
static bool match( Input& ) noexcept
53+
{
54+
static_assert( sizeof( Input ) == 0, "empty keywords not allowed" );
55+
return false;
56+
}
57+
};
58+
4859
} // namespace ascii
4960

5061
} // namespace TAOCPP_JSON_PEGTL_NAMESPACE

include/tao/json/external/pegtl/contrib/http.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ namespace tao
6363

6464
struct request_line : if_must< method, SP, request_target, SP, HTTP_version, CRLF > {};
6565
struct status_line : if_must< HTTP_version, SP, status_code, SP, reason_phrase, CRLF > {};
66-
struct start_line : sor< request_line, status_line > {};
66+
struct start_line : sor< status_line, request_line > {};
6767

6868
struct message_body : star< OCTET > {};
6969
struct HTTP_message : seq< start_line, star< header_field, CRLF >, CRLF, opt< message_body > > {};

include/tao/json/external/pegtl/contrib/raw_string.hpp

Lines changed: 29 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@ namespace tao
2323
{
2424
namespace internal
2525
{
26-
template< char Open, char Marker, char Close >
27-
struct raw_string_tag
28-
{
29-
};
26+
template< char Open, char Marker, char Close, typename... Contents >
27+
struct raw_string_tag;
3028

3129
template< bool use_action, bool use_apply0, typename Tag >
3230
struct raw_string_state_apply;
@@ -176,35 +174,6 @@ namespace tao
176174
{
177175
};
178176

179-
template< class Tag, typename... Rules >
180-
struct raw_string_switch_state
181-
{
182-
using analyze_t = analysis::generic< analysis::rule_type::SEQ, Rules... >;
183-
184-
template< apply_mode A,
185-
rewind_mode M,
186-
template< typename... > class Action,
187-
template< typename... > class Control,
188-
typename Input,
189-
typename... States >
190-
static bool match( Input& in, States&&... st )
191-
{
192-
using Iterator = typename Input::iterator_t;
193-
raw_string_state< Tag, Iterator > s( const_cast< const Input& >( in ), st... );
194-
195-
if( duseltronik< seq< Rules... >, A, M, Action, Control >::match( in, s ) ) {
196-
s.template success< A, M, Action, Control >( in, st... );
197-
return true;
198-
}
199-
return false;
200-
}
201-
};
202-
203-
template< typename Tag, typename... Rules >
204-
struct skip_control< raw_string_switch_state< Tag, Rules... > > : std::true_type
205-
{
206-
};
207-
208177
} // namespace internal
209178

210179
// raw_string matches Lua-style long literals.
@@ -232,17 +201,37 @@ namespace tao
232201
// introduced newline-specific replacements in Lua 5.2, which we do not
233202
// support on the grammar level.
234203

235-
template< char Open, char Marker, char Close >
204+
template< char Open, char Marker, char Close, typename... Contents >
236205
struct raw_string
237-
: internal::raw_string_switch_state< internal::raw_string_tag< Open, Marker, Close >,
238-
internal::raw_string_open< Open, Marker >,
239-
internal::must< internal::until< internal::at_raw_string_close< Marker, Close > > > >
240206
{
241-
// This is used to bind an action to the content.
242-
using content = internal::raw_string_tag< Open, Marker, Close >;
207+
// This is used as a tag to bind an action to the content.
208+
using content = internal::raw_string_tag< Open, Marker, Close, Contents... >;
209+
210+
// This is used internally.
211+
using open = internal::raw_string_open< Open, Marker >;
243212

244213
// This is used for error-reporting when a raw string is not closed properly.
245-
using close = internal::until< internal::at_raw_string_close< Marker, Close > >;
214+
using close = internal::until< internal::at_raw_string_close< Marker, Close >, Contents... >;
215+
216+
using analyze_t = analysis::generic< analysis::rule_type::SEQ, open, internal::must< close > >;
217+
218+
template< apply_mode A,
219+
rewind_mode M,
220+
template< typename... > class Action,
221+
template< typename... > class Control,
222+
typename Input,
223+
typename... States >
224+
static bool match( Input& in, States&&... st )
225+
{
226+
using Iterator = typename Input::iterator_t;
227+
internal::raw_string_state< content, Iterator > s( const_cast< const Input& >( in ), st... );
228+
229+
if( Control< internal::seq< open, internal::must< close > > >::template match< A, M, Action, Control >( in, s ) ) {
230+
s.template success< A, M, Action, Control >( in, st... );
231+
return true;
232+
}
233+
return false;
234+
}
246235
};
247236

248237
} // namespace TAOCPP_JSON_PEGTL_NAMESPACE
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Copyright (c) 2017 Dr. Colin Hirsch and Daniel Frey
2+
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
3+
4+
#ifndef TAOCPP_JSON_PEGTL_INCLUDE_CONTRIB_REP_ONE_MIN_MAX_HPP
5+
#define TAOCPP_JSON_PEGTL_INCLUDE_CONTRIB_REP_ONE_MIN_MAX_HPP
6+
7+
#include <algorithm>
8+
9+
#include "../config.hpp"
10+
11+
#include "../analysis/counted.hpp"
12+
13+
#include "../internal/bump_help.hpp"
14+
#include "../internal/skip_control.hpp"
15+
16+
namespace tao
17+
{
18+
namespace TAOCPP_JSON_PEGTL_NAMESPACE
19+
{
20+
namespace internal
21+
{
22+
template< unsigned Min, unsigned Max, char C >
23+
struct rep_one_min_max
24+
{
25+
using analyze_t = analysis::counted< analysis::rule_type::ANY, Min >;
26+
27+
static_assert( Min <= Max, "invalid rep_one_min_max rule (maximum number of repetitions smaller than minimum)" );
28+
29+
template< typename Input >
30+
static bool match( Input& in )
31+
{
32+
const auto size = in.size( Max + 1 );
33+
if( size < Min ) {
34+
return false;
35+
}
36+
std::size_t i = 0;
37+
while( ( i < size ) && ( in.peek_char( i ) == C ) ) {
38+
++i;
39+
}
40+
if( ( Min <= i ) && ( i <= Max ) ) {
41+
bump_help< result_on_found::SUCCESS, Input, char, C >( in, i );
42+
return true;
43+
}
44+
return false;
45+
}
46+
};
47+
48+
template< unsigned Min, unsigned Max, char C >
49+
struct skip_control< rep_one_min_max< Min, Max, C > > : std::true_type
50+
{
51+
};
52+
53+
} // namespace internal
54+
55+
inline namespace ascii
56+
{
57+
template< unsigned Min, unsigned Max, char C >
58+
struct rep_one_min_max : internal::rep_one_min_max< Min, Max, C >
59+
{
60+
};
61+
62+
struct ellipsis : internal::rep_one_min_max< 3, 3, '.' >
63+
{
64+
};
65+
66+
} // namespace ascii
67+
68+
} // namespace TAOCPP_JSON_PEGTL_NAMESPACE
69+
70+
} // namespace tao
71+
72+
#endif

include/tao/json/external/pegtl/internal/file_mapper.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace tao
2929

3030
explicit file_mapper( const file_opener& reader )
3131
: m_size( reader.size() ),
32-
m_data( static_cast< const char* >(::mmap( nullptr, m_size, PROT_READ, MAP_FILE | MAP_PRIVATE, reader.m_fd, 0 ) ) )
32+
m_data( static_cast< const char* >(::mmap( nullptr, m_size, PROT_READ, MAP_PRIVATE, reader.m_fd, 0 ) ) )
3333
{
3434
if( m_size && ( intptr_t( m_data ) == -1 ) ) {
3535
TAOCPP_JSON_PEGTL_THROW_INPUT_ERROR( "unable to mmap() file " << reader.m_source << " descriptor " << reader.m_fd );

include/tao/json/external/pegtl/internal/file_reader.hpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,20 @@ namespace tao
1818
{
1919
namespace internal
2020
{
21+
struct file_close
22+
{
23+
void operator()( FILE* f ) const
24+
{
25+
std::fclose( f );
26+
}
27+
};
28+
2129
class file_reader
2230
{
2331
public:
2432
explicit file_reader( const char* filename )
2533
: m_source( filename ),
26-
m_file( open(), &std::fclose )
34+
m_file( open() )
2735
{
2836
}
2937

@@ -61,12 +69,12 @@ namespace tao
6169

6270
private:
6371
const char* const m_source;
64-
const std::unique_ptr< std::FILE, decltype( &std::fclose ) > m_file;
72+
const std::unique_ptr< std::FILE, file_close > m_file;
6573

6674
std::FILE* open() const
6775
{
6876
errno = 0;
69-
#if defined( _WIN32 )
77+
#if defined( _MSC_VER )
7078
std::FILE* file;
7179
if(::fopen_s( &file, m_source, "rb" ) == 0 )
7280
#else

include/tao/json/external/pegtl/internal/raise.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace tao
3535
static bool match( Input& in, States&&... st )
3636
{
3737
Control< T >::raise( const_cast< const Input& >( in ), st... );
38-
#if defined( _WIN32 )
38+
#if defined( _MSC_VER )
3939
__assume( false ); // LCOV_EXCL_LINE
4040
#else
4141
std::abort(); // LCOV_EXCL_LINE

include/tao/json/external/pegtl/version.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
#ifndef TAOCPP_JSON_PEGTL_INCLUDE_VERSION_HPP
55
#define TAOCPP_JSON_PEGTL_INCLUDE_VERSION_HPP
66

7-
#define TAOCPP_JSON_PEGTL_VERSION "2.0.0"
7+
#define TAOCPP_JSON_PEGTL_VERSION "2.1.3"
88

99
#define TAOCPP_JSON_PEGTL_VERSION_MAJOR 2
10-
#define TAOCPP_JSON_PEGTL_VERSION_MINOR 0
11-
#define TAOCPP_JSON_PEGTL_VERSION_PATCH 0
10+
#define TAOCPP_JSON_PEGTL_VERSION_MINOR 1
11+
#define TAOCPP_JSON_PEGTL_VERSION_PATCH 3
1212

1313
#endif

0 commit comments

Comments
 (0)