From 33899ae66eab7af8ce2f777764bee17d61820532 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Mon, 29 Jan 2024 19:37:18 -0800 Subject: [PATCH] Fix parsing --- src/primitives.rs | 1 - src/sequence.rs | 4 ---- src/test/sexp.rs | 9 +++++---- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/primitives.rs b/src/primitives.rs index 9011d8b..a6f74d8 100644 --- a/src/primitives.rs +++ b/src/primitives.rs @@ -49,7 +49,6 @@ pub fn identifier(input: &str) -> ParseResult<&str, String, ()> { } pub fn whitespace(input: &str) -> ParseResult<&str, char, ()> { - println!("whitespace: `{input}`"); match input.chars().next() { Some(ch) if ch.is_whitespace() => Ok((ch, &input[1..])), _ => Err(((), input)), diff --git a/src/sequence.rs b/src/sequence.rs index 791d756..7fa4aac 100644 --- a/src/sequence.rs +++ b/src/sequence.rs @@ -12,13 +12,9 @@ pub fn surrounded_by( surrounding: impl Parser, ) -> impl Parser { move |input| { - println!("surrounded_by"); let (_result1, rest1) = surrounding.parse(input)?; - println!("A"); let (result2, rest2) = main.parse(rest1)?; - println!("B"); let (_result3, rest3) = surrounding.parse(rest2)?; - println!("C"); Ok((result2, rest3)) } } diff --git a/src/test/sexp.rs b/src/test/sexp.rs index 234a463..52fae60 100644 --- a/src/test/sexp.rs +++ b/src/test/sexp.rs @@ -48,7 +48,6 @@ fn test_parse_atom() { } fn parse_expr(input: &str) -> ParseResult<&str, Expr, ()> { - println!("parse_expr: {input}"); choice((parse_list, parse_atom.map(Expr::Atom))).parse(input) } @@ -61,15 +60,17 @@ fn parse_list(input: &str) -> ParseResult<&str, Expr, ()> { ) .then_ignore(literal_char(')')) .map(Expr::List) - .surrounded_by(repeated(whitespace)) .parse(input) } #[test] fn test_parse_list() { - let output = parse_list.parse("\n(1 2 (1 2) 9999 3)").unwrap(); + let output = parse_list.parse("(1 2 (1 2) 9999 3)").unwrap(); assert_eq!(output.1, ""); +} +fn parse_sexp(input: &str) -> ParseResult<&str, Expr, ()> { + parse_list.surrounded_by(repeated(whitespace)).parse(input) } #[test] @@ -91,6 +92,6 @@ fn test_parse_sexp() { )"# .trim(); - let output = parse_expr(complex_input).unwrap(); + let output = parse_sexp(complex_input).unwrap(); assert_eq!(output.1, ""); }