Use macros for creating the intermediate stage.
This is to make it easier to change function signatures by consolidating the places where the signatures exist.
This commit is contained in:
@@ -9,14 +9,17 @@ use super::ast_node::IAstNode;
|
||||
|
||||
type IdCounter = u16;
|
||||
|
||||
pub(crate) struct Registry<'parse> {
|
||||
pub(crate) struct Registry<'orig, 'parse> {
|
||||
id_counter: IdCounter,
|
||||
targets: HashMap<&'parse str, String>,
|
||||
footnote_ids: Vec<(Option<&'parse str>, Vec<IAstNode>)>,
|
||||
footnote_ids: Vec<(
|
||||
Option<&'parse str>,
|
||||
FootnoteDefinitionContents<'orig, 'parse>,
|
||||
)>,
|
||||
}
|
||||
|
||||
impl<'parse> Registry<'parse> {
|
||||
pub(crate) fn new() -> Registry<'parse> {
|
||||
impl<'orig, 'parse> Registry<'orig, 'parse> {
|
||||
pub(crate) fn new() -> Registry<'orig, 'parse> {
|
||||
Registry {
|
||||
id_counter: 0,
|
||||
targets: HashMap::new(),
|
||||
@@ -24,7 +27,7 @@ impl<'parse> Registry<'parse> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn get_target<'b>(&'b mut self, body: &'parse str) -> &'b String {
|
||||
pub(crate) fn get_target<'reg>(&'reg mut self, body: &'parse str) -> &'reg String {
|
||||
self.targets.entry(body).or_insert_with(|| {
|
||||
self.id_counter += 1;
|
||||
format!("target_{}", self.id_counter)
|
||||
@@ -32,19 +35,21 @@ impl<'parse> Registry<'parse> {
|
||||
}
|
||||
|
||||
pub(crate) fn get_footnote_ids(&self) -> impl Iterator<Item = (usize, &Vec<IAstNode>)> {
|
||||
self.footnote_ids
|
||||
.iter()
|
||||
.map(|(_label, definition)| definition)
|
||||
.enumerate()
|
||||
// TODO
|
||||
std::iter::empty()
|
||||
// self.footnote_ids
|
||||
// .iter()
|
||||
// .map(|(_label, definition)| definition)
|
||||
// .enumerate()
|
||||
}
|
||||
|
||||
/// Get a 0-indexed ID for a footnote.
|
||||
///
|
||||
/// This needs to be incremented to be 1-indexed for render.
|
||||
pub(crate) async fn get_footnote_reference_id<'b>(
|
||||
&'b mut self,
|
||||
pub(crate) async fn get_footnote_reference_id<'reg>(
|
||||
&'reg mut self,
|
||||
label: Option<&'parse str>,
|
||||
definition: &'b Vec<Object<'parse>>,
|
||||
definition: &'orig Vec<Object<'parse>>,
|
||||
) -> Result<usize, CustomError> {
|
||||
if let None = label {
|
||||
// If it has no label then it must always get a new ID.
|
||||
@@ -75,10 +80,10 @@ impl<'parse> Registry<'parse> {
|
||||
}
|
||||
|
||||
/// Update the definition to a footnote but do not mark it as referenced.
|
||||
pub(crate) async fn register_footnote_definition<'b>(
|
||||
&'b mut self,
|
||||
pub(crate) async fn register_footnote_definition<'reg>(
|
||||
&'reg mut self,
|
||||
label: &'parse str,
|
||||
definition: &'b Vec<Element<'parse>>,
|
||||
definition: &'orig Vec<Element<'parse>>,
|
||||
) -> Result<(), CustomError> {
|
||||
let contents = convert_definition_contents(self, definition).await?;
|
||||
if let Some((_existing_id, existing_definition)) = self
|
||||
@@ -92,9 +97,9 @@ impl<'parse> Registry<'parse> {
|
||||
}
|
||||
}
|
||||
|
||||
async fn convert_reference_contents<'b, 'parse>(
|
||||
registry: &'b mut Registry<'parse>,
|
||||
contents: &'b Vec<Object<'parse>>,
|
||||
async fn convert_reference_contents<'reg, 'orig, 'parse>(
|
||||
registry: &'reg mut Registry<'orig, 'parse>,
|
||||
contents: &'orig Vec<Object<'parse>>,
|
||||
) -> Result<Vec<IAstNode>, CustomError> {
|
||||
let contents = {
|
||||
let mut ret = Vec::new();
|
||||
@@ -107,9 +112,9 @@ async fn convert_reference_contents<'b, 'parse>(
|
||||
Ok(contents)
|
||||
}
|
||||
|
||||
async fn convert_definition_contents<'b, 'parse>(
|
||||
registry: &'b mut Registry<'parse>,
|
||||
contents: &'b Vec<Element<'parse>>,
|
||||
async fn convert_definition_contents<'reg, 'orig, 'parse>(
|
||||
registry: &'reg mut Registry<'orig, 'parse>,
|
||||
contents: &'orig Vec<Element<'parse>>,
|
||||
) -> Result<Vec<IAstNode>, CustomError> {
|
||||
let contents = {
|
||||
let mut ret = Vec::new();
|
||||
@@ -121,3 +126,8 @@ async fn convert_definition_contents<'b, 'parse>(
|
||||
|
||||
Ok(contents)
|
||||
}
|
||||
|
||||
enum FootnoteDefinitionContents<'orig, 'parse> {
|
||||
FromReference(&'orig Vec<Object<'parse>>),
|
||||
FromDefinition(&'orig Vec<Object<'parse>>),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user