Skip to content

Commit

Permalink
templater: rename "logical" eq/ne operators
Browse files Browse the repository at this point in the history
They are the equality operators. There aren't logical, bitwise, arithmetic
thingy.
  • Loading branch information
yuja committed Dec 12, 2024
1 parent da5b790 commit 53b8eeb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
8 changes: 4 additions & 4 deletions cli/src/template.pest
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ identifier = @{ (ASCII_ALPHA | "_") ~ (ASCII_ALPHANUMERIC | "_")* }
concat_op = { "++" }
logical_or_op = { "||" }
logical_and_op = { "&&" }
logical_eq_op = { "==" }
logical_ne_op = { "!=" }
eq_op = { "==" }
ne_op = { "!=" }
ge_op = { ">=" }
gt_op = { ">" }
le_op = { "<=" }
Expand All @@ -52,8 +52,8 @@ prefix_ops = _{ logical_not_op | negate_op }
infix_ops = _{
logical_or_op
| logical_and_op
| logical_eq_op
| logical_ne_op
| eq_op
| ne_op
| ge_op
| gt_op
| le_op
Expand Down
6 changes: 3 additions & 3 deletions cli/src/template_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ fn build_binary_operation<'a, L: TemplateLanguage<'a> + ?Sized>(
let out = lhs.and_then(move |l| Ok(l && rhs.extract()?));
Ok(L::wrap_boolean(out))
}
BinaryOp::LogicalEq | BinaryOp::LogicalNe => {
BinaryOp::Eq | BinaryOp::Ne => {
let lhs = build_expression(language, diagnostics, build_ctx, lhs_node)?;
let rhs = build_expression(language, diagnostics, build_ctx, rhs_node)?;
let lty = lhs.type_name();
Expand All @@ -682,8 +682,8 @@ fn build_binary_operation<'a, L: TemplateLanguage<'a> + ?Sized>(
TemplateParseError::expression(message, span)
})?;
match op {
BinaryOp::LogicalEq => Ok(L::wrap_boolean(out)),
BinaryOp::LogicalNe => Ok(L::wrap_boolean(out.map(|eq| !eq))),
BinaryOp::Eq => Ok(L::wrap_boolean(out)),
BinaryOp::Ne => Ok(L::wrap_boolean(out.map(|eq| !eq))),
_ => unreachable!(),
}
}
Expand Down
15 changes: 7 additions & 8 deletions cli/src/template_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ impl Rule {
Rule::concat_op => Some("++"),
Rule::logical_or_op => Some("||"),
Rule::logical_and_op => Some("&&"),
Rule::logical_eq_op => Some("=="),
Rule::logical_ne_op => Some("!="),
Rule::eq_op => Some("=="),
Rule::ne_op => Some("!="),
Rule::ge_op => Some(">="),
Rule::gt_op => Some(">"),
Rule::le_op => Some("<="),
Expand Down Expand Up @@ -381,9 +381,9 @@ pub enum BinaryOp {
/// `&&`
LogicalAnd,
/// `==`
LogicalEq,
Eq,
/// `!=`
LogicalNe,
Ne,
/// `>=`
Ge,
/// `>`
Expand Down Expand Up @@ -522,8 +522,7 @@ fn parse_expression_node(pair: Pair<Rule>) -> TemplateParseResult<ExpressionNode
PrattParser::new()
.op(Op::infix(Rule::logical_or_op, Assoc::Left))
.op(Op::infix(Rule::logical_and_op, Assoc::Left))
.op(Op::infix(Rule::logical_eq_op, Assoc::Left)
| Op::infix(Rule::logical_ne_op, Assoc::Left))
.op(Op::infix(Rule::eq_op, Assoc::Left) | Op::infix(Rule::ne_op, Assoc::Left))
.op(Op::infix(Rule::ge_op, Assoc::Left)
| Op::infix(Rule::gt_op, Assoc::Left)
| Op::infix(Rule::le_op, Assoc::Left)
Expand All @@ -547,8 +546,8 @@ fn parse_expression_node(pair: Pair<Rule>) -> TemplateParseResult<ExpressionNode
let op_kind = match op.as_rule() {
Rule::logical_or_op => BinaryOp::LogicalOr,
Rule::logical_and_op => BinaryOp::LogicalAnd,
Rule::logical_eq_op => BinaryOp::LogicalEq,
Rule::logical_ne_op => BinaryOp::LogicalNe,
Rule::eq_op => BinaryOp::Eq,
Rule::ne_op => BinaryOp::Ne,
Rule::ge_op => BinaryOp::Ge,
Rule::gt_op => BinaryOp::Gt,
Rule::le_op => BinaryOp::Le,
Expand Down
4 changes: 2 additions & 2 deletions docs/templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ The following operators are supported.
* `!x`: Logical not.
* `x >= y`, `x > y`, `x <= y`, `x < y`: Greater than or equal/greater than/
lesser than or equal/lesser than. Operands must be `Integer`s.
* `x == y`, `x != y`: Logical equal/not equal. Operands must be either
`Boolean`, `Integer`, or `String`.
* `x == y`, `x != y`: Equal/not equal. Operands must be either `Boolean`,
`Integer`, or `String`.
* `x && y`: Logical and, short-circuiting.
* `x || y`: Logical or, short-circuiting.
* `x ++ y`: Concatenate `x` and `y` templates.
Expand Down

0 comments on commit 53b8eeb

Please sign in to comment.