Read affiliated keywords.
This commit is contained in:
parent
759d9088f2
commit
7df899e3a7
@ -16,24 +16,32 @@ use super::lesser_block::src_block;
|
|||||||
use super::lesser_block::verse_block;
|
use super::lesser_block::verse_block;
|
||||||
use super::paragraph::paragraph;
|
use super::paragraph::paragraph;
|
||||||
use super::plain_list::plain_list;
|
use super::plain_list::plain_list;
|
||||||
|
use super::util::start_of_line;
|
||||||
use super::Context;
|
use super::Context;
|
||||||
use crate::error::Res;
|
use crate::error::Res;
|
||||||
use crate::parser::parser_with_context::parser_with_context;
|
use crate::parser::parser_with_context::parser_with_context;
|
||||||
use crate::parser::table::org_mode_table;
|
use crate::parser::table::org_mode_table;
|
||||||
use nom::branch::alt;
|
use nom::branch::alt;
|
||||||
use nom::combinator::map;
|
use nom::combinator::map;
|
||||||
|
use nom::multi::many0;
|
||||||
|
|
||||||
#[tracing::instrument(ret, level = "debug")]
|
#[tracing::instrument(ret, level = "debug")]
|
||||||
pub fn element<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Element<'s>> {
|
pub fn element<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Element<'s>> {
|
||||||
let non_paragraph_matcher = parser_with_context!(non_paragraph_element)(context);
|
let non_paragraph_matcher = parser_with_context!(non_paragraph_element)(context);
|
||||||
let paragraph_matcher = parser_with_context!(paragraph)(context);
|
let paragraph_matcher = parser_with_context!(paragraph_element)(context);
|
||||||
|
|
||||||
alt((
|
alt((non_paragraph_matcher, paragraph_matcher))(input)
|
||||||
non_paragraph_matcher,
|
|
||||||
map(paragraph_matcher, Element::Paragraph),
|
|
||||||
))(input)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn paragraph_element<'r, 's>(
|
||||||
|
context: Context<'r, 's>,
|
||||||
|
input: &'s str,
|
||||||
|
) -> Res<&'s str, Element<'s>> {
|
||||||
|
let paragraph_matcher = parser_with_context!(paragraph)(context);
|
||||||
|
let keyword_matcher = parser_with_context!(keyword)(context);
|
||||||
|
let (remaining, affiliated_keywords) = many0(keyword_matcher)(input)?;
|
||||||
|
map(paragraph_matcher, Element::Paragraph)(remaining)
|
||||||
|
}
|
||||||
pub fn non_paragraph_element<'r, 's>(
|
pub fn non_paragraph_element<'r, 's>(
|
||||||
context: Context<'r, 's>,
|
context: Context<'r, 's>,
|
||||||
input: &'s str,
|
input: &'s str,
|
||||||
@ -55,7 +63,8 @@ pub fn non_paragraph_element<'r, 's>(
|
|||||||
let fixed_width_area_matcher = parser_with_context!(fixed_width_area)(context);
|
let fixed_width_area_matcher = parser_with_context!(fixed_width_area)(context);
|
||||||
let horizontal_rule_matcher = parser_with_context!(horizontal_rule)(context);
|
let horizontal_rule_matcher = parser_with_context!(horizontal_rule)(context);
|
||||||
let keyword_matcher = parser_with_context!(keyword)(context);
|
let keyword_matcher = parser_with_context!(keyword)(context);
|
||||||
alt((
|
let (remaining, mut affiliated_keywords) = many0(keyword_matcher)(input)?;
|
||||||
|
let (remaining, element) = match alt((
|
||||||
map(plain_list_matcher, Element::PlainList),
|
map(plain_list_matcher, Element::PlainList),
|
||||||
map(greater_block_matcher, Element::GreaterBlock),
|
map(greater_block_matcher, Element::GreaterBlock),
|
||||||
map(dynamic_block_matcher, Element::DynamicBlock),
|
map(dynamic_block_matcher, Element::DynamicBlock),
|
||||||
@ -72,6 +81,13 @@ pub fn non_paragraph_element<'r, 's>(
|
|||||||
map(diary_sexp_matcher, Element::DiarySexp),
|
map(diary_sexp_matcher, Element::DiarySexp),
|
||||||
map(fixed_width_area_matcher, Element::FixedWidthArea),
|
map(fixed_width_area_matcher, Element::FixedWidthArea),
|
||||||
map(horizontal_rule_matcher, Element::HorizontalRule),
|
map(horizontal_rule_matcher, Element::HorizontalRule),
|
||||||
map(keyword_matcher, Element::Keyword),
|
))(remaining)
|
||||||
))(input)
|
{
|
||||||
|
the_ok @ Ok(_) => the_ok,
|
||||||
|
Err(_) => {
|
||||||
|
affiliated_keywords.clear();
|
||||||
|
map(keyword_matcher, Element::Keyword)(input)
|
||||||
|
}
|
||||||
|
}?;
|
||||||
|
Ok((remaining, element))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user