Skip to content

Commit

Permalink
refactor: Make all ast binary op has similar name for nodes and op
Browse files Browse the repository at this point in the history
  • Loading branch information
AmrDeveloper committed Sep 13, 2024
1 parent ae107fc commit 8be92c7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
10 changes: 5 additions & 5 deletions crates/gitql-ast/src/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ impl Expression for BooleanExpression {

pub struct UnaryExpression {
pub right: Box<dyn Expression>,
pub op: PrefixUnaryOperator,
pub operator: PrefixUnaryOperator,
}

impl Expression for UnaryExpression {
Expand All @@ -228,7 +228,7 @@ impl Expression for UnaryExpression {
}

fn expr_type(&self, scope: &Environment) -> DataType {
if self.op == PrefixUnaryOperator::Bang {
if self.operator == PrefixUnaryOperator::Bang {
DataType::Boolean
} else {
self.right.expr_type(scope)
Expand Down Expand Up @@ -339,9 +339,9 @@ impl Expression for ComparisonExpression {
}

pub struct ContainsExpression {
pub lhs: Box<dyn Expression>,
pub rhs: Box<dyn Expression>,
pub op: ContainsOperator,
pub left: Box<dyn Expression>,
pub right: Box<dyn Expression>,
pub operator: ContainsOperator,
}

impl Expression for ContainsExpression {
Expand Down
8 changes: 4 additions & 4 deletions crates/gitql-engine/src/engine_evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ fn evaluate_prefix_unary(
object: &Vec<Value>,
) -> Result<Value, String> {
let rhs = evaluate_expression(env, &expr.right, titles, object)?;
match expr.op {
match expr.operator {
PrefixUnaryOperator::Minus => {
if rhs.data_type().is_int() {
Ok(Value::Integer(-rhs.as_int()))
Expand Down Expand Up @@ -494,10 +494,10 @@ fn evaluate_contains(
titles: &[String],
object: &Vec<Value>,
) -> Result<Value, String> {
let lhs = evaluate_expression(env, &expr.lhs, titles, object)?;
let rhs = evaluate_expression(env, &expr.rhs, titles, object)?;
let lhs = evaluate_expression(env, &expr.left, titles, object)?;
let rhs = evaluate_expression(env, &expr.right, titles, object)?;

match expr.op {
match expr.operator {
ContainsOperator::RangeContainsElement => {
let collection_range = lhs.as_range();
let is_in_range = Ordering::is_ge(collection_range.0.compare(&rhs))
Expand Down
19 changes: 11 additions & 8 deletions crates/gitql-parser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1478,7 +1478,7 @@ fn parse_regex_expression(
return Ok(if has_not_keyword {
Box::new(UnaryExpression {
right: regex_expr,
op: PrefixUnaryOperator::Bang,
operator: PrefixUnaryOperator::Bang,
})
} else {
regex_expr
Expand Down Expand Up @@ -2039,19 +2039,19 @@ fn parse_contains_expression(
// Example: Range<T> @> Range<T>
if is_both_side_has_same_type {
return Ok(Box::new(ContainsExpression {
lhs,
rhs,
op: ContainsOperator::RangeContainsRange,
left: lhs,
right: rhs,
operator: ContainsOperator::RangeContainsRange,
}));
}

// Is Range contains another element of the same Range element type
// Example: Range<T> @> T
if *range_element_type == rhs_type {
return Ok(Box::new(ContainsExpression {
lhs,
rhs,
op: ContainsOperator::RangeContainsElement,
left: lhs,
right: rhs,
operator: ContainsOperator::RangeContainsElement,
}));
}

Expand Down Expand Up @@ -2504,7 +2504,10 @@ fn parse_prefix_unary_expression(
_ => {}
}

return Ok(Box::new(UnaryExpression { right: rhs, op }));
return Ok(Box::new(UnaryExpression {
right: rhs,
operator: op,
}));
}

parse_function_call_expression(context, env, tokens, position)
Expand Down

0 comments on commit 8be92c7

Please sign in to comment.