use num_enum::TryFromPrimitive;
#[derive(Debug, Clone)]
pub struct Abbreviation {
pub operands: Vec<Operand>,
}
#[derive(Debug, Clone)]
pub enum Operand {
Literal(u64),
Fixed(u8),
Vbr(u8),
Array(Box<Operand>),
Char6,
Blob,
}
impl Operand {
pub fn is_payload(&self) -> bool {
use Operand::*;
match self {
Array(_) | Blob => true,
Literal(_) | Fixed(_) | Vbr(_) | Char6 => false,
}
}
pub fn is_literal(&self) -> bool {
matches!(self, Operand::Literal(_))
}
pub fn is_array(&self) -> bool {
matches!(self, Operand::Array(_))
}
pub fn is_blob(&self) -> bool {
matches!(self, Operand::Blob)
}
pub fn encoded_kind(&self) -> u8 {
use Operand::*;
match self {
Literal(_) => 0,
Fixed(_) => 1,
Vbr(_) => 2,
Array(_) => 3,
Char6 => 4,
Blob => 5,
}
}
}
#[derive(Debug, Clone, Copy, TryFromPrimitive)]
#[repr(u8)]
pub enum BlockInfoCode {
SetBid = 1,
BlockName = 2,
SetRecordName = 3,
}
#[derive(Debug, Clone, Copy, TryFromPrimitive)]
#[repr(u64)]
pub enum BuiltinAbbreviationId {
EndBlock = 0,
EnterSubBlock = 1,
DefineAbbreviation = 2,
UnabbreviatedRecord = 3,
}