use crate::source::SourceSpan;
use super::{ComposeScalar, FieldReference, Located};
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum ProviderOptionValue {
Scalar(Located<ComposeScalar>),
Sequence {
span: SourceSpan,
items: Vec<ProviderOptionItem>,
},
}
impl ProviderOptionValue {
#[must_use]
pub const fn span(&self) -> SourceSpan {
match self {
Self::Scalar(value) => value.span(),
Self::Sequence { span, .. } => *span,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum ProviderOptionItem {
Scalar(Located<ComposeScalar>),
Unmodeled {
span: SourceSpan,
},
}
impl ProviderOptionItem {
#[must_use]
pub const fn span(&self) -> SourceSpan {
match self {
Self::Scalar(value) => value.span(),
Self::Unmodeled { span } => *span,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ProviderOption {
name: Located<String>,
value: ProviderOptionValue,
span: SourceSpan,
}
impl ProviderOption {
pub(crate) const fn new(name: Located<String>, value: ProviderOptionValue, span: SourceSpan) -> Self {
Self { name, value, span }
}
#[must_use]
pub const fn name(&self) -> &Located<String> {
&self.name
}
#[must_use]
pub const fn value(&self) -> &ProviderOptionValue {
&self.value
}
#[must_use]
pub const fn span(&self) -> SourceSpan {
self.span
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ProviderOptions {
span: SourceSpan,
entries: Vec<ProviderOption>,
unmodeled_entries: Vec<FieldReference>,
}
impl ProviderOptions {
pub(crate) const fn new(
span: SourceSpan,
entries: Vec<ProviderOption>,
unmodeled_entries: Vec<FieldReference>,
) -> Self {
Self {
span,
entries,
unmodeled_entries,
}
}
#[must_use]
pub const fn span(&self) -> SourceSpan {
self.span
}
#[must_use]
pub fn entries(&self) -> &[ProviderOption] {
&self.entries
}
#[must_use]
pub fn unmodeled_entries(&self) -> &[FieldReference] {
&self.unmodeled_entries
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Provider {
span: SourceSpan,
type_: Option<Located<String>>,
options: Option<ProviderOptions>,
extension_fields: Vec<FieldReference>,
unknown_fields: Vec<FieldReference>,
}
impl Provider {
pub(crate) const fn new(span: SourceSpan) -> Self {
Self {
span,
type_: None,
options: None,
extension_fields: Vec::new(),
unknown_fields: Vec::new(),
}
}
pub(crate) fn set_type(&mut self, value: Located<String>) {
self.type_ = Some(value);
}
pub(crate) fn set_options(&mut self, value: ProviderOptions) {
self.options = Some(value);
}
pub(crate) fn push_extension(&mut self, field: FieldReference) {
self.extension_fields.push(field);
}
pub(crate) fn push_unknown(&mut self, field: FieldReference) {
self.unknown_fields.push(field);
}
#[must_use]
pub const fn span(&self) -> SourceSpan {
self.span
}
#[must_use]
pub const fn type_(&self) -> Option<&Located<String>> {
self.type_.as_ref()
}
#[must_use]
pub const fn options(&self) -> Option<&ProviderOptions> {
self.options.as_ref()
}
#[must_use]
pub fn extension_fields(&self) -> &[FieldReference] {
&self.extension_fields
}
#[must_use]
pub fn unknown_fields(&self) -> &[FieldReference] {
&self.unknown_fields
}
}