diff --git a/src/parser/comment.rs b/src/parser/comment.rs index a6d539c..5ea95d3 100644 --- a/src/parser/comment.rs +++ b/src/parser/comment.rs @@ -67,6 +67,17 @@ fn comment_line<'b, 'g, 'r, 's>( Ok((remaining, source)) } +#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +pub fn detect_comment<'s>(input: OrgSource<'s>) -> Res, ()> { + tuple(( + start_of_line, + space0, + tag("#"), + alt((tag(" "), line_ending, eof)), + ))(input)?; + Ok((input, ())) +} + #[cfg(test)] mod tests { use super::*; diff --git a/src/parser/diary_sexp.rs b/src/parser/diary_sexp.rs index abadd4d..376b18c 100644 --- a/src/parser/diary_sexp.rs +++ b/src/parser/diary_sexp.rs @@ -23,9 +23,7 @@ pub fn diary_sexp<'b, 'g, 'r, 's>( input: OrgSource<'s>, ) -> Res, DiarySexp<'s>> { start_of_line(input)?; - let (remaining, _leading_whitespace) = space0(input)?; - let (remaining, _clock) = tag("%%")(remaining)?; - let (remaining, _gap_whitespace) = space0(remaining)?; + let (remaining, _clock) = tag("%%")(input)?; let (remaining, _sexp) = recognize(sexp)(remaining)?; let (remaining, _trailing_comment) = opt(tuple(( space0, @@ -43,3 +41,9 @@ pub fn diary_sexp<'b, 'g, 'r, 's>( }, )) } + +#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +pub fn detect_diary_sexp<'s>(input: OrgSource<'s>) -> Res, ()> { + tuple((start_of_line, tag("%%(")))(input)?; + Ok((input, ())) +} diff --git a/src/parser/element_parser.rs b/src/parser/element_parser.rs index 9dabf33..2f6b22a 100644 --- a/src/parser/element_parser.rs +++ b/src/parser/element_parser.rs @@ -4,10 +4,14 @@ use nom::multi::many0; use super::clock::clock; use super::comment::comment; +use super::comment::detect_comment; +use super::diary_sexp::detect_diary_sexp; use super::diary_sexp::diary_sexp; use super::drawer::drawer; use super::dynamic_block::dynamic_block; +use super::fixed_width_area::detect_fixed_width_area; use super::fixed_width_area::fixed_width_area; +use super::footnote_definition::detect_footnote_definition; use super::footnote_definition::footnote_definition; use super::greater_block::greater_block; use super::horizontal_rule::horizontal_rule; @@ -24,6 +28,7 @@ use super::org_source::OrgSource; use super::paragraph::paragraph; use super::plain_list::detect_plain_list; use super::plain_list::plain_list; +use super::table::detect_table; use super::util::get_consumed; use super::util::maybe_consume_trailing_whitespace_if_not_exiting; use crate::context::parser_with_context; @@ -135,7 +140,16 @@ fn _detect_element<'b, 'g, 'r, 's>( input: OrgSource<'s>, can_be_paragraph: bool, ) -> Res, ()> { - if detect_plain_list(input).is_ok() { + if alt(( + detect_plain_list, + detect_footnote_definition, + detect_diary_sexp, + detect_comment, + detect_fixed_width_area, + detect_table, + ))(input) + .is_ok() + { return Ok((input, ())); } if _element(context, input, can_be_paragraph).is_ok() { diff --git a/src/parser/fixed_width_area.rs b/src/parser/fixed_width_area.rs index b579ced..d3a0962 100644 --- a/src/parser/fixed_width_area.rs +++ b/src/parser/fixed_width_area.rs @@ -47,7 +47,7 @@ fn fixed_width_area_line<'b, 'g, 'r, 's>( ) -> Res, OrgSource<'s>> { start_of_line(input)?; let (remaining, _indent) = space0(input)?; - let (remaining, (_hash, _leading_whitespace_and_content, _line_ending)) = tuple(( + let (remaining, (_colon, _leading_whitespace_and_content, _line_ending)) = tuple(( tag(":"), opt(tuple((space1, is_not("\r\n")))), alt((line_ending, eof)), @@ -55,3 +55,14 @@ fn fixed_width_area_line<'b, 'g, 'r, 's>( let source = get_consumed(input, remaining); Ok((remaining, source)) } + +#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +pub fn detect_fixed_width_area<'s>(input: OrgSource<'s>) -> Res, ()> { + tuple(( + start_of_line, + space0, + tag(":"), + alt((tag(" "), line_ending, eof)), + ))(input)?; + Ok((input, ())) +} diff --git a/src/parser/footnote_definition.rs b/src/parser/footnote_definition.rs index 9d5d79a..a4053f1 100644 --- a/src/parser/footnote_definition.rs +++ b/src/parser/footnote_definition.rs @@ -122,7 +122,7 @@ fn footnote_definition_end<'b, 'g, 'r, 's>( } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -fn detect_footnote_definition<'s>(input: OrgSource<'s>) -> Res, ()> { +pub fn detect_footnote_definition<'s>(input: OrgSource<'s>) -> Res, ()> { tuple((start_of_line, tag_no_case("[fn:"), label, tag("]")))(input)?; Ok((input, ())) } diff --git a/src/parser/table.rs b/src/parser/table.rs index b1fe948..e836cdf 100644 --- a/src/parser/table.rs +++ b/src/parser/table.rs @@ -73,6 +73,12 @@ pub fn org_mode_table<'b, 'g, 'r, 's>( )) } +#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +pub fn detect_table<'s>(input: OrgSource<'s>) -> Res, ()> { + tuple((start_of_line, space0, tag("|")))(input)?; + Ok((input, ())) +} + #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn table_end<'b, 'g, 'r, 's>( _context: RefContext<'b, 'g, 'r, 's>,