Rust's number parsing supports parsing floats in the scientific notation format (playground example). This is useful for dealing with values of electronic components (resistance, capacitance), that are often very small/large.
Right now evalexpr correctly recognizes input of the form 10e3 as it's parsed as a single PartialToken::Literal. However, adding a + or - for negative values i.e. 10e-3 will cause str_to_partial_tokens to output [Literal("10e"), Minus, Literal("3")] due to the parsing logic not handling e in any special way. This causes evalexpr to not find a variable with the identifier 10e and fail. The proposed fix for this issue doesn't alter the partial token logic, but instead adds some extra handling when resolving partial tokens to full tokens. This is the smallest change I could come up with to implement this, let me know if it would be better to do it another way (the current architecture doesn't adapt to supporting this very easily). I've also added some additional cases to the integration tests to cover the scientific notation parsing.
Rust's number parsing supports parsing floats in the scientific notation format (playground example). This is useful for dealing with values of electronic components (resistance, capacitance), that are often very small/large.
Right now
evalexpr
correctly recognizes input of the form10e3
as it's parsed as a singlePartialToken::Literal
. However, adding a+
or-
for negative values i.e.10e-3
will causestr_to_partial_tokens
to output[Literal("10e"), Minus, Literal("3")]
due to the parsing logic not handlinge
in any special way. This causesevalexpr
to not find a variable with the identifier10e
and fail. The proposed fix for this issue doesn't alter the partial token logic, but instead adds some extra handling when resolving partial tokens to full tokens. This is the smallest change I could come up with to implement this, let me know if it would be better to do it another way (the current architecture doesn't adapt to supporting this very easily). I've also added some additional cases to the integration tests to cover the scientific notation parsing.