Implement a parser for a bullet in a list item.
This commit is contained in:
parent
76b2325486
commit
b4e28f3d4d
@ -1,4 +1,12 @@
|
||||
use nom::branch::alt;
|
||||
use nom::bytes::complete::tag;
|
||||
use nom::character::complete::digit1;
|
||||
use nom::character::complete::one_of;
|
||||
use nom::combinator::recognize;
|
||||
use nom::sequence::tuple;
|
||||
|
||||
use super::error::Res;
|
||||
use super::token::ListItem;
|
||||
use super::token::PlainList;
|
||||
use super::Context;
|
||||
|
||||
@ -6,3 +14,21 @@ pub fn plain_list<'r, 's>(context: Context<'r, 's>, i: &'s str) -> Res<&'s str,
|
||||
// todo
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn item<'r, 's>(context: Context<'r, 's>, i: &'s str) -> Res<&'s str, ListItem<'s>> {
|
||||
// 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)
|
||||
}
|
||||
|
@ -106,3 +106,25 @@ impl<'a> Source<'a> for PlainList<'a> {
|
||||
self.source
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ListItem<'a> {
|
||||
pub source: &'a str,
|
||||
}
|
||||
|
||||
impl<'a> Source<'a> for ListItem<'a> {
|
||||
fn get_source(&'a self) -> &'a str {
|
||||
self.source
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ListCounter<'a> {
|
||||
pub source: &'a str,
|
||||
}
|
||||
|
||||
impl<'a> Source<'a> for ListCounter<'a> {
|
||||
fn get_source(&'a self) -> &'a str {
|
||||
self.source
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user