Function nom_locate::position

source ·
pub fn position<T, E>(s: T) -> IResult<T, T, E>where
    E: ParseError<T>,
    T: InputIter + InputTake,
Expand description

Capture the position of the current fragment

Examples found in repository?
examples/position.rs (line 18)
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
fn parse_foobar(s: Span) -> IResult<Span, Token> {
    let (s, _) = take_until("foo")(s)?;
    let (s, pos) = position(s)?;
    let (s, foo) = tag("foo")(s)?;
    let (s, bar) = tag("bar")(s)?;

    Ok((
        s,
        Token {
            position: pos,
            _foo: foo.fragment(),
            _bar: bar.fragment(),
        },
    ))
}