Expose a document parser and implement the paragraph parser so something is hitting our macro.
This commit is contained in:
parent
040671b98f
commit
fdd5b532fc
@ -1,6 +1,4 @@
|
|||||||
use nom::multi::many1;
|
use crate::parser::document;
|
||||||
|
|
||||||
use crate::parser::paragraph;
|
|
||||||
|
|
||||||
mod parser;
|
mod parser;
|
||||||
|
|
||||||
@ -9,6 +7,6 @@ const TEST_DOC: &'static str = include_str!("../toy_language.txt");
|
|||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
pretty_env_logger::init();
|
pretty_env_logger::init();
|
||||||
println!("{}\n\n\n", TEST_DOC);
|
println!("{}\n\n\n", TEST_DOC);
|
||||||
println!("{:#?}", many1(paragraph)(TEST_DOC));
|
println!("{:#?}", document(TEST_DOC));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -2,4 +2,4 @@ mod nom_context;
|
|||||||
mod parser_with_context;
|
mod parser_with_context;
|
||||||
mod text;
|
mod text;
|
||||||
mod text_element_parser;
|
mod text_element_parser;
|
||||||
pub use text::paragraph;
|
pub use text::document;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
macro_rules! parser_with_context {
|
macro_rules! parser_with_context {
|
||||||
($name:ident,$typ:ty,$inp:ident,$context:ident,$fnbody:block) => {
|
($name:ident,$typ:ty,$inp:ident,$context:ident,$fnbody:block) => {
|
||||||
pub fn $name<'c, I: Clone, O, E: nom::error::ParseError<I>>(
|
pub fn $name<'c, I: Clone, O, E: nom::error::ParseError<I>>(
|
||||||
$context: &mut NomContext<'c, I, O, E>,
|
$context: NomContext<'c, I, O, E>,
|
||||||
) -> impl for<'a> FnMut(&'a str) -> IResult<&'a str, $typ, VerboseError<&'a str>> + 'c {
|
) -> impl for<'a> FnMut(&'a str) -> IResult<&'a str, $typ, VerboseError<&'a str>> + 'c {
|
||||||
|$inp| $fnbody
|
|$inp| $fnbody
|
||||||
}
|
}
|
||||||
|
@ -18,10 +18,14 @@ use nom::character::complete::space1;
|
|||||||
use nom::combinator::map;
|
use nom::combinator::map;
|
||||||
use nom::combinator::recognize;
|
use nom::combinator::recognize;
|
||||||
use nom::error::VerboseError;
|
use nom::error::VerboseError;
|
||||||
|
use nom::multi::many1;
|
||||||
use nom::multi::many_till;
|
use nom::multi::many_till;
|
||||||
use nom::sequence::tuple;
|
use nom::sequence::tuple;
|
||||||
use nom::IResult;
|
use nom::IResult;
|
||||||
|
|
||||||
|
use super::nom_context::NomContext;
|
||||||
|
use super::text_element_parser::text_element;
|
||||||
|
|
||||||
pub type Res<T, U> = IResult<T, U, VerboseError<T>>;
|
pub type Res<T, U> = IResult<T, U, VerboseError<T>>;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -125,10 +129,14 @@ pub fn link_end(input: &str) -> Res<&str, TextElement> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn paragraph(input: &str) -> Res<&str, (Vec<TextElement>, &str)> {
|
pub fn paragraph(input: &str) -> Res<&str, (Vec<TextElement>, &str)> {
|
||||||
todo!()
|
let initial_context = NomContext::new(¶graph_end);
|
||||||
// many_till(TextElementParser::new(paragraph_end), paragraph_end)(input)
|
many_till(text_element(initial_context), paragraph_end)(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn paragraph_end(input: &str) -> Res<&str, &str> {
|
fn paragraph_end(input: &str) -> Res<&str, &str> {
|
||||||
recognize(tuple((map(line_break, TextElement::LineBreak), blank_line)))(input)
|
recognize(tuple((map(line_break, TextElement::LineBreak), blank_line)))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn document(input: &str) -> Res<&str, Vec<(Vec<TextElement>, &str)>> {
|
||||||
|
many1(paragraph)(input)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user