Parse a floating point literal into an [AlgebraicValue]
(
literal: &str,
ty: AlgebraicType,
to_float: ToFloat,
to_value: ToValue,
)
| 198 | |
| 199 | /// Parse a floating point literal into an [AlgebraicValue] |
| 200 | fn parse_float<Float, Value, ToFloat, ToValue>( |
| 201 | literal: &str, |
| 202 | ty: AlgebraicType, |
| 203 | to_float: ToFloat, |
| 204 | to_value: ToValue, |
| 205 | ) -> anyhow::Result<AlgebraicValue> |
| 206 | where |
| 207 | Float: Into<Value>, |
| 208 | ToFloat: FnOnce(&BigDecimal) -> Option<Float>, |
| 209 | ToValue: FnOnce(Value) -> AlgebraicValue, |
| 210 | { |
| 211 | BigDecimal::from_str(literal) |
| 212 | .ok() |
| 213 | .and_then(|decimal| to_float(&decimal)) |
| 214 | .map(|value| value.into()) |
| 215 | .map(to_value) |
| 216 | .ok_or_else(|| anyhow!("{literal} is not a valid {}", fmt_algebraic_type(&ty))) |
| 217 | } |
| 218 | |
| 219 | /// Parses a source text literal as a particular type |
| 220 | pub(crate) fn parse(value: &str, ty: &AlgebraicType) -> anyhow::Result<AlgebraicValue> { |