Function parse_relational

Source
pub fn parse_relational(input: &str) -> IResult<&str, Relational>
Expand description

Parse a relational expression from a string.

This function parses relational expressions which compare two additive expressions using relational operators. It handles operator precedence and optional whitespace around operators. The parser follows the AIMX grammar rules for relational expressions.

§Grammar Rules

relational := additive (relational_op additive)?
relational_op := '<' | '>' | '<=' | '>='

§Arguments

  • input - A string slice containing the relational expression to parse

§Returns

  • IResult<&str, Relational> - A nom result with remaining input and parsed relational expression

§Examples

use aimx::expressions::relational::parse_relational;
 
// Basic numeric comparisons
let (remaining, expr) = parse_relational("5 < 10").unwrap();
assert_eq!(remaining, "");
 
// Floating point comparisons
let (remaining, expr) = parse_relational("3.14 >= 2.71").unwrap();
assert_eq!(remaining, "");
 
// Variable comparisons
let (remaining, expr) = parse_relational("x <= y").unwrap();
assert_eq!(remaining, "");
 
// With whitespace
let (remaining, expr) = parse_relational("123     <     456").unwrap();
assert_eq!(remaining, "");
 
// Complex expressions
let (remaining, expr) = parse_relational("1 + 2 < 3 + 4").unwrap();
assert_eq!(remaining, "");

§Error Handling

The parser returns a nom IResult which can be used to handle parsing errors.