From 908ae078b06f1df9397662b520570f8688ce14ab Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 3 May 2020 13:43:49 -0400 Subject: [PATCH] Start of making ignored whitespace a top-level template element to handle it in a more generic fashion. --- src/parser/parser.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/parser/parser.rs b/src/parser/parser.rs index 28b4381..7079a73 100644 --- a/src/parser/parser.rs +++ b/src/parser/parser.rs @@ -53,6 +53,11 @@ pub enum Special { RightCurlyBrace, } +#[derive(Clone, Debug, PartialEq)] +pub enum IgnoredWhitespace<'a> { + StartOfLine(&'a str), +} + #[derive(Clone, Debug, PartialEq)] pub struct Comment<'a> { value: &'a str, @@ -141,6 +146,7 @@ pub struct Template<'a> { pub enum TemplateElement<'a> { TESpan(Span<'a>), TETag(DustTag<'a>), + TEIgnoredWhitespace(IgnoredWhitespace<'a>), } /// Any element significant to dust that isn't plain text @@ -478,10 +484,9 @@ fn filter(i: &str) -> IResult<&str, Filter> { )(i) } -/// Whitespace at the beginning of lines is ignored so inside a span -/// we are matching a newline character followed by as much contiguous -/// whitespace as possible, all of which will be thrown away by other -/// parsers. +/// Whitespace at the beginning of lines is ignored so we are matching +/// a newline character followed by as much contiguous whitespace as +/// possible, all of which will be thrown away by other parsers. fn span_end_of_line(i: &str) -> IResult<&str, (&str, &str)> { tuple((line_ending, multispace0))(i) }