Starting to parse text markup.
This commit is contained in:
parent
80f43d54da
commit
c0809cce10
@ -1,5 +1,11 @@
|
|||||||
|
use nom::branch::alt;
|
||||||
|
use nom::bytes::complete::tag;
|
||||||
|
|
||||||
use super::Context;
|
use super::Context;
|
||||||
|
use crate::error::CustomError;
|
||||||
|
use crate::error::MyError;
|
||||||
use crate::error::Res;
|
use crate::error::Res;
|
||||||
|
use crate::parser::util::get_one_before;
|
||||||
use crate::parser::TextMarkup;
|
use crate::parser::TextMarkup;
|
||||||
|
|
||||||
#[tracing::instrument(ret, level = "debug")]
|
#[tracing::instrument(ret, level = "debug")]
|
||||||
@ -7,5 +13,36 @@ pub fn text_markup<'r, 's>(
|
|||||||
context: Context<'r, 's>,
|
context: Context<'r, 's>,
|
||||||
input: &'s str,
|
input: &'s str,
|
||||||
) -> Res<&'s str, TextMarkup<'s>> {
|
) -> Res<&'s str, TextMarkup<'s>> {
|
||||||
|
let (remaining, _) = pre(context, input)?;
|
||||||
|
let (remaining, open) = marker(remaining)?;
|
||||||
|
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
||||||
|
"text markup not implemented yet.",
|
||||||
|
))));
|
||||||
|
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(ret, level = "debug")]
|
||||||
|
pub fn pre<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, ()> {
|
||||||
|
let document_root = context.get_document_root().unwrap();
|
||||||
|
let preceding_character = get_one_before(document_root, input)
|
||||||
|
.map(|slice| slice.chars().next())
|
||||||
|
.flatten();
|
||||||
|
match preceding_character {
|
||||||
|
// If None, we are at the start of the file which is technically the beginning of a line.
|
||||||
|
None | Some('\r') | Some('\n') | Some(' ') | Some('\t') | Some('-') | Some('(')
|
||||||
|
| Some('{') | Some('\'') | Some('"') => {}
|
||||||
|
Some(_) => {
|
||||||
|
// Not at start of line, cannot be a heading
|
||||||
|
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
||||||
|
"Not a valid pre character for text markup.",
|
||||||
|
))));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Ok((input, ()))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(ret, level = "debug")]
|
||||||
|
pub fn marker(input: &str) -> Res<&str, &str> {
|
||||||
|
alt((tag("*"), tag("/"), tag("_"), tag("="), tag("~"), tag("+")))(input)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user