Module binary

Module binary 

Source
Expand description

Binary expression parsing for PromQL.

This module handles parsing of binary operators and their modifiers.

§Binary Operators

Operators listed from lowest to highest precedence:

PrecedenceOperatorsDescription
1orSet union
2and, unlessSet intersection/diff
3==, !=, <, <=, >, >=Comparison
4+, -Addition/subtraction
5*, /, %, atan2Multiplication/division
6^Power (right-associative)

§Vector Matching Modifiers

Binary operations between vectors can use matching modifiers:

  • on(label, ...) - Match only on specified labels
  • ignoring(label, ...) - Match ignoring specified labels
  • group_left(label, ...) - Many-to-one matching
  • group_right(label, ...) - One-to-many matching
  • bool - Return 0/1 instead of filtering (for comparisons)

§Examples

use rusty_promql_parser::parser::binary::binary_op;
use rusty_promql_parser::ast::BinaryOp;

let (_, op) = binary_op("+").unwrap();
assert_eq!(op, BinaryOp::Add);

let (_, op) = binary_op("and").unwrap();
assert_eq!(op, BinaryOp::And);

Functions§

binary_op
Parse a binary operator