Skip to content

Commit

Permalink
Check opposite eq
Browse files Browse the repository at this point in the history
  • Loading branch information
nickdrozd committed Oct 29, 2024
1 parent 2594f79 commit dc095bf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/reason.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,14 @@ impl Alignment for Backstepper {
self.rspan.len()
}

fn l_eq(&self, prev: &Self) -> bool {
self.lspan == prev.lspan
}

fn r_eq(&self, prev: &Self) -> bool {
self.rspan == prev.rspan
}

fn get_slice(&self, start: Pos, ltr: bool) -> TapeSlice {
let (lspan, rspan, diff) = if ltr {
(&self.lspan, &self.rspan, self.head() - start)
Expand Down
18 changes: 16 additions & 2 deletions src/tape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,13 +431,16 @@ impl HeadTape {
}
}

pub trait Alignment: Eq {
pub trait Alignment {
fn head(&self) -> Pos;
fn scan(&self) -> Color;

fn l_len(&self) -> usize;
fn r_len(&self) -> usize;

fn l_eq(&self, prev: &Self) -> bool;
fn r_eq(&self, prev: &Self) -> bool;

fn get_slice(&self, start: Pos, ltr: bool) -> TapeSlice;

fn get_ltr(&self, start: Pos) -> TapeSlice {
Expand All @@ -464,17 +467,20 @@ pub trait Alignment: Eq {
if 0 < diff {
self.r_len() == prev.r_len()
&& self.l_len() >= prev.l_len()
&& self.r_eq(prev)
&& prev.get_ltr(leftmost)
== self.get_ltr(leftmost + diff)
} else if diff < 0 {
self.l_len() == prev.l_len()
&& self.r_len() >= prev.r_len()
&& self.l_eq(prev)
&& prev.get_rtl(rightmost)
== self.get_rtl(rightmost + diff)
} else {
self.l_len() == prev.l_len()
&& self.r_len() == prev.r_len()
&& self == prev
&& self.l_eq(prev)
&& self.r_eq(prev)
}
}
}
Expand All @@ -496,6 +502,14 @@ impl Alignment for HeadTape {
self.tape.rspan.len()
}

fn l_eq(&self, prev: &Self) -> bool {
self.tape.lspan == prev.tape.lspan
}

fn r_eq(&self, prev: &Self) -> bool {
self.tape.rspan == prev.tape.rspan
}

fn get_slice(&self, start: Pos, ltr: bool) -> TapeSlice {
let (lspan, rspan, diff) = if ltr {
(&self.tape.lspan, &self.tape.rspan, self.head() - start)
Expand Down

0 comments on commit dc095bf

Please sign in to comment.