1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/// Macro to check if the sequence is infinite. If it is, it will return an
/// error. The check fails if the parser does not consume any input.
///
/// # Examples
///
/// Note that the macro will return an error if the parser does not consume any
/// input. But it will not return an end of file error, even if the parser is
/// at the end of the input. In order to check for end of file, the parser
/// must do actual progress.
///
/// ```rust
/// # use kamo::{
/// # infinite_loop_check,
/// # Position,
/// # parser::{
/// # prelude::*, SequenceError, code, Input, Span
/// # }
/// # };
/// fn parser<'a>(input: Input<'a>) -> ParseResult<'a, usize> {
/// let mut acc = 0;
/// let mut cursor = input;
/// let mut element = ascii::alpha0;
///
/// while let Ok((_, next)) = element.parse(cursor) {
/// infinite_loop_check!(cursor, next);
/// acc += 1;
/// cursor = next;
/// }
/// Ok((acc, cursor))
/// }
///
/// assert_eq!(parser(Input::new("abc1")), Err(ParseError::new(
/// Position::new(3, 1, 4),
/// code::ERR_INFINITE,
/// SequenceError::Infinite
/// )));
/// assert_eq!(parser(Input::new("abc")), Err(ParseError::new(
/// Position::new(3, 1, 4),
/// code::ERR_INFINITE,
/// SequenceError::Infinite
/// )));
/// assert_eq!(parser(Input::new("")), Err(ParseError::new(
/// Position::new(0, 1, 1),
/// code::ERR_INFINITE,
/// SequenceError::Infinite
/// )));
/// ```