Avoid duplicate effort when parsing floats in the EDN parser.

This commit is contained in:
Kevin Mehall 2018-03-05 16:16:46 -08:00 committed by Richard Newman
parent c117f1e958
commit 2d7df69507

View file

@ -120,14 +120,8 @@ pub integer -> ValueAndSpan =
}
}
frac = sign? digit+ "." digit+
exp = sign? digit+ ("e" / "E") sign? digit+
frac_exp = sign? digit+ "." digit+ ("e" / "E") sign? digit+
// The order here is important - frac_exp must come before (exp / frac) or the
// parser assumes exp or frac when the float is really a frac_exp and fails
pub float -> ValueAndSpan =
start:#position f:$( frac_exp / exp / frac ) end:#position {
start:#position f:$(sign? digit+ ("." digit+)? (("e" / "E") sign? digit+)?) end:#position {
ValueAndSpan {
inner: SpannedValue::Float(OrderedFloat(f.parse::<f64>().unwrap())),
span: Span::new(start, end)