[−][src]Crate nom5_locate
nom_locate, a special input type to locate tokens
The source code is available on Github
Features
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.
#[macro_use] extern crate nom; #[macro_use] 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() {}
Macros
impl_compare | Implement nom::Compare for a specific fragment type. |
impl_extend_into | Implement nom::ExtendInto for a specific fragment type. |
impl_hex_display | |
impl_input_iter | Implement nom::InputIter for a specific fragment type |
impl_slice_range | Implement nom::Slice for a specific fragment type and range type. |
impl_slice_ranges | Implement nom::Slice for a specific fragment type and for these types of range: |
position | Capture the position of the current fragment |
Structs
LocatedSpan | A LocatedSpan is a set of meta information about the location of a token. |