organic/src/parser/text_markup.rs

49 lines
1.6 KiB
Rust
Raw Normal View History

2023-04-22 23:06:48 +00:00
use nom::branch::alt;
use nom::bytes::complete::tag;
2023-04-22 22:54:19 +00:00
use super::Context;
2023-04-22 23:06:48 +00:00
use crate::error::CustomError;
use crate::error::MyError;
2023-04-22 22:54:19 +00:00
use crate::error::Res;
2023-04-22 23:06:48 +00:00
use crate::parser::util::get_one_before;
2023-04-22 22:54:19 +00:00
use crate::parser::TextMarkup;
#[tracing::instrument(ret, level = "debug")]
pub fn text_markup<'r, 's>(
context: Context<'r, 's>,
input: &'s str,
) -> Res<&'s str, TextMarkup<'s>> {
2023-04-22 23:06:48 +00:00
let (remaining, _) = pre(context, input)?;
let (remaining, open) = marker(remaining)?;
return Err(nom::Err::Error(CustomError::MyError(MyError(
"text markup not implemented yet.",
))));
2023-04-22 22:54:19 +00:00
todo!()
}
2023-04-22 23:06:48 +00:00
#[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)
}