From e3957a5dbe49d0ed77ac357405f20595e1848ac3 Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Thu, 20 Jul 2023 00:42:49 -0400 Subject: [PATCH] Allow newlines and whitespace in more sequence locations --- go-sgf/src/tree.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/go-sgf/src/tree.rs b/go-sgf/src/tree.rs index 2840eef..deb050b 100644 --- a/go-sgf/src/tree.rs +++ b/go-sgf/src/tree.rs @@ -131,7 +131,9 @@ fn parse_sequence<'a, E: nom::error::ParseError<&'a str>>( println!("::: parse_sequence: {}", input); let (input, _) = multispace0(input)?; let (input, nodes) = many1(parse_node)(input)?; + let (input, _) = multispace0(input)?; let (input, sub_sequences) = many0(parse_tree)(input)?; + let (input, _) = multispace0(input)?; Ok(( input, @@ -157,6 +159,7 @@ fn parse_property<'a, E: nom::error::ParseError<&'a str>>( let (input, _) = multispace0(input)?; let (input, ident) = alpha1(input)?; let (input, values) = many1(parse_propval)(input)?; + let (input, _) = multispace0(input)?; let values = values .into_iter() @@ -477,4 +480,22 @@ k<. Hard line breaks are all other linebreaks.", .to_owned() ); } + + #[test] + fn it_parses_sgf_with_newline_in_sequence() { + let data = String::from( + "(;FF[4]C[root](;C[a];C[b](;C[c])(;C[d];C[e] +))(;C[f](;C[g];C[h];C[i])(;C[j])))", + ); + parse_tree::>(&data).unwrap(); + } + + #[test] + fn it_parses_sgf_with_newline_between_two_sequence_closings() { + let data = String::from( + "(;FF[4]C[root](;C[a];C[b](;C[c])(;C[d];C[e]) +)(;C[f](;C[g];C[h];C[i])(;C[j])))", + ); + parse_tree::>(&data).unwrap(); + } }