Parse an integer literal into an [AlgebraicValue]
(
literal: &str,
ty: AlgebraicType,
to_int: ToInt,
to_val: ToVal,
)
| 175 | |
| 176 | /// Parse an integer literal into an [AlgebraicValue] |
| 177 | fn parse_int<Int, Val, ToInt, ToVal>( |
| 178 | literal: &str, |
| 179 | ty: AlgebraicType, |
| 180 | to_int: ToInt, |
| 181 | to_val: ToVal, |
| 182 | ) -> anyhow::Result<AlgebraicValue> |
| 183 | where |
| 184 | Int: Into<Val>, |
| 185 | ToInt: FnOnce(&BigDecimal) -> Option<Int>, |
| 186 | ToVal: FnOnce(Val) -> AlgebraicValue, |
| 187 | { |
| 188 | // Why are we using an arbitrary precision type? |
| 189 | // For scientific notation as well as i256 and u256. |
| 190 | BigDecimal::from_str(literal) |
| 191 | .ok() |
| 192 | .filter(|decimal| decimal.is_integer()) |
| 193 | .ok_or_else(|| anyhow!("{literal} is not an integer")) |
| 194 | .map(|decimal| to_int(&decimal).map(|val| val.into()).map(to_val)) |
| 195 | .transpose() |
| 196 | .ok_or_else(|| anyhow!("{literal} is out of bounds for type {}", fmt_algebraic_type(&ty)))? |
| 197 | } |
| 198 | |
| 199 | /// Parse a floating point literal into an [AlgebraicValue] |
| 200 | fn parse_float<Float, Value, ToFloat, ToValue>( |
no test coverage detected
searching dependent graphs…