Compare commits

...

5 Commits

Author SHA1 Message Date
Tom Alexander
f49a1853ad
Merge branch 'fixed_width_area_properties'
All checks were successful
rustfmt Build rustfmt has succeeded
rust-build Build rust-build has succeeded
rust-test Build rust-test has succeeded
rust-foreign-document-test Build rust-foreign-document-test has succeeded
2023-10-05 04:14:35 -04:00
Tom Alexander
6bd8d9efd7
Cleanup. 2023-10-05 04:04:18 -04:00
Tom Alexander
18ad80e018
Compare value. 2023-10-05 03:58:42 -04:00
Tom Alexander
34a0858473
Merge branch 'diary_sexp' 2023-10-05 03:58:19 -04:00
Tom Alexander
4ba9d7439a
Compare value. 2023-10-05 03:46:14 -04:00
5 changed files with 67 additions and 34 deletions

View File

@ -2161,8 +2161,6 @@ fn compare_diary_sexp<'b, 's>(
let mut this_status = DiffStatus::Good;
let mut message = None;
// TODO: Compare :value
// TODO: Compare :caption
// Compare name
let name = get_property_quoted_string(emacs, ":name")?;
@ -2174,6 +2172,16 @@ fn compare_diary_sexp<'b, 's>(
));
}
// Compare value
let value = get_property_quoted_string(emacs, ":value")?;
if value.as_ref().map(String::as_str) != Some(rust.value) {
this_status = DiffStatus::Bad;
message = Some(format!(
"Value mismatch (emacs != rust) {:?} != {:?}",
value, rust.value
));
}
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
@ -2265,8 +2273,6 @@ fn compare_fixed_width_area<'b, 's>(
let mut this_status = DiffStatus::Good;
let mut message = None;
// TODO: Compare :value
// TODO: Compare :caption
// Compare name
let name = get_property_quoted_string(emacs, ":name")?;
@ -2278,6 +2284,18 @@ fn compare_fixed_width_area<'b, 's>(
));
}
// Compare value
let value = get_property_quoted_string(emacs, ":value")?
.ok_or("Fixed width area should have a value.")?;
let rust_value = rust.get_value();
if value != rust_value {
this_status = DiffStatus::Bad;
message = Some(format!(
"Value mismatch (emacs != rust) {:?} != {:?}",
value, rust_value
));
}
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),

View File

@ -1,14 +1,13 @@
use nom::branch::alt;
use nom::bytes::complete::is_not;
use nom::bytes::complete::tag;
use nom::character::complete::line_ending;
use nom::combinator::eof;
use nom::combinator::recognize;
use nom::multi::many0;
use nom::sequence::tuple;
use super::keyword::affiliated_keyword;
use super::org_source::OrgSource;
use super::util::get_name;
use super::util::org_line_ending;
use crate::context::RefContext;
use crate::error::Res;
use crate::parser::util::get_consumed;
@ -22,9 +21,8 @@ pub(crate) fn diary_sexp<'b, 'g, 'r, 's>(
) -> Res<OrgSource<'s>, DiarySexp<'s>> {
let (input, affiliated_keywords) = many0(affiliated_keyword)(input)?;
start_of_line(input)?;
let (remaining, _clock) = tag("%%(")(input)?;
let (remaining, _contents) = is_not("\r\n")(remaining)?;
let (remaining, _eol) = alt((line_ending, eof))(remaining)?;
let (remaining, value) = recognize(tuple((tag("%%("), is_not("\r\n"))))(input)?;
let (remaining, _eol) = org_line_ending(remaining)?;
let source = get_consumed(input, remaining);
Ok((
@ -32,6 +30,7 @@ pub(crate) fn diary_sexp<'b, 'g, 'r, 's>(
DiarySexp {
source: source.into(),
name: get_name(&affiliated_keywords),
value: Into::<&str>::into(value),
},
))
}

View File

@ -1,19 +1,17 @@
use nom::branch::alt;
use nom::bytes::complete::is_not;
use nom::bytes::complete::tag;
use nom::character::complete::line_ending;
use nom::character::complete::anychar;
use nom::character::complete::space0;
use nom::combinator::eof;
use nom::combinator::not;
use nom::combinator::recognize;
use nom::multi::many0;
use nom::multi::many_till;
use nom::sequence::preceded;
use nom::sequence::tuple;
use super::keyword::affiliated_keyword;
use super::org_source::OrgSource;
use super::util::get_name;
use super::util::only_space1;
use super::util::org_line_ending;
use crate::context::parser_with_context;
use crate::context::RefContext;
@ -31,16 +29,30 @@ pub(crate) fn fixed_width_area<'b, 'g, 'r, 's>(
let (input, affiliated_keywords) = many0(affiliated_keyword)(input)?;
let fixed_width_area_line_matcher = parser_with_context!(fixed_width_area_line)(context);
let exit_matcher = parser_with_context!(exit_matcher_parser)(context);
let (remaining, _first_line) = fixed_width_area_line_matcher(input)?;
let (remaining, _remaining_lines) =
let (remaining, first_line) = fixed_width_area_line_matcher(input)?;
let (remaining, mut remaining_lines) =
many0(preceded(not(exit_matcher), fixed_width_area_line_matcher))(remaining)?;
let source = get_consumed(input, remaining);
let mut value = Vec::with_capacity(remaining_lines.len() + 1);
let last_line = remaining_lines.pop();
if let Some(last_line) = last_line {
value.push(Into::<&str>::into(first_line));
value.extend(remaining_lines.into_iter().map(Into::<&str>::into));
let last_line = Into::<&str>::into(last_line);
// Trim the line ending from the final line.
value.push(&last_line[..(last_line.len() - 1)])
} else {
// Trim the line ending from the only line.
let only_line = Into::<&str>::into(first_line);
value.push(&only_line[..(only_line.len() - 1)])
}
Ok((
remaining,
FixedWidthArea {
source: source.into(),
name: get_name(&affiliated_keywords),
value,
},
))
}
@ -51,14 +63,13 @@ fn fixed_width_area_line<'b, 'g, 'r, 's>(
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, OrgSource<'s>> {
start_of_line(input)?;
let (remaining, _indent) = space0(input)?;
let (remaining, _) = tuple((
tag(":"),
alt((recognize(tuple((only_space1, is_not("\r\n")))), space0)),
org_line_ending,
))(remaining)?;
let source = get_consumed(input, remaining);
Ok((remaining, source))
let (remaining, _) = tuple((space0, tag(":")))(input)?;
if let Ok((remaining, line_break)) = org_line_ending(remaining) {
return Ok((remaining, line_break));
}
let (remaining, _) = tag(" ")(remaining)?;
let (remaining, value) = recognize(many_till(anychar, org_line_ending))(remaining)?;
Ok((remaining, value))
}
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
@ -68,7 +79,7 @@ pub(crate) fn detect_fixed_width_area<'s>(input: OrgSource<'s>) -> Res<OrgSource
start_of_line,
space0,
tag(":"),
alt((tag(" "), line_ending, eof)),
alt((tag(" "), org_line_ending)),
))(input)?;
Ok((input, ()))
}

View File

@ -1,5 +1,4 @@
use nom::branch::alt;
use nom::bytes::complete::is_a;
use nom::character::complete::anychar;
use nom::character::complete::line_ending;
use nom::character::complete::none_of;
@ -230,13 +229,6 @@ where
}
}
/// Match at least one space character.
///
/// This is similar to nom's space1 parser except space1 matches both spaces and tabs whereas this only matches spaces.
pub(crate) fn only_space1<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
is_a(" ")(input)
}
/// Match single space or tab.
///
/// In org-mode syntax, spaces and tabs are often (but not always!) interchangeable.

View File

@ -102,6 +102,7 @@ pub struct Clock<'s> {
pub struct DiarySexp<'s> {
pub source: &'s str,
pub name: Option<&'s str>,
pub value: &'s str,
}
#[derive(Debug)]
@ -116,6 +117,7 @@ pub struct Planning<'s> {
pub struct FixedWidthArea<'s> {
pub source: &'s str,
pub name: Option<&'s str>,
pub value: Vec<&'s str>,
}
#[derive(Debug)]
@ -266,7 +268,18 @@ impl<'s> StandardProperties<'s> for LatexEnvironment<'s> {
impl<'s> Comment<'s> {
pub fn get_value(&self) -> String {
// TODO: maybe we should handle parsing here instead of storing the parsing result in the AST since I imagine getting the value of comments won't be a common operation.
let final_size = self.value.iter().map(|line| line.len()).sum();
let mut ret = String::with_capacity(final_size);
for line in &self.value {
ret.push_str(line);
}
ret
}
}
impl<'s> FixedWidthArea<'s> {
pub fn get_value(&self) -> String {
let final_size = self.value.iter().map(|line| line.len()).sum();
let mut ret = String::with_capacity(final_size);
for line in &self.value {