#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Syntax {
Portable,
Node,
Python,
Compose,
Docker,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum InlineComments {
Whitespace,
Space,
AnyHash,
Python,
None,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct DoubleEscapes(u16);
impl DoubleEscapes {
pub const NONE: Self = Self(0);
pub const LF: Self = Self(1);
pub const CR: Self = Self(1 << 1);
pub const TAB: Self = Self(1 << 2);
pub const BACKSLASH: Self = Self(1 << 3);
pub const DOUBLE_QUOTE: Self = Self(1 << 4);
pub const DOLLAR: Self = Self(1 << 5);
pub const SINGLE_QUOTE: Self = Self(1 << 6);
pub const BELL: Self = Self(1 << 7);
pub const BACKSPACE: Self = Self(1 << 8);
pub const FORM_FEED: Self = Self(1 << 9);
pub const VERTICAL_TAB: Self = Self(1 << 10);
pub const OCTAL: Self = Self(1 << 11);
pub const PORTABLE: Self = Self(0x3f);
pub const NODE: Self = Self(3);
pub const PYTHON: Self = Self(0x7df);
pub const COMPOSE: Self = Self(0xfbf);
#[must_use]
pub const fn union(self, other: Self) -> Self {
Self(self.0 | other.0)
}
#[must_use]
pub const fn contains(self, other: Self) -> bool {
self.0 & other.0 == other.0
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum UnknownEscapes {
Preserve,
Warn,
DropBackslash,
Error,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum SingleEscapes {
None,
Quote,
QuoteAndBackslash,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ColonSeparator {
None,
Whitespace,
Any,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum KeySyntax {
Posix,
Portable,
Unicode,
NonWhitespace,
Python,
Compose,
Docker,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum BareKeys {
Preserve,
Ignore,
Empty,
Error,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum LineBreaks {
Universal,
Lf,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum BomPolicy {
Strip,
Keep,
Error,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Duplicates {
First,
Last,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum QuotedTail {
Error,
Ignore,
Append,
LiteralFallback,
Skip,
NextStatement,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Multiline {
pub single: bool,
pub double: bool,
pub backtick: bool,
}
impl Multiline {
pub const ALL: Self = Self {
single: true,
double: true,
backtick: true,
};
pub const NONE: Self = Self {
single: false,
double: false,
backtick: false,
};
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Whitespace {
Ascii,
Unicode,
EcmaScript,
Python,
Compose,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum MalformedLines {
Error,
Ignore,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[allow(clippy::struct_excessive_bools)]
pub struct Dialect {
pub syntax: Syntax,
pub inline_comments: InlineComments,
pub double_escapes: DoubleEscapes,
pub unknown_escapes: UnknownEscapes,
pub single_escapes: SingleEscapes,
pub backticks: bool,
pub colon: ColonSeparator,
pub keys: KeySyntax,
pub bare_keys: BareKeys,
pub raw_values: bool,
pub line_breaks: LineBreaks,
pub bom: BomPolicy,
pub duplicates: Duplicates,
pub quoted_tail: QuotedTail,
pub multiline: Multiline,
pub whitespace: Whitespace,
pub export: bool,
pub quoted_keys: bool,
pub quoted_comments: bool,
pub normalize_newlines: bool,
pub malformed_lines: MalformedLines,
pub node_object_keys: bool,
pub line_byte_limit: Option<usize>,
}
impl Dialect {
pub const PORTABLE: Self = Self {
syntax: Syntax::Portable,
inline_comments: InlineComments::Whitespace,
double_escapes: DoubleEscapes::PORTABLE,
unknown_escapes: UnknownEscapes::Warn,
single_escapes: SingleEscapes::None,
backticks: false,
colon: ColonSeparator::None,
keys: KeySyntax::Portable,
bare_keys: BareKeys::Preserve,
raw_values: false,
line_breaks: LineBreaks::Universal,
bom: BomPolicy::Strip,
duplicates: Duplicates::Last,
quoted_tail: QuotedTail::Error,
multiline: Multiline::ALL,
whitespace: Whitespace::Ascii,
export: true,
quoted_keys: false,
quoted_comments: false,
normalize_newlines: false,
malformed_lines: MalformedLines::Error,
node_object_keys: false,
line_byte_limit: None,
};
pub const NODE_DOTENV: Self = Self {
syntax: Syntax::Node,
whitespace: Whitespace::EcmaScript,
inline_comments: InlineComments::AnyHash,
double_escapes: DoubleEscapes::NODE,
unknown_escapes: UnknownEscapes::Preserve,
backticks: true,
colon: ColonSeparator::Whitespace,
bare_keys: BareKeys::Ignore,
quoted_tail: QuotedTail::LiteralFallback,
quoted_comments: true,
normalize_newlines: true,
malformed_lines: MalformedLines::Ignore,
node_object_keys: true,
..Self::PORTABLE
};
pub const PYTHON_DOTENV: Self = Self {
syntax: Syntax::Python,
whitespace: Whitespace::Python,
inline_comments: InlineComments::Python,
double_escapes: DoubleEscapes::PYTHON,
unknown_escapes: UnknownEscapes::Preserve,
single_escapes: SingleEscapes::QuoteAndBackslash,
keys: KeySyntax::Python,
quoted_keys: true,
quoted_comments: true,
..Self::PORTABLE
};
pub const COMPOSE: Self = Self {
syntax: Syntax::Compose,
whitespace: Whitespace::Compose,
inline_comments: InlineComments::Space,
double_escapes: DoubleEscapes::COMPOSE,
unknown_escapes: UnknownEscapes::Preserve,
single_escapes: SingleEscapes::Quote,
colon: ColonSeparator::Any,
keys: KeySyntax::Compose,
bare_keys: BareKeys::Ignore,
line_breaks: LineBreaks::Lf,
quoted_tail: QuotedTail::NextStatement,
quoted_comments: true,
..Self::PORTABLE
};
pub const DOCKER_RAW: Self = Self {
syntax: Syntax::Docker,
whitespace: Whitespace::Unicode,
inline_comments: InlineComments::None,
double_escapes: DoubleEscapes::NONE,
unknown_escapes: UnknownEscapes::Preserve,
keys: KeySyntax::Docker,
bare_keys: BareKeys::Ignore,
raw_values: true,
line_breaks: LineBreaks::Lf,
multiline: Multiline::NONE,
export: false,
line_byte_limit: Some(65_535),
..Self::PORTABLE
};
}
impl Default for Dialect {
fn default() -> Self {
Self::PORTABLE
}
}