Replace old iteration with new iteration.
This commit is contained in:
parent
8784da5179
commit
9ce042d5b6
@ -69,7 +69,7 @@ use crate::types::VerseBlock;
|
|||||||
/// This only iterates over the children, not the starting node itself. So an AstNodeIter::PlainList would only return PlainListItems, not the PlainList.
|
/// This only iterates over the children, not the starting node itself. So an AstNodeIter::PlainList would only return PlainListItems, not the PlainList.
|
||||||
///
|
///
|
||||||
/// This only iterates over AST nodes, so an AstNodeIter::Heading would iterate over both the title and section contents, but it would not iterate over simple strings like the TODO keyword or priority.
|
/// This only iterates over AST nodes, so an AstNodeIter::Heading would iterate over both the title and section contents, but it would not iterate over simple strings like the TODO keyword or priority.
|
||||||
pub enum AstNodeIter<'r, 's> {
|
pub(crate) enum AstNodeIter<'r, 's> {
|
||||||
// Document Nodes
|
// Document Nodes
|
||||||
Document(DocumentIter<'r, 's>),
|
Document(DocumentIter<'r, 's>),
|
||||||
Heading(HeadingIter<'r, 's>),
|
Heading(HeadingIter<'r, 's>),
|
||||||
@ -132,7 +132,7 @@ pub enum AstNodeIter<'r, 's> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'r, 's> AstNodeIter<'r, 's> {
|
impl<'r, 's> AstNodeIter<'r, 's> {
|
||||||
pub fn from_ast_node(node: &AstNode<'r, 's>) -> AstNodeIter<'r, 's> {
|
pub(crate) fn from_ast_node(node: &AstNode<'r, 's>) -> AstNodeIter<'r, 's> {
|
||||||
match node {
|
match node {
|
||||||
AstNode::Document(inner) => AstNodeIter::Document(inner.into_iter()),
|
AstNode::Document(inner) => AstNodeIter::Document(inner.into_iter()),
|
||||||
AstNode::Heading(inner) => AstNodeIter::Heading(inner.into_iter()),
|
AstNode::Heading(inner) => AstNodeIter::Heading(inner.into_iter()),
|
||||||
|
@ -2,3 +2,4 @@ mod all_ast_node_iter;
|
|||||||
mod ast_node;
|
mod ast_node;
|
||||||
mod ast_node_iter;
|
mod ast_node_iter;
|
||||||
mod macros;
|
mod macros;
|
||||||
|
pub(crate) use ast_node::AstNode;
|
||||||
|
@ -19,6 +19,7 @@ use crate::context::RefContext;
|
|||||||
use crate::error::CustomError;
|
use crate::error::CustomError;
|
||||||
use crate::error::MyError;
|
use crate::error::MyError;
|
||||||
use crate::error::Res;
|
use crate::error::Res;
|
||||||
|
use crate::iter::AstNode;
|
||||||
use crate::parser::org_source::convert_error;
|
use crate::parser::org_source::convert_error;
|
||||||
use crate::parser::util::blank_line;
|
use crate::parser::util::blank_line;
|
||||||
use crate::types::Document;
|
use crate::types::Document;
|
||||||
@ -111,15 +112,14 @@ fn document_org_source<'b, 'g, 'r, 's>(
|
|||||||
_document(context, input).map(|(rem, out)| (Into::<&str>::into(rem), out))?;
|
_document(context, input).map(|(rem, out)| (Into::<&str>::into(rem), out))?;
|
||||||
{
|
{
|
||||||
// If there are radio targets in this document then we need to parse the entire document again with the knowledge of the radio targets.
|
// If there are radio targets in this document then we need to parse the entire document again with the knowledge of the radio targets.
|
||||||
let all_radio_targets: Vec<&Vec<Object<'_>>> = document
|
let all_radio_targets: Vec<&Vec<Object<'_>>> = Into::<AstNode>::into(&document)
|
||||||
.iter_tokens()
|
.into_iter()
|
||||||
.filter_map(|tkn| match tkn {
|
.filter_map(|ast_node| {
|
||||||
Token::Object(obj) => Some(obj),
|
if let AstNode::RadioTarget(ast_node) = ast_node {
|
||||||
_ => None,
|
Some(ast_node)
|
||||||
})
|
} else {
|
||||||
.filter_map(|obj| match obj {
|
None
|
||||||
Object::RadioTarget(rt) => Some(rt),
|
}
|
||||||
_ => None,
|
|
||||||
})
|
})
|
||||||
.map(|rt| &rt.children)
|
.map(|rt| &rt.children)
|
||||||
.collect();
|
.collect();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user