devela/text/parse/scanner/define.rs
1// devela::text::parse::scanner
2//
3//! Defines [`TextScanner`].
4//
5
6#![allow(unused, missing_docs)]
7
8#[cfg(doc)]
9use crate::TextParseErrorKind;
10use crate::{_impl_init, Slice, Str, is, unwrap, whilst};
11use crate::{InvalidUtf8, TextCursor, TextIndex, TextParseError, TextRange, TextUnit};
12
13#[must_use]
14#[doc = crate::_tags!(text parser)]
15/// A byte scanner over source text.
16#[doc = crate::_doc_meta!{location("text/parse")}]
17///
18/// `TextScanner` provides incremental, allocation-free traversal over a borrowed
19/// text source, exposing byte-oriented operations suitable for building parsers.
20///
21/// # Methods
22///
23/// - Construction and views:
24/// - [new](#method.new).
25/// - [from_bytes](#method.from_bytes).
26/// - [slice](#method.slice).
27/// - [slice_str](#method.slice_str)
28/// ([*unchecked*](#method.slice_str_unchecked)<sup title="unsafe method">⚠</sup>).
29/// - [rest](#method.rest).
30/// - [take_rest](#method.take_rest).
31///
32/// - Cursor state and range construction:
33/// - [pos](#method.pos).
34/// - [mark](#method.mark).
35/// - [remaining_len](#method.remaining_len).
36/// - [advance](#method.advance).
37/// - [is_eof](#method.is_eof).
38/// - [range_from](#method.range_from).
39///
40/// - Predicate-driven scanning adapters:
41/// - [eat_if](#method.eat_if).
42/// - [skip_while](#method.skip_while).
43/// - [take_while](#method.take_while).
44///
45/// - Byte inspection and exact consumption:
46/// - [peek_byte](#method.peek_byte) ([*at*](#method.peek_byte_at)).
47/// - [starts_with](#method.starts_with).
48/// - [next_byte](#method.next_byte).
49/// - [skip_byte](#method.skip_byte).
50/// - [eat_byte](#method.eat_byte) ([*s*](#method.eat_bytes)).
51/// - [expect_byte](#method.expect_byte) ([*s*](#method.expect_bytes)).
52///
53/// - Byte-delimited range scanning:
54/// - [take_until_byte](#method.take_until_byte) ([*s*](#method.take_until_bytes)).
55/// - [take_until_any](#method.take_until_any)
56/// ([*2*](#method.take_until_any2), [*3*](#method.take_until_any3)).
57///
58/// - Quoted string scanning and decoding:
59/// - [take_quoted_basic](#method.take_quoted_basic)
60/// ([*or_rest*](#method.take_quoted_basic_or_rest)).
61/// - [take_quoted_literal](#method.take_quoted_literal).
62/// - [decode_quoted_basic_into](#method.decode_quoted_basic_into).
63/// - [decode_quoted_basic_str_into](#method.decode_quoted_basic_str_into).
64///
65/// - ASCII scanning and range-taking operations:
66/// - [skip_ascii_ws](#method.skip_ascii_ws).
67/// - [skip_ascii_hws](#method.skip_ascii_hws).
68/// - [take_ascii_ident](#method.take_ascii_ident) ([*tail*](#method.take_ascii_ident_tail)).
69/// - [trim_ascii_ws](#method.trim_ascii_ws).
70/// - [trim_ascii_hws](#method.trim_ascii_hws).
71///
72/// - `AsciiSet` scanning:
73/// - [eat_ascii_set](#method.eat_ascii_set).
74/// - [skip_ascii_set](#method.skip_ascii_set).
75/// - [skip_until_ascii_set](#method.skip_until_ascii_set).
76/// - [take_ascii_set](#method.take_ascii_set).
77/// - [take_ascii_run](#method.take_ascii_run).
78/// - [take_until_ascii_set](#method.take_until_ascii_set).
79///
80/// - ASCII numeric parsing:
81/// - [take_ascii_u64](#method.take_ascii_u64).
82/// - [expect_ascii_u64](#method.expect_ascii_u64).
83///
84/// - EOL and line-oriented scanning:
85/// - [eat_eol](#method.eat_eol).
86/// - [take_until_eol](#method.take_until_eol).
87/// - [next_line](#method.next_line) ([*trimmed*](#method.next_line_trimmed),
88/// [*trimmed_before*](#method.next_line_trimmed_before)).
89///
90/// - UTF-8 Unicode scalar scanning:
91/// - [peek_char](#method.peek_char) ([*u*](#method.peek_charu)).
92/// - [next_char](#method.next_char) ([*u*](#method.next_charu)).
93/// - [take_char](#method.take_char).
94/// - [eat_char](#method.eat_char) ([*u*](#method.eat_charu)).
95/// - [take_char_if](#method.take_char_if) ([*u*](#method.take_charu_if)).
96/// - [skip_char_while](#method.skip_char_while) ([*u*](#method.skip_charu_while)).
97/// - [take_char_while](#method.take_char_while) ([*u*](#method.take_charu_while)).
98#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
99pub struct TextScanner<'a> {
100 pub(crate) bytes: &'a [u8],
101 pub(crate) cursor: TextCursor,
102}
103_impl_init![Self::new("") => TextScanner<'_>];