From f7afcec824b81d3d46af6dcd78b8050fb95dd73c Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 13 Aug 2023 00:46:15 -0400 Subject: [PATCH] Add support for hash notation in the elisp parser. --- src/parser/sexp.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/parser/sexp.rs b/src/parser/sexp.rs index 5b89153f..cb44d5f7 100644 --- a/src/parser/sexp.rs +++ b/src/parser/sexp.rs @@ -167,8 +167,12 @@ fn vector<'s>(input: &'s str) -> Res<&'s str, Token<'s>> { #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn atom<'s>(input: &'s str) -> Res<&'s str, Token<'s>> { not(peek(one_of(")]")))(input)?; - // TODO: Add calls to hash notation - alt((text_with_properties, quoted_atom, unquoted_atom))(input) + alt(( + text_with_properties, + hash_notation, + quoted_atom, + unquoted_atom, + ))(input) } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] @@ -196,6 +200,18 @@ fn quoted_atom<'s>(input: &'s str) -> Res<&'s str, Token<'s>> { Ok((remaining, Token::Atom(source))) } +#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +fn hash_notation<'s>(input: &'s str) -> Res<&'s str, Token<'s>> { + let (remaining, _) = tag("#<")(input)?; + let (remaining, _body) = take_till1(|c| match c { + '>' => true, + _ => false, + })(remaining)?; + let (remaining, _) = tag(">")(remaining)?; + let source = get_consumed(input, remaining); + Ok((remaining, Token::Atom(source))) +} + fn text_with_properties<'s>(input: &'s str) -> Res<&'s str, Token<'s>> { let (remaining, _) = tag("#(")(input)?; let (remaining, (text, props)) = delimited(