use crate::pos::Span;
use oxc_allocator::{Box, Vec};
#[derive(Clone, Copy, Debug)]
pub struct Comment {
pub span: Span,
}
#[derive(Clone, Copy, Debug)]
pub struct Anchor {
pub span: Span,
}
#[derive(Clone, Copy, Debug)]
pub struct Tag {
pub span: Span,
}
#[derive(Clone, Copy, Debug)]
pub struct Props {
pub anchor: Option<Anchor>,
pub tag: Option<Tag>,
}
#[derive(Debug)]
pub struct Root<'a> {
pub children: Vec<'a, Document<'a>>,
pub comments: Vec<'a, Comment>,
pub span: Span,
}
#[derive(Debug)]
#[expect(clippy::struct_field_names)] pub struct Document<'a> {
pub head: DocumentHead<'a>,
pub body: DocumentBody<'a>,
pub directives_end_marker: Option<Span>,
pub document_end_marker: Option<Span>,
pub span: Span,
}
#[derive(Debug)]
pub struct DocumentHead<'a> {
pub directives: Vec<'a, Directive<'a>>,
pub span: Span,
}
#[derive(Debug)]
pub struct DocumentBody<'a> {
pub content: Option<Content<'a>>,
pub span: Span,
}
#[derive(Debug)]
pub struct Directive<'a> {
pub name: &'a str,
pub parameters: Vec<'a, &'a str>,
pub span: Span,
}
#[derive(Debug)]
pub enum Content<'a> {
Plain(Box<'a, Plain>),
QuoteSingle(Box<'a, QuoteSingle>),
QuoteDouble(Box<'a, QuoteDouble>),
BlockLiteral(Box<'a, BlockScalar>),
BlockFolded(Box<'a, BlockScalar>),
Mapping(Box<'a, Mapping<'a>>),
Sequence(Box<'a, Sequence<'a>>),
FlowMapping(Box<'a, FlowMapping<'a>>),
FlowSequence(Box<'a, FlowSequence<'a>>),
Alias(Box<'a, Alias>),
}
impl Content<'_> {
pub fn span(&self) -> Span {
match self {
Content::Plain(n) => n.span,
Content::QuoteSingle(n) => n.span,
Content::QuoteDouble(n) => n.span,
Content::BlockLiteral(n) | Content::BlockFolded(n) => n.span,
Content::Mapping(n) => n.span,
Content::Sequence(n) => n.span,
Content::FlowMapping(n) => n.span,
Content::FlowSequence(n) => n.span,
Content::Alias(n) => n.span,
}
}
pub fn props(&self) -> &Props {
match self {
Content::Plain(n) => &n.props,
Content::QuoteSingle(n) => &n.props,
Content::QuoteDouble(n) => &n.props,
Content::BlockLiteral(n) | Content::BlockFolded(n) => &n.props,
Content::Mapping(n) => &n.props,
Content::Sequence(n) => &n.props,
Content::FlowMapping(n) => &n.props,
Content::FlowSequence(n) => &n.props,
Content::Alias(n) => &n.props,
}
}
}
#[derive(Debug)]
pub struct Plain {
pub props: Props,
pub span: Span,
}
#[derive(Debug)]
pub struct QuoteSingle {
pub props: Props,
pub span: Span,
}
#[derive(Debug)]
pub struct QuoteDouble {
pub props: Props,
pub span: Span,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Chomping {
Clip,
Keep,
Strip,
}
#[derive(Debug)]
pub struct BlockScalar {
pub props: Props,
pub chomping: Chomping,
pub indent: Option<u32>,
pub content_start: u32,
pub span: Span,
}
#[derive(Debug)]
pub struct Mapping<'a> {
pub props: Props,
pub children: Vec<'a, MappingItem<'a>>,
pub span: Span,
}
#[derive(Debug)]
pub struct MappingItem<'a> {
pub key: MappingKey<'a>,
pub value: MappingValue<'a>,
pub span: Span,
}
#[derive(Debug)]
pub struct MappingKey<'a> {
pub content: Option<Content<'a>>,
pub explicit: bool,
pub span: Span,
}
#[derive(Debug)]
pub struct MappingValue<'a> {
pub content: Option<Content<'a>>,
pub span: Span,
}
#[derive(Debug)]
pub struct Sequence<'a> {
pub props: Props,
pub children: Vec<'a, SequenceItem<'a>>,
pub span: Span,
}
#[derive(Debug)]
pub struct SequenceItem<'a> {
pub content: Option<Content<'a>>,
pub span: Span,
}
#[derive(Debug)]
pub struct FlowMapping<'a> {
pub props: Props,
pub children: Vec<'a, MappingItem<'a>>,
pub span: Span,
}
#[derive(Debug)]
pub struct FlowSequence<'a> {
pub props: Props,
pub children: Vec<'a, FlowSequenceEntry<'a>>,
pub span: Span,
}
#[derive(Debug)]
pub enum FlowSequenceEntry<'a> {
Item(FlowSequenceItem<'a>),
Pair(Box<'a, MappingItem<'a>>),
}
#[derive(Debug)]
pub struct FlowSequenceItem<'a> {
pub content: Content<'a>,
pub span: Span,
}
#[derive(Debug)]
pub struct Alias {
pub props: Props,
pub span: Span,
}