Populate entity fields.

This commit is contained in:
Tom Alexander
2023-10-08 18:06:56 -04:00
parent c150aa4dea
commit ef591556fe
4 changed files with 17 additions and 4 deletions

View File

@@ -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<OrgSource<'s>, 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>, OrgSource<'s>> {
) -> Res<OrgSource<'s>, (&'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(_) => {}
}