Update all elements to the new AffiliatedKeywords.

This commit is contained in:
Tom Alexander 2023-10-11 14:44:25 -04:00
parent aa33fe42a8
commit 9523365090
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
19 changed files with 162 additions and 97 deletions

View File

@ -27,7 +27,6 @@ use super::util::compare_affiliated_keywords;
use super::util::compare_children; use super::util::compare_children;
use super::util::compare_children_iter; use super::util::compare_children_iter;
use super::util::compare_standard_properties; use super::util::compare_standard_properties;
use super::util::get_property_quoted_string;
use crate::compare::compare_field::ComparePropertiesResult; use crate::compare::compare_field::ComparePropertiesResult;
use crate::compare::compare_field::EmacsField; use crate::compare::compare_field::EmacsField;
use crate::compare::macros::compare_properties; use crate::compare::macros::compare_properties;
@ -900,24 +899,42 @@ fn compare_center_block<'b, 's>(
emacs: &'b Token<'s>, emacs: &'b Token<'s>,
rust: &'b CenterBlock<'s>, rust: &'b CenterBlock<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> { ) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let children = emacs.as_list()?;
let mut child_status = Vec::new();
let mut this_status = DiffStatus::Good; let mut this_status = DiffStatus::Good;
let mut child_status = Vec::new();
let mut message = None; let mut message = None;
// TODO: Compare :caption compare_children(
// Compare name source,
let name = get_property_quoted_string(emacs, ":name")?; emacs,
if name.as_ref().map(String::as_str) != rust.name { &rust.children,
this_status = DiffStatus::Bad; &mut child_status,
message = Some(format!( &mut this_status,
"Name mismatch (emacs != rust) {:?} != {:?}", &mut message,
name, rust.name )?;
));
}
for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) { for diff in compare_properties!(
child_status.push(compare_ast_node(source, emacs_child, rust_child.into())?); source,
emacs,
rust,
(
EmacsField::Optional(":name"),
|r| r.name,
compare_property_quoted_string
),
(
EmacsField::Optional(":caption"),
compare_identity,
compare_noop
)
) {
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 {

View File

@ -14,9 +14,9 @@ use nom::multi::many_till;
use nom::sequence::tuple; use nom::sequence::tuple;
use nom::InputTake; use nom::InputTake;
use super::affiliated_keyword::parse_affiliated_keywords;
use super::keyword::affiliated_keyword; use super::keyword::affiliated_keyword;
use super::org_source::BracketDepth; use super::org_source::BracketDepth;
use super::util::get_name;
use super::util::maybe_consume_trailing_whitespace_if_not_exiting; use super::util::maybe_consume_trailing_whitespace_if_not_exiting;
use super::util::start_of_line; use super::util::start_of_line;
use super::OrgSource; use super::OrgSource;
@ -50,7 +50,10 @@ pub(crate) fn babel_call<'b, 'g, 'r, 's>(
remaining, remaining,
BabelCall { BabelCall {
source: Into::<&str>::into(source), source: Into::<&str>::into(source),
name: get_name(&affiliated_keywords), affiliated_keywords: parse_affiliated_keywords(
context.get_global_settings(),
affiliated_keywords,
),
value: Into::<&str>::into(line_break.take(0)), value: Into::<&str>::into(line_break.take(0)),
call: None, call: None,
inside_header: None, inside_header: None,
@ -73,7 +76,10 @@ pub(crate) fn babel_call<'b, 'g, 'r, 's>(
remaining, remaining,
BabelCall { BabelCall {
source: Into::<&str>::into(source), source: Into::<&str>::into(source),
name: get_name(&affiliated_keywords), affiliated_keywords: parse_affiliated_keywords(
context.get_global_settings(),
affiliated_keywords,
),
value: Into::<&str>::into(value).trim_end(), value: Into::<&str>::into(value).trim_end(),
call: call.map(Into::<&str>::into), call: call.map(Into::<&str>::into),
inside_header: inside_header.map(Into::<&str>::into), inside_header: inside_header.map(Into::<&str>::into),

View File

@ -4,9 +4,9 @@ use nom::combinator::recognize;
use nom::multi::many0; use nom::multi::many0;
use nom::sequence::tuple; use nom::sequence::tuple;
use super::affiliated_keyword::parse_affiliated_keywords;
use super::keyword::affiliated_keyword; use super::keyword::affiliated_keyword;
use super::org_source::OrgSource; use super::org_source::OrgSource;
use super::util::get_name;
use super::util::maybe_consume_trailing_whitespace_if_not_exiting; use super::util::maybe_consume_trailing_whitespace_if_not_exiting;
use super::util::org_line_ending; use super::util::org_line_ending;
use crate::context::RefContext; use crate::context::RefContext;
@ -35,7 +35,10 @@ pub(crate) fn diary_sexp<'b, 'g, 'r, 's>(
remaining, remaining,
DiarySexp { DiarySexp {
source: source.into(), source: source.into(),
name: get_name(&affiliated_keywords), affiliated_keywords: parse_affiliated_keywords(
context.get_global_settings(),
affiliated_keywords,
),
value: Into::<&str>::into(value), value: Into::<&str>::into(value),
}, },
)) ))

View File

@ -11,9 +11,9 @@ use nom::multi::many0;
use nom::multi::many_till; use nom::multi::many_till;
use nom::sequence::tuple; use nom::sequence::tuple;
use super::affiliated_keyword::parse_affiliated_keywords;
use super::keyword::affiliated_keyword; use super::keyword::affiliated_keyword;
use super::org_source::OrgSource; use super::org_source::OrgSource;
use super::util::get_name;
use super::util::maybe_consume_trailing_whitespace_if_not_exiting; use super::util::maybe_consume_trailing_whitespace_if_not_exiting;
use crate::context::parser_with_context; use crate::context::parser_with_context;
use crate::context::ContextElement; use crate::context::ContextElement;
@ -100,7 +100,10 @@ pub(crate) fn drawer<'b, 'g, 'r, 's>(
remaining, remaining,
Drawer { Drawer {
source: source.into(), source: source.into(),
name: get_name(&affiliated_keywords), affiliated_keywords: parse_affiliated_keywords(
context.get_global_settings(),
affiliated_keywords,
),
drawer_name: drawer_name.into(), drawer_name: drawer_name.into(),
children, children,
}, },

View File

@ -17,9 +17,9 @@ use nom::multi::many_till;
use nom::sequence::preceded; use nom::sequence::preceded;
use nom::sequence::tuple; use nom::sequence::tuple;
use super::affiliated_keyword::parse_affiliated_keywords;
use super::keyword::affiliated_keyword; use super::keyword::affiliated_keyword;
use super::org_source::OrgSource; use super::org_source::OrgSource;
use super::util::get_name;
use super::util::maybe_consume_trailing_whitespace_if_not_exiting; use super::util::maybe_consume_trailing_whitespace_if_not_exiting;
use crate::context::parser_with_context; use crate::context::parser_with_context;
use crate::context::ContextElement; use crate::context::ContextElement;
@ -107,7 +107,10 @@ pub(crate) fn dynamic_block<'b, 'g, 'r, 's>(
remaining, remaining,
DynamicBlock { DynamicBlock {
source: source.into(), source: source.into(),
name: get_name(&affiliated_keywords), affiliated_keywords: parse_affiliated_keywords(
context.get_global_settings(),
affiliated_keywords,
),
block_name: name.into(), block_name: name.into(),
parameters: parameters.map(|val| val.into()), parameters: parameters.map(|val| val.into()),
children, children,

View File

@ -9,9 +9,9 @@ use nom::multi::many_till;
use nom::sequence::preceded; use nom::sequence::preceded;
use nom::sequence::tuple; use nom::sequence::tuple;
use super::affiliated_keyword::parse_affiliated_keywords;
use super::keyword::affiliated_keyword; use super::keyword::affiliated_keyword;
use super::org_source::OrgSource; use super::org_source::OrgSource;
use super::util::get_name;
use super::util::maybe_consume_trailing_whitespace_if_not_exiting; use super::util::maybe_consume_trailing_whitespace_if_not_exiting;
use super::util::org_line_ending; use super::util::org_line_ending;
use crate::context::parser_with_context; use crate::context::parser_with_context;
@ -57,7 +57,10 @@ pub(crate) fn fixed_width_area<'b, 'g, 'r, 's>(
remaining, remaining,
FixedWidthArea { FixedWidthArea {
source: source.into(), source: source.into(),
name: get_name(&affiliated_keywords), affiliated_keywords: parse_affiliated_keywords(
context.get_global_settings(),
affiliated_keywords,
),
value, value,
}, },
)) ))

View File

@ -11,9 +11,9 @@ use nom::multi::many1;
use nom::multi::many_till; use nom::multi::many_till;
use nom::sequence::tuple; use nom::sequence::tuple;
use super::affiliated_keyword::parse_affiliated_keywords;
use super::keyword::affiliated_keyword; use super::keyword::affiliated_keyword;
use super::org_source::OrgSource; use super::org_source::OrgSource;
use super::util::get_name;
use super::util::include_input; use super::util::include_input;
use super::util::maybe_consume_trailing_whitespace_if_not_exiting; use super::util::maybe_consume_trailing_whitespace_if_not_exiting;
use super::util::WORD_CONSTITUENT_CHARACTERS; use super::util::WORD_CONSTITUENT_CHARACTERS;
@ -94,7 +94,10 @@ pub(crate) fn footnote_definition<'b, 'g, 'r, 's>(
remaining, remaining,
FootnoteDefinition { FootnoteDefinition {
source: source.into(), source: source.into(),
name: get_name(&affiliated_keywords), affiliated_keywords: parse_affiliated_keywords(
context.get_global_settings(),
affiliated_keywords,
),
label: lbl.into(), label: lbl.into(),
children: children.into_iter().map(|(_, item)| item).collect(), children: children.into_iter().map(|(_, item)| item).collect(),
}, },

View File

@ -17,9 +17,9 @@ use nom::multi::many_till;
use nom::sequence::preceded; use nom::sequence::preceded;
use nom::sequence::tuple; use nom::sequence::tuple;
use super::affiliated_keyword::parse_affiliated_keywords;
use super::keyword::affiliated_keyword; use super::keyword::affiliated_keyword;
use super::org_source::OrgSource; use super::org_source::OrgSource;
use super::util::get_name;
use super::util::in_section; use super::util::in_section;
use super::util::maybe_consume_trailing_whitespace_if_not_exiting; use super::util::maybe_consume_trailing_whitespace_if_not_exiting;
use crate::context::parser_with_context; use crate::context::parser_with_context;
@ -71,19 +71,19 @@ pub(crate) fn greater_block<'b, 'g, 'r, 's>(
context, context,
remaining, remaining,
pre_affiliated_keywords_input, pre_affiliated_keywords_input,
&affiliated_keywords, affiliated_keywords,
)?, )?,
"quote" => quote_block( "quote" => quote_block(
context, context,
remaining, remaining,
pre_affiliated_keywords_input, pre_affiliated_keywords_input,
&affiliated_keywords, affiliated_keywords,
)?, )?,
_ => special_block(name)( _ => special_block(name)(
context, context,
remaining, remaining,
pre_affiliated_keywords_input, pre_affiliated_keywords_input,
&affiliated_keywords, affiliated_keywords,
)?, )?,
}; };
Ok((remaining, element)) Ok((remaining, element))
@ -97,7 +97,7 @@ fn center_block<'b, 'g, 'r, 's>(
context: RefContext<'b, 'g, 'r, 's>, context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>, input: OrgSource<'s>,
pre_affiliated_keywords_input: OrgSource<'s>, pre_affiliated_keywords_input: OrgSource<'s>,
affiliated_keywords: &Vec<Keyword<'s>>, affiliated_keywords: Vec<Keyword<'s>>,
) -> Res<OrgSource<'s>, Element<'s>> { ) -> Res<OrgSource<'s>, Element<'s>> {
let (remaining, (source, children)) = greater_block_body( let (remaining, (source, children)) = greater_block_body(
context, context,
@ -110,7 +110,10 @@ fn center_block<'b, 'g, 'r, 's>(
remaining, remaining,
Element::CenterBlock(CenterBlock { Element::CenterBlock(CenterBlock {
source, source,
name: get_name(&affiliated_keywords), affiliated_keywords: parse_affiliated_keywords(
context.get_global_settings(),
affiliated_keywords,
),
children, children,
}), }),
)) ))
@ -124,7 +127,7 @@ fn quote_block<'b, 'g, 'r, 's>(
context: RefContext<'b, 'g, 'r, 's>, context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>, input: OrgSource<'s>,
pre_affiliated_keywords_input: OrgSource<'s>, pre_affiliated_keywords_input: OrgSource<'s>,
affiliated_keywords: &Vec<Keyword<'s>>, affiliated_keywords: Vec<Keyword<'s>>,
) -> Res<OrgSource<'s>, Element<'s>> { ) -> Res<OrgSource<'s>, Element<'s>> {
let (remaining, (source, children)) = greater_block_body( let (remaining, (source, children)) = greater_block_body(
context, context,
@ -137,7 +140,10 @@ fn quote_block<'b, 'g, 'r, 's>(
remaining, remaining,
Element::QuoteBlock(QuoteBlock { Element::QuoteBlock(QuoteBlock {
source, source,
name: get_name(&affiliated_keywords), affiliated_keywords: parse_affiliated_keywords(
context.get_global_settings(),
affiliated_keywords,
),
children, children,
}), }),
)) ))
@ -149,7 +155,7 @@ fn special_block<'s>(
RefContext<'b, 'g, 'r, 's>, RefContext<'b, 'g, 'r, 's>,
OrgSource<'s>, OrgSource<'s>,
OrgSource<'s>, OrgSource<'s>,
&Vec<Keyword<'s>>, Vec<Keyword<'s>>,
) -> Res<OrgSource<'s>, Element<'s>> ) -> Res<OrgSource<'s>, Element<'s>>
+ 's { + 's {
let context_name = format!("special block {}", name); let context_name = format!("special block {}", name);
@ -175,7 +181,7 @@ fn _special_block<'c, 'b, 'g, 'r, 's>(
pre_affiliated_keywords_input: OrgSource<'s>, pre_affiliated_keywords_input: OrgSource<'s>,
name: &'s str, name: &'s str,
context_name: &'c str, context_name: &'c str,
affiliated_keywords: &Vec<Keyword<'s>>, affiliated_keywords: Vec<Keyword<'s>>,
) -> Res<OrgSource<'s>, Element<'s>> { ) -> Res<OrgSource<'s>, Element<'s>> {
let (remaining, parameters) = opt(tuple((space1, parameters)))(input)?; let (remaining, parameters) = opt(tuple((space1, parameters)))(input)?;
let (remaining, (source, children)) = greater_block_body( let (remaining, (source, children)) = greater_block_body(
@ -189,7 +195,10 @@ fn _special_block<'c, 'b, 'g, 'r, 's>(
remaining, remaining,
Element::SpecialBlock(SpecialBlock { Element::SpecialBlock(SpecialBlock {
source, source,
name: get_name(&affiliated_keywords), affiliated_keywords: parse_affiliated_keywords(
context.get_global_settings(),
affiliated_keywords,
),
children, children,
block_type: name, block_type: name,
parameters: parameters.map(|(_, parameters)| Into::<&str>::into(parameters)), parameters: parameters.map(|(_, parameters)| Into::<&str>::into(parameters)),

View File

@ -9,10 +9,10 @@ use nom::multi::many0;
use nom::multi::many1_count; use nom::multi::many1_count;
use nom::sequence::tuple; use nom::sequence::tuple;
use super::affiliated_keyword::parse_affiliated_keywords;
use super::keyword::affiliated_keyword; use super::keyword::affiliated_keyword;
use super::org_source::OrgSource; use super::org_source::OrgSource;
use super::util::get_consumed; use super::util::get_consumed;
use super::util::get_name;
use super::util::maybe_consume_trailing_whitespace_if_not_exiting; use super::util::maybe_consume_trailing_whitespace_if_not_exiting;
use crate::context::RefContext; use crate::context::RefContext;
use crate::error::Res; use crate::error::Res;
@ -42,7 +42,10 @@ pub(crate) fn horizontal_rule<'b, 'g, 'r, 's>(
remaining, remaining,
HorizontalRule { HorizontalRule {
source: source.into(), source: source.into(),
name: get_name(&affiliated_keywords), affiliated_keywords: parse_affiliated_keywords(
context.get_global_settings(),
affiliated_keywords,
),
}, },
)) ))
} }

View File

@ -17,10 +17,10 @@ use nom::multi::many0;
use nom::multi::many_till; use nom::multi::many_till;
use nom::sequence::tuple; use nom::sequence::tuple;
use super::affiliated_keyword::parse_affiliated_keywords;
use super::org_source::BracketDepth; use super::org_source::BracketDepth;
use super::org_source::OrgSource; use super::org_source::OrgSource;
use super::util::get_consumed; use super::util::get_consumed;
use super::util::get_name;
use super::util::maybe_consume_trailing_whitespace_if_not_exiting; use super::util::maybe_consume_trailing_whitespace_if_not_exiting;
use crate::context::Matcher; use crate::context::Matcher;
use crate::context::RefContext; use crate::context::RefContext;
@ -28,6 +28,7 @@ use crate::error::CustomError;
use crate::error::MyError; use crate::error::MyError;
use crate::error::Res; use crate::error::Res;
use crate::parser::util::start_of_line; use crate::parser::util::start_of_line;
use crate::types::AffiliatedKeywords;
use crate::types::Keyword; use crate::types::Keyword;
const ORG_ELEMENT_AFFILIATED_KEYWORDS: [&'static str; 13] = [ const ORG_ELEMENT_AFFILIATED_KEYWORDS: [&'static str; 13] = [
@ -64,7 +65,7 @@ fn _filtered_keyword<'s, F: Matcher>(
remaining, remaining,
Keyword { Keyword {
source: consumed_input.into(), source: consumed_input.into(),
name: None, // To be populated by the caller if this keyword is in a context to support affiliated keywords. affiliated_keywords: AffiliatedKeywords::default(), // To be populated by the caller if this keyword is in a context to support affiliated keywords.
key: parsed_key.into(), key: parsed_key.into(),
value: "".into(), value: "".into(),
}, },
@ -82,7 +83,7 @@ fn _filtered_keyword<'s, F: Matcher>(
remaining, remaining,
Keyword { Keyword {
source: consumed_input.into(), source: consumed_input.into(),
name: None, // To be populated by the caller if this keyword is in a context to support affiliated keywords. affiliated_keywords: AffiliatedKeywords::default(), // To be populated by the caller if this keyword is in a context to support affiliated keywords.
key: parsed_key.into(), key: parsed_key.into(),
value: parsed_value.into(), value: parsed_value.into(),
}, },
@ -102,7 +103,8 @@ pub(crate) fn keyword<'b, 'g, 'r, 's>(
let (remaining, _trailing_ws) = let (remaining, _trailing_ws) =
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?; maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
let source = get_consumed(input, remaining); let source = get_consumed(input, remaining);
kw.name = get_name(&affiliated_keywords); kw.affiliated_keywords =
parse_affiliated_keywords(context.get_global_settings(), affiliated_keywords);
kw.source = Into::<&str>::into(source); kw.source = Into::<&str>::into(source);
Ok((remaining, kw)) Ok((remaining, kw))
} }

View File

@ -12,10 +12,10 @@ use nom::multi::many0;
use nom::multi::many_till; use nom::multi::many_till;
use nom::sequence::tuple; use nom::sequence::tuple;
use super::affiliated_keyword::parse_affiliated_keywords;
use super::keyword::affiliated_keyword; use super::keyword::affiliated_keyword;
use super::org_source::OrgSource; use super::org_source::OrgSource;
use super::util::get_consumed; use super::util::get_consumed;
use super::util::get_name;
use super::util::maybe_consume_trailing_whitespace_if_not_exiting; use super::util::maybe_consume_trailing_whitespace_if_not_exiting;
use crate::context::parser_with_context; use crate::context::parser_with_context;
use crate::context::ContextElement; use crate::context::ContextElement;
@ -67,7 +67,10 @@ pub(crate) fn latex_environment<'b, 'g, 'r, 's>(
remaining, remaining,
LatexEnvironment { LatexEnvironment {
source: source.into(), source: source.into(),
name: get_name(&affiliated_keywords), affiliated_keywords: parse_affiliated_keywords(
context.get_global_settings(),
affiliated_keywords,
),
value: value.into(), value: value.into(),
}, },
)) ))

View File

@ -18,9 +18,9 @@ use nom::multi::many_till;
use nom::sequence::tuple; use nom::sequence::tuple;
use nom::InputTake; use nom::InputTake;
use super::affiliated_keyword::parse_affiliated_keywords;
use super::keyword::affiliated_keyword; use super::keyword::affiliated_keyword;
use super::org_source::OrgSource; use super::org_source::OrgSource;
use super::util::get_name;
use super::util::maybe_consume_trailing_whitespace_if_not_exiting; use super::util::maybe_consume_trailing_whitespace_if_not_exiting;
use crate::context::parser_with_context; use crate::context::parser_with_context;
use crate::context::ContextElement; use crate::context::ContextElement;
@ -103,7 +103,10 @@ pub(crate) fn verse_block<'b, 'g, 'r, 's>(
remaining, remaining,
VerseBlock { VerseBlock {
source: source.into(), source: source.into(),
name: get_name(&affiliated_keywords), affiliated_keywords: parse_affiliated_keywords(
context.get_global_settings(),
affiliated_keywords,
),
data: parameters.map(|parameters| Into::<&str>::into(parameters)), data: parameters.map(|parameters| Into::<&str>::into(parameters)),
children, children,
}, },
@ -145,7 +148,10 @@ pub(crate) fn comment_block<'b, 'g, 'r, 's>(
remaining, remaining,
CommentBlock { CommentBlock {
source: source.into(), source: source.into(),
name: get_name(&affiliated_keywords), affiliated_keywords: parse_affiliated_keywords(
context.get_global_settings(),
affiliated_keywords,
),
contents: contents.into(), contents: contents.into(),
}, },
)) ))
@ -213,7 +219,10 @@ pub(crate) fn example_block<'b, 'g, 'r, 's>(
remaining, remaining,
ExampleBlock { ExampleBlock {
source: source.into(), source: source.into(),
name: get_name(&affiliated_keywords), affiliated_keywords: parse_affiliated_keywords(
context.get_global_settings(),
affiliated_keywords,
),
switches, switches,
number_lines, number_lines,
preserve_indent, preserve_indent,
@ -266,7 +275,10 @@ pub(crate) fn export_block<'b, 'g, 'r, 's>(
remaining, remaining,
ExportBlock { ExportBlock {
source: source.into(), source: source.into(),
name: get_name(&affiliated_keywords), affiliated_keywords: parse_affiliated_keywords(
context.get_global_settings(),
affiliated_keywords,
),
export_type: export_type.map(Into::<&str>::into), export_type: export_type.map(Into::<&str>::into),
data: parameters.map(|parameters| Into::<&str>::into(parameters)), data: parameters.map(|parameters| Into::<&str>::into(parameters)),
contents, contents,
@ -332,7 +344,10 @@ pub(crate) fn src_block<'b, 'g, 'r, 's>(
remaining, remaining,
SrcBlock { SrcBlock {
source: source.into(), source: source.into(),
name: get_name(&affiliated_keywords), affiliated_keywords: parse_affiliated_keywords(
context.get_global_settings(),
affiliated_keywords,
),
language: language.map(Into::<&str>::into), language: language.map(Into::<&str>::into),
switches, switches,
parameters: parameters.map(Into::<&str>::into), parameters: parameters.map(Into::<&str>::into),

View File

@ -7,13 +7,13 @@ use nom::multi::many1;
use nom::multi::many_till; use nom::multi::many_till;
use nom::sequence::tuple; use nom::sequence::tuple;
use super::affiliated_keyword::parse_affiliated_keywords;
use super::element_parser::detect_element; use super::element_parser::detect_element;
use super::keyword::affiliated_keyword; use super::keyword::affiliated_keyword;
use super::org_source::OrgSource; use super::org_source::OrgSource;
use super::util::blank_line; use super::util::blank_line;
use super::util::get_consumed; use super::util::get_consumed;
use super::util::get_has_affiliated_keyword; use super::util::get_has_affiliated_keyword;
use super::util::get_name;
use super::util::maybe_consume_trailing_whitespace_if_not_exiting; use super::util::maybe_consume_trailing_whitespace_if_not_exiting;
use crate::context::parser_with_context; use crate::context::parser_with_context;
use crate::context::ContextElement; use crate::context::ContextElement;
@ -68,7 +68,10 @@ pub(crate) fn paragraph<'b, 'g, 'r, 's>(
remaining, remaining,
Paragraph { Paragraph {
source: source.into(), source: source.into(),
name: get_name(&affiliated_keywords), affiliated_keywords: parse_affiliated_keywords(
context.get_global_settings(),
affiliated_keywords,
),
children, children,
}, },
)) ))

View File

@ -23,7 +23,6 @@ use super::element_parser::element;
use super::keyword::affiliated_keyword; use super::keyword::affiliated_keyword;
use super::object_parser::standard_set_object; use super::object_parser::standard_set_object;
use super::org_source::OrgSource; use super::org_source::OrgSource;
use super::util::get_name;
use super::util::include_input; use super::util::include_input;
use super::util::indentation_level; use super::util::indentation_level;
use super::util::non_whitespace_character; use super::util::non_whitespace_character;
@ -160,7 +159,6 @@ pub(crate) fn plain_list<'b, 'g, 'r, 's>(
let (remaining, _trailing_ws) = let (remaining, _trailing_ws) =
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?; maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
let source = get_consumed(input, remaining); let source = get_consumed(input, remaining);
let name = get_name(&affiliated_keywords);
Ok(( Ok((
remaining, remaining,
PlainList { PlainList {
@ -169,7 +167,6 @@ pub(crate) fn plain_list<'b, 'g, 'r, 's>(
context.get_global_settings(), context.get_global_settings(),
affiliated_keywords, affiliated_keywords,
), ),
name,
list_type: first_item_list_type.expect("Plain lists require at least one element."), list_type: first_item_list_type.expect("Plain lists require at least one element."),
children: children.into_iter().map(|(_start, item)| item).collect(), children: children.into_iter().map(|(_start, item)| item).collect(),
}, },

View File

@ -13,12 +13,12 @@ use nom::multi::many1;
use nom::multi::many_till; use nom::multi::many_till;
use nom::sequence::tuple; use nom::sequence::tuple;
use super::affiliated_keyword::parse_affiliated_keywords;
use super::keyword::affiliated_keyword; use super::keyword::affiliated_keyword;
use super::keyword::table_formula_keyword; use super::keyword::table_formula_keyword;
use super::object_parser::table_cell_set_object; use super::object_parser::table_cell_set_object;
use super::org_source::OrgSource; use super::org_source::OrgSource;
use super::util::exit_matcher_parser; use super::util::exit_matcher_parser;
use super::util::get_name;
use super::util::maybe_consume_trailing_whitespace_if_not_exiting; use super::util::maybe_consume_trailing_whitespace_if_not_exiting;
use super::util::org_line_ending; use super::util::org_line_ending;
use crate::context::parser_with_context; use crate::context::parser_with_context;
@ -77,7 +77,10 @@ pub(crate) fn org_mode_table<'b, 'g, 'r, 's>(
remaining, remaining,
Table { Table {
source: source.into(), source: source.into(),
name: get_name(&affiliated_keywords), affiliated_keywords: parse_affiliated_keywords(
context.get_global_settings(),
affiliated_keywords,
),
formulas, formulas,
children, children,
}, },

View File

@ -23,7 +23,6 @@ use crate::error::CustomError;
use crate::error::MyError; use crate::error::MyError;
use crate::error::Res; use crate::error::Res;
use crate::types::IndentationLevel; use crate::types::IndentationLevel;
use crate::types::Keyword;
pub(crate) const WORD_CONSTITUENT_CHARACTERS: &str = pub(crate) const WORD_CONSTITUENT_CHARACTERS: &str =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
@ -272,21 +271,6 @@ pub(crate) fn indentation_level<'b, 'g, 'r, 's>(
Ok((remaining, (indentation_level, leading_whitespace))) Ok((remaining, (indentation_level, leading_whitespace)))
} }
pub(crate) fn get_name<'s>(affiliated_keywords: &Vec<Keyword<'s>>) -> Option<&'s str> {
let name_keyword = affiliated_keywords
.iter()
.filter(|kw| {
kw.key.eq_ignore_ascii_case("name")
|| kw.key.eq_ignore_ascii_case("source")
|| kw.key.eq_ignore_ascii_case("tblname")
|| kw.key.eq_ignore_ascii_case("resname")
|| kw.key.eq_ignore_ascii_case("srcname")
|| kw.key.eq_ignore_ascii_case("label")
})
.last();
name_keyword.map(|kw| kw.value)
}
pub(crate) fn get_has_affiliated_keyword<'b, 'g, 'r, 's>( pub(crate) fn get_has_affiliated_keyword<'b, 'g, 'r, 's>(
context: RefContext<'b, 'g, 'r, 's>, context: RefContext<'b, 'g, 'r, 's>,
) -> Option<OrgSource<'s>> { ) -> Option<OrgSource<'s>> {

View File

@ -23,3 +23,11 @@ pub struct AffiliatedKeywords<'s> {
pub trait GetAffiliatedKeywords<'s> { pub trait GetAffiliatedKeywords<'s> {
fn get_affiliated_keywords<'a>(&'a self) -> &'a AffiliatedKeywords<'s>; fn get_affiliated_keywords<'a>(&'a self) -> &'a AffiliatedKeywords<'s>;
} }
impl<'s> Default for AffiliatedKeywords<'s> {
fn default() -> Self {
AffiliatedKeywords {
keywords: BTreeMap::new(),
}
}
}

View File

@ -10,7 +10,6 @@ use super::StandardProperties;
pub struct PlainList<'s> { pub struct PlainList<'s> {
pub source: &'s str, pub source: &'s str,
pub affiliated_keywords: AffiliatedKeywords<'s>, pub affiliated_keywords: AffiliatedKeywords<'s>,
pub name: Option<&'s str>,
pub list_type: PlainListType, pub list_type: PlainListType,
pub children: Vec<PlainListItem<'s>>, pub children: Vec<PlainListItem<'s>>,
} }
@ -50,21 +49,21 @@ pub enum CheckboxType {
#[derive(Debug)] #[derive(Debug)]
pub struct CenterBlock<'s> { pub struct CenterBlock<'s> {
pub source: &'s str, pub source: &'s str,
pub name: Option<&'s str>, pub affiliated_keywords: AffiliatedKeywords<'s>,
pub children: Vec<Element<'s>>, pub children: Vec<Element<'s>>,
} }
#[derive(Debug)] #[derive(Debug)]
pub struct QuoteBlock<'s> { pub struct QuoteBlock<'s> {
pub source: &'s str, pub source: &'s str,
pub name: Option<&'s str>, pub affiliated_keywords: AffiliatedKeywords<'s>,
pub children: Vec<Element<'s>>, pub children: Vec<Element<'s>>,
} }
#[derive(Debug)] #[derive(Debug)]
pub struct SpecialBlock<'s> { pub struct SpecialBlock<'s> {
pub source: &'s str, pub source: &'s str,
pub name: Option<&'s str>, pub affiliated_keywords: AffiliatedKeywords<'s>,
pub block_type: &'s str, pub block_type: &'s str,
pub parameters: Option<&'s str>, pub parameters: Option<&'s str>,
pub children: Vec<Element<'s>>, pub children: Vec<Element<'s>>,
@ -73,7 +72,7 @@ pub struct SpecialBlock<'s> {
#[derive(Debug)] #[derive(Debug)]
pub struct DynamicBlock<'s> { pub struct DynamicBlock<'s> {
pub source: &'s str, pub source: &'s str,
pub name: Option<&'s str>, pub affiliated_keywords: AffiliatedKeywords<'s>,
pub block_name: &'s str, pub block_name: &'s str,
pub parameters: Option<&'s str>, pub parameters: Option<&'s str>,
pub children: Vec<Element<'s>>, pub children: Vec<Element<'s>>,
@ -82,7 +81,7 @@ pub struct DynamicBlock<'s> {
#[derive(Debug)] #[derive(Debug)]
pub struct FootnoteDefinition<'s> { pub struct FootnoteDefinition<'s> {
pub source: &'s str, pub source: &'s str,
pub name: Option<&'s str>, pub affiliated_keywords: AffiliatedKeywords<'s>,
pub label: &'s str, pub label: &'s str,
pub children: Vec<Element<'s>>, pub children: Vec<Element<'s>>,
} }
@ -90,7 +89,7 @@ pub struct FootnoteDefinition<'s> {
#[derive(Debug)] #[derive(Debug)]
pub struct Drawer<'s> { pub struct Drawer<'s> {
pub source: &'s str, pub source: &'s str,
pub name: Option<&'s str>, pub affiliated_keywords: AffiliatedKeywords<'s>,
pub drawer_name: &'s str, pub drawer_name: &'s str,
pub children: Vec<Element<'s>>, pub children: Vec<Element<'s>>,
} }
@ -111,7 +110,7 @@ pub struct NodeProperty<'s> {
#[derive(Debug)] #[derive(Debug)]
pub struct Table<'s> { pub struct Table<'s> {
pub source: &'s str, pub source: &'s str,
pub name: Option<&'s str>, pub affiliated_keywords: AffiliatedKeywords<'s>,
pub formulas: Vec<Keyword<'s>>, pub formulas: Vec<Keyword<'s>>,
pub children: Vec<TableRow<'s>>, pub children: Vec<TableRow<'s>>,
} }

View File

@ -1,4 +1,5 @@
use super::object::Object; use super::object::Object;
use super::AffiliatedKeywords;
use super::PlainText; use super::PlainText;
use super::StandardProperties; use super::StandardProperties;
use super::Timestamp; use super::Timestamp;
@ -6,7 +7,7 @@ use super::Timestamp;
#[derive(Debug)] #[derive(Debug)]
pub struct Paragraph<'s> { pub struct Paragraph<'s> {
pub source: &'s str, pub source: &'s str,
pub name: Option<&'s str>, pub affiliated_keywords: AffiliatedKeywords<'s>,
pub children: Vec<Object<'s>>, pub children: Vec<Object<'s>>,
} }
@ -25,7 +26,7 @@ pub struct TableCell<'s> {
#[derive(Debug)] #[derive(Debug)]
pub struct VerseBlock<'s> { pub struct VerseBlock<'s> {
pub source: &'s str, pub source: &'s str,
pub name: Option<&'s str>, pub affiliated_keywords: AffiliatedKeywords<'s>,
pub data: Option<&'s str>, pub data: Option<&'s str>,
pub children: Vec<Object<'s>>, pub children: Vec<Object<'s>>,
} }
@ -33,7 +34,7 @@ pub struct VerseBlock<'s> {
#[derive(Debug)] #[derive(Debug)]
pub struct CommentBlock<'s> { pub struct CommentBlock<'s> {
pub source: &'s str, pub source: &'s str,
pub name: Option<&'s str>, pub affiliated_keywords: AffiliatedKeywords<'s>,
pub contents: &'s str, pub contents: &'s str,
} }
@ -50,7 +51,7 @@ pub enum RetainLabels {
#[derive(Debug)] #[derive(Debug)]
pub struct ExampleBlock<'s> { pub struct ExampleBlock<'s> {
pub source: &'s str, pub source: &'s str,
pub name: Option<&'s str>, pub affiliated_keywords: AffiliatedKeywords<'s>,
pub switches: Option<&'s str>, pub switches: Option<&'s str>,
pub number_lines: Option<SwitchNumberLines>, pub number_lines: Option<SwitchNumberLines>,
pub preserve_indent: Option<CharOffsetInLine>, pub preserve_indent: Option<CharOffsetInLine>,
@ -63,7 +64,7 @@ pub struct ExampleBlock<'s> {
#[derive(Debug)] #[derive(Debug)]
pub struct ExportBlock<'s> { pub struct ExportBlock<'s> {
pub source: &'s str, pub source: &'s str,
pub name: Option<&'s str>, pub affiliated_keywords: AffiliatedKeywords<'s>,
pub export_type: Option<&'s str>, pub export_type: Option<&'s str>,
pub data: Option<&'s str>, pub data: Option<&'s str>,
pub contents: String, pub contents: String,
@ -72,7 +73,7 @@ pub struct ExportBlock<'s> {
#[derive(Debug)] #[derive(Debug)]
pub struct SrcBlock<'s> { pub struct SrcBlock<'s> {
pub source: &'s str, pub source: &'s str,
pub name: Option<&'s str>, pub affiliated_keywords: AffiliatedKeywords<'s>,
pub language: Option<&'s str>, pub language: Option<&'s str>,
pub switches: Option<&'s str>, pub switches: Option<&'s str>,
pub parameters: Option<&'s str>, pub parameters: Option<&'s str>,
@ -101,7 +102,7 @@ pub struct Clock<'s> {
#[derive(Debug)] #[derive(Debug)]
pub struct DiarySexp<'s> { pub struct DiarySexp<'s> {
pub source: &'s str, pub source: &'s str,
pub name: Option<&'s str>, pub affiliated_keywords: AffiliatedKeywords<'s>,
pub value: &'s str, pub value: &'s str,
} }
@ -116,20 +117,20 @@ pub struct Planning<'s> {
#[derive(Debug)] #[derive(Debug)]
pub struct FixedWidthArea<'s> { pub struct FixedWidthArea<'s> {
pub source: &'s str, pub source: &'s str,
pub name: Option<&'s str>, pub affiliated_keywords: AffiliatedKeywords<'s>,
pub value: Vec<&'s str>, pub value: Vec<&'s str>,
} }
#[derive(Debug)] #[derive(Debug)]
pub struct HorizontalRule<'s> { pub struct HorizontalRule<'s> {
pub source: &'s str, pub source: &'s str,
pub name: Option<&'s str>, pub affiliated_keywords: AffiliatedKeywords<'s>,
} }
#[derive(Debug)] #[derive(Debug)]
pub struct Keyword<'s> { pub struct Keyword<'s> {
pub source: &'s str, pub source: &'s str,
pub name: Option<&'s str>, pub affiliated_keywords: AffiliatedKeywords<'s>,
pub key: &'s str, pub key: &'s str,
pub value: &'s str, pub value: &'s str,
} }
@ -137,7 +138,7 @@ pub struct Keyword<'s> {
#[derive(Debug)] #[derive(Debug)]
pub struct BabelCall<'s> { pub struct BabelCall<'s> {
pub source: &'s str, pub source: &'s str,
pub name: Option<&'s str>, pub affiliated_keywords: AffiliatedKeywords<'s>,
pub value: &'s str, pub value: &'s str,
pub call: Option<&'s str>, pub call: Option<&'s str>,
pub inside_header: Option<&'s str>, pub inside_header: Option<&'s str>,
@ -148,7 +149,7 @@ pub struct BabelCall<'s> {
#[derive(Debug)] #[derive(Debug)]
pub struct LatexEnvironment<'s> { pub struct LatexEnvironment<'s> {
pub source: &'s str, pub source: &'s str,
pub name: Option<&'s str>, pub affiliated_keywords: AffiliatedKeywords<'s>,
pub value: &'s str, pub value: &'s str,
} }
@ -172,7 +173,7 @@ impl<'s> Paragraph<'s> {
objects.push(Object::PlainText(PlainText { source: input })); objects.push(Object::PlainText(PlainText { source: input }));
Paragraph { Paragraph {
source: input, source: input,
name: None, affiliated_keywords: AffiliatedKeywords::default(),
children: objects, children: objects,
} }
} }