1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//! # Display Trait Implementations for AST (Plain Text)
//!
//! This module provides `std::fmt::Display` implementations for all AST types,
//! converting them back to plain text mathematical notation.
//!
//! ## Design Philosophy
//!
//! - **Minimal Parentheses**: Use operator precedence to minimize parenthesization
//! - **Readable Output**: Generate human-readable plain text
//! - **Round-trip Capable**: Output can be parsed back (though not guaranteed identical AST)
//!
//! ## Precedence Levels
//!
//! 1. Addition, Subtraction: precedence = 1
//! 2. Multiplication, Division, Modulo: precedence = 2
//! 3. Exponentiation: precedence = 3
//! 4. Unary operations: precedence = 4 (implicit, highest)
//!
//! ## Examples
//!
//! ```ignore
//! use mathlex::ast::{Expression, BinaryOp};
//!
//! // 2 + 3 * 4 → "2 + 3 * 4" (no parens needed)
//! let expr = ExprKind::Binary {
//! op: BinaryOp::Add,
//! left: Box::new(Expression::integer(2)),
//! right: Box::new(ExprKind::Binary {
//! op: BinaryOp::Mul,
//! left: Box::new(Expression::integer(3)),
//! right: Box::new(Expression::integer(4)),
//! }),
//! };
//! assert_eq!(format!("{}", expr), "2 + 3 * 4");
//! ```
pub