Skip to content

Instantly share code, notes, and snippets.

@Slabity
Created July 30, 2018 15:32
Show Gist options
  • Select an option

  • Save Slabity/dab2cb5f311de80cdf5ef5973be3fe6e to your computer and use it in GitHub Desktop.

Select an option

Save Slabity/dab2cb5f311de80cdf5ef5973be3fe6e to your computer and use it in GitHub Desktop.
#[macro_use]
extern crate nom;
use nom::*;
named! {
parse_str<&str, &str>,
delimited!(
char!('"'),
escaped!(
call!(anychar),
'\\',
one_of!("\"\\")
),
char!('"')
)
}
fn main() {
let input = format!("\"This is a string with a quote: {} and a backslash: {} and then we end\"", "\\\"", "\\\\");
println!("Input: {}", input);
let parsed = parse_str(&input);
match parsed {
Ok((n, p)) => {
println!("{}", p);
println!("{}", n);
},
Err(e) => {
println!("{:#?}", e);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment