tom icon indicating copy to clipboard operation
tom copied to clipboard

Fix `ast::Number::value`

Open matklad opened this issue 7 years ago • 3 comments
trafficstars

https://github.com/matklad/tom/blob/5a1b98e0b0b13529a917a9c2212f6813a9eb1948/src/ast/mod.rs#L46 is just an unimplemented!() stub.

I think we should replace it with two methods: value_i64() -> Option<i64> and value_f64() -> f64, because TOML supports both floats and ints.

The tests should go here: https://github.com/matklad/tom/blob/5a1b98e0b0b13529a917a9c2212f6813a9eb1948/tests/suite/ast.rs#L26-L32

See https://github.com/matklad/tom/issues/2 as well.

matklad avatar Jul 14 '18 15:07 matklad

What do you think about keeping integers and floats as separate types? The model API will need to differentiate between them (currently it panics when it sees a float), and since Rust generally doesn't let integers/floats mix I think it would be more convenient. That may require pushing the distinction down all the way into the lexer. Was there some motivation for treating them the same?

ehuss avatar Jul 29 '18 18:07 ehuss

Agree, it makes sense to distinguish between floats and ints in all of lexer, CST and AST.

matklad avatar Jul 29 '18 19:07 matklad

As for original motivation, it’s basically a historic accident.

An interesting question is what should we do if a number overflows i64? Optoind are either to return an option or to produce an error during validation and panic in the value method.

matklad avatar Jul 29 '18 19:07 matklad