Created
July 30, 2018 15:32
-
-
Save Slabity/dab2cb5f311de80cdf5ef5973be3fe6e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #[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