Code structure for radio links and radio targets.
This commit is contained in:
parent
5c37373419
commit
64c17e654a
@ -29,6 +29,8 @@ use crate::parser::PlainListItem;
|
|||||||
use crate::parser::PlainText;
|
use crate::parser::PlainText;
|
||||||
use crate::parser::Planning;
|
use crate::parser::Planning;
|
||||||
use crate::parser::PropertyDrawer;
|
use crate::parser::PropertyDrawer;
|
||||||
|
use crate::parser::RadioLink;
|
||||||
|
use crate::parser::RadioTarget;
|
||||||
use crate::parser::RegularLink;
|
use crate::parser::RegularLink;
|
||||||
use crate::parser::Section;
|
use crate::parser::Section;
|
||||||
use crate::parser::SrcBlock;
|
use crate::parser::SrcBlock;
|
||||||
@ -144,6 +146,8 @@ fn compare_object<'s>(
|
|||||||
Object::StrikeThrough(obj) => compare_strike_through(source, emacs, obj),
|
Object::StrikeThrough(obj) => compare_strike_through(source, emacs, obj),
|
||||||
Object::PlainText(obj) => compare_plain_text(source, emacs, obj),
|
Object::PlainText(obj) => compare_plain_text(source, emacs, obj),
|
||||||
Object::RegularLink(obj) => compare_regular_link(source, emacs, obj),
|
Object::RegularLink(obj) => compare_regular_link(source, emacs, obj),
|
||||||
|
Object::RadioLink(obj) => compare_radio_link(source, emacs, obj),
|
||||||
|
Object::RadioTarget(obj) => compare_radio_target(source, emacs, obj),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -915,16 +919,25 @@ fn compare_plain_text<'s>(
|
|||||||
let mut this_status = DiffStatus::Good;
|
let mut this_status = DiffStatus::Good;
|
||||||
let mut message = None;
|
let mut message = None;
|
||||||
let text = emacs.as_text()?;
|
let text = emacs.as_text()?;
|
||||||
let emacs_text_length = {
|
let start_ind: usize = text
|
||||||
let start_ind: usize = text.properties.get(0).expect("Should have start index.").as_atom()?.parse()?;
|
.properties
|
||||||
let end_ind: usize = text.properties.get(1).expect("Should have end index.").as_atom()?.parse()?;
|
.get(0)
|
||||||
end_ind - start_ind
|
.expect("Should have start index.")
|
||||||
};
|
.as_atom()?
|
||||||
|
.parse()?;
|
||||||
|
let end_ind: usize = text
|
||||||
|
.properties
|
||||||
|
.get(1)
|
||||||
|
.expect("Should have end index.")
|
||||||
|
.as_atom()?
|
||||||
|
.parse()?;
|
||||||
|
let emacs_text_length = end_ind - start_ind;
|
||||||
if rust.source.len() != emacs_text_length {
|
if rust.source.len() != emacs_text_length {
|
||||||
this_status = DiffStatus::Bad;
|
this_status = DiffStatus::Bad;
|
||||||
message = Some(format!(
|
message = Some(format!(
|
||||||
"(emacs len != rust len) {:?} != {:?}",
|
"(emacs len != rust len) {:?} != {:?}",
|
||||||
emacs_text_length, rust.source.len()
|
emacs_text_length,
|
||||||
|
rust.source.len()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
let unquoted_text = text.unquote()?;
|
let unquoted_text = text.unquote()?;
|
||||||
@ -1104,3 +1117,49 @@ fn compare_regular_link<'s>(
|
|||||||
children: Vec::new(),
|
children: Vec::new(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn compare_radio_link<'s>(
|
||||||
|
source: &'s str,
|
||||||
|
emacs: &'s Token<'s>,
|
||||||
|
rust: &'s RadioLink<'s>,
|
||||||
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
||||||
|
let mut this_status = DiffStatus::Good;
|
||||||
|
let emacs_name = "link";
|
||||||
|
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: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn compare_radio_target<'s>(
|
||||||
|
source: &'s str,
|
||||||
|
emacs: &'s Token<'s>,
|
||||||
|
rust: &'s RadioTarget<'s>,
|
||||||
|
) -> Result<DiffResult, Box<dyn std::error::Error>> {
|
||||||
|
let mut this_status = DiffStatus::Good;
|
||||||
|
let emacs_name = "radio-target";
|
||||||
|
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: Vec::new(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
@ -26,6 +26,7 @@ mod plain_list;
|
|||||||
mod plain_text;
|
mod plain_text;
|
||||||
mod planning;
|
mod planning;
|
||||||
mod property_drawer;
|
mod property_drawer;
|
||||||
|
mod radio_link;
|
||||||
mod regular_link;
|
mod regular_link;
|
||||||
pub mod sexp;
|
pub mod sexp;
|
||||||
mod source;
|
mod source;
|
||||||
@ -67,6 +68,8 @@ pub use object::Code;
|
|||||||
pub use object::Italic;
|
pub use object::Italic;
|
||||||
pub use object::Object;
|
pub use object::Object;
|
||||||
pub use object::PlainText;
|
pub use object::PlainText;
|
||||||
|
pub use object::RadioLink;
|
||||||
|
pub use object::RadioTarget;
|
||||||
pub use object::RegularLink;
|
pub use object::RegularLink;
|
||||||
pub use object::StrikeThrough;
|
pub use object::StrikeThrough;
|
||||||
pub use object::Underline;
|
pub use object::Underline;
|
||||||
|
@ -3,6 +3,8 @@ use super::source::Source;
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Object<'s> {
|
pub enum Object<'s> {
|
||||||
RegularLink(RegularLink<'s>),
|
RegularLink(RegularLink<'s>),
|
||||||
|
RadioLink(RadioLink<'s>),
|
||||||
|
RadioTarget(RadioTarget<'s>),
|
||||||
Bold(Bold<'s>),
|
Bold(Bold<'s>),
|
||||||
Italic(Italic<'s>),
|
Italic(Italic<'s>),
|
||||||
Underline(Underline<'s>),
|
Underline(Underline<'s>),
|
||||||
@ -58,6 +60,18 @@ pub struct RegularLink<'s> {
|
|||||||
pub source: &'s str,
|
pub source: &'s str,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct RadioTarget<'s> {
|
||||||
|
pub source: &'s str,
|
||||||
|
pub children: Vec<Object<'s>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct RadioLink<'s> {
|
||||||
|
pub source: &'s str,
|
||||||
|
pub children: Vec<Object<'s>>,
|
||||||
|
}
|
||||||
|
|
||||||
impl<'s> Source<'s> for Object<'s> {
|
impl<'s> Source<'s> for Object<'s> {
|
||||||
fn get_source(&'s self) -> &'s str {
|
fn get_source(&'s self) -> &'s str {
|
||||||
match self {
|
match self {
|
||||||
@ -69,6 +83,8 @@ impl<'s> Source<'s> for Object<'s> {
|
|||||||
Object::Verbatim(obj) => obj.source,
|
Object::Verbatim(obj) => obj.source,
|
||||||
Object::PlainText(obj) => obj.source,
|
Object::PlainText(obj) => obj.source,
|
||||||
Object::RegularLink(obj) => obj.source,
|
Object::RegularLink(obj) => obj.source,
|
||||||
|
Object::RadioLink(obj) => obj.source,
|
||||||
|
Object::RadioTarget(obj) => obj.source,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -114,3 +130,15 @@ impl<'s> Source<'s> for RegularLink<'s> {
|
|||||||
self.source
|
self.source
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'s> Source<'s> for RadioLink<'s> {
|
||||||
|
fn get_source(&'s self) -> &'s str {
|
||||||
|
self.source
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'s> Source<'s> for RadioTarget<'s> {
|
||||||
|
fn get_source(&'s self) -> &'s str {
|
||||||
|
self.source
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -8,6 +8,8 @@ use super::regular_link::regular_link;
|
|||||||
use super::Context;
|
use super::Context;
|
||||||
use crate::error::Res;
|
use crate::error::Res;
|
||||||
use crate::parser::object::Object;
|
use crate::parser::object::Object;
|
||||||
|
use crate::parser::radio_link::radio_link;
|
||||||
|
use crate::parser::radio_link::radio_target;
|
||||||
use crate::parser::text_markup::text_markup;
|
use crate::parser::text_markup::text_markup;
|
||||||
|
|
||||||
#[tracing::instrument(ret, level = "debug")]
|
#[tracing::instrument(ret, level = "debug")]
|
||||||
@ -19,6 +21,11 @@ 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!(radio_link)(context), Object::RadioLink),
|
||||||
|
map(
|
||||||
|
parser_with_context!(radio_target)(context),
|
||||||
|
Object::RadioTarget,
|
||||||
|
),
|
||||||
parser_with_context!(text_markup)(context),
|
parser_with_context!(text_markup)(context),
|
||||||
map(
|
map(
|
||||||
parser_with_context!(regular_link)(context),
|
parser_with_context!(regular_link)(context),
|
||||||
@ -33,7 +40,7 @@ pub fn minimal_set_object<'r, 's>(
|
|||||||
context: Context<'r, 's>,
|
context: Context<'r, 's>,
|
||||||
input: &'s str,
|
input: &'s str,
|
||||||
) -> Res<&'s str, Object<'s>> {
|
) -> Res<&'s str, Object<'s>> {
|
||||||
// TODO: add text markup, entities, LaTeX fragments, superscripts and subscripts
|
// TODO: add entities, LaTeX fragments, superscripts and subscripts
|
||||||
not(|i| context.check_exit_matcher(i))(input)?;
|
not(|i| context.check_exit_matcher(i))(input)?;
|
||||||
|
|
||||||
alt((
|
alt((
|
||||||
@ -49,6 +56,11 @@ pub fn any_object_except_plain_text<'r, 's>(
|
|||||||
) -> 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((
|
alt((
|
||||||
|
map(parser_with_context!(radio_link)(context), Object::RadioLink),
|
||||||
|
map(
|
||||||
|
parser_with_context!(radio_target)(context),
|
||||||
|
Object::RadioTarget,
|
||||||
|
),
|
||||||
parser_with_context!(text_markup)(context),
|
parser_with_context!(text_markup)(context),
|
||||||
map(
|
map(
|
||||||
parser_with_context!(regular_link)(context),
|
parser_with_context!(regular_link)(context),
|
||||||
|
23
src/parser/radio_link.rs
Normal file
23
src/parser/radio_link.rs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
use super::Context;
|
||||||
|
use crate::error::CustomError;
|
||||||
|
use crate::error::MyError;
|
||||||
|
use crate::error::Res;
|
||||||
|
use crate::parser::RadioLink;
|
||||||
|
use crate::parser::RadioTarget;
|
||||||
|
|
||||||
|
#[tracing::instrument(ret, level = "debug")]
|
||||||
|
pub fn radio_link<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, RadioLink<'s>> {
|
||||||
|
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
||||||
|
"Not implemented yet.",
|
||||||
|
))));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(ret, level = "debug")]
|
||||||
|
pub fn radio_target<'r, 's>(
|
||||||
|
context: Context<'r, 's>,
|
||||||
|
input: &'s str,
|
||||||
|
) -> Res<&'s str, RadioTarget<'s>> {
|
||||||
|
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
||||||
|
"Not implemented yet.",
|
||||||
|
))));
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user