2022-12-18 10:02:32 +00:00
|
|
|
use nom::branch::alt;
|
|
|
|
use nom::bytes::complete::tag;
|
2022-12-18 11:31:40 +00:00
|
|
|
use nom::character::complete::anychar;
|
2022-12-18 10:02:32 +00:00
|
|
|
use nom::character::complete::digit1;
|
2022-12-18 11:31:40 +00:00
|
|
|
use nom::character::complete::line_ending;
|
2022-12-18 10:02:32 +00:00
|
|
|
use nom::character::complete::one_of;
|
2022-12-18 12:18:42 +00:00
|
|
|
use nom::combinator::consumed;
|
2022-12-18 11:31:40 +00:00
|
|
|
use nom::combinator::not;
|
2022-12-18 12:18:42 +00:00
|
|
|
use nom::combinator::opt;
|
2022-12-18 10:02:32 +00:00
|
|
|
use nom::combinator::recognize;
|
2022-12-18 11:31:40 +00:00
|
|
|
use nom::multi::many1;
|
2022-12-18 10:02:32 +00:00
|
|
|
use nom::sequence::tuple;
|
|
|
|
|
2022-12-18 12:18:42 +00:00
|
|
|
use super::combinator::context_many_till;
|
2022-12-18 08:29:01 +00:00
|
|
|
use super::error::Res;
|
2022-12-18 12:18:42 +00:00
|
|
|
use super::text::space;
|
|
|
|
use super::text::text_element;
|
2022-12-18 10:02:32 +00:00
|
|
|
use super::token::ListItem;
|
2022-12-18 08:29:01 +00:00
|
|
|
use super::token::PlainList;
|
|
|
|
use super::Context;
|
|
|
|
|
|
|
|
pub fn plain_list<'r, 's>(context: Context<'r, 's>, i: &'s str) -> Res<&'s str, PlainList<'s>> {
|
|
|
|
// todo
|
|
|
|
todo!()
|
|
|
|
}
|
2022-12-18 10:02:32 +00:00
|
|
|
|
|
|
|
fn item<'r, 's>(context: Context<'r, 's>, i: &'s str) -> Res<&'s str, ListItem<'s>> {
|
2022-12-18 12:18:42 +00:00
|
|
|
let _ = consumed(tuple((
|
|
|
|
bullet,
|
|
|
|
opt(tuple((space, counter_set))),
|
|
|
|
opt(tuple((space, check_box))),
|
|
|
|
opt(tuple((space, item_tag))),
|
|
|
|
space,
|
|
|
|
context_many_till(context, text_element, item_end),
|
|
|
|
)))(i)?;
|
2022-12-18 10:02:32 +00:00
|
|
|
// todo
|
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn counter<'s>(i: &'s str) -> Res<&'s str, &'s str> {
|
|
|
|
alt((recognize(one_of("abcdefghijklmnopqrstuvwxyz")), digit1))(i)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn bullet<'s>(i: &'s str) -> Res<&'s str, &'s str> {
|
|
|
|
alt((
|
|
|
|
tag("*"),
|
|
|
|
tag("-"),
|
|
|
|
tag("+"),
|
|
|
|
recognize(tuple((counter, alt((tag("."), tag(")")))))),
|
|
|
|
))(i)
|
|
|
|
}
|
2022-12-18 11:31:40 +00:00
|
|
|
|
|
|
|
fn counter_set<'s>(i: &'s str) -> Res<&'s str, &'s str> {
|
|
|
|
recognize(tuple((tag("[@"), counter, tag("]"))))(i)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn check_box<'s>(i: &'s str) -> Res<&'s str, &'s str> {
|
|
|
|
recognize(alt((tag("[ ]"), tag("[X]"), tag("[-]"))))(i)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn item_tag<'s>(i: &'s str) -> Res<&'s str, &'s str> {
|
|
|
|
recognize(tuple((tag_text, tag_separator)))(i)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn tag_text<'s>(i: &'s str) -> Res<&'s str, &'s str> {
|
|
|
|
recognize(many1(tag_text_character))(i)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn tag_text_character<'s>(i: &'s str) -> Res<&'s str, &'s str> {
|
|
|
|
not(alt((tag_separator, line_ending)))(i)?;
|
|
|
|
recognize(anychar)(i)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn tag_separator<'s>(i: &'s str) -> Res<&'s str, &'s str> {
|
|
|
|
tag(" :: ")(i)
|
|
|
|
}
|
2022-12-18 12:18:42 +00:00
|
|
|
|
|
|
|
pub fn item_end<'r, 's>(context: Context<'r, 's>, i: &'s str) -> Res<&'s str, &'s str> {
|
|
|
|
// todo
|
|
|
|
todo!()
|
|
|
|
}
|