aboutsummaryrefslogtreecommitdiff
path: root/MoonParser/pegtl/memory_input.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'MoonParser/pegtl/memory_input.hpp')
-rw-r--r--MoonParser/pegtl/memory_input.hpp285
1 files changed, 0 insertions, 285 deletions
diff --git a/MoonParser/pegtl/memory_input.hpp b/MoonParser/pegtl/memory_input.hpp
deleted file mode 100644
index 2d7fa42..0000000
--- a/MoonParser/pegtl/memory_input.hpp
+++ /dev/null
@@ -1,285 +0,0 @@
1// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey
2// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
3
4#ifndef TAOCPP_PEGTL_INCLUDE_MEMORY_INPUT_HPP
5#define TAOCPP_PEGTL_INCLUDE_MEMORY_INPUT_HPP
6
7#include <cstddef>
8#include <cstring>
9#include <string>
10#include <type_traits>
11#include <utility>
12
13#include "config.hpp"
14#include "eol.hpp"
15#include "position.hpp"
16#include "tracking_mode.hpp"
17
18#include "internal/action_input.hpp"
19#include "internal/bump_impl.hpp"
20#include "internal/iterator.hpp"
21#include "internal/marker.hpp"
22
23namespace tao
24{
25 namespace TAOCPP_PEGTL_NAMESPACE
26 {
27 namespace internal
28 {
29 template< tracking_mode, typename Eol, typename Source >
30 class memory_input_base;
31
32 template< typename Eol, typename Source >
33 class memory_input_base< tracking_mode::IMMEDIATE, Eol, Source >
34 {
35 public:
36 using iterator_t = internal::iterator;
37
38 template< typename T >
39 memory_input_base( const iterator_t& in_begin, const char* in_end, T&& in_source ) noexcept( std::is_nothrow_constructible< Source, T&& >::value )
40 : m_current( in_begin ),
41 m_end( in_end ),
42 m_source( std::forward< T >( in_source ) )
43 {
44 }
45
46 template< typename T >
47 memory_input_base( const char* in_begin, const char* in_end, T&& in_source ) noexcept( std::is_nothrow_constructible< Source, T&& >::value )
48 : m_current( in_begin ),
49 m_end( in_end ),
50 m_source( std::forward< T >( in_source ) )
51 {
52 }
53
54 memory_input_base( const memory_input_base& ) = delete;
55 memory_input_base operator=( const memory_input_base& ) = delete;
56
57 const char* current() const noexcept
58 {
59 return m_current.data;
60 }
61
62 const char* end( const std::size_t = 0 ) const noexcept
63 {
64 return m_end;
65 }
66
67 std::size_t byte() const noexcept
68 {
69 return m_current.byte;
70 }
71
72 std::size_t line() const noexcept
73 {
74 return m_current.line;
75 }
76
77 std::size_t byte_in_line() const noexcept
78 {
79 return m_current.byte_in_line;
80 }
81
82 void bump( const std::size_t in_count = 1 ) noexcept
83 {
84 internal::bump( m_current, in_count, Eol::ch );
85 }
86
87 void bump_in_this_line( const std::size_t in_count = 1 ) noexcept
88 {
89 internal::bump_in_this_line( m_current, in_count );
90 }
91
92 void bump_to_next_line( const std::size_t in_count = 1 ) noexcept
93 {
94 internal::bump_to_next_line( m_current, in_count );
95 }
96
97 TAOCPP_PEGTL_NAMESPACE::position position( const iterator_t& it ) const
98 {
99 return TAOCPP_PEGTL_NAMESPACE::position( it, m_source );
100 }
101
102 protected:
103 iterator_t m_current;
104 const char* const m_end;
105 const Source m_source;
106 };
107
108 template< typename Eol, typename Source >
109 class memory_input_base< tracking_mode::LAZY, Eol, Source >
110 {
111 public:
112 using iterator_t = const char*;
113
114 template< typename T >
115 memory_input_base( const internal::iterator& in_begin, const char* in_end, T&& in_source ) noexcept( std::is_nothrow_constructible< Source, T&& >::value )
116 : m_begin( in_begin ),
117 m_current( in_begin.data ),
118 m_end( in_end ),
119 m_source( std::forward< T >( in_source ) )
120 {
121 }
122
123 template< typename T >
124 memory_input_base( const char* in_begin, const char* in_end, T&& in_source ) noexcept( std::is_nothrow_constructible< Source, T&& >::value )
125 : m_begin( in_begin ),
126 m_current( in_begin ),
127 m_end( in_end ),
128 m_source( std::forward< T >( in_source ) )
129 {
130 }
131
132 memory_input_base( const memory_input_base& ) = delete;
133 memory_input_base operator=( const memory_input_base& ) = delete;
134
135 const char* current() const noexcept
136 {
137 return m_current;
138 }
139
140 const char* end( const std::size_t = 0 ) const noexcept
141 {
142 return m_end;
143 }
144
145 std::size_t byte() const noexcept
146 {
147 return std::size_t( current() - m_begin.data );
148 }
149
150 void bump( const std::size_t in_count = 1 ) noexcept
151 {
152 m_current += in_count;
153 }
154
155 void bump_in_this_line( const std::size_t in_count = 1 ) noexcept
156 {
157 m_current += in_count;
158 }
159
160 void bump_to_next_line( const std::size_t in_count = 1 ) noexcept
161 {
162 m_current += in_count;
163 }
164
165 TAOCPP_PEGTL_NAMESPACE::position position( const iterator_t it ) const
166 {
167 internal::iterator c( m_begin );
168 internal::bump( c, std::size_t( it - m_begin.data ), Eol::ch );
169 return TAOCPP_PEGTL_NAMESPACE::position( c, m_source );
170 }
171
172 protected:
173 const internal::iterator m_begin;
174 iterator_t m_current;
175 const char* const m_end;
176 const Source m_source;
177 };
178
179 } // namespace internal
180
181 template< tracking_mode P = tracking_mode::IMMEDIATE, typename Eol = eol::lf_crlf, typename Source = std::string >
182 class memory_input
183 : public internal::memory_input_base< P, Eol, Source >
184 {
185 public:
186 static constexpr tracking_mode tracking_mode_v = P;
187
188 using eol_t = Eol;
189 using source_t = Source;
190
191 using typename internal::memory_input_base< P, Eol, Source >::iterator_t;
192
193 using action_t = internal::action_input< memory_input >;
194
195 using internal::memory_input_base< P, Eol, Source >::memory_input_base;
196
197 template< typename T >
198 memory_input( const char* in_begin, const std::size_t in_size, T&& in_source ) noexcept( std::is_nothrow_constructible< Source, T&& >::value )
199 : memory_input( in_begin, in_begin + in_size, std::forward< T >( in_source ) )
200 {
201 }
202
203 template< typename T >
204 memory_input( const std::string& in_string, T&& in_source ) noexcept( std::is_nothrow_constructible< Source, T&& >::value )
205 : memory_input( in_string.data(), in_string.size(), std::forward< T >( in_source ) )
206 {
207 }
208
209 template< typename T >
210 memory_input( const char* in_begin, T&& in_source ) noexcept( std::is_nothrow_constructible< Source, T&& >::value )
211 : memory_input( in_begin, std::strlen( in_begin ), std::forward< T >( in_source ) )
212 {
213 }
214
215 template< typename T >
216 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_byte_in_line ) noexcept( std::is_nothrow_constructible< Source, T&& >::value )
217 : memory_input( { in_begin, in_byte, in_line, in_byte_in_line }, in_end, std::forward< T >( in_source ) )
218 {
219 }
220
221 memory_input( const memory_input& ) = delete;
222 memory_input operator=( const memory_input& ) = delete;
223
224 const Source& source() const noexcept
225 {
226 return this->m_source;
227 }
228
229 bool empty() const noexcept
230 {
231 return this->current() == this->end();
232 }
233
234 std::size_t size( const std::size_t = 0 ) const noexcept
235 {
236 return std::size_t( this->end() - this->current() );
237 }
238
239 char peek_char( const std::size_t offset = 0 ) const noexcept
240 {
241 return this->current()[ offset ];
242 }
243
244 unsigned char peek_byte( const std::size_t offset = 0 ) const noexcept
245 {
246 return static_cast< unsigned char >( peek_char( offset ) );
247 }
248
249 iterator_t& iterator() noexcept
250 {
251 return this->m_current;
252 }
253
254 const iterator_t& iterator() const noexcept
255 {
256 return this->m_current;
257 }
258
259 using internal::memory_input_base< P, Eol, Source >::position;
260
261 TAOCPP_PEGTL_NAMESPACE::position position() const
262 {
263 return position( iterator() );
264 }
265
266 void discard() const noexcept
267 {
268 }
269
270 void require( const std::size_t ) const noexcept
271 {
272 }
273
274 template< rewind_mode M >
275 internal::marker< iterator_t, M > mark() noexcept
276 {
277 return internal::marker< iterator_t, M >( iterator() );
278 }
279 };
280
281 } // namespace TAOCPP_PEGTL_NAMESPACE
282
283} // namespace tao
284
285#endif