The object parsers separated out.
This commit is contained in:
parent
d2fc8a513f
commit
036f4add4a
@ -917,78 +917,138 @@ fn compare_plain_text<'s>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn compare_bold<'s>(
|
fn compare_bold<'s>(
|
||||||
_source: &'s str,
|
source: &'s str,
|
||||||
emacs: &'s Token<'s>,
|
emacs: &'s Token<'s>,
|
||||||
rust: &'s Bold<'s>,
|
rust: &'s Bold<'s>,
|
||||||
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
||||||
|
let mut this_status = DiffStatus::Good;
|
||||||
|
let emacs_name = "bold";
|
||||||
|
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 {
|
Ok(DiffResult {
|
||||||
status: DiffStatus::Good,
|
status: this_status,
|
||||||
name: "bold".to_owned(),
|
name: emacs_name.to_owned(),
|
||||||
message: None,
|
message: None,
|
||||||
children: Vec::new(),
|
children: Vec::new(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compare_italic<'s>(
|
fn compare_italic<'s>(
|
||||||
_source: &'s str,
|
source: &'s str,
|
||||||
emacs: &'s Token<'s>,
|
emacs: &'s Token<'s>,
|
||||||
rust: &'s Italic<'s>,
|
rust: &'s Italic<'s>,
|
||||||
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
||||||
|
let mut this_status = DiffStatus::Good;
|
||||||
|
let emacs_name = "italic";
|
||||||
|
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 {
|
Ok(DiffResult {
|
||||||
status: DiffStatus::Good,
|
status: this_status,
|
||||||
name: "italic".to_owned(),
|
name: emacs_name.to_owned(),
|
||||||
message: None,
|
message: None,
|
||||||
children: Vec::new(),
|
children: Vec::new(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compare_underline<'s>(
|
fn compare_underline<'s>(
|
||||||
_source: &'s str,
|
source: &'s str,
|
||||||
emacs: &'s Token<'s>,
|
emacs: &'s Token<'s>,
|
||||||
rust: &'s Underline<'s>,
|
rust: &'s Underline<'s>,
|
||||||
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
||||||
|
let mut this_status = DiffStatus::Good;
|
||||||
|
let emacs_name = "underline";
|
||||||
|
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 {
|
Ok(DiffResult {
|
||||||
status: DiffStatus::Good,
|
status: this_status,
|
||||||
name: "underline".to_owned(),
|
name: emacs_name.to_owned(),
|
||||||
message: None,
|
message: None,
|
||||||
children: Vec::new(),
|
children: Vec::new(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compare_verbatim<'s>(
|
fn compare_verbatim<'s>(
|
||||||
_source: &'s str,
|
source: &'s str,
|
||||||
emacs: &'s Token<'s>,
|
emacs: &'s Token<'s>,
|
||||||
rust: &'s Verbatim<'s>,
|
rust: &'s Verbatim<'s>,
|
||||||
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
||||||
|
let mut this_status = DiffStatus::Good;
|
||||||
|
let emacs_name = "verbatim";
|
||||||
|
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 {
|
Ok(DiffResult {
|
||||||
status: DiffStatus::Good,
|
status: this_status,
|
||||||
name: "verbatim".to_owned(),
|
name: emacs_name.to_owned(),
|
||||||
message: None,
|
message: None,
|
||||||
children: Vec::new(),
|
children: Vec::new(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compare_code<'s>(
|
fn compare_code<'s>(
|
||||||
_source: &'s str,
|
source: &'s str,
|
||||||
emacs: &'s Token<'s>,
|
emacs: &'s Token<'s>,
|
||||||
rust: &'s Code<'s>,
|
rust: &'s Code<'s>,
|
||||||
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
||||||
|
let mut this_status = DiffStatus::Good;
|
||||||
|
let emacs_name = "code";
|
||||||
|
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 {
|
Ok(DiffResult {
|
||||||
status: DiffStatus::Good,
|
status: this_status,
|
||||||
name: "code".to_owned(),
|
name: emacs_name.to_owned(),
|
||||||
message: None,
|
message: None,
|
||||||
children: Vec::new(),
|
children: Vec::new(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compare_strike_through<'s>(
|
fn compare_strike_through<'s>(
|
||||||
_source: &'s str,
|
source: &'s str,
|
||||||
emacs: &'s Token<'s>,
|
emacs: &'s Token<'s>,
|
||||||
rust: &'s StrikeThrough<'s>,
|
rust: &'s StrikeThrough<'s>,
|
||||||
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
||||||
|
let mut this_status = DiffStatus::Good;
|
||||||
|
let emacs_name = "strike-through";
|
||||||
|
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 {
|
Ok(DiffResult {
|
||||||
status: DiffStatus::Good,
|
status: this_status,
|
||||||
name: "strike-through".to_owned(),
|
name: emacs_name.to_owned(),
|
||||||
message: None,
|
message: None,
|
||||||
children: Vec::new(),
|
children: Vec::new(),
|
||||||
})
|
})
|
||||||
@ -996,8 +1056,8 @@ fn compare_strike_through<'s>(
|
|||||||
|
|
||||||
fn compare_regular_link<'s>(
|
fn compare_regular_link<'s>(
|
||||||
_source: &'s str,
|
_source: &'s str,
|
||||||
emacs: &'s Token<'s>,
|
_emacs: &'s Token<'s>,
|
||||||
rust: &'s RegularLink<'s>,
|
_rust: &'s RegularLink<'s>,
|
||||||
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
||||||
Ok(DiffResult {
|
Ok(DiffResult {
|
||||||
status: DiffStatus::Good,
|
status: DiffStatus::Good,
|
||||||
|
@ -75,3 +75,39 @@ impl<'s> Source<'s> for Object<'s> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'s> Source<'s> for Bold<'s> {
|
||||||
|
fn get_source(&'s self) -> &'s str {
|
||||||
|
self.source
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'s> Source<'s> for Italic<'s> {
|
||||||
|
fn get_source(&'s self) -> &'s str {
|
||||||
|
self.source
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'s> Source<'s> for Underline<'s> {
|
||||||
|
fn get_source(&'s self) -> &'s str {
|
||||||
|
self.source
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'s> Source<'s> for StrikeThrough<'s> {
|
||||||
|
fn get_source(&'s self) -> &'s str {
|
||||||
|
self.source
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'s> Source<'s> for Code<'s> {
|
||||||
|
fn get_source(&'s self) -> &'s str {
|
||||||
|
self.source
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'s> Source<'s> for Verbatim<'s> {
|
||||||
|
fn get_source(&'s self) -> &'s str {
|
||||||
|
self.source
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -18,10 +18,7 @@ pub fn standard_set_object<'r, 's>(
|
|||||||
not(|i| context.check_exit_matcher(i))(input)?;
|
not(|i| context.check_exit_matcher(i))(input)?;
|
||||||
|
|
||||||
alt((
|
alt((
|
||||||
map(
|
|
||||||
parser_with_context!(text_markup)(context),
|
parser_with_context!(text_markup)(context),
|
||||||
Object::TextMarkup,
|
|
||||||
),
|
|
||||||
map(parser_with_context!(plain_text)(context), Object::PlainText),
|
map(parser_with_context!(plain_text)(context), Object::PlainText),
|
||||||
))(input)
|
))(input)
|
||||||
}
|
}
|
||||||
@ -35,10 +32,7 @@ pub fn minimal_set_object<'r, 's>(
|
|||||||
not(|i| context.check_exit_matcher(i))(input)?;
|
not(|i| context.check_exit_matcher(i))(input)?;
|
||||||
|
|
||||||
alt((
|
alt((
|
||||||
map(
|
|
||||||
parser_with_context!(text_markup)(context),
|
parser_with_context!(text_markup)(context),
|
||||||
Object::TextMarkup,
|
|
||||||
),
|
|
||||||
map(parser_with_context!(plain_text)(context), Object::PlainText),
|
map(parser_with_context!(plain_text)(context), Object::PlainText),
|
||||||
))(input)
|
))(input)
|
||||||
}
|
}
|
||||||
@ -49,8 +43,5 @@ pub fn any_object_except_plain_text<'r, 's>(
|
|||||||
input: &'s str,
|
input: &'s str,
|
||||||
) -> Res<&'s str, Object<'s>> {
|
) -> Res<&'s str, Object<'s>> {
|
||||||
// Used for exit matchers so this does not check exit matcher condition.
|
// Used for exit matchers so this does not check exit matcher condition.
|
||||||
alt((map(
|
alt((parser_with_context!(text_markup)(context),))(input)
|
||||||
parser_with_context!(text_markup)(context),
|
|
||||||
Object::TextMarkup,
|
|
||||||
),))(input)
|
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ use nom::bytes::complete::tag;
|
|||||||
use nom::character::complete::line_ending;
|
use nom::character::complete::line_ending;
|
||||||
use nom::character::complete::one_of;
|
use nom::character::complete::one_of;
|
||||||
use nom::character::complete::space0;
|
use nom::character::complete::space0;
|
||||||
|
use nom::combinator::map;
|
||||||
use nom::combinator::peek;
|
use nom::combinator::peek;
|
||||||
use nom::combinator::recognize;
|
use nom::combinator::recognize;
|
||||||
use nom::combinator::verify;
|
use nom::combinator::verify;
|
||||||
@ -21,12 +22,75 @@ use crate::parser::parser_with_context::parser_with_context;
|
|||||||
use crate::parser::util::exit_matcher_parser;
|
use crate::parser::util::exit_matcher_parser;
|
||||||
use crate::parser::util::get_consumed;
|
use crate::parser::util::get_consumed;
|
||||||
use crate::parser::util::get_one_before;
|
use crate::parser::util::get_one_before;
|
||||||
|
use crate::parser::Bold;
|
||||||
|
use crate::parser::Italic;
|
||||||
|
use crate::parser::Object;
|
||||||
|
use crate::parser::StrikeThrough;
|
||||||
|
use crate::parser::Underline;
|
||||||
|
|
||||||
#[tracing::instrument(ret, level = "debug")]
|
#[tracing::instrument(ret, level = "debug")]
|
||||||
pub fn text_markup<'r, 's>(
|
pub fn text_markup<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Object<'s>> {
|
||||||
|
alt((
|
||||||
|
map(parser_with_context!(bold)(context), Object::Bold),
|
||||||
|
map(parser_with_context!(italic)(context), Object::Italic),
|
||||||
|
map(parser_with_context!(underline)(context), Object::Underline),
|
||||||
|
map(
|
||||||
|
parser_with_context!(strike_through)(context),
|
||||||
|
Object::StrikeThrough,
|
||||||
|
),
|
||||||
|
// map(parser_with_context!(verbatim)(context), Object::Verbatim),
|
||||||
|
// map(parser_with_context!(code)(context), Object::Code),
|
||||||
|
))(input)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(ret, level = "debug")]
|
||||||
|
pub fn bold<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Bold<'s>> {
|
||||||
|
let text_markup_object_specialized = text_markup_object("*");
|
||||||
|
let (remaining, children) = text_markup_object_specialized(context, input)?;
|
||||||
|
let source = get_consumed(input, remaining);
|
||||||
|
Ok((remaining, Bold { source, children }))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(ret, level = "debug")]
|
||||||
|
pub fn italic<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Italic<'s>> {
|
||||||
|
let text_markup_object_specialized = text_markup_object("/");
|
||||||
|
let (remaining, children) = text_markup_object_specialized(context, input)?;
|
||||||
|
let source = get_consumed(input, remaining);
|
||||||
|
Ok((remaining, Italic { source, children }))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(ret, level = "debug")]
|
||||||
|
pub fn underline<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Underline<'s>> {
|
||||||
|
let text_markup_object_specialized = text_markup_object("_");
|
||||||
|
let (remaining, children) = text_markup_object_specialized(context, input)?;
|
||||||
|
let source = get_consumed(input, remaining);
|
||||||
|
Ok((remaining, Underline { source, children }))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(ret, level = "debug")]
|
||||||
|
pub fn strike_through<'r, 's>(
|
||||||
context: Context<'r, 's>,
|
context: Context<'r, 's>,
|
||||||
input: &'s str,
|
input: &'s str,
|
||||||
) -> Res<&'s str, TextMarkupObject<'s>> {
|
) -> Res<&'s str, StrikeThrough<'s>> {
|
||||||
|
let text_markup_object_specialized = text_markup_object("+");
|
||||||
|
let (remaining, children) = text_markup_object_specialized(context, input)?;
|
||||||
|
let source = get_consumed(input, remaining);
|
||||||
|
Ok((remaining, StrikeThrough { source, children }))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn text_markup_object(
|
||||||
|
marker_symbol: &str,
|
||||||
|
) -> impl for<'r, 's> Fn(Context<'r, 's>, &'s str) -> Res<&'s str, Vec<Object<'s>>> {
|
||||||
|
let marker_symbol = marker_symbol.to_owned();
|
||||||
|
move |context: Context, input: &str| _text_markup_object(context, input, marker_symbol.as_str())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(ret, level = "debug")]
|
||||||
|
fn _text_markup_object<'r, 's, 'x>(
|
||||||
|
context: Context<'r, 's>,
|
||||||
|
input: &'s str,
|
||||||
|
marker_symbol: &'x str,
|
||||||
|
) -> Res<&'s str, Vec<Object<'s>>> {
|
||||||
let (remaining, _) = pre(context, input)?;
|
let (remaining, _) = pre(context, input)?;
|
||||||
let (remaining, open) = marker(remaining)?;
|
let (remaining, open) = marker(remaining)?;
|
||||||
let text_markup_end_specialized = text_markup_end(open);
|
let text_markup_end_specialized = text_markup_end(open);
|
||||||
@ -47,10 +111,7 @@ pub fn text_markup<'r, 's>(
|
|||||||
// TODO: Sometimes its plain text, not objects
|
// TODO: Sometimes its plain text, not objects
|
||||||
let (remaining, _close) = text_markup_end_specialized(context, remaining)?;
|
let (remaining, _close) = text_markup_end_specialized(context, remaining)?;
|
||||||
let (remaining, _trailing_whitespace) = space0(remaining)?;
|
let (remaining, _trailing_whitespace) = space0(remaining)?;
|
||||||
|
Ok((remaining, children))
|
||||||
let source = get_consumed(input, remaining);
|
|
||||||
|
|
||||||
Ok((remaining, TextMarkupObject { source, children }))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(ret, level = "debug")]
|
#[tracing::instrument(ret, level = "debug")]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user