[][src]Crate nom5_locate

nom_locate, a special input type to locate tokens

The source code is available on Github


This crate exposes two cargo feature flags, avx-accel and simd-accel. These correspond to the features exposed by bytecount. Compile with SSE support (available on most modern x86_64 processors) using simd-accel, or with AVX support (which likely requires compiling for the native target CPU) with both.

How to use it

The explanations are given in the README of the Github repository. You may also consult the FAQ.

extern crate nom;
extern crate nom_locate;

use nom_locate::LocatedSpan;
type Span<'a> = LocatedSpan<&'a str>;

struct Token<'a> {
    pub position: Span<'a>,
    pub foo: String,
    pub bar: String,

named!(parse_foobar( Span ) -> Token, do_parse!(
    take_until!("foo") >>
    position: position!() >>
    foo: tag!("foo") >>
    bar: tag!("bar") >>
    (Token {
        position: position,
        foo: foo.to_string(),
        bar: bar.to_string()

fn main () {
    let input = Span::new("Lorem ipsum \n foobar");
    let output = parse_foobar(input);
    let position = output.unwrap().1.position;
    assert_eq!(position, Span {
        offset: 14,
        line: 2,
        fragment: ""
    assert_eq!(position.get_column(), 2);
fn main() {}



Implement nom::Compare for a specific fragment type.


Implement nom::ExtendInto for a specific fragment type.


Implement nom::InputIter for a specific fragment type


Implement nom::Slice for a specific fragment type and range type.


Implement nom::Slice for a specific fragment type and for these types of range:


Capture the position of the current fragment



A LocatedSpan is a set of meta information about the location of a token.