From ef591556fed1a5988b1f3428c996fab02a36221d Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 8 Oct 2023 18:06:56 -0400 Subject: [PATCH] Populate entity fields. --- src/context/global_settings.rs | 2 +- src/context/mod.rs | 1 + src/parser/entity.rs | 12 +++++++++--- src/types/object.rs | 6 ++++++ 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/context/global_settings.rs b/src/context/global_settings.rs index 161cb23..0ee7b4d 100644 --- a/src/context/global_settings.rs +++ b/src/context/global_settings.rs @@ -51,7 +51,7 @@ pub struct GlobalSettings<'g, 's> { /// The special characters that can be written in org-mode like \infin for the infinity symbol. /// /// Corresponds to org-entities elisp variable. - pub entities: &'g [EntityDefinition<'g>], + pub entities: &'g [EntityDefinition<'s>], } pub const DEFAULT_TAB_WIDTH: IndentationLevel = 8; diff --git a/src/context/mod.rs b/src/context/mod.rs index 983a1a8..40b7e27 100644 --- a/src/context/mod.rs +++ b/src/context/mod.rs @@ -26,6 +26,7 @@ pub(crate) use context::HasAffiliatedKeywordInner; pub(crate) use exiting::ExitClass; pub use file_access_interface::FileAccessInterface; pub use file_access_interface::LocalFileAccessInterface; +pub use global_settings::EntityDefinition; pub use global_settings::GlobalSettings; pub use global_settings::HeadlineLevelFilter; pub use global_settings::DEFAULT_TAB_WIDTH; diff --git a/src/parser/entity.rs b/src/parser/entity.rs index 1efac02..452b970 100644 --- a/src/parser/entity.rs +++ b/src/parser/entity.rs @@ -8,6 +8,7 @@ use nom::sequence::tuple; use super::org_source::OrgSource; use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting; +use crate::context::EntityDefinition; use crate::context::RefContext; use crate::error::CustomError; use crate::error::MyError; @@ -21,7 +22,7 @@ pub(crate) fn entity<'b, 'g, 'r, 's>( input: OrgSource<'s>, ) -> Res, Entity<'s>> { let (remaining, _) = tag("\\")(input)?; - let (remaining, entity_name) = name(context, remaining)?; + let (remaining, (entity_definition, entity_name)) = name(context, remaining)?; let (remaining, _trailing_whitespace) = maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?; @@ -32,6 +33,11 @@ pub(crate) fn entity<'b, 'g, 'r, 's>( Entity { source: source.into(), name: entity_name.into(), + latex_math_mode: entity_definition.latex_math_mode, + latex: entity_definition.latex, + html: entity_definition.html, + ascii: entity_definition.ascii, + utf8: entity_definition.utf8, }, )) } @@ -40,7 +46,7 @@ pub(crate) fn entity<'b, 'g, 'r, 's>( fn name<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, -) -> Res, OrgSource<'s>> { +) -> Res, (&'g EntityDefinition<'s>, OrgSource<'s>)> { for entity in context.get_global_settings().entities { let result = tuple(( tag::<_, _, CustomError<_>>(entity.name), @@ -48,7 +54,7 @@ fn name<'b, 'g, 'r, 's>( ))(input); match result { Ok((remaining, (ent, _))) => { - return Ok((remaining, ent)); + return Ok((remaining, (entity, ent))); } Err(_) => {} } diff --git a/src/types/object.rs b/src/types/object.rs index f769b06..1683b77 100644 --- a/src/types/object.rs +++ b/src/types/object.rs @@ -168,6 +168,12 @@ pub struct OrgMacro<'s> { pub struct Entity<'s> { pub source: &'s str, pub name: &'s str, + pub latex_math_mode: bool, + pub latex: &'s str, + pub html: &'s str, + pub ascii: &'s str, + // Skipping latin1 because it is detrimental to the future. If anyone out there is using latin1, take a long look in the mirror and change your ways. + pub utf8: &'s str, } #[derive(Debug, PartialEq)]