From 3962db12a88413b06d3ed3d5ee0ec1adaa4ae00a Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Fri, 15 Dec 2023 12:29:46 -0500 Subject: [PATCH] Implement the new fields for fixed width area. --- src/compare/util.rs | 2 +- src/parser/fixed_width_area.rs | 3 ++- src/types/lesser_element.rs | 9 +++++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/compare/util.rs b/src/compare/util.rs index e1df0db8..79cefcd2 100644 --- a/src/compare/util.rs +++ b/src/compare/util.rs @@ -139,7 +139,7 @@ fn assert_post_blank<'b, 's, S: StandardProperties<'s> + ?Sized>( .post_blank .ok_or("Token should have a post-blank.")?; if rust_post_blank as usize != emacs_post_blank { - Err(format!("Rust post-blank (in chars) {rust_post_blank} does not match emacs post-blank ({emacs_post_blank})", rust_post_blank = rust_post_blank, emacs_post_blank = emacs_post_blank))?; + Err(format!("Rust post-blank {rust_post_blank} does not match emacs post-blank ({emacs_post_blank})", rust_post_blank = rust_post_blank, emacs_post_blank = emacs_post_blank))?; } Ok(()) diff --git a/src/parser/fixed_width_area.rs b/src/parser/fixed_width_area.rs index 73f4d150..eae3833d 100644 --- a/src/parser/fixed_width_area.rs +++ b/src/parser/fixed_width_area.rs @@ -41,7 +41,7 @@ where let (remaining, mut remaining_lines) = many0(preceded(not(exit_matcher), fixed_width_area_line_matcher))(remaining)?; - let (remaining, _trailing_ws) = + let (remaining, post_blank) = maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?; let source = get_consumed(input, remaining); let mut value = Vec::with_capacity(remaining_lines.len() + 1); @@ -66,6 +66,7 @@ where affiliated_keywords, ), value, + post_blank: post_blank.map(Into::<&str>::into), }, )) } diff --git a/src/types/lesser_element.rs b/src/types/lesser_element.rs index 9c4ff951..8ddaa123 100644 --- a/src/types/lesser_element.rs +++ b/src/types/lesser_element.rs @@ -148,6 +148,7 @@ pub struct FixedWidthArea<'s> { pub source: &'s str, pub affiliated_keywords: AffiliatedKeywords<'s>, pub value: Vec<&'s str>, + pub post_blank: Option<&'s str>, } #[derive(Debug)] @@ -403,11 +404,15 @@ impl<'s> StandardProperties<'s> for FixedWidthArea<'s> { } fn get_contents<'b>(&'b self) -> Option<&'s str> { - todo!() + None } fn get_post_blank(&self) -> PostBlank { - todo!() + self.post_blank + .map(|text| text.lines().count()) + .unwrap_or(0) + .try_into() + .expect("Too much post-blank to fit into a PostBlank.") } }