use super::{MovePlan, Operand, PlaceId, StepPlan, StorePlan};
use crate::vocab::InspectMode;
use crate::{codec_enum, codec_struct};
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Chars<P = PlaceId, O = Operand> {
Literal(Vec<u8>),
Place(P),
Value(O),
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct InspectPlan<P = PlaceId, O = Operand> {
pub target: P,
pub tallying: Vec<InspectPhrase<P, O>>,
pub replacing: Vec<InspectPhrase<P, O>>,
pub converting: Option<Converting<P, O>>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct InspectPhrase<P = PlaceId, O = Operand> {
pub mode: InspectMode,
pub pattern: Option<Chars<P, O>>,
pub by: Option<Replacement<P, O>>,
pub counter: Option<(P, StepPlan)>,
pub bounds: Vec<Bound<P, O>>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Replacement<P = PlaceId, O = Operand> {
Chars(Chars<P, O>),
Fill(u8),
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Bound<P = PlaceId, O = Operand> {
pub after: bool,
pub value: Chars<P, O>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Converting<P = PlaceId, O = Operand> {
pub table: ConvertTable<P, O>,
pub bounds: Vec<Bound<P, O>>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum ConvertTable<P = PlaceId, O = Operand> {
Built(Vec<(u8, u8)>),
Operands { from: Chars<P, O>, to: Chars<P, O> },
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct StringPlan<P = PlaceId, O = Operand> {
pub into: P,
pub pointer: Option<(P, StorePlan)>,
pub sources: Vec<StringSource<P, O>>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct StringSource<P = PlaceId, O = Operand> {
pub chars: Chars<P, O>,
pub delimiter: Option<Chars<P, O>>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct UnstringPlan<P = PlaceId, O = Operand> {
pub source: P,
pub pointer: Option<(P, StorePlan)>,
pub delimiters: Vec<(bool, Chars<P, O>)>,
pub into: Vec<UnstringInto<P>>,
pub tallying: Option<(P, StepPlan)>,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct UnstringInto<P = PlaceId> {
pub target: P,
pub plan: MovePlan,
pub delimiter: Option<DelimiterIn<P>>,
pub count: Option<(P, StorePlan)>,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct DelimiterIn<P = PlaceId> {
pub target: P,
pub found: MovePlan,
pub none: MovePlan,
}
codec_enum!(Chars { Literal(bytes) = 0, Place(place) = 1, Value(value) = 2 });
codec_struct!(InspectPlan { target, tallying, replacing, converting });
codec_struct!(InspectPhrase { mode, pattern, by, counter, bounds });
codec_enum!(Replacement { Chars(chars) = 0, Fill(byte) = 1 });
codec_struct!(Bound { after, value });
codec_struct!(Converting { table, bounds });
codec_enum!(ConvertTable { Built(pairs) = 0, Operands { from, to } = 1 });
codec_struct!(StringPlan { into, pointer, sources });
codec_struct!(StringSource { chars, delimiter });
codec_struct!(UnstringPlan { source, pointer, delimiters, into, tallying });
codec_struct!(UnstringInto { target, plan, delimiter, count });
codec_struct!(DelimiterIn { target, found, none });