use crate::spec::fun_spec::{FunctionSignatureStyle, ParamListStyle, WhereClauseStyle};
use crate::spec::modifiers::ConstructorDelegationStyle;
use crate::type_name::{
AssociatedTypeStyle, BoundsPresentation, FunctionPresentation, GenericApplicationStyle,
TypePresentation, WildcardPresentation,
};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, serde::Serialize, serde::Deserialize)]
pub enum QuoteStyle {
#[default]
Single,
Double,
}
impl QuoteStyle {
pub fn char(self) -> char {
match self {
QuoteStyle::Single => '\'',
QuoteStyle::Double => '"',
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum OptionalFieldStyle {
NameSuffix(&'static str),
TypeSuffix(&'static str),
TypeWrap {
open: &'static str,
close: &'static str,
},
TypePrefix(&'static str),
UnionWithNone(&'static str),
Ignored,
}
#[derive(Debug, Clone, Copy)]
pub struct TypePresentationConfig<'a> {
pub array: TypePresentation<'a>,
pub readonly_array: Option<TypePresentation<'a>>,
pub optional: TypePresentation<'a>,
pub optional_absent_literal: &'a str,
pub map: TypePresentation<'a>,
pub union: TypePresentation<'a>,
pub intersection: TypePresentation<'a>,
pub pointer: TypePresentation<'a>,
pub slice: TypePresentation<'a>,
pub tuple: TypePresentation<'a>,
pub reference: TypePresentation<'a>,
pub reference_mut: TypePresentation<'a>,
pub function: FunctionPresentation<'a>,
pub associated_type: AssociatedTypeStyle<'a>,
pub impl_trait: BoundsPresentation<'a>,
pub dyn_trait: BoundsPresentation<'a>,
pub wildcard: WildcardPresentation<'a>,
}
impl Default for TypePresentationConfig<'_> {
fn default() -> Self {
Self {
array: TypePresentation::Postfix { suffix: "[]" },
readonly_array: None,
optional: TypePresentation::Infix { sep: " | " },
optional_absent_literal: "null",
map: TypePresentation::GenericWrap { name: "Map" },
union: TypePresentation::Infix { sep: " | " },
intersection: TypePresentation::Infix { sep: " & " },
pointer: TypePresentation::Prefix { prefix: "*" },
slice: TypePresentation::Prefix { prefix: "[]" },
tuple: TypePresentation::Delimited {
open: "(",
sep: ", ",
close: ")",
},
reference: TypePresentation::Prefix { prefix: "" },
reference_mut: TypePresentation::Prefix { prefix: "" },
function: FunctionPresentation {
keyword: "",
params_open: "(",
params_sep: ", ",
params_close: ")",
arrow: " => ",
return_first: false,
curried: false,
wrapper_open: "",
wrapper_close: "",
},
associated_type: AssociatedTypeStyle::QualifiedPath {
open: "<",
as_kw: " as ",
close_sep: ">::",
simple_sep: "::",
},
impl_trait: BoundsPresentation {
keyword: "impl ",
separator: " + ",
},
dyn_trait: BoundsPresentation {
keyword: "dyn ",
separator: " + ",
},
wildcard: WildcardPresentation {
unbounded: "?",
upper_keyword: "? extends ",
lower_keyword: "? super ",
},
}
}
}
#[derive(Debug, Clone, Copy)]
pub struct GenericSyntaxConfig<'a> {
pub open: &'a str,
pub close: &'a str,
pub application_style: GenericApplicationStyle,
pub constraint_keyword: &'a str,
pub constraint_separator: &'a str,
pub context_bound_keyword: &'a str,
}
impl Default for GenericSyntaxConfig<'_> {
fn default() -> Self {
Self {
open: "<",
close: ">",
application_style: GenericApplicationStyle::Delimited,
constraint_keyword: ": ",
constraint_separator: " + ",
context_bound_keyword: ": ",
}
}
}
#[derive(Debug, Clone, Copy)]
pub struct BlockSyntaxConfig<'a> {
pub block_open: &'a str,
pub block_close: &'a str,
pub indent_unit: &'a str,
pub uses_semicolons: bool,
pub field_terminator: &'a str,
pub type_close_terminator: &'a str,
pub bases_close: &'a str,
}
impl Default for BlockSyntaxConfig<'_> {
fn default() -> Self {
Self {
block_open: " {",
block_close: "}",
indent_unit: " ",
uses_semicolons: true,
field_terminator: ",",
type_close_terminator: "",
bases_close: "",
}
}
}
#[derive(Debug, Clone, Copy)]
pub struct FunctionSyntaxConfig<'a> {
pub return_type_separator: &'a str,
pub async_keyword: &'a str,
pub abstract_keyword: &'a str,
pub param_list_style: ParamListStyle,
pub function_signature_style: FunctionSignatureStyle,
pub constructor_keyword: &'a str,
pub constructor_delegation_style: ConstructorDelegationStyle,
pub where_clause_style: WhereClauseStyle,
pub empty_body: &'a str,
}
impl Default for FunctionSyntaxConfig<'_> {
fn default() -> Self {
Self {
return_type_separator: ": ",
async_keyword: "async ",
abstract_keyword: "abstract ",
param_list_style: ParamListStyle::Tupled,
function_signature_style: FunctionSignatureStyle::Merged,
constructor_keyword: "",
constructor_delegation_style: ConstructorDelegationStyle::Body,
where_clause_style: WhereClauseStyle::Inline,
empty_body: "",
}
}
}
#[derive(Debug, Clone, Copy)]
pub struct TypeDeclSyntaxConfig<'a> {
pub type_before_name: bool,
pub return_type_is_prefix: bool,
pub type_annotation_separator: &'a str,
pub super_type_keyword: &'a str,
pub super_type_separator: &'a str,
pub super_type_subsequent_separator: Option<&'a str>,
pub implements_keyword: &'a str,
pub type_alias_target_first: bool,
pub supports_primary_constructor: bool,
}
impl Default for TypeDeclSyntaxConfig<'_> {
fn default() -> Self {
Self {
type_before_name: false,
return_type_is_prefix: false,
type_annotation_separator: ": ",
super_type_keyword: "",
super_type_separator: ", ",
super_type_subsequent_separator: None,
implements_keyword: "",
type_alias_target_first: false,
supports_primary_constructor: false,
}
}
}
#[derive(Debug, Clone, Copy)]
pub struct EnumAndAnnotationConfig<'a> {
pub variant_prefix: &'a str,
pub variant_prefix_first: Option<&'a str>,
pub variant_separator: &'a str,
pub variant_trailing_separator: bool,
pub annotation_prefix: &'a str,
pub annotation_suffix: &'a str,
pub readonly_keyword: &'a str,
pub mutable_field_keyword: &'a str,
}
impl Default for EnumAndAnnotationConfig<'_> {
fn default() -> Self {
Self {
variant_prefix: "",
variant_prefix_first: None,
variant_separator: ",",
variant_trailing_separator: false,
annotation_prefix: "@",
annotation_suffix: "",
readonly_keyword: "const ",
mutable_field_keyword: "",
}
}
}