split binop into separate struct
This commit is contained in:
parent
190201bcce
commit
02d36f872a
@ -40,15 +40,18 @@ pub(crate) struct InterpolatedFunction {
|
|||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub(crate) struct AstSassMap(pub Vec<(Spanned<AstExpr>, AstExpr)>);
|
pub(crate) struct AstSassMap(pub Vec<(Spanned<AstExpr>, AstExpr)>);
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub(crate) struct BinaryOpExpr {
|
||||||
|
pub lhs: AstExpr,
|
||||||
|
pub op: BinaryOp,
|
||||||
|
pub rhs: AstExpr,
|
||||||
|
pub allows_slash: bool,
|
||||||
|
pub span: Span,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub(crate) enum AstExpr {
|
pub(crate) enum AstExpr {
|
||||||
BinaryOp {
|
BinaryOp(Arc<BinaryOpExpr>),
|
||||||
lhs: Arc<Self>,
|
|
||||||
op: BinaryOp,
|
|
||||||
rhs: Arc<Self>,
|
|
||||||
allows_slash: bool,
|
|
||||||
span: Span,
|
|
||||||
},
|
|
||||||
True,
|
True,
|
||||||
False,
|
False,
|
||||||
Calculation {
|
Calculation {
|
||||||
@ -167,19 +170,19 @@ impl AstExpr {
|
|||||||
pub fn is_slash_operand(&self) -> bool {
|
pub fn is_slash_operand(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Self::Number { .. } | Self::Calculation { .. } => true,
|
Self::Number { .. } | Self::Calculation { .. } => true,
|
||||||
Self::BinaryOp { allows_slash, .. } => *allows_slash,
|
Self::BinaryOp(binop) => binop.allows_slash,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn slash(left: Self, right: Self, span: Span) -> Self {
|
pub fn slash(left: Self, right: Self, span: Span) -> Self {
|
||||||
Self::BinaryOp {
|
Self::BinaryOp(Arc::new(BinaryOpExpr {
|
||||||
lhs: Arc::new(left),
|
lhs: left,
|
||||||
op: BinaryOp::Div,
|
op: BinaryOp::Div,
|
||||||
rhs: Arc::new(right),
|
rhs: right,
|
||||||
allows_slash: true,
|
allows_slash: true,
|
||||||
span,
|
span,
|
||||||
}
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const fn span(self, span: Span) -> Spanned<Self> {
|
pub const fn span(self, span: Span) -> Spanned<Self> {
|
||||||
|
@ -2421,13 +2421,15 @@ impl<'a> Visitor<'a> {
|
|||||||
}),
|
}),
|
||||||
AstExpr::List(list) => self.visit_list_expr(list)?,
|
AstExpr::List(list) => self.visit_list_expr(list)?,
|
||||||
AstExpr::String(StringExpr(text, quote), ..) => self.visit_string(text, quote)?,
|
AstExpr::String(StringExpr(text, quote), ..) => self.visit_string(text, quote)?,
|
||||||
AstExpr::BinaryOp {
|
AstExpr::BinaryOp(binop) => {
|
||||||
lhs,
|
self.visit_bin_op(
|
||||||
op,
|
binop.lhs.clone(),
|
||||||
rhs,
|
binop.op,
|
||||||
allows_slash,
|
binop.rhs.clone(),
|
||||||
span,
|
binop.allows_slash,
|
||||||
} => self.visit_bin_op((*lhs).clone(), op, (*rhs).clone(), allows_slash, span)?,
|
binop.span,
|
||||||
|
)?
|
||||||
|
}
|
||||||
AstExpr::True => Value::True,
|
AstExpr::True => Value::True,
|
||||||
AstExpr::False => Value::False,
|
AstExpr::False => Value::False,
|
||||||
AstExpr::Calculation { name, args } => {
|
AstExpr::Calculation { name, args } => {
|
||||||
@ -2475,15 +2477,17 @@ impl<'a> Visitor<'a> {
|
|||||||
debug_assert!(string_expr.1 == QuoteKind::None);
|
debug_assert!(string_expr.1 == QuoteKind::None);
|
||||||
CalculationArg::Interpolation(self.perform_interpolation(string_expr.0, false)?)
|
CalculationArg::Interpolation(self.perform_interpolation(string_expr.0, false)?)
|
||||||
}
|
}
|
||||||
AstExpr::BinaryOp { lhs, op, rhs, .. } => SassCalculation::operate_internal(
|
AstExpr::BinaryOp(binop) => {
|
||||||
op,
|
SassCalculation::operate_internal(
|
||||||
self.visit_calculation_value((*lhs).clone(), in_min_or_max, span)?,
|
binop.op,
|
||||||
self.visit_calculation_value((*rhs).clone(), in_min_or_max, span)?,
|
self.visit_calculation_value(binop.lhs.clone(), in_min_or_max, span)?,
|
||||||
|
self.visit_calculation_value(binop.rhs.clone(), in_min_or_max, span)?,
|
||||||
in_min_or_max,
|
in_min_or_max,
|
||||||
!self.flags.in_supports_declaration(),
|
!self.flags.in_supports_declaration(),
|
||||||
self.options,
|
self.options,
|
||||||
span,
|
span,
|
||||||
)?,
|
)?
|
||||||
|
}
|
||||||
AstExpr::Number { .. }
|
AstExpr::Number { .. }
|
||||||
| AstExpr::Calculation { .. }
|
| AstExpr::Calculation { .. }
|
||||||
| AstExpr::Variable { .. }
|
| AstExpr::Variable { .. }
|
||||||
|
@ -538,13 +538,13 @@ impl<'a, 'c, P: StylesheetParser<'a>> ValueParser<'a, 'c, P> {
|
|||||||
self.single_expression = Some(AstExpr::slash(left.node, right.node, span).span(span));
|
self.single_expression = Some(AstExpr::slash(left.node, right.node, span).span(span));
|
||||||
} else {
|
} else {
|
||||||
self.single_expression = Some(
|
self.single_expression = Some(
|
||||||
AstExpr::BinaryOp {
|
AstExpr::BinaryOp(Arc::new(BinaryOpExpr {
|
||||||
lhs: Arc::new(left.node),
|
lhs: left.node,
|
||||||
op: operator,
|
op: operator,
|
||||||
rhs: Arc::new(right.node),
|
rhs: right.node,
|
||||||
allows_slash: false,
|
allows_slash: false,
|
||||||
span,
|
span,
|
||||||
}
|
}))
|
||||||
.span(span),
|
.span(span),
|
||||||
);
|
);
|
||||||
self.allow_slash = false;
|
self.allow_slash = false;
|
||||||
@ -1600,17 +1600,17 @@ impl<'a, 'c, P: StylesheetParser<'a>> ValueParser<'a, 'c, P> {
|
|||||||
|
|
||||||
let span = product.span.merge(rhs.span);
|
let span = product.span.merge(rhs.span);
|
||||||
|
|
||||||
product.node = AstExpr::BinaryOp {
|
product.node = AstExpr::BinaryOp(Arc::new(BinaryOpExpr {
|
||||||
lhs: Arc::new(product.node),
|
lhs: product.node,
|
||||||
op: if op == '*' {
|
op: if op == '*' {
|
||||||
BinaryOp::Mul
|
BinaryOp::Mul
|
||||||
} else {
|
} else {
|
||||||
BinaryOp::Div
|
BinaryOp::Div
|
||||||
},
|
},
|
||||||
rhs: Arc::new(rhs.node),
|
rhs: rhs.node,
|
||||||
allows_slash: false,
|
allows_slash: false,
|
||||||
span,
|
span,
|
||||||
};
|
}));
|
||||||
|
|
||||||
product.span = span;
|
product.span = span;
|
||||||
}
|
}
|
||||||
@ -1654,17 +1654,17 @@ impl<'a, 'c, P: StylesheetParser<'a>> ValueParser<'a, 'c, P> {
|
|||||||
|
|
||||||
let span = sum.span.merge(rhs.span);
|
let span = sum.span.merge(rhs.span);
|
||||||
|
|
||||||
sum = AstExpr::BinaryOp {
|
sum = AstExpr::BinaryOp(Arc::new(BinaryOpExpr {
|
||||||
lhs: Arc::new(sum.node),
|
lhs: sum.node,
|
||||||
op: if next == '+' {
|
op: if next == '+' {
|
||||||
BinaryOp::Plus
|
BinaryOp::Plus
|
||||||
} else {
|
} else {
|
||||||
BinaryOp::Minus
|
BinaryOp::Minus
|
||||||
},
|
},
|
||||||
rhs: Arc::new(rhs.node),
|
rhs: rhs.node,
|
||||||
allows_slash: false,
|
allows_slash: false,
|
||||||
span,
|
span,
|
||||||
}
|
}))
|
||||||
.span(span);
|
.span(span);
|
||||||
}
|
}
|
||||||
_ => return Ok(sum),
|
_ => return Ok(sum),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user