1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

toml: improve number conversion (#12509)

This commit is contained in:
Larpon
2021-11-18 18:46:19 +01:00
committed by GitHub
parent 3caeadfa0d
commit 96554fad71
4 changed files with 41 additions and 31 deletions

View File

@@ -7,7 +7,6 @@ import toml.ast
import toml.input
import toml.scanner
import toml.parser
import strconv
// Null is used in sumtype checks as a "default" value when nothing else is possible.
pub struct Null {
@@ -199,11 +198,14 @@ pub fn (d Doc) ast_to_any(value ast.Value) Any {
return Any(value.text)
}
ast.Number {
if value.text.contains('.') || value.text.to_lower().contains('e') {
return Any(value.text.f64())
// if value.text.contains('inf') || value.text.contains('nan') {
// return Any() // TODO
//}
if !value.text.starts_with('0x')
&& (value.text.contains('.') || value.text.to_lower().contains('e')) {
return Any(value.f64())
}
v := strconv.parse_int(value.text, 0, 0) or { i64(0) }
return Any(v)
return Any(value.i64())
}
ast.Bool {
str := (value as ast.Bool).text