2022-07-15 23:26:49 -04:00
|
|
|
//! A single element of text.
|
2022-10-15 14:28:24 -04:00
|
|
|
use std::cell::RefCell;
|
|
|
|
use std::rc::Rc;
|
|
|
|
|
2022-07-16 21:32:23 -04:00
|
|
|
use crate::parser::parser_with_context::parser_with_context;
|
|
|
|
use crate::parser::text::paragraph_end;
|
|
|
|
|
2022-11-24 15:40:07 -05:00
|
|
|
use super::nom_context::OrgModeContext;
|
2022-11-24 16:01:52 -05:00
|
|
|
use super::nom_context::OrgModeContextTree;
|
2022-07-16 21:55:33 -04:00
|
|
|
use super::text::bold_end;
|
|
|
|
use super::text::bold_start;
|
2022-07-15 23:26:49 -04:00
|
|
|
use super::text::line_break;
|
|
|
|
use super::text::space;
|
|
|
|
use super::text::span;
|
|
|
|
use super::text::symbol;
|
2022-07-16 21:55:33 -04:00
|
|
|
use super::text::Bold;
|
2022-07-16 20:42:56 -04:00
|
|
|
use super::text::Res;
|
2022-07-15 23:26:49 -04:00
|
|
|
use super::text::TextElement;
|
|
|
|
use nom::branch::alt;
|
|
|
|
use nom::combinator::map;
|
|
|
|
use nom::combinator::not;
|
2022-07-16 21:55:33 -04:00
|
|
|
use nom::combinator::recognize;
|
2022-07-15 23:26:49 -04:00
|
|
|
use nom::error::VerboseError;
|
2022-07-16 21:32:23 -04:00
|
|
|
use nom::multi::many_till;
|
2022-07-16 21:55:33 -04:00
|
|
|
use nom::sequence::tuple;
|
2022-07-15 23:26:49 -04:00
|
|
|
use nom::IResult;
|
2022-10-14 20:17:48 -04:00
|
|
|
|
2022-11-24 15:40:07 -05:00
|
|
|
fn flat_text_element<'s, 'r>(
|
|
|
|
i: &'s str,
|
|
|
|
context: &'r OrgModeContext<'r>,
|
|
|
|
) -> Res<&'s str, TextElement<'s>> {
|
2022-11-24 16:01:52 -05:00
|
|
|
not(|i| context.match_fail(i))(i)?;
|
2022-10-15 14:04:24 -04:00
|
|
|
|
|
|
|
alt((
|
|
|
|
map(span, TextElement::Span),
|
|
|
|
map(symbol("*"), TextElement::Symbol),
|
|
|
|
map(symbol("["), TextElement::Symbol),
|
|
|
|
map(symbol("]"), TextElement::Symbol),
|
|
|
|
map(space, TextElement::Space),
|
|
|
|
map(line_break, TextElement::LineBreak),
|
|
|
|
))(i)
|
2022-10-14 20:17:48 -04:00
|
|
|
}
|
2022-10-15 14:16:52 -04:00
|
|
|
|
2022-11-24 15:40:07 -05:00
|
|
|
fn flat_bold<'s, 'r>(i: &'s str, context: &'r OrgModeContext<'r>) -> Res<&'s str, TextElement<'s>> {
|
2022-10-30 05:54:51 -04:00
|
|
|
// let fail_matcher = recognize(bold_end);
|
|
|
|
// let new_context = context.with_additional_fail_matcher(Rc::new(RefCell::new(paragraph_end)));
|
2022-11-24 14:30:54 -05:00
|
|
|
// let new_context =
|
|
|
|
// context.with_additional_fail_matcher(Rc::new(RefCell::new(recognize(bold_end))));
|
2022-10-30 03:49:50 -04:00
|
|
|
// let new_context = context.without_bold(Rc::new(RefCell::new(recognize(bold_end))));
|
2022-10-15 14:28:24 -04:00
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
|
2022-10-15 14:16:52 -04:00
|
|
|
pub fn paragraph<'s, 'r>(
|
|
|
|
i: &'s str,
|
2022-11-24 15:40:07 -05:00
|
|
|
context: &'r OrgModeContext<'r>,
|
2022-10-15 14:16:52 -04:00
|
|
|
) -> Res<&'s str, (Vec<TextElement<'s>>, &'s str)> {
|
|
|
|
let text_element_parser = parser_with_context!(flat_text_element)(context);
|
|
|
|
many_till(text_element_parser, paragraph_end)(i)
|
|
|
|
}
|