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>
45 static_assert(lexy::is_char_encoding<typename Reader::encoding>);
49 template <
typename Reader>
52 static_assert(lexy::is_char_encoding<typename Reader::encoding>);
61 template <
typename Reader>
64 static_assert(lexy::is_char_encoding<typename Reader::encoding>);
68 template <
typename Reader>
71 static_assert(lexy::is_char_encoding<typename Reader::encoding>);
78 template <std::
size_t LineW
idth = 16>
82 template <
typename Reader>
85 static_assert(lexy::is_byte_encoding<typename Reader::encoding>);
103 template <
typename Reader>
106 static_assert(lexy::is_byte_encoding<typename Reader::encoding>);
116 template <
typename Input>
120 if constexpr (lexy::is_byte_encoding<encoding>)
122 else if constexpr (lexy::is_char_encoding<encoding>)
125 static_assert(_detail::error<Input>,
126 "input encoding does not have a default location counting policy");
129 template <
typename Input>
137 template <
typename Input,
typename Counting = _default_location_counting<Input>>
176 return !(lhs == rhs);
208 template <
typename C,
typename I>
216 template <
typename Counting,
typename Input>
222 auto reader = input.reader();
223 reader.reset(anchor._line_begin);
226 auto line_nr = anchor._line_nr;
227 auto column_begin = line_begin;
244 LEXY_ASSERT(
false,
"invalid position + anchor combination");
246 else if (counting.try_match_newline(reader))
249 auto newline_end = reader.current();
252 != newline_end.position())
257 line_begin = newline_end;
259 column_begin = line_begin;
263 counting.match_column(reader);
266 auto column_end = reader.current();
269 != column_end.position())
274 column_begin = column_end;
278 return {line_begin, line_nr, column_begin.position(), column_nr};
281 template <
typename Counting,
typename Input>
287 template <
typename Input>
292 return get_input_location<_default_location_counting<Input>>(input,
position, anchor);
294 template <
typename Input>
298 return get_input_location<_default_location_counting<Input>>(input,
position,
306 template <
typename Counting,
typename Input>
310 auto reader = input.reader();
311 reader.reset(line_begin);
313 auto line_end = reader.position();
314 for (Counting counting;
315 reader.peek() != decltype(reader)::
encoding::eof() && !counting.try_match_newline(reader);
316 line_end = reader.position())
318 counting.match_column(reader);
320 auto newline_end = reader.position();
327 return result_t{{line_begin.position(), line_end}, {line_end, newline_end}};
331 template <
typename Encoding,
typename Iterator>
334 auto is_cp_continuation = [](
auto c) {
335 if constexpr (std::is_same_v<Encoding,
337 || std::is_same_v<Encoding, lexy::utf8_char_encoding>)
338 return (c & 0b1100
'0000) == (0b10 << 6);
339 else if constexpr (std::is_same_v<Encoding, lexy::utf16_encoding>)
340 return 0xDC00 <= c && c <= 0xDFFF;
343 // This encoding doesn't have continuation code units.
345 return std::false_type{};
349 while (cur !=
end && is_cp_continuation(*cur))
357 template <
typename Input>
375 template <
typename Input>
392 end = _detail::find_cp_boundary<encoding>(
end,
newline.end());
417 template <
typename Input,
typename Counting>
426 = _detail::get_input_line<Counting>(input, begin_location.anchor()._line_begin);
429 auto begin = begin_location.position();
452 result.truncated_multiline =
true;
460 template <
typename Input,
typename Counting>
466 auto [line,
newline] = _detail::get_input_line<Counting>(input, location.
anchor()._line_begin);
477 result.truncated_multiline =
true;
485 #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 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())
auto _compute_default_location_counting()
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)
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 auto get_input_line(const Input &input, typename lexy::input_reader< Input >::marker line_begin)
constexpr iterator end() const noexcept
constexpr auto begin(const C &c) -> decltype(c.begin())
decltype(_compute_default_location_counting< Input >()) _default_location_counting
Counts code points for columns, newlines for lines.
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.