diff --git a/src/parser/affiliated_keyword.rs b/src/parser/affiliated_keyword.rs index 0dc9cfa..dc43820 100644 --- a/src/parser/affiliated_keyword.rs +++ b/src/parser/affiliated_keyword.rs @@ -1,7 +1,18 @@ use std::collections::BTreeMap; +use nom::bytes::complete::tag; +use nom::bytes::complete::take_until; +use nom::character::complete::anychar; use nom::combinator::all_consuming; +use nom::combinator::eof; +use nom::combinator::map; +use nom::combinator::map_parser; +use nom::combinator::opt; +use nom::combinator::peek; +use nom::combinator::recognize; use nom::multi::many0; +use nom::multi::many_till; +use nom::sequence::tuple; use super::object_parser::standard_set_object; use crate::context::parser_with_context; @@ -45,6 +56,23 @@ pub(crate) fn parse_affiliated_keywords<'g, 's>( let initial_context = ContextElement::document_context(); let initial_context = Context::new(global_settings, List::new(&initial_context)); + let (_remaining, optional_objects) = opt(all_consuming(map( + tuple(( + take_until("["), + tag("["), + map_parser( + recognize(many_till(anychar, peek(tuple((tag("]"), eof))))), + all_consuming(many0(parser_with_context!(standard_set_object)( + &initial_context, + ))), + ), + tag("]"), + eof, + )), + |(_, _, objects, _, _)| objects, + )))(kw.key.into()) + .expect("Object parser should always succeed."); + // TODO: This should be omitting footnote references let (_remaining, objects) = all_consuming(many0(parser_with_context!( standard_set_object @@ -55,7 +83,7 @@ pub(crate) fn parse_affiliated_keywords<'g, 's>( }); match list_of_lists { AffiliatedKeywordValue::ListOfListsOfObjects(list_of_lists) => { - list_of_lists.push(objects); + list_of_lists.push((optional_objects, objects)); } _ => panic!("Invalid AffiliatedKeywordValue type."), } diff --git a/src/types/affiliated_keyword.rs b/src/types/affiliated_keyword.rs index f3dd94e..5831a4d 100644 --- a/src/types/affiliated_keyword.rs +++ b/src/types/affiliated_keyword.rs @@ -6,7 +6,7 @@ use super::Object; pub enum AffiliatedKeywordValue<'s> { SingleString(&'s str), ListOfStrings(Vec<&'s str>), - ListOfListsOfObjects(Vec>>), + ListOfListsOfObjects(Vec<(Option>>, Vec>)>), } #[derive(Debug)]