-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
semver: chore
- Loading branch information
Lucas de Jong
committed
Oct 29, 2024
1 parent
d2629bf
commit 8af81f8
Showing
7 changed files
with
233 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use crate::{ | ||
lexer::TokenKind, | ||
parser::{ | ||
ast::{Expression, UnaryOperator}, | ||
lookup::BindingPower, | ||
Parser, | ||
}, | ||
}; | ||
use miette::Result; | ||
|
||
pub fn negate<'de>(parser: &mut Parser<'de>) -> Result<Expression<'de>> { | ||
parser | ||
.lexer | ||
.expect(TokenKind::Not, "expected a negate operator")?; | ||
let expression = crate::parser::expression::parse(parser, BindingPower::None)?; | ||
|
||
Ok(Expression::Unary { | ||
operator: UnaryOperator::Negate, | ||
operand: Box::new(expression), | ||
}) | ||
} | ||
|
||
pub fn negative<'de>(parser: &mut Parser<'de>) -> Result<Expression<'de>> { | ||
parser | ||
.lexer | ||
.expect(TokenKind::Minus, "expected a negative operator")?; | ||
let expression = crate::parser::expression::parse(parser, BindingPower::None)?; | ||
|
||
Ok(Expression::Unary { | ||
operator: UnaryOperator::Negative, | ||
operand: Box::new(expression), | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters