#[derive(Default, Clone, Copy)]
pub(super) struct PatternSideEffectFlags {
pub(super) clause_labels: LabelMixFlags,
pub(super) read_labels: LabelMixFlags,
pub(super) write_labels: LabelMixFlags,
pub(super) expression_labels: LabelMixFlags,
pub(super) label_saw_paren_group: bool,
pub(super) quantifiers: QuantifierForms,
pub(super) comprehension_quantifiers: QuantifierForms,
}
impl PatternSideEffectFlags {
pub(super) fn delta_from(before: &Self, after: &Self) -> Self {
let mix = |b: LabelMixFlags, a: LabelMixFlags| LabelMixFlags {
legacy_conjunction: a.legacy_conjunction && !b.legacy_conjunction,
gql_symbol: a.gql_symbol && !b.gql_symbol,
is_introducer: a.is_introducer && !b.is_introducer,
};
let forms = |b: QuantifierForms, a: QuantifierForms| QuantifierForms {
legacy_bracket: a.legacy_bracket && !b.legacy_bracket,
gpm_form: a.gpm_form && !b.gpm_form,
};
Self {
clause_labels: mix(before.clause_labels, after.clause_labels),
read_labels: mix(before.read_labels, after.read_labels),
write_labels: mix(before.write_labels, after.write_labels),
expression_labels: after.expression_labels,
label_saw_paren_group: after.label_saw_paren_group && !before.label_saw_paren_group,
quantifiers: after.quantifiers,
comprehension_quantifiers: forms(
before.comprehension_quantifiers,
after.comprehension_quantifiers,
),
}
}
pub(super) fn absorb(&mut self, delta: &Self) {
self.clause_labels.union_with(delta.clause_labels);
self.read_labels.union_with(delta.read_labels);
self.write_labels.union_with(delta.write_labels);
self.expression_labels = delta.expression_labels;
self.label_saw_paren_group |= delta.label_saw_paren_group;
self.quantifiers.absorb(delta.quantifiers);
self.comprehension_quantifiers
.absorb(delta.comprehension_quantifiers);
}
}
#[derive(Default, Clone, Copy)]
pub(super) struct QuantifierForms {
pub(super) legacy_bracket: bool,
pub(super) gpm_form: bool,
}
impl QuantifierForms {
pub(super) fn mixed(self) -> bool {
self.legacy_bracket && self.gpm_form
}
pub(super) fn absorb(&mut self, other: Self) {
self.legacy_bracket |= other.legacy_bracket;
self.gpm_form |= other.gpm_form;
}
}
#[derive(Default, Clone, Copy)]
pub(super) struct LabelMixFlags {
pub(super) legacy_conjunction: bool,
pub(super) gql_symbol: bool,
pub(super) is_introducer: bool,
}
impl LabelMixFlags {
pub(super) fn union_with(&mut self, other: Self) {
self.legacy_conjunction |= other.legacy_conjunction;
self.gql_symbol |= other.gql_symbol;
self.is_introducer |= other.is_introducer;
}
pub(super) fn within_expression_mixing(&self) -> bool {
self.legacy_conjunction && self.gql_symbol
}
pub(super) fn mixing(&self) -> Option<&'static str> {
if self.legacy_conjunction && self.gql_symbol {
return Some(
"InvalidLabelExpression: mixing label expression symbols (|, &, !, and %) with colon (:) between labels is not allowed",
);
}
if self.legacy_conjunction && self.is_introducer {
return Some(
"MixedIsAndColonConjunction: cannot mix the IS introducer with colon-conjunction within the same clause",
);
}
None
}
}
#[derive(Clone, Copy, Default, PartialEq, Eq)]
pub(super) enum LabelMixTarget {
#[default]
None,
Read,
Write,
Both,
}