Fix handling of whitespace.

This commit is contained in:
Tom Alexander
2023-04-11 15:08:46 -04:00
parent 751a3beffd
commit 5d7ca1b966
5 changed files with 52 additions and 31 deletions

View File

@@ -2,3 +2,4 @@ mod error;
mod parse;
mod sexp;
pub use parse::emacs_parse_org_document;
pub use sexp::sexp;

View File

@@ -3,7 +3,10 @@ use nom::bytes::complete::tag;
use nom::bytes::complete::take_till1;
use nom::character::complete::multispace0;
use nom::character::complete::multispace1;
use nom::combinator::not;
use nom::combinator::peek;
use nom::multi::separated_list1;
use nom::sequence::delimited;
use super::error::Res;
@@ -29,13 +32,14 @@ fn token<'s>(input: &'s str) -> Res<&'s str, Token<'s>> {
#[tracing::instrument(ret, level = "debug")]
fn list<'s>(input: &'s str) -> Res<&'s str, Token<'s>> {
let (remaining, opening_paren) = tag("(")(input)?;
let (remaining, children) = separated_list1(multispace1, token)(remaining)?;
let (remaining, children) = delimited(multispace0, separated_list1(multispace1, token), multispace0)(remaining)?;
let (remaining, closing_paren) = tag(")")(remaining)?;
Ok((remaining, Token::List(children)))
}
#[tracing::instrument(ret, level = "debug")]
fn atom<'s>(input: &'s str) -> Res<&'s str, Token<'s>> {
not(peek(tag(")")))(input)?;
unquoted_atom(input)
}