aboutsummaryrefslogtreecommitdiff
path: root/MoonParser/pegtl/buffer_input.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'MoonParser/pegtl/buffer_input.hpp')
-rw-r--r--MoonParser/pegtl/buffer_input.hpp179
1 files changed, 0 insertions, 179 deletions
diff --git a/MoonParser/pegtl/buffer_input.hpp b/MoonParser/pegtl/buffer_input.hpp
deleted file mode 100644
index b65e365..0000000
--- a/MoonParser/pegtl/buffer_input.hpp
+++ /dev/null
@@ -1,179 +0,0 @@
1// Copyright (c) 2016-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_BUFFER_INPUT_HPP
5#define TAOCPP_PEGTL_INCLUDE_BUFFER_INPUT_HPP
6
7#include <cstddef>
8#include <cstring>
9#include <memory>
10#include <string>
11
12#include "config.hpp"
13#include "eol.hpp"
14#include "memory_input.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 template< typename Reader, typename Eol = eol::lf_crlf, typename Source = std::string >
28 class buffer_input
29 {
30 public:
31 static constexpr tracking_mode tracking_mode_v = tracking_mode::IMMEDIATE;
32 using reader_t = Reader;
33
34 using eol_t = Eol;
35 using source_t = Source;
36
37 using iterator_t = internal::iterator;
38
39 using action_t = internal::action_input< buffer_input >;
40
41 template< typename T, typename... As >
42 buffer_input( T&& in_source, const std::size_t maximum, As&&... as )
43 : m_reader( std::forward< As >( as )... ),
44 m_maximum( maximum ),
45 m_buffer( new char[ maximum ] ),
46 m_current( m_buffer.get() ),
47 m_end( m_buffer.get() ),
48 m_source( std::forward< T >( in_source ) )
49 {
50 }
51
52 buffer_input( const buffer_input& ) = delete;
53 void operator=( const buffer_input& ) = delete;
54
55 bool empty()
56 {
57 require( 1 );
58 return m_current.data == m_end;
59 }
60
61 std::size_t size( const std::size_t amount )
62 {
63 require( amount );
64 return std::size_t( m_end - m_current.data );
65 }
66
67 const char* current() const noexcept
68 {
69 return m_current.data;
70 }
71
72 const char* end( const std::size_t amount )
73 {
74 require( amount );
75 return m_end;
76 }
77
78 std::size_t byte() const noexcept
79 {
80 return m_current.byte;
81 }
82
83 std::size_t line() const noexcept
84 {
85 return m_current.line;
86 }
87
88 std::size_t byte_in_line() const noexcept
89 {
90 return m_current.byte_in_line;
91 }
92
93 const Source& source() const noexcept
94 {
95 return m_source;
96 }
97
98 char peek_char( const std::size_t offset = 0 ) const noexcept
99 {
100 return m_current.data[ offset ];
101 }
102
103 unsigned char peek_byte( const std::size_t offset = 0 ) const noexcept
104 {
105 return static_cast< unsigned char >( peek_char( offset ) );
106 }
107
108 void bump( const std::size_t in_count = 1 ) noexcept
109 {
110 internal::bump( m_current, in_count, Eol::ch );
111 }
112
113 void bump_in_this_line( const std::size_t in_count = 1 ) noexcept
114 {
115 internal::bump_in_this_line( m_current, in_count );
116 }
117
118 void bump_to_next_line( const std::size_t in_count = 1 ) noexcept
119 {
120 internal::bump_to_next_line( m_current, in_count );
121 }
122
123 void discard() noexcept
124 {
125 const auto s = m_end - m_current.data;
126 std::memmove( m_buffer.get(), m_current.data, s );
127 m_current.data = m_buffer.get();
128 m_end = m_buffer.get() + s;
129 }
130
131 void require( const std::size_t amount )
132 {
133 if( m_current.data + amount > m_end ) {
134 if( m_current.data + amount <= m_buffer.get() + m_maximum ) {
135 if( const auto r = m_reader( const_cast< char* >( m_end ), amount - std::size_t( m_end - m_current.data ) ) ) {
136 m_end += r;
137 }
138 else {
139 m_maximum = 0;
140 }
141 }
142 }
143 }
144
145 template< rewind_mode M >
146 internal::marker< iterator_t, M > mark() noexcept
147 {
148 return internal::marker< iterator_t, M >( m_current );
149 }
150
151 TAOCPP_PEGTL_NAMESPACE::position position( const iterator_t& it ) const
152 {
153 return TAOCPP_PEGTL_NAMESPACE::position( it, m_source );
154 }
155
156 TAOCPP_PEGTL_NAMESPACE::position position() const
157 {
158 return position( m_current );
159 }
160
161 const iterator_t& iterator() const noexcept
162 {
163 return m_current;
164 }
165
166 private:
167 Reader m_reader;
168 std::size_t m_maximum;
169 std::unique_ptr< char[] > m_buffer;
170 iterator_t m_current;
171 const char* m_end;
172 const Source m_source;
173 };
174
175 } // namespace TAOCPP_PEGTL_NAMESPACE
176
177} // namespace tao
178
179#endif