use crate::pos::Span;
use oxc_allocator::{Box, Vec};
#[derive(Clone, Copy, Debug)]
pub struct Comment {
pub span: Span,
pub own_line_column: Option<u32>,
}
#[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>,
}
impl Props {
pub fn start(&self) -> Option<u32> {
match (self.anchor, self.tag) {
(Some(a), Some(t)) => Some(a.span.start.min(t.span.start)),
(Some(a), None) => Some(a.span.start),
(None, Some(t)) => Some(t.span.start),
(None, None) => None,
}
}
}
#[derive(Debug)]
pub struct Root<'a> {
pub span: Span,
pub children: Vec<'a, Document<'a>>,
pub comments: Vec<'a, Comment>,
}
#[derive(Debug)]
#[expect(clippy::struct_field_names)] pub struct Document<'a> {
pub span: Span,
pub head: DocumentHead<'a>,
pub body: DocumentBody<'a>,
pub directives_end_marker: Option<Span>,
pub document_end_marker: Option<Span>,
}
#[derive(Debug)]
pub struct DocumentHead<'a> {
pub span: Span,
pub directives: Vec<'a, Directive<'a>>,
}
#[derive(Debug)]
pub struct DocumentBody<'a> {
pub span: Span,
pub content: Option<Box<'a, Node<'a>>>,
}
#[derive(Debug)]
pub struct Directive<'a> {
pub span: Span,
pub name: &'a str,
pub parameters: Vec<'a, &'a str>,
}
#[derive(Debug)]
pub struct Node<'a> {
pub span: Span,
pub props: Props,
pub content: Content<'a>,
}
#[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,
}
}
}
#[derive(Debug)]
pub struct Plain {
pub span: Span,
}
#[derive(Debug)]
pub struct QuoteSingle {
pub span: Span,
}
#[derive(Debug)]
pub struct QuoteDouble {
pub span: Span,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Chomping {
Clip,
Keep,
Strip,
}
#[derive(Debug)]
pub struct BlockScalar {
pub span: Span,
pub chomping: Chomping,
pub indent: Option<u32>,
pub content_start: u32,
pub content_end: u32,
}
#[derive(Debug)]
pub struct Mapping<'a> {
pub span: Span,
pub children: Vec<'a, MappingItem<'a>>,
}
#[derive(Debug)]
pub struct MappingItem<'a> {
pub span: Span,
pub key: Option<MappingKey<'a>>,
pub value: Option<MappingValue<'a>>,
}
impl<'a> MappingItem<'a> {
pub fn key_content(&self) -> Option<&Node<'a>> {
self.key.as_ref().and_then(|key| key.content.as_deref())
}
pub fn value_content(&self) -> Option<&Node<'a>> {
self.value.as_ref().and_then(|value| value.content.as_deref())
}
}
#[derive(Debug)]
pub struct MappingKey<'a> {
pub span: Span,
pub content: Option<Box<'a, Node<'a>>>,
pub explicit: bool,
}
#[derive(Debug)]
pub struct MappingValue<'a> {
pub span: Span,
pub content: Option<Box<'a, Node<'a>>>,
}
#[derive(Debug)]
pub struct Sequence<'a> {
pub span: Span,
pub children: Vec<'a, SequenceItem<'a>>,
}
#[derive(Debug)]
pub struct SequenceItem<'a> {
pub span: Span,
pub content: Option<Box<'a, Node<'a>>>,
}
#[derive(Debug)]
pub struct FlowMapping<'a> {
pub span: Span,
pub children: Vec<'a, MappingItem<'a>>,
}
#[derive(Debug)]
pub struct FlowSequence<'a> {
pub span: Span,
pub children: Vec<'a, FlowSequenceEntry<'a>>,
}
#[derive(Debug)]
pub enum FlowSequenceEntry<'a> {
Item(Box<'a, Node<'a>>),
Pair(Box<'a, MappingItem<'a>>),
}
#[derive(Debug)]
pub struct Alias {
pub span: Span,
}