use super::{Directive, Scope};
use crate::rules::{Head, Rule, Tail};
use crate::state::{RawState, State};
use crate::{Direction, Symbol};
pub trait Transition<Q, S>
where
Q: RawState,
{
fn direction(&self) -> Direction;
fn current_state(&self) -> &State<Q>;
fn next_state(&self) -> &State<Q>;
fn symbol(&self) -> &S;
fn write_symbol(&self) -> &S;
fn head(&self) -> Head<&Q, &S> {
Head {
state: self.current_state().view(),
symbol: self.symbol(),
}
}
fn tail(&self) -> Tail<&Q, &S> {
Tail {
direction: self.direction(),
state: self.next_state().view(),
symbol: self.write_symbol(),
}
}
fn as_rule(&self) -> Rule<&Q, &S> {
Rule {
head: self.head(),
tail: self.tail(),
}
}
}
impl<A, Q, S> Transition<Q, S> for A
where
A: Scope<Q, S> + Directive<Q, S>,
Q: RawState,
S: Symbol,
{
fn direction(&self) -> Direction {
self.direction()
}
fn current_state(&self) -> &State<Q> {
self.current_state()
}
fn next_state(&self) -> &State<Q> {
self.next_state()
}
fn symbol(&self) -> &S {
self.current_symbol()
}
fn write_symbol(&self) -> &S {
self.next_symbol()
}
}