use crate::refs_impl::format;
use std::fmt;
use std::fmt::{Debug, Display, Formatter};
use std::marker::PhantomData;
#[derive(PartialEq)]
#[allow(unused)]
pub(crate) struct OFAst<'a> {
pub(crate) phantom: PhantomData<&'a str>,
}
impl<'a> OFAst<'a> {
pub(crate) fn iri(iri: String) -> OFIri<'a> {
OFIri {
iri,
phantom: Default::default(),
}
}
pub(crate) fn sheet_name(abs: bool, name: String) -> OFSheetName<'a> {
OFSheetName {
abs,
name,
phantom: Default::default(),
}
}
pub(crate) fn row(abs: bool, row: u32) -> OFRow<'a> {
OFRow {
abs,
row,
phantom: Default::default(),
}
}
pub(crate) fn col(abs: bool, col: u32) -> OFCol<'a> {
OFCol {
abs,
col,
phantom: Default::default(),
}
}
}
pub(crate) struct OFIri<'a> {
pub(crate) iri: String,
pub(crate) phantom: PhantomData<&'a str>,
}
impl<'a> Debug for OFIri<'a> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "'{}'#", self.iri)
}
}
impl<'a> Display for OFIri<'a> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "'{}'#", self.iri)
}
}
impl<'a> PartialEq for OFIri<'a> {
fn eq(&self, other: &Self) -> bool {
self.iri == other.iri
}
}
pub(crate) struct OFSheetName<'a> {
pub(crate) abs: bool,
pub(crate) name: String,
pub(crate) phantom: PhantomData<&'a str>,
}
impl<'a> Debug for OFSheetName<'a> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
if self.abs {
write!(f, "$")?;
}
write!(f, "'{}'.", self.name)?;
Ok(())
}
}
impl<'a> Display for OFSheetName<'a> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
if self.abs {
write!(f, "$")?;
}
write!(f, "'{}'.", self.name)?;
Ok(())
}
}
impl<'a> PartialEq for OFSheetName<'a> {
fn eq(&self, other: &Self) -> bool {
self.abs == other.abs && self.name == other.name
}
}
pub(crate) struct OFRow<'a> {
pub(crate) abs: bool,
pub(crate) row: u32,
pub(crate) phantom: PhantomData<&'a str>,
}
impl<'a> Debug for OFRow<'a> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
format::fmt_abs(f, self.abs)?;
format::fmt_row_name(f, self.row)?;
Ok(())
}
}
impl<'a> Display for OFRow<'a> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
format::fmt_abs(f, self.abs)?;
format::fmt_row_name(f, self.row)?;
Ok(())
}
}
impl<'a> PartialEq for OFRow<'a> {
fn eq(&self, other: &Self) -> bool {
self.abs == other.abs && self.row == other.row
}
}
pub(crate) struct OFCol<'a> {
pub(crate) abs: bool,
pub(crate) col: u32,
pub(crate) phantom: PhantomData<&'a str>,
}
impl<'a> Debug for OFCol<'a> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
format::fmt_abs(f, self.abs)?;
format::fmt_col_name(f, self.col)?;
Ok(())
}
}
impl<'a> Display for OFCol<'a> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
format::fmt_abs(f, self.abs)?;
format::fmt_col_name(f, self.col)?;
Ok(())
}
}
impl<'a> PartialEq for OFCol<'a> {
fn eq(&self, other: &Self) -> bool {
self.abs == other.abs && self.col == other.col
}
}
pub(crate) struct OFCellRef<'a> {
pub(crate) iri: Option<OFIri<'a>>,
pub(crate) table: Option<OFSheetName<'a>>,
pub(crate) row: OFRow<'a>,
pub(crate) col: OFCol<'a>,
}
impl<'a> Debug for OFCellRef<'a> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
if let Some(iri) = &self.iri {
write!(f, "{}", iri)?;
}
if let Some(table) = &self.table {
write!(f, "{}", table)?;
}
write!(f, "{}{}", self.col, self.row)
}
}
impl<'a> Display for OFCellRef<'a> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
if let Some(iri) = &self.iri {
write!(f, "{}", iri)?;
}
if let Some(table) = &self.table {
write!(f, "{}", table)?;
}
write!(f, "{}{}", self.col, self.row)
}
}
impl<'a> PartialEq for OFCellRef<'a> {
fn eq(&self, other: &Self) -> bool {
self.iri == other.iri
&& self.table == other.table
&& self.col == other.col
&& self.row == other.row
}
}
pub(crate) struct OFCellRange<'a> {
pub(crate) iri: Option<OFIri<'a>>,
pub(crate) table: Option<OFSheetName<'a>>,
pub(crate) row: OFRow<'a>,
pub(crate) col: OFCol<'a>,
pub(crate) to_table: Option<OFSheetName<'a>>,
pub(crate) to_row: OFRow<'a>,
pub(crate) to_col: OFCol<'a>,
}
impl<'a> Debug for OFCellRange<'a> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
if let Some(iri) = &self.iri {
write!(f, "{}", iri)?;
}
if let Some(table) = &self.table {
write!(f, "{}", table)?;
}
write!(f, "{}{}", self.col, self.row)?;
write!(f, ":")?;
if let Some(to_table) = &self.to_table {
write!(f, "{}", to_table)?;
}
write!(f, "{}{}", self.to_col, self.to_row)?;
Ok(())
}
}
impl<'a> Display for OFCellRange<'a> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
if let Some(iri) = &self.iri {
write!(f, "{}", iri)?;
}
if let Some(table) = &self.table {
write!(f, "{}", table)?;
}
write!(f, "{}{}", self.col, self.row)?;
write!(f, ":")?;
if let Some(to_table) = &self.to_table {
write!(f, "{}", to_table)?;
}
write!(f, "{}{}", self.to_col, self.to_row)?;
Ok(())
}
}
impl<'a> PartialEq for OFCellRange<'a> {
fn eq(&self, other: &Self) -> bool {
self.iri == other.iri
&& self.table == other.table
&& self.col == other.col
&& self.row == other.row
&& self.to_table == other.to_table
&& self.to_col == other.to_col
&& self.to_row == other.to_row
}
}
pub(crate) struct OFRowRange<'a> {
pub(crate) iri: Option<OFIri<'a>>,
pub(crate) table: Option<OFSheetName<'a>>,
pub(crate) row: OFRow<'a>,
pub(crate) to_table: Option<OFSheetName<'a>>,
pub(crate) to_row: OFRow<'a>,
}
impl<'a> Debug for OFRowRange<'a> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
if let Some(iri) = &self.iri {
write!(f, "{}", iri)?;
}
if let Some(table) = &self.table {
write!(f, "{}", table)?;
}
write!(f, "{}", self.row)?;
write!(f, ":")?;
if let Some(to_table) = &self.to_table {
write!(f, "{}", to_table)?;
}
write!(f, "{}", self.to_row)?;
Ok(())
}
}
impl<'a> Display for OFRowRange<'a> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
if let Some(iri) = &self.iri {
write!(f, "{}", iri)?;
}
if let Some(table) = &self.table {
write!(f, "{}", table)?;
}
write!(f, "{}", self.row)?;
write!(f, ":")?;
if let Some(to_table) = &self.to_table {
write!(f, "{}", to_table)?;
}
write!(f, "{}", self.to_row)?;
Ok(())
}
}
impl<'a> PartialEq for OFRowRange<'a> {
fn eq(&self, other: &Self) -> bool {
self.iri == other.iri
&& self.table == other.table
&& self.row == other.row
&& self.to_table == other.to_table
&& self.to_row == other.to_row
}
}
pub(crate) struct OFColRange<'a> {
pub(crate) iri: Option<OFIri<'a>>,
pub(crate) table: Option<OFSheetName<'a>>,
pub(crate) col: OFCol<'a>,
pub(crate) to_table: Option<OFSheetName<'a>>,
pub(crate) to_col: OFCol<'a>,
}
impl<'a> Debug for OFColRange<'a> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
if let Some(iri) = &self.iri {
write!(f, "{}", iri)?;
}
if let Some(table) = &self.table {
write!(f, "{}", table)?;
}
write!(f, "{}", self.col)?;
write!(f, ":")?;
if let Some(to_table) = &self.to_table {
write!(f, "{}", to_table)?;
}
write!(f, "{}", self.to_col)?;
Ok(())
}
}
impl<'a> Display for OFColRange<'a> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
if let Some(iri) = &self.iri {
write!(f, "{}", iri)?;
}
if let Some(table) = &self.table {
write!(f, "{}", table)?;
}
write!(f, "{}", self.col)?;
write!(f, ":")?;
if let Some(to_table) = &self.to_table {
write!(f, "{}", to_table)?;
}
write!(f, "{}", self.to_col)?;
Ok(())
}
}
impl<'a> PartialEq for OFColRange<'a> {
fn eq(&self, other: &Self) -> bool {
self.iri == other.iri
&& self.table == other.table
&& self.col == other.col
&& self.to_table == other.to_table
&& self.to_col == other.to_col
}
}