From 84d2babda9ab6ed8b08746a0df39de7d70716c6d Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Fri, 8 Sep 2023 22:47:07 -0400 Subject: [PATCH] Parse table formulas. --- src/parser/keyword.rs | 13 +++++++++++++ src/parser/table.rs | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/src/parser/keyword.rs b/src/parser/keyword.rs index 321118e..c5cc476 100644 --- a/src/parser/keyword.rs +++ b/src/parser/keyword.rs @@ -111,6 +111,19 @@ fn babel_call_key<'s>(input: OrgSource<'s>) -> Res, OrgSource<'s>> tag_no_case("call")(input) } +#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +pub fn table_formula_keyword<'b, 'g, 'r, 's>( + _context: RefContext<'b, 'g, 'r, 's>, + input: OrgSource<'s>, +) -> Res, Keyword<'s>> { + filtered_keyword(table_formula_key)(input) +} + +#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +fn table_formula_key<'s>(input: OrgSource<'s>) -> Res, OrgSource<'s>> { + tag_no_case("tblfm")(input) +} + #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn regular_keyword_key<'s>(input: OrgSource<'s>) -> Res, OrgSource<'s>> { not(peek(alt((tag_no_case("call"), tag_no_case("begin")))))(input)?; diff --git a/src/parser/table.rs b/src/parser/table.rs index 2dbe014..69c829e 100644 --- a/src/parser/table.rs +++ b/src/parser/table.rs @@ -8,10 +8,12 @@ use nom::combinator::not; use nom::combinator::peek; use nom::combinator::recognize; use nom::combinator::verify; +use nom::multi::many0; use nom::multi::many1; use nom::multi::many_till; use nom::sequence::tuple; +use super::keyword::table_formula_keyword; use super::object_parser::table_cell_set_object; use super::org_source::OrgSource; use super::util::exit_matcher_parser; @@ -56,6 +58,9 @@ pub fn org_mode_table<'b, 'g, 'r, 's>( let (remaining, (children, _exit_contents)) = many_till(org_mode_table_row_matcher, exit_matcher)(input)?; + let (remaining, _formulas) = + many0(parser_with_context!(table_formula_keyword)(context))(remaining)?; + // TODO: Consume trailing formulas let source = get_consumed(input, remaining);