Compare table formulas.
This commit is contained in:
parent
84d2babda9
commit
80f7098f9b
@ -1,3 +1,4 @@
|
|||||||
|
use std::collections::BTreeSet;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
use super::util::assert_bounds;
|
use super::util::assert_bounds;
|
||||||
@ -491,7 +492,7 @@ fn compare_heading<'s>(
|
|||||||
if rust.stars.to_string() != level {
|
if rust.stars.to_string() != level {
|
||||||
this_status = DiffStatus::Bad;
|
this_status = DiffStatus::Bad;
|
||||||
message = Some(format!(
|
message = Some(format!(
|
||||||
"Headline level do not much (emacs != rust): {} != {}",
|
"Headline level do not match (emacs != rust): {} != {}",
|
||||||
level, rust.stars
|
level, rust.stars
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
@ -1075,9 +1076,43 @@ fn compare_table<'s>(
|
|||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: Compare :type :tblfm :value
|
// Compare formulas
|
||||||
//
|
//
|
||||||
// :tblfm is a list () filled with quoted strings containing the value for any tblfm keywords at the end of the table.
|
// :tblfm is either nil or a list () filled with quoted strings containing the value for any tblfm keywords at the end of the table.
|
||||||
|
let emacs_formulas = get_property(emacs, ":tblfm")?;
|
||||||
|
if let Some(emacs_formulas) = emacs_formulas {
|
||||||
|
let emacs_formulas = emacs_formulas.as_list()?;
|
||||||
|
if emacs_formulas.len() != rust.formulas.len() {
|
||||||
|
this_status = DiffStatus::Bad;
|
||||||
|
message = Some(format!(
|
||||||
|
"Formulas do not match (emacs != rust): {:?} != {:?}",
|
||||||
|
emacs_formulas, rust.formulas
|
||||||
|
))
|
||||||
|
} else {
|
||||||
|
let atoms = emacs_formulas
|
||||||
|
.into_iter()
|
||||||
|
.map(Token::as_atom)
|
||||||
|
.collect::<Result<Vec<_>, _>>()?;
|
||||||
|
let unquoted = atoms
|
||||||
|
.into_iter()
|
||||||
|
.map(unquote)
|
||||||
|
.collect::<Result<BTreeSet<_>, _>>()?;
|
||||||
|
for kw in &rust.formulas {
|
||||||
|
if !unquoted.contains(kw.value) {
|
||||||
|
this_status = DiffStatus::Bad;
|
||||||
|
message = Some(format!("Could not find formula in emacs: {}", kw.value))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if !rust.formulas.is_empty() {
|
||||||
|
this_status = DiffStatus::Bad;
|
||||||
|
message = Some(format!(
|
||||||
|
"Formulas do not match (emacs != rust): {:?} != {:?}",
|
||||||
|
emacs_formulas, rust.formulas
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) {
|
for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) {
|
||||||
child_status.push(compare_table_row(source, emacs_child, rust_child)?);
|
child_status.push(compare_table_row(source, emacs_child, rust_child)?);
|
||||||
|
@ -58,7 +58,7 @@ pub fn org_mode_table<'b, 'g, 'r, 's>(
|
|||||||
let (remaining, (children, _exit_contents)) =
|
let (remaining, (children, _exit_contents)) =
|
||||||
many_till(org_mode_table_row_matcher, exit_matcher)(input)?;
|
many_till(org_mode_table_row_matcher, exit_matcher)(input)?;
|
||||||
|
|
||||||
let (remaining, _formulas) =
|
let (remaining, formulas) =
|
||||||
many0(parser_with_context!(table_formula_keyword)(context))(remaining)?;
|
many0(parser_with_context!(table_formula_keyword)(context))(remaining)?;
|
||||||
|
|
||||||
// TODO: Consume trailing formulas
|
// TODO: Consume trailing formulas
|
||||||
@ -68,6 +68,7 @@ pub fn org_mode_table<'b, 'g, 'r, 's>(
|
|||||||
remaining,
|
remaining,
|
||||||
Table {
|
Table {
|
||||||
source: source.into(),
|
source: source.into(),
|
||||||
|
formulas,
|
||||||
children,
|
children,
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use super::element::Element;
|
use super::element::Element;
|
||||||
use super::lesser_element::TableCell;
|
use super::lesser_element::TableCell;
|
||||||
|
use super::Keyword;
|
||||||
use super::Object;
|
use super::Object;
|
||||||
use super::Source;
|
use super::Source;
|
||||||
|
|
||||||
@ -63,6 +64,7 @@ pub struct NodeProperty<'s> {
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Table<'s> {
|
pub struct Table<'s> {
|
||||||
pub source: &'s str,
|
pub source: &'s str,
|
||||||
|
pub formulas: Vec<Keyword<'s>>,
|
||||||
pub children: Vec<TableRow<'s>>,
|
pub children: Vec<TableRow<'s>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user