Merge branch 'fixed_width_area'
This commit is contained in:
commit
3fb0de97cf
8
org_mode_samples/fixed_width_area/indented.org
Normal file
8
org_mode_samples/fixed_width_area/indented.org
Normal file
@ -0,0 +1,8 @@
|
||||
: Fixed width area
|
||||
: indented line
|
||||
: At the top of the file
|
||||
|
||||
|
||||
|
||||
foo
|
||||
: Another fixed width area
|
@ -12,6 +12,7 @@ use crate::parser::DynamicBlock;
|
||||
use crate::parser::Element;
|
||||
use crate::parser::ExampleBlock;
|
||||
use crate::parser::ExportBlock;
|
||||
use crate::parser::FixedWidthArea;
|
||||
use crate::parser::FootnoteDefinition;
|
||||
use crate::parser::GreaterBlock;
|
||||
use crate::parser::Heading;
|
||||
@ -219,6 +220,7 @@ fn compare_element<'s>(
|
||||
Element::Clock(obj) => compare_clock(source, emacs, obj),
|
||||
Element::DiarySexp(obj) => compare_diary_sexp(source, emacs, obj),
|
||||
Element::Planning(obj) => compare_planning(source, emacs, obj),
|
||||
Element::FixedWidthArea(obj) => compare_fixed_width_area(source, emacs, obj),
|
||||
}
|
||||
}
|
||||
|
||||
@ -752,3 +754,27 @@ fn compare_planning<'s>(
|
||||
children: Vec::new(),
|
||||
})
|
||||
}
|
||||
|
||||
fn compare_fixed_width_area<'s>(
|
||||
source: &'s str,
|
||||
emacs: &'s Token<'s>,
|
||||
rust: &'s FixedWidthArea<'s>,
|
||||
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
||||
let child_status = Vec::new();
|
||||
let mut this_status = DiffStatus::Good;
|
||||
let emacs_name = "fixed-width";
|
||||
if assert_name(emacs, emacs_name).is_err() {
|
||||
this_status = DiffStatus::Bad;
|
||||
}
|
||||
|
||||
if assert_bounds(source, emacs, rust).is_err() {
|
||||
this_status = DiffStatus::Bad;
|
||||
}
|
||||
|
||||
Ok(DiffResult {
|
||||
status: this_status,
|
||||
name: emacs_name.to_owned(),
|
||||
message: None,
|
||||
children: child_status,
|
||||
})
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ use super::lesser_element::CommentBlock;
|
||||
use super::lesser_element::DiarySexp;
|
||||
use super::lesser_element::ExampleBlock;
|
||||
use super::lesser_element::ExportBlock;
|
||||
use super::lesser_element::FixedWidthArea;
|
||||
use super::lesser_element::Paragraph;
|
||||
use super::lesser_element::Planning;
|
||||
use super::lesser_element::SrcBlock;
|
||||
@ -36,6 +37,7 @@ pub enum Element<'s> {
|
||||
Clock(Clock<'s>),
|
||||
DiarySexp(DiarySexp<'s>),
|
||||
Planning(Planning<'s>),
|
||||
FixedWidthArea(FixedWidthArea<'s>),
|
||||
}
|
||||
|
||||
impl<'s> Source<'s> for Element<'s> {
|
||||
@ -58,6 +60,7 @@ impl<'s> Source<'s> for Element<'s> {
|
||||
Element::Clock(obj) => obj.source,
|
||||
Element::DiarySexp(obj) => obj.source,
|
||||
Element::Planning(obj) => obj.source,
|
||||
Element::FixedWidthArea(obj) => obj.source,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ 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;
|
||||
use super::lesser_block::comment_block;
|
||||
@ -49,6 +50,7 @@ pub fn non_paragraph_element<'r, 's>(
|
||||
let src_block_matcher = parser_with_context!(src_block)(context);
|
||||
let clock_matcher = parser_with_context!(clock)(context);
|
||||
let diary_sexp_matcher = parser_with_context!(diary_sexp)(context);
|
||||
let fixed_width_area_matcher = parser_with_context!(fixed_width_area)(context);
|
||||
alt((
|
||||
map(plain_list_matcher, Element::PlainList),
|
||||
map(greater_block_matcher, Element::GreaterBlock),
|
||||
@ -64,5 +66,6 @@ pub fn non_paragraph_element<'r, 's>(
|
||||
map(src_block_matcher, Element::SrcBlock),
|
||||
map(clock_matcher, Element::Clock),
|
||||
map(diary_sexp_matcher, Element::DiarySexp),
|
||||
map(fixed_width_area_matcher, Element::FixedWidthArea),
|
||||
))(input)
|
||||
}
|
||||
|
55
src/parser/fixed_width_area.rs
Normal file
55
src/parser/fixed_width_area.rs
Normal file
@ -0,0 +1,55 @@
|
||||
use nom::branch::alt;
|
||||
use nom::bytes::complete::is_not;
|
||||
use nom::bytes::complete::tag;
|
||||
use nom::character::complete::line_ending;
|
||||
use nom::character::complete::space0;
|
||||
use nom::character::complete::space1;
|
||||
use nom::combinator::eof;
|
||||
use nom::combinator::not;
|
||||
use nom::combinator::opt;
|
||||
use nom::multi::many0;
|
||||
use nom::sequence::preceded;
|
||||
use nom::sequence::tuple;
|
||||
|
||||
use super::Context;
|
||||
use crate::error::Res;
|
||||
use crate::parser::parser_with_context::parser_with_context;
|
||||
use crate::parser::util::exit_matcher_parser;
|
||||
use crate::parser::util::get_consumed;
|
||||
use crate::parser::util::maybe_consume_trailing_whitespace_if_not_exiting;
|
||||
use crate::parser::util::start_of_line;
|
||||
use crate::parser::FixedWidthArea;
|
||||
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
pub fn fixed_width_area<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: &'s str,
|
||||
) -> Res<&'s str, FixedWidthArea<'s>> {
|
||||
let fixed_width_area_line_matcher = parser_with_context!(fixed_width_area_line)(context);
|
||||
let exit_matcher = parser_with_context!(exit_matcher_parser)(context);
|
||||
let (remaining, _first_line) = fixed_width_area_line_matcher(input)?;
|
||||
let (remaining, _remaining_lines) =
|
||||
many0(preceded(not(exit_matcher), fixed_width_area_line_matcher))(remaining)?;
|
||||
|
||||
let (remaining, _trailing_ws) =
|
||||
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||
|
||||
let source = get_consumed(input, remaining);
|
||||
Ok((remaining, FixedWidthArea { source }))
|
||||
}
|
||||
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
fn fixed_width_area_line<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
input: &'s str,
|
||||
) -> Res<&'s str, &'s str> {
|
||||
start_of_line(context, input)?;
|
||||
let (remaining, _indent) = space0(input)?;
|
||||
let (remaining, (_hash, _leading_whitespace_and_content, _line_ending)) = tuple((
|
||||
tag(":"),
|
||||
opt(tuple((space1, is_not("\r\n")))),
|
||||
alt((line_ending, eof)),
|
||||
))(remaining)?;
|
||||
let source = get_consumed(input, remaining);
|
||||
Ok((remaining, source))
|
||||
}
|
@ -74,6 +74,11 @@ pub struct Planning<'s> {
|
||||
pub source: &'s str,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct FixedWidthArea<'s> {
|
||||
pub source: &'s str,
|
||||
}
|
||||
|
||||
impl<'s> Paragraph<'s> {
|
||||
pub fn of_text(input: &'s str) -> Self {
|
||||
let mut objects = Vec::with_capacity(1);
|
||||
@ -146,3 +151,9 @@ impl<'s> Source<'s> for Planning<'s> {
|
||||
self.source
|
||||
}
|
||||
}
|
||||
|
||||
impl<'s> Source<'s> for FixedWidthArea<'s> {
|
||||
fn get_source(&'s self) -> &'s str {
|
||||
self.source
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ mod dynamic_block;
|
||||
mod element;
|
||||
mod element_parser;
|
||||
mod exiting;
|
||||
mod fixed_width_area;
|
||||
mod footnote_definition;
|
||||
mod greater_block;
|
||||
mod greater_element;
|
||||
@ -47,6 +48,7 @@ pub use lesser_element::CommentBlock;
|
||||
pub use lesser_element::DiarySexp;
|
||||
pub use lesser_element::ExampleBlock;
|
||||
pub use lesser_element::ExportBlock;
|
||||
pub use lesser_element::FixedWidthArea;
|
||||
pub use lesser_element::Paragraph;
|
||||
pub use lesser_element::Planning;
|
||||
pub use lesser_element::SrcBlock;
|
||||
|
Loading…
Reference in New Issue
Block a user