Starting to implement table cell.

This commit is contained in:
Tom Alexander 2023-04-19 21:57:08 -04:00
parent 9747e0ba11
commit 55201e905a
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
3 changed files with 56 additions and 1 deletions

View File

@ -65,4 +65,10 @@ pub struct Table<'s> {
#[derive(Debug)] #[derive(Debug)]
pub struct TableRow<'s> { pub struct TableRow<'s> {
pub source: &'s str, pub source: &'s str,
pub children: Vec<TableCell<'s>>,
}
#[derive(Debug)]
pub struct TableCell<'s> {
pub source: &'s str,
} }

View File

@ -54,3 +54,15 @@ pub fn standard_set_object<'r, 's>(
map(plain_text_matcher, Object::PlainText)(input) map(plain_text_matcher, Object::PlainText)(input)
} }
#[tracing::instrument(ret, level = "debug")]
pub fn minimal_set_object<'r, 's>(
context: Context<'r, 's>,
input: &'s str,
) -> Res<&'s str, Object<'s>> {
not(|i| context.check_exit_matcher(i))(input)?;
let plain_text_matcher = parser_with_context!(plain_text)(context);
map(plain_text_matcher, Object::PlainText)(input)
}

View File

@ -6,13 +6,16 @@ use nom::character::complete::space0;
use nom::combinator::not; use nom::combinator::not;
use nom::combinator::peek; use nom::combinator::peek;
use nom::combinator::recognize; use nom::combinator::recognize;
use nom::multi::many1;
use nom::multi::many_till; use nom::multi::many_till;
use nom::sequence::tuple; use nom::sequence::tuple;
use super::Context; use super::Context;
use crate::parser::error::Res; use crate::parser::error::Res;
use crate::parser::exiting::ExitClass; use crate::parser::exiting::ExitClass;
use crate::parser::greater_element::TableCell;
use crate::parser::greater_element::TableRow; use crate::parser::greater_element::TableRow;
use crate::parser::object::minimal_set_object;
use crate::parser::parser_context::ContextElement; use crate::parser::parser_context::ContextElement;
use crate::parser::parser_context::ExitMatcherNode; use crate::parser::parser_context::ExitMatcherNode;
use crate::parser::parser_with_context::parser_with_context; use crate::parser::parser_with_context::parser_with_context;
@ -77,7 +80,13 @@ pub fn org_mode_table_row_rule<'r, 's>(
start_of_line(context, input)?; start_of_line(context, input)?;
let (remaining, _) = tuple((space0, tag("|-"), is_not("\r\n"), line_ending))(input)?; let (remaining, _) = tuple((space0, tag("|-"), is_not("\r\n"), line_ending))(input)?;
let source = get_consumed(input, remaining); let source = get_consumed(input, remaining);
Ok((remaining, TableRow { source })) Ok((
remaining,
TableRow {
source,
children: Vec::new(),
},
))
} }
#[tracing::instrument(ret, level = "debug")] #[tracing::instrument(ret, level = "debug")]
@ -85,5 +94,33 @@ pub fn org_mode_table_row_regular<'r, 's>(
context: Context<'r, 's>, context: Context<'r, 's>,
input: &'s str, input: &'s str,
) -> Res<&'s str, TableRow<'s>> { ) -> Res<&'s str, TableRow<'s>> {
start_of_line(context, input)?;
let (remaining, _) = tuple((space0, tag("|")))(input)?;
let (remaining, children) =
many1(parser_with_context!(org_mode_table_cell)(context))(remaining)?;
let source = get_consumed(input, remaining);
Ok((remaining, TableRow { source, children }))
}
#[tracing::instrument(ret, level = "debug")]
pub fn org_mode_table_cell<'r, 's>(
context: Context<'r, 's>,
input: &'s str,
) -> Res<&'s str, TableCell<'s>> {
let parser_context =
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
class: ExitClass::Beta,
exit_matcher: &org_mode_table_cell_end,
}));
let minimal_set_object_matcher = parser_with_context!(minimal_set_object)(&parser_context);
todo!() todo!()
} }
#[tracing::instrument(ret, level = "debug")]
fn org_mode_table_cell_end<'r, 's>(
context: Context<'r, 's>,
input: &'s str,
) -> Res<&'s str, &'s str> {
recognize(tuple((space0, alt((tag("|"), peek(line_ending))))))(input)
}