Document the aggregation operator

Documents #4
This commit is contained in:
Sebastian Schmidt 2019-03-19 18:49:59 +02:00
parent 55e8b51228
commit 8e898044c0
2 changed files with 19 additions and 4 deletions

View File

@ -104,8 +104,9 @@ Supported binary operators:
| * | 100 | Product | | <= | 80 | Lower than or equal | | * | 100 | Product | | <= | 80 | Lower than or equal |
| / | 100 | Division | | \>= | 80 | Greater than or equal | | / | 100 | Division | | \>= | 80 | Greater than or equal |
| % | 100 | Modulo | | == | 80 | Equal | | % | 100 | Modulo | | == | 80 | Equal |
| && | 75 | Logical and | | != | 80 | Not equal | | ^ | 120 | Exponentiation | | != | 80 | Not equal |
| &#124;&#124; | 70 | Logical or | ^ | 120 | Exponentiation | | && | 75 | Logical and | | , | 40 | Aggregation |
| &#124;&#124; | 70 | Logical or | | | | |
Supported unary operators: Supported unary operators:
@ -131,6 +132,7 @@ Integers are internally represented as `i64`, and floating point numbers are rep
Operators that take numbers as arguments can either take integers or floating point numbers. Operators that take numbers as arguments can either take integers or floating point numbers.
If one of the arguments is a floating point number, all others are converted to floating point numbers as well, and the resulting value is a floating point number as well. If one of the arguments is a floating point number, all others are converted to floating point numbers as well, and the resulting value is a floating point number as well.
Otherwise, the result is an integer. Otherwise, the result is an integer.
An exception to this is the exponentiation operator that always returns a floating point number.
Values have a precedence of 200. Values have a precedence of 200.

View File

@ -93,8 +93,9 @@
//! | * | 100 | Product | | <= | 80 | Lower than or equal | //! | * | 100 | Product | | <= | 80 | Lower than or equal |
//! | / | 100 | Division | | \>= | 80 | Greater than or equal | //! | / | 100 | Division | | \>= | 80 | Greater than or equal |
//! | % | 100 | Modulo | | == | 80 | Equal | //! | % | 100 | Modulo | | == | 80 | Equal |
//! | && | 75 | Logical and | | != | 80 | Not equal | //! | ^ | 120 | Exponentiation | | != | 80 | Not equal |
//! | &#124;&#124; | 70 | Logical or | ^ | 120 | Exponentiation | //! | && | 75 | Logical and | | , | 40 | Aggregation |
//! | &#124;&#124; | 70 | Logical or | | | | |
//! //!
//! Supported unary operators: //! Supported unary operators:
//! //!
@ -103,6 +104,18 @@
//! | - | 110 | Negation | //! | - | 110 | Negation |
//! | ! | 110 | Logical not | //! | ! | 110 | Logical not |
//! //!
//! #### The Aggregation Operator
//!
//! The aggregation operator aggregates two values into a tuple.
//! If one of the values is a tuple already, the resulting tuple will be flattened.
//! Example:
//!
//! ```rust
//! use evalexpr::*;
//!
//! assert_eq!(eval("1, 2, 3"), Ok(Value::from(vec![Value::from(1), Value::from(2), Value::from(3)])));
//! ```
//!
//! ### Values //! ### Values
//! //!
//! Operators take values as arguments and produce values as results. //! Operators take values as arguments and produce values as results.