use crate::types::Span;
use super::oid::OidComponent;
#[derive(Debug, Clone)]
pub enum TypeSyntax {
TypeRef { name: String, span: Span },
IntegerEnum {
base: String,
named_numbers: Vec<NamedNumber>,
span: Span,
},
Bits {
named_bits: Vec<NamedBit>,
span: Span,
},
Constrained {
base: Box<TypeSyntax>,
constraint: Constraint,
span: Span,
},
SequenceOf { entry_type: String, span: Span },
Sequence {
fields: Vec<SequenceField>,
span: Span,
},
OctetString,
ObjectIdentifier,
}
impl TypeSyntax {
pub fn span(&self) -> Span {
match self {
TypeSyntax::TypeRef { span, .. }
| TypeSyntax::IntegerEnum { span, .. }
| TypeSyntax::Bits { span, .. }
| TypeSyntax::Constrained { span, .. }
| TypeSyntax::SequenceOf { span, .. }
| TypeSyntax::Sequence { span, .. } => *span,
TypeSyntax::OctetString | TypeSyntax::ObjectIdentifier => Span::ZERO,
}
}
}
#[derive(Debug, Clone)]
pub struct NamedNumber {
pub name: String,
pub value: i64,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct NamedBit {
pub name: String,
pub position: u32,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct SequenceField {
pub name: String,
pub syntax: TypeSyntax,
pub span: Span,
}
#[derive(Debug, Clone)]
pub enum Constraint {
Size { ranges: Vec<Range>, span: Span },
Range { ranges: Vec<Range>, span: Span },
}
impl Constraint {
pub fn span(&self) -> Span {
match self {
Constraint::Size { span, .. } | Constraint::Range { span, .. } => *span,
}
}
}
#[derive(Debug, Clone)]
pub struct Range {
pub min: RangeValue,
pub max: Option<RangeValue>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub enum RangeValue {
Signed(i64),
Unsigned(u64),
Min,
Max,
}
#[derive(Debug, Clone)]
pub enum DefVal {
Integer(i64),
Unsigned(u64),
String(String),
HexString(String),
BinaryString(String),
Enum(String),
Bits { labels: Vec<String> },
OidRef(String),
OidValue { components: Vec<OidComponent> },
Unparsed,
}