|
63 | 63 | //! let op = |c| just(c).padded(); |
64 | 64 | //! |
65 | 65 | //! let expr = atom.pratt(( |
66 | | -//! // We want factorial to happen before any negation, so we need its precedence to be higher than `Expr::Neg`. |
| 66 | +//! // We want factorial to happen before any negation, so we |
| 67 | +//! // need its precedence to be higher than `Expr::Neg`. |
67 | 68 | //! postfix(4, op('!'), |lhs, _, _| Expr::Factorial(Box::new(lhs))), |
68 | | -//! // Just like in math, we want that if we write -x^2, our parser parses that as -(x^2), so we need it to have |
69 | | -//! // exponents bind tighter than our prefix operators. |
| 69 | +//! // Just like in math, we want that if we write -x^2, our parser |
| 70 | +//! // parses that as -(x^2), so we need it to have exponents bind |
| 71 | +//! // tighter than our prefix operators. |
70 | 72 | //! infix(right(3), op('^'), |l, _, r, _| Expr::Pow(Box::new(l), Box::new(r))), |
71 | | -//! // Notice the conflict with our `Expr::Sub`. This will still parse correctly. We want negation to happen before |
72 | | -//! // `+` and `-`, so we set its precedence higher. |
| 73 | +//! // Notice the conflict with our `Expr::Sub`. This will still |
| 74 | +//! // parse correctly. We want negation to happen before `+` and |
| 75 | +//! // `-`, so we set its precedence higher. |
73 | 76 | //! prefix(2, op('-'), |_, rhs, _| Expr::Neg(Box::new(rhs))), |
74 | 77 | //! prefix(2, op('*'), |_, rhs, _| Expr::Deref(Box::new(rhs))), |
75 | | -//! // Our `-` and `+` bind the weakest, meaning that even if they occur first in an expression, they will be the |
76 | | -//! // last executed. |
| 78 | +//! // Our `-` and `+` bind the weakest, meaning that even if they |
| 79 | +//! // occur first in an expression, they will be the last executed. |
77 | 80 | //! infix(left(1), op('+'), |l, _, r, _| Expr::Add(Box::new(l), Box::new(r))), |
78 | 81 | //! infix(left(1), op('-'), |l, _, r, _| Expr::Sub(Box::new(l), Box::new(r))), |
79 | 82 | //! )) |
|
0 commit comments