daily pastebin goal
35%
SHARE
TWEET

Untitled

a guest Feb 12th, 2019 41 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use std::collections::BTreeMap;
  2.  
  3. #[derive(Debug, PartialEq)]
  4. pub struct Service {
  5.     pub name: String,
  6.     pub fields: BTreeMap<String, String>,
  7. }
  8.  
  9. named!(parse_service<&str, Service>, do_parse!(
  10.         tag!("service") >>
  11.         take_while1!(char::is_whitespace) >>
  12.         name: take_while1!(char::is_alphanumeric) >>
  13.         // FIXME parse fields
  14.         take_while!(char::is_whitespace) >>
  15.         char!('{') >>
  16.         take_while!(char::is_whitespace) >>
  17.         // fields: parse_fields() >>
  18.         //take_while!(char::is_whitespace) >>
  19.         char!('}') >>
  20.         (Service { name: name.to_string(), fields: BTreeMap::new() })
  21. ));
  22.  
  23. #[test]
  24. fn test_parse_service() {
  25.     let contents = [
  26.         "service Pinger{}",
  27.         "service Pinger {}",
  28.         "service Pinger{ }",
  29.         "service Pinger { }",
  30.     ];
  31.     for content in contents.iter() {
  32.         assert_eq!(
  33.             parse_service(content),
  34.             Ok(("", Service {
  35.                 name: "Pinger".to_string(),
  36.                 fields: BTreeMap::new(),
  37.             }))
  38.         );
  39.     }
  40. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top