diff --git a/src/parser/sexp.rs b/src/parser/sexp.rs index 25a866a..ea4a5a6 100644 --- a/src/parser/sexp.rs +++ b/src/parser/sexp.rs @@ -124,7 +124,7 @@ fn quoted_atom<'s>(input: &'s str) -> Res<&'s str, Token<'s>> { let (remaining, _) = tag(r#"""#)(input)?; let (remaining, _) = escaped( take_till1(|c| match c { - '\\' | '"' | ')' => true, + '\\' | '"' => true, _ => false, }), '\\', @@ -215,4 +215,40 @@ mod tests { r#""foo""# ) } + + #[test] + fn quoted_containing_paren() { + let input = r#" (foo "b(a)r" baz ) "#; + let (remaining, parsed) = sexp_with_padding(input).expect("Parse the input"); + assert_eq!(remaining, ""); + assert!(match parsed { + Token::List(_) => true, + _ => false, + }); + let children = match parsed { + Token::List(children) => children, + _ => panic!("Should be a list."), + }; + assert_eq!( + match children.first() { + Some(Token::Atom(body)) => *body, + _ => panic!("First child should be an atom."), + }, + r#"foo"# + ); + assert_eq!( + match children.iter().nth(1) { + Some(Token::Atom(body)) => *body, + _ => panic!("Second child should be an atom."), + }, + r#""b(a)r""# + ); + assert_eq!( + match children.iter().nth(2) { + Some(Token::Atom(body)) => *body, + _ => panic!("Third child should be an atom."), + }, + r#"baz"# + ); + } }