diff options
| author | jockus <joakim.hentula@gmail.com> | 2020-09-15 11:39:34 +0100 |
|---|---|---|
| committer | jockus <joakim.hentula@gmail.com> | 2020-09-15 11:39:34 +0100 |
| commit | 195dbd658dd5518ab10c8f143f477d0e29dc751e (patch) | |
| tree | ae6c6bc21cf972ef25406f4f2ee2704dbe9d17e1 /core/encoding/json/tokenizer.odin | |
| parent | 0cd681e6b76896e671d11007966b118b2b263e39 (diff) | |
Added option to parse number as integer, disabled by default
Diffstat (limited to 'core/encoding/json/tokenizer.odin')
| -rw-r--r-- | core/encoding/json/tokenizer.odin | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/core/encoding/json/tokenizer.odin b/core/encoding/json/tokenizer.odin index 9527cc07f..f5fab47f2 100644 --- a/core/encoding/json/tokenizer.odin +++ b/core/encoding/json/tokenizer.odin @@ -42,12 +42,13 @@ Tokenizer :: struct { w: int, // current rune width in bytes curr_line_offset: int, spec: Specification, + parse_integers: bool, } -make_tokenizer :: proc(data: []byte, spec := Specification.JSON) -> Tokenizer { - t := Tokenizer{pos = {line=1}, data = data, spec = spec}; +make_tokenizer :: proc(data: []byte, spec := Specification.JSON, parse_integers := false) -> Tokenizer { + t := Tokenizer{pos = {line=1}, data = data, spec = spec, parse_integers = parse_integers}; next_rune(&t); if t.r == utf8.RUNE_BOM { next_rune(&t); @@ -217,7 +218,7 @@ get_token :: proc(t: ^Tokenizer) -> (token: Token, err: Error) { fallthrough; case '0'..'9': - token.kind = .Integer; + token.kind = t.parse_integers ? .Integer : .Float; if t.spec == .JSON5 { // Hexadecimal Numbers if curr_rune == '0' && (t.r == 'x' || t.r == 'X') { next_rune(t); |