From 05c9ada7c6fd6951a4dfadbb9d62d92c9f3f54f5 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Sun, 28 Jan 2024 12:03:30 -0800 Subject: [PATCH] Work --- src/primitives.rs | 4 ++-- src/test/sexp.rs | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/primitives.rs b/src/primitives.rs index 62db1cd..45196c8 100644 --- a/src/primitives.rs +++ b/src/primitives.rs @@ -27,13 +27,13 @@ pub fn one_of<'a>(items: &'static str) -> impl Parser<&'a str, char, ()> { } /// Parses a standard identifier in a programming language -pub fn identifier(input: &str) -> ParseResult<&str, String, &str> { +pub fn identifier(input: &str) -> ParseResult<&str, String, ()> { let mut chars = input.chars(); let mut buf = String::new(); match chars.next() { Some(ch) if ch.is_alphabetic() => buf.push(ch), - _ => return Err((input, input)), + _ => return Err(((), input)), } for next in chars { diff --git a/src/test/sexp.rs b/src/test/sexp.rs index be6c1aa..5b2adad 100644 --- a/src/test/sexp.rs +++ b/src/test/sexp.rs @@ -22,13 +22,16 @@ fn parse_sexp() { literal("#f").to(Atom::Bool(false)), )); - let parse_symbol = identifier; + let parse_symbol = identifier.map(Atom::Symbol); let parse_number = repeated(one_of("1234567890")) .at_least(1) .map(|n| Atom::Num(n.iter().collect::().parse::().unwrap())); - let parser = choice((parse_bool, parse_number)); + let parser = choice((parse_symbol, parse_bool, parse_number)); let output = parser.parse("#t").unwrap(); assert_eq!(output.0, Atom::Bool(true)); + + let output = parser.parse("384").unwrap(); + assert_eq!(output.0, Atom::Num(384)); }