Skip to content

Commit

Permalink
Added negative integer/float literals so that coercion works correctl…
Browse files Browse the repository at this point in the history
…y with them
  • Loading branch information
IsaacShelton committed Oct 18, 2024
1 parent 52821da commit 050bd82
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/parser/parse_expr/primary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,23 @@ impl<'a, I: Inflow<Token>> Parser<'a, I> {
TokenKind::Subtract => {
self.input.advance();

Ok(ExprKind::UnaryOperation(Box::new(UnaryOperation::new_math(
UnaryMathOperator::Negate,
self.parse_expr_primary()?,
)))
.at(source))
let mut inside = self.parse_expr_primary()?;

match &mut inside.kind {
ExprKind::Integer(Integer::Generic(value)) => {
*value = -(&*value);
Ok(inside)
}
ExprKind::Float(value) => {
*value = -*value;
Ok(inside)
}
_ => Ok(ExprKind::UnaryOperation(Box::new(UnaryOperation::new_math(
UnaryMathOperator::Negate,
inside,
)))
.at(source)),
}
}
TokenKind::AddressOf => {
self.input.advance();
Expand Down

0 comments on commit 050bd82

Please sign in to comment.