nombine

Build Status Docs Gitter

Converters between combine and nom.

```rust extern crate combine; extern crate nom; extern crate nombine;

use std::collections::HashMap;

use combine::error::ParseError; use combine::parser::char::char; use combine::parser::range; use combine::stream::FullRangeStream; use combine::{Parser, sep_by};

use nombine::{convertfromcombine, fromcombine, fromnom};

fn fromhex(input: &str) -> Result { u8::fromstr_radix(input, 16) }

fn ishexdigit(c: char) -> bool { match c { '0'..='9' | 'a'..='f' | 'A'..='F' => true, _ => false, } }

named!(hex<&str, u8>, mapres!(takewhilemn!(2, 2, ishexdigit), from_hex) );

fn identifier<'a, I>() -> impl Parser where I: FullRangeStream + 'a, // Necessary due to rust-lang/rust#24159 I::Error: ParseError, { range::takewhile1(|c: char| c.isalphabetic()) }

named!(field<&str, (&str, u8)>, map!(convertfromcombine((identifier(), char('='), fromnom(hex)), || 0), move |(name, _, value)| (name, value)) );

fn fields<'a, I>() -> impl Parser> where I: FullRangeStream + 'a, // Necessary due to rust-lang/rust#24159 I::Error: ParseError, { sepby(fromnom(field), char(',')) }

// Parse using nom's interface asserteq!( fromcombine(fields())("fieldA=2F,fieldB=00"), Ok(( "", vec![ ( "fieldA", 47, ), ( "fieldB", 0, ), ].into_iter().collect(), )) );

// Parse using combine's interface asserteq!( fields().easyparse("fieldA=2F,fieldB=00"), Ok(( vec![ ( "fieldA", 47, ), ( "fieldB", 0, ), ].into_iter().collect(), "", )) ); ```