Go to the documentation of this file.
4 #ifndef LEXY_INPUT_LOCATION_HPP_INCLUDED
5 #define LEXY_INPUT_LOCATION_HPP_INCLUDED
16 template <
typename Input>
42 template <
typename Reader>
48 template <
typename Reader>
59 template <
typename Reader>
65 template <
typename Reader>
74 template <std::
size_t LineW
idth = 16>
78 template <
typename Reader>
98 template <
typename Reader>
101 static_assert(std::is_same_v<typename Reader::encoding, lexy::byte_encoding>);
111 template <
typename Input>
121 template <
typename Input,
typename Counting = _default_location_counting<Input>>
158 return !(lhs == rhs);
189 template <
typename C,
typename I>
197 template <
typename Counting,
typename Input>
203 auto reader = input.reader();
204 reader.set_position(anchor._line_begin);
207 auto line_nr = anchor._line_nr;
208 auto column_begin = line_begin;
225 LEXY_ASSERT(
false,
"invalid position + anchor combination");
227 else if (counting.try_match_newline(reader))
230 auto newline_end = reader.position();
236 line_begin = newline_end;
238 column_begin = line_begin;
242 counting.match_column(reader);
245 auto column_end = reader.position();
251 column_begin = column_end;
255 return {line_begin, line_nr, column_begin, column_nr};
258 template <
typename Counting,
typename Input>
264 template <
typename Input>
269 return get_input_location<_default_location_counting<Input>>(input,
position, anchor);
271 template <
typename Input>
275 return get_input_location<_default_location_counting<Input>>(input,
position,
283 template <
typename Counting,
typename Input>
287 auto reader = input.reader();
288 reader.set_position(line_begin);
290 auto line_end = reader.position();
291 for (Counting counting;
292 reader.peek() != decltype(reader)::
encoding::eof() && !counting.try_match_newline(reader);
293 line_end = reader.position())
295 counting.match_column(reader);
297 auto newline_end = reader.position();
304 return result_t{{line_begin, line_end}, {line_end, newline_end}};
308 template <
typename Encoding,
typename Iterator>
311 auto is_cp_continuation = [](
auto c) {
312 if constexpr (std::is_same_v<Encoding,
314 || std::is_same_v<Encoding, lexy::utf8_char_encoding>)
315 return (c & 0b1100
'0000) == (0b10 << 6);
316 else if constexpr (std::is_same_v<Encoding, lexy::utf16_encoding>)
317 return 0xDC00 <= c && c <= 0xDFFF;
320 // This encoding doesn't have continuation code units.
322 return std::false_type{};
326 while (cur !=
end && is_cp_continuation(*cur))
334 template <
typename Input>
352 template <
typename Input>
369 end = _detail::find_cp_boundary<encoding>(
end,
newline.end());
394 template <
typename Input,
typename Counting>
403 = _detail::get_input_line<Counting>(input, begin_location.anchor()._line_begin);
406 auto begin = begin_location.position();
429 result.truncated_multiline =
true;
437 template <
typename Input,
typename Counting>
443 auto [line,
newline] = _detail::get_input_line<Counting>(input, location.
anchor()._line_begin);
454 result.truncated_multiline =
true;
462 #endif // LEXY_INPUT_LOCATION_HPP_INCLUDED
constexpr auto size(const C &c) -> decltype(c.size())
constexpr auto position
Produces an iterator to the current reader position without parsing anything.
constexpr bool try_match_newline(Reader &reader)
constexpr void match_column(Reader &reader)
constexpr void match_column(Reader &reader)
constexpr bool try_match_newline(Reader &reader)
constexpr void _get_input_line_annotation(input_line_annotation< Input > &result, lexy::lexeme_for< Input > line, lexy::lexeme_for< Input > newline, typename lexy::input_reader< Input >::iterator begin, typename lexy::input_reader< Input >::iterator end)
constexpr bool try_match_newline(Reader &reader)
constexpr auto get_input_line(const Input &input, typename lexy::input_reader< Input >::iterator line_begin)
constexpr iterator begin() const noexcept
constexpr auto code_point
Matches a single unicode code point in the current unicode encoding.
constexpr auto get_input_location(const Input &input, typename lexy::input_reader< Input >::iterator position, input_location_anchor< Input > anchor) -> input_location< Input, Counting >
The location for a position in the input; search starts at the anchor.
#define LEXY_PRECONDITION(Expr)
constexpr auto end(const C &c) -> decltype(c.end())
constexpr Iterator next_clamped(Iterator iter, std::size_t n, Sentinel end)
constexpr auto get_input_line_annotation(const Input &input, const input_location< Input, Counting > &begin_location, typename lexy::input_reader< Input >::iterator end) -> input_line_annotation< Input >
constexpr LEXY_FORCE_INLINE auto try_match_token(TokenRule, Reader &reader)
An encoding where the input is just raw bytes, not characters.
constexpr void match_column(Reader &reader)
Counts bytes for columns, lines end after LineWidth bytes.
An encoding where the input is assumed to be valid UTF-8.
constexpr std::size_t range_size(Iterator begin, Sentinel end)
constexpr iterator end() const noexcept
constexpr auto begin(const C &c) -> decltype(c.begin())
Counts code points for columns, newlines for lines.
std::conditional_t< std::is_same_v< typename lexy::input_reader< Input >::encoding, lexy::byte_encoding >, byte_location_counting<>, code_unit_location_counting > _default_location_counting
constexpr Iterator min_range_end(Iterator begin, Iterator end_a, Iterator end_b)
constexpr Iterator find_cp_boundary(Iterator cur, Iterator end)
constexpr auto eof
Matches EOF.
#define LEXY_ASSERT(Expr, Msg)
decltype(LEXY_DECLVAL(Input).reader()) input_reader
Counts code units for columns, newlines for lines.