From 701c493c7adca171ef34a0195931931ce5cea5a3 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Thu, 12 Dec 2024 19:51:48 +0900 Subject: [PATCH] templater: rename "logical" eq/ne operators They are the equality operators. There aren't logical, bitwise, arithmetic thingy. --- cli/src/template.pest | 8 ++++---- cli/src/template_builder.rs | 6 +++--- cli/src/template_parser.rs | 15 +++++++-------- docs/templates.md | 4 ++-- 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/cli/src/template.pest b/cli/src/template.pest index 6dac26a926..227745f6fc 100644 --- a/cli/src/template.pest +++ b/cli/src/template.pest @@ -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 = { "<=" } @@ -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 diff --git a/cli/src/template_builder.rs b/cli/src/template_builder.rs index 5773e1d730..13a9450d5a 100644 --- a/cli/src/template_builder.rs +++ b/cli/src/template_builder.rs @@ -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(); @@ -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!(), } } diff --git a/cli/src/template_parser.rs b/cli/src/template_parser.rs index 2bb8aabe1f..5d5120bec4 100644 --- a/cli/src/template_parser.rs +++ b/cli/src/template_parser.rs @@ -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("<="), @@ -381,9 +381,9 @@ pub enum BinaryOp { /// `&&` LogicalAnd, /// `==` - LogicalEq, + Eq, /// `!=` - LogicalNe, + Ne, /// `>=` Ge, /// `>` @@ -522,8 +522,7 @@ fn parse_expression_node(pair: Pair) -> TemplateParseResult) -> TemplateParseResult 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, diff --git a/docs/templates.md b/docs/templates.md index 8c927c6839..30bb71349b 100644 --- a/docs/templates.md +++ b/docs/templates.md @@ -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.