Merge branch 'inline_source_block_properties'

This commit is contained in:
Tom Alexander 2023-10-09 19:32:04 -04:00
commit 0374743cad
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
4 changed files with 48 additions and 10 deletions

View File

@ -1,2 +1,3 @@
before src_foo{ipsum} after src_foo{}
src_bar[lorem]{ipsum} before src_bar{lorem} after
src_baz[ipsum]{dolar}

View File

@ -3654,20 +3654,51 @@ fn compare_inline_babel_call<'b, 's>(
} }
fn compare_inline_source_block<'b, 's>( fn compare_inline_source_block<'b, 's>(
_source: &'s str, source: &'s str,
emacs: &'b Token<'s>, emacs: &'b Token<'s>,
rust: &'b InlineSourceBlock<'s>, rust: &'b InlineSourceBlock<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> { ) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let this_status = DiffStatus::Good; let mut this_status = DiffStatus::Good;
let message = None; let mut child_status = Vec::new();
let mut message = None;
// TODO: Compare :language :value :parameters assert_no_children(emacs, &mut this_status, &mut message)?;
for diff in compare_properties!(
source,
emacs,
rust,
(
EmacsField::Required(":language"),
|r| Some(r.language),
compare_property_quoted_string
),
(
EmacsField::Required(":value"),
|r| Some(r.value),
compare_property_quoted_string
),
(
EmacsField::Required(":parameters"),
|r| r.parameters,
compare_property_quoted_string
)
) {
match diff {
ComparePropertiesResult::NoChange => {}
ComparePropertiesResult::SelfChange(new_status, new_message) => {
this_status = new_status;
message = new_message
}
ComparePropertiesResult::DiffEntry(diff_entry) => child_status.push(diff_entry),
}
}
Ok(DiffResult { Ok(DiffResult {
status: this_status, status: this_status,
name: rust.get_elisp_name(), name: rust.get_elisp_name(),
message, message,
children: Vec::new(), children: child_status,
rust_source: rust.get_source(), rust_source: rust.get_source(),
emacs_token: emacs, emacs_token: emacs,
} }

View File

@ -36,9 +36,9 @@ pub(crate) fn inline_source_block<'b, 'g, 'r, 's>(
input: OrgSource<'s>, input: OrgSource<'s>,
) -> Res<OrgSource<'s>, InlineSourceBlock<'s>> { ) -> Res<OrgSource<'s>, InlineSourceBlock<'s>> {
let (remaining, _) = tag_no_case("src_")(input)?; let (remaining, _) = tag_no_case("src_")(input)?;
let (remaining, _) = lang(context, remaining)?; let (remaining, language) = lang(context, remaining)?;
let (remaining, _header1) = opt(parser_with_context!(header)(context))(remaining)?; let (remaining, parameters) = opt(parser_with_context!(header)(context))(remaining)?;
let (remaining, _body) = body(context, remaining)?; let (remaining, value) = body(context, remaining)?;
let (remaining, _trailing_whitespace) = let (remaining, _trailing_whitespace) =
maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?; maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?;
let source = get_consumed(input, remaining); let source = get_consumed(input, remaining);
@ -46,6 +46,9 @@ pub(crate) fn inline_source_block<'b, 'g, 'r, 's>(
remaining, remaining,
InlineSourceBlock { InlineSourceBlock {
source: source.into(), source: source.into(),
language: language.into(),
parameters: parameters.map(Into::<&str>::into),
value: value.into(),
}, },
)) ))
} }

View File

@ -227,6 +227,9 @@ pub struct InlineBabelCall<'s> {
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
pub struct InlineSourceBlock<'s> { pub struct InlineSourceBlock<'s> {
pub source: &'s str, pub source: &'s str,
pub language: &'s str,
pub parameters: Option<&'s str>,
pub value: &'s str,
} }
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]