Fixing more errors.

This commit is contained in:
Tom Alexander 2023-09-03 12:23:18 -04:00
parent fdf35ba23c
commit 3bdb24ad88
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
15 changed files with 62 additions and 29 deletions

View File

@ -12,10 +12,12 @@ use nom::combinator::verify;
use nom::sequence::tuple;
use super::org_source::OrgSource;
use crate::context::parser_with_context;
use crate::context::RefContext;
use crate::error::Res;
use crate::parser::util::get_consumed;
use crate::parser::util::start_of_line;
use crate::parser::Clock;
use crate::types::Clock;
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
pub fn clock<'r, 's>(

View File

@ -14,6 +14,7 @@ use nom::sequence::tuple;
use super::org_source::OrgSource;
use super::util::get_consumed;
use crate::context::parser_with_context;
use crate::context::ContextElement;
use crate::context::RefContext;
use crate::error::CustomError;
use crate::error::MyError;
@ -33,7 +34,8 @@ pub fn comment<'r, 's>(
"Cannot nest objects of the same element".into(),
))));
}
let parser_context = context.with_additional_node(ContextElement::Context("comment"));
let parser_context = ContextElement::Context("comment");
let parser_context = context.with_additional_node(&parser_context);
let comment_line_matcher = parser_with_context!(comment_line)(&parser_context);
let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context);
let (remaining, _first_line) = comment_line_matcher(input)?;

View File

@ -11,10 +11,11 @@ use nom::sequence::tuple;
use super::org_source::OrgSource;
use super::sexp::sexp;
use crate::context::RefContext;
use crate::error::Res;
use crate::parser::util::get_consumed;
use crate::parser::util::start_of_line;
use crate::parser::DiarySexp;
use crate::types::DiarySexp;
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
pub fn diary_sexp<'r, 's>(

View File

@ -7,7 +7,6 @@ use super::comment::comment;
use super::diary_sexp::diary_sexp;
use super::drawer::drawer;
use super::dynamic_block::dynamic_block;
use super::element::Element;
use super::fixed_width_area::fixed_width_area;
use super::footnote_definition::footnote_definition;
use super::greater_block::greater_block;
@ -26,15 +25,20 @@ use super::plain_list::detect_plain_list;
use super::plain_list::plain_list;
use super::util::get_consumed;
use super::util::maybe_consume_trailing_whitespace_if_not_exiting;
use crate::context::parser_with_context;
use crate::context::RefContext;
use crate::error::CustomError;
use crate::error::MyError;
use crate::error::Res;
use crate::parser::table::org_mode_table;
use crate::types::Element;
use crate::types::SetSource;
pub const fn element(
can_be_paragraph: bool,
) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res<OrgSource<'s>, Element<'s>> {
move |context: Context, input: OrgSource<'_>| _element(context, input, can_be_paragraph)
) -> impl for<'b, 'r, 's> Fn(RefContext<'b, 'r, 's>, OrgSource<'s>) -> Res<OrgSource<'s>, Element<'s>>
{
move |context, input: OrgSource<'_>| _element(context, input, can_be_paragraph)
}
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
@ -115,8 +119,8 @@ fn _element<'r, 's>(
pub const fn detect_element(
can_be_paragraph: bool,
) -> impl for<'r, 's> Fn(Context<'r, 's>, OrgSource<'s>) -> Res<OrgSource<'s>, ()> {
move |context: Context, input: OrgSource<'_>| _detect_element(context, input, can_be_paragraph)
) -> impl for<'b, 'r, 's> Fn(RefContext<'b, 'r, 's>, OrgSource<'s>) -> Res<OrgSource<'s>, ()> {
move |context, input: OrgSource<'_>| _detect_element(context, input, can_be_paragraph)
}
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]

View File

@ -8,11 +8,12 @@ use nom::combinator::recognize;
use super::org_source::OrgSource;
use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting;
use crate::context::RefContext;
use crate::error::CustomError;
use crate::error::MyError;
use crate::error::Res;
use crate::parser::object::Entity;
use crate::parser::util::get_consumed;
use crate::types::Entity;
// TODO: Make this a user-provided variable corresponding to elisp's org-entities
const ORG_ENTITIES: [&'static str; 413] = [

View File

@ -12,11 +12,13 @@ use nom::sequence::preceded;
use nom::sequence::tuple;
use super::org_source::OrgSource;
use crate::context::parser_with_context;
use crate::context::RefContext;
use crate::error::Res;
use crate::parser::util::exit_matcher_parser;
use crate::parser::util::get_consumed;
use crate::parser::util::start_of_line;
use crate::parser::FixedWidthArea;
use crate::types::FixedWidthArea;
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
pub fn fixed_width_area<'r, 's>(

View File

@ -9,9 +9,10 @@ use nom::multi::many1_count;
use nom::sequence::tuple;
use super::org_source::OrgSource;
use crate::context::RefContext;
use crate::error::Res;
use crate::parser::util::start_of_line;
use crate::parser::HorizontalRule;
use crate::types::HorizontalRule;
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
pub fn horizontal_rule<'r, 's>(

View File

@ -16,11 +16,12 @@ use nom::sequence::tuple;
use super::org_source::BracketDepth;
use super::org_source::OrgSource;
use crate::context::RefContext;
use crate::error::CustomError;
use crate::error::MyError;
use crate::error::Res;
use crate::parser::util::start_of_line;
use crate::parser::Keyword;
use crate::types::Keyword;
const ORG_ELEMENT_AFFILIATED_KEYWORDS: [&'static str; 13] = [
"caption", "data", "header", "headers", "label", "name", "plot", "resname", "result",

View File

@ -14,12 +14,14 @@ use nom::sequence::tuple;
use super::org_source::OrgSource;
use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting;
use crate::context::parser_with_context;
use crate::context::RefContext;
use crate::error::CustomError;
use crate::error::MyError;
use crate::error::Res;
use crate::parser::util::exit_matcher_parser;
use crate::parser::util::get_consumed;
use crate::parser::LatexFragment;
use crate::types::LatexFragment;
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
pub fn latex_fragment<'r, 's>(
@ -172,7 +174,10 @@ fn dollar_char_fragment<'r, 's>(
}
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
pub fn pre<'r, 's>(_context: RefContext<'_, 'r, 's>, input: OrgSource<'s>) -> Res<OrgSource<'s>, ()> {
pub fn pre<'r, 's>(
_context: RefContext<'_, 'r, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, ()> {
let preceding_character = input.get_preceding_character();
if let Some('$') = preceding_character {
return Err(nom::Err::Error(CustomError::MyError(MyError(
@ -183,7 +188,10 @@ pub fn pre<'r, 's>(_context: RefContext<'_, 'r, 's>, input: OrgSource<'s>) -> Re
}
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
pub fn post<'r, 's>(_context: RefContext<'_, 'r, 's>, input: OrgSource<'s>) -> Res<OrgSource<'s>, ()> {
pub fn post<'r, 's>(
_context: RefContext<'_, 'r, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, ()> {
// TODO: What about eof? Test to find out.
// TODO: Figure out which punctuation characters should be included.

View File

@ -5,11 +5,12 @@ use nom::combinator::recognize;
use nom::multi::many0;
use super::org_source::OrgSource;
use crate::context::RefContext;
use crate::error::CustomError;
use crate::error::MyError;
use crate::error::Res;
use crate::parser::util::get_consumed;
use crate::parser::LineBreak;
use crate::types::LineBreak;
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
pub fn line_break<'r, 's>(

View File

@ -9,12 +9,13 @@ use nom::multi::separated_list0;
use super::org_source::OrgSource;
use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting;
use super::Context;
use crate::context::parser_with_context;
use crate::context::RefContext;
use crate::error::CustomError;
use crate::error::Res;
use crate::parser::object::OrgMacro;
use crate::parser::util::exit_matcher_parser;
use crate::parser::util::get_consumed;
use crate::types::OrgMacro;
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
pub fn org_macro<'r, 's>(

View File

@ -373,6 +373,7 @@ mod tests {
use crate::context::Context;
use crate::context::GlobalSettings;
use crate::context::List;
use crate::types::Source;
#[test]
fn plain_list_item_empty() {

View File

@ -7,12 +7,15 @@ use nom::combinator::recognize;
use nom::combinator::verify;
use nom::multi::many_till;
use super::object::PlainText;
use super::object_parser::any_object_except_plain_text;
use super::org_source::OrgSource;
use super::radio_link::RematchObject;
use super::Context;
use super::Object;
use super::util::exit_matcher_parser;
use crate::context::parser_with_context;
use crate::context::RefContext;
use crate::error::Res;
use crate::types::Object;
use crate::types::PlainText;
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
pub fn plain_text<'r, 's>(
@ -66,14 +69,18 @@ mod tests {
use nom::combinator::map;
use super::*;
use crate::parser::parser_context::ContextTree;
use crate::parser::parser_with_context::parser_with_context;
use crate::parser::source::Source;
use crate::context::Context;
use crate::context::ContextElement;
use crate::context::GlobalSettings;
use crate::context::List;
use crate::types::Source;
#[test]
fn plain_text_simple() {
let input = OrgSource::new("foobarbaz");
let initial_context: ContextTree<'_, '_> = ContextTree::new();
let global_settings = GlobalSettings::default();
let initial_context = ContextElement::document_context();
let initial_context = Context::new(&global_settings, List::new(&initial_context));
let plain_text_matcher = parser_with_context!(plain_text)(&initial_context);
let (remaining, result) = map(plain_text_matcher, Object::PlainText)(input).unwrap();
assert_eq!(Into::<&str>::into(remaining), "");

View File

@ -10,11 +10,11 @@ use nom::multi::separated_list1;
use nom::sequence::tuple;
use super::org_source::OrgSource;
use super::Context;
use crate::context::RefContext;
use crate::error::Res;
use crate::parser::lesser_element::Planning;
use crate::parser::util::get_consumed;
use crate::parser::util::start_of_line;
use crate::types::Planning;
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
pub fn planning<'r, 's>(

View File

@ -5,9 +5,10 @@ use nom::sequence::tuple;
use super::org_source::OrgSource;
use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting;
use super::Context;
use crate::context::parser_with_context;
use crate::context::RefContext;
use crate::error::Res;
use crate::parser::StatisticsCookie;
use crate::types::StatisticsCookie;
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
pub fn statistics_cookie<'r, 's>(