Skip to content

Commit 861bc3d

Browse files
committed
Update PEGTL
1 parent 312db12 commit 861bc3d

23 files changed

+229
-301
lines changed

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

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,15 @@ namespace tao
2727
return os.str();
2828
}
2929

30-
struct argv_holder
31-
{
32-
const std::string argv_source;
33-
34-
template< typename T >
35-
explicit argv_holder( T&& in_argv_source )
36-
: argv_source( std::forward< T >( in_argv_source ) )
37-
{
38-
}
39-
};
40-
4130
} // namespace internal
4231

43-
template< typename Eol = lf_crlf_eol, tracking_mode P = tracking_mode::IMMEDIATE >
32+
template< tracking_mode P = tracking_mode::IMMEDIATE, typename Eol = lf_crlf_eol >
4433
struct argv_input
45-
: private internal::argv_holder,
46-
public memory_input< Eol, P >
34+
: public memory_input< P, Eol >
4735
{
4836
template< typename T >
4937
argv_input( char** argv, const std::size_t argn, T&& in_source )
50-
: internal::argv_holder( std::forward< T >( in_source ) ),
51-
memory_input< Eol, P >( static_cast< const char* >( argv[ argn ] ), argv_source )
38+
: memory_input< P, Eol >( static_cast< const char* >( argv[ argn ] ), std::forward< T >( in_source ) )
5239
{
5340
}
5441

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

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <cstddef>
88
#include <cstring>
99
#include <memory>
10+
#include <string>
1011

1112
#include "config.hpp"
1213
#include "eol.hpp"
@@ -23,30 +24,29 @@ namespace tao
2324
{
2425
namespace TAOCPP_JSON_PEGTL_NAMESPACE
2526
{
26-
template< typename Reader, typename Eol = lf_crlf_eol >
27+
template< typename Reader, typename Eol = lf_crlf_eol, typename Source = std::string >
2728
class buffer_input
2829
{
2930
public:
31+
static constexpr tracking_mode tracking_mode_v = tracking_mode::IMMEDIATE;
3032
using reader_t = Reader;
33+
3134
using eol_t = Eol;
35+
using source_t = Source;
36+
37+
using iterator_t = internal::iterator;
3238

33-
using memory_t = memory_input< Eol >;
34-
using action_t = internal::action_input< Eol, tracking_mode::IMMEDIATE >;
39+
using memory_t = memory_input< tracking_mode::IMMEDIATE, Eol, Source >;
40+
using action_t = internal::action_input< buffer_input, tracking_mode::IMMEDIATE >;
3541

3642
template< typename... As >
37-
buffer_input( const char* in_source, const std::size_t maximum, As&&... as )
43+
buffer_input( Source in_source, const std::size_t maximum, As&&... as )
3844
: m_reader( std::forward< As >( as )... ),
3945
m_maximum( maximum ),
4046
m_buffer( new char[ maximum ] ),
41-
m_data( { 0, 1, 0, m_buffer.get() } ),
47+
m_current( { 0, 1, 0, m_buffer.get() } ),
4248
m_end( m_buffer.get() ),
43-
m_source( in_source )
44-
{
45-
}
46-
47-
template< typename... As >
48-
buffer_input( const std::string& in_source, As&&... as )
49-
: buffer_input( in_source.c_str(), std::forward< As >( as )... )
49+
m_source( std::move( in_source ) )
5050
{
5151
}
5252

@@ -56,18 +56,18 @@ namespace tao
5656
bool empty()
5757
{
5858
require( 1 );
59-
return m_data.data == m_end;
59+
return m_current.data == m_end;
6060
}
6161

6262
std::size_t size( const std::size_t amount )
6363
{
6464
require( amount );
65-
return std::size_t( m_end - m_data.data );
65+
return std::size_t( m_end - m_current.data );
6666
}
6767

68-
const char* begin() const noexcept
68+
const char* current() const noexcept
6969
{
70-
return m_data.data;
70+
return m_current.data;
7171
}
7272

7373
const char* end( const std::size_t amount )
@@ -78,27 +78,27 @@ namespace tao
7878

7979
std::size_t byte() const noexcept
8080
{
81-
return m_data.byte;
81+
return m_current.byte;
8282
}
8383

8484
std::size_t line() const noexcept
8585
{
86-
return m_data.line;
86+
return m_current.line;
8787
}
8888

8989
std::size_t byte_in_line() const noexcept
9090
{
91-
return m_data.byte_in_line;
91+
return m_current.byte_in_line;
9292
}
9393

94-
const char* source() const noexcept
94+
const Source& source() const noexcept
9595
{
9696
return m_source;
9797
}
9898

9999
char peek_char( const std::size_t offset = 0 ) const noexcept
100100
{
101-
return m_data.data[ offset ];
101+
return m_current.data[ offset ];
102102
}
103103

104104
unsigned char peek_byte( const std::size_t offset = 0 ) const noexcept
@@ -108,32 +108,32 @@ namespace tao
108108

109109
void bump( const std::size_t in_count = 1 ) noexcept
110110
{
111-
internal::bump( m_data, in_count, Eol::ch );
111+
internal::bump( m_current, in_count, Eol::ch );
112112
}
113113

114114
void bump_in_this_line( const std::size_t in_count = 1 ) noexcept
115115
{
116-
internal::bump_in_this_line( m_data, in_count );
116+
internal::bump_in_this_line( m_current, in_count );
117117
}
118118

119119
void bump_to_next_line( const std::size_t in_count = 1 ) noexcept
120120
{
121-
internal::bump_to_next_line( m_data, in_count );
121+
internal::bump_to_next_line( m_current, in_count );
122122
}
123123

124124
void discard() noexcept
125125
{
126-
const auto s = m_end - m_data.data;
127-
std::memmove( m_buffer.get(), m_data.data, s );
128-
m_data.data = m_buffer.get();
126+
const auto s = m_end - m_current.data;
127+
std::memmove( m_buffer.get(), m_current.data, s );
128+
m_current.data = m_buffer.get();
129129
m_end = m_buffer.get() + s;
130130
}
131131

132132
void require( const std::size_t amount )
133133
{
134-
if( m_data.data + amount > m_end ) {
135-
if( m_data.data + amount <= m_buffer.get() + m_maximum ) {
136-
if( const auto r = m_reader( const_cast< char* >( m_end ), amount - std::size_t( m_end - m_data.data ) ) ) {
134+
if( m_current.data + amount > m_end ) {
135+
if( m_current.data + amount <= m_buffer.get() + m_maximum ) {
136+
if( const auto r = m_reader( const_cast< char* >( m_end ), amount - std::size_t( m_end - m_current.data ) ) ) {
137137
m_end += r;
138138
}
139139
else {
@@ -144,28 +144,33 @@ namespace tao
144144
}
145145

146146
template< rewind_mode M >
147-
internal::marker< internal::iterator, M > mark() noexcept
147+
internal::marker< iterator_t, M > mark() noexcept
148+
{
149+
return internal::marker< iterator_t, M >( m_current );
150+
}
151+
152+
TAOCPP_JSON_PEGTL_NAMESPACE::position position( const iterator_t& it ) const noexcept
148153
{
149-
return internal::marker< internal::iterator, M >( m_data );
154+
return TAOCPP_JSON_PEGTL_NAMESPACE::position( it, m_source );
150155
}
151156

152157
TAOCPP_JSON_PEGTL_NAMESPACE::position position() const noexcept
153158
{
154-
return TAOCPP_JSON_PEGTL_NAMESPACE::position( m_data, m_source );
159+
return position( m_current );
155160
}
156161

157-
const internal::iterator& iterator() const noexcept
162+
const iterator_t& iterator() const noexcept
158163
{
159-
return m_data;
164+
return m_current;
160165
}
161166

162167
private:
163168
Reader m_reader;
164169
std::size_t m_maximum;
165170
std::unique_ptr< char[] > m_buffer;
166-
internal::iterator m_data;
171+
iterator_t m_current;
167172
const char* m_end;
168-
const char* const m_source;
173+
const Source m_source;
169174
};
170175

171176
} // namespace TAOCPP_JSON_PEGTL_NAMESPACE

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

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,6 @@ namespace tao
4444
}
4545
};
4646

47-
void raw_adjust( const char*& i, const std::size_t s ) noexcept
48-
{
49-
i -= s;
50-
}
51-
52-
void raw_adjust( iterator& i, const std::size_t s ) noexcept
53-
{
54-
i.byte -= s;
55-
i.byte_in_line -= s;
56-
i.data -= s;
57-
}
58-
5947
template< typename Tag >
6048
struct raw_string_state_apply< true, false, Tag >
6149
{
@@ -66,9 +54,7 @@ namespace tao
6654
typename... States >
6755
static void success( const State& s, const Input& in, States&&... st )
6856
{
69-
auto dend = in.iterator();
70-
raw_adjust( dend, s.marker_size );
71-
Control< Tag >::template apply< Action >( s.iter, dend, in, st... );
57+
Control< Tag >::template apply< Action >( s.iter, in, st... );
7258
}
7359
};
7460

@@ -100,11 +86,12 @@ namespace tao
10086
template< typename... > class Control,
10187
typename Input,
10288
typename... States >
103-
void success( const Input& in, States&&... st ) const
89+
void success( Input& in, States&&... st ) const
10490
{
10591
constexpr bool use_action = ( A == apply_mode::ACTION ) && ( !is_nothing< Action, Tag >::value );
10692
constexpr bool use_apply0 = use_action && has_apply0< Action< Tag >, type_list< States... > >::value;
10793
raw_string_state_apply< use_action, use_apply0, Tag >::template success< Action, Control >( *this, in, st... );
94+
in.bump_in_this_line( marker_size );
10895
}
10996

11097
raw_string_state( const raw_string_state& ) = delete;
@@ -154,7 +141,7 @@ namespace tao
154141
};
155142

156143
template< char Marker, char Close >
157-
struct raw_string_close
144+
struct at_raw_string_close
158145
{
159146
using analyze_t = analysis::generic< analysis::rule_type::ANY >;
160147

@@ -180,13 +167,12 @@ namespace tao
180167
return false;
181168
}
182169
}
183-
in.bump( ls.marker_size );
184170
return true;
185171
}
186172
};
187173

188174
template< char Marker, char Close >
189-
struct skip_control< raw_string_close< Marker, Close > > : std::true_type
175+
struct skip_control< at_raw_string_close< Marker, Close > > : std::true_type
190176
{
191177
};
192178

@@ -250,13 +236,13 @@ namespace tao
250236
struct raw_string
251237
: internal::raw_string_switch_state< internal::raw_string_tag< Open, Marker, Close >,
252238
internal::raw_string_open< Open, Marker >,
253-
internal::must< internal::until< internal::raw_string_close< Marker, Close > > > >
239+
internal::must< internal::until< internal::at_raw_string_close< Marker, Close > > > >
254240
{
255241
// This is used to bind an action to the content.
256242
using content = internal::raw_string_tag< Open, Marker, Close >;
257243

258244
// This is used for error-reporting when a raw string is not closed properly.
259-
using close = internal::until< internal::raw_string_close< Marker, Close > >;
245+
using close = internal::until< internal::at_raw_string_close< Marker, Close > >;
260246
};
261247

262248
} // namespace TAOCPP_JSON_PEGTL_NAMESPACE

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ namespace tao
2323
namespace TAOCPP_JSON_PEGTL_NAMESPACE
2424
{
2525
#if defined( _POSIX_MAPPED_FILES )
26-
template< typename Eol = lf_crlf_eol, tracking_mode P = tracking_mode::IMMEDIATE >
27-
using file_input = mmap_input< Eol, P >;
26+
template< tracking_mode P = tracking_mode::IMMEDIATE, typename Eol = lf_crlf_eol >
27+
using file_input = mmap_input< P, Eol >;
2828
#else
29-
template< typename Eol = lf_crlf_eol, tracking_mode P = tracking_mode::IMMEDIATE >
30-
using file_input = read_input< Eol, P >;
29+
template< tracking_mode P = tracking_mode::IMMEDIATE, typename Eol = lf_crlf_eol >
30+
using file_input = read_input< P, Eol >;
3131
#endif
3232

3333
} // namespace TAOCPP_JSON_PEGTL_NAMESPACE

0 commit comments

Comments
 (0)