From e6f9b4fb11285c5ceea3b3cc7cee26aa9f5ae3d2 Mon Sep 17 00:00:00 2001 From: Kevin Watters Date: Mon, 25 Mar 2019 09:23:46 -0400 Subject: [PATCH 1/3] Fix some -vet warnings; change import to core:math/bits --- core/encoding/json/marshal.odin | 2 +- core/encoding/json/tokenizer.odin | 4 ++-- core/encoding/json/types.odin | 2 -- core/strconv/strconv.odin | 4 ++-- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/core/encoding/json/marshal.odin b/core/encoding/json/marshal.odin index d25758275..4f5ee6880 100644 --- a/core/encoding/json/marshal.odin +++ b/core/encoding/json/marshal.odin @@ -1,7 +1,7 @@ package json import "core:mem" -import "core:bits" +import "core:math/bits" import "core:runtime" import "core:strconv" import "core:strings" diff --git a/core/encoding/json/tokenizer.odin b/core/encoding/json/tokenizer.odin index dd1704ba7..f9da8437e 100644 --- a/core/encoding/json/tokenizer.odin +++ b/core/encoding/json/tokenizer.odin @@ -436,8 +436,8 @@ is_valid_string_literal :: proc(s: string, spec: Specification) -> bool { i += 5; for j := 0; j < 4; j += 1 { - c := hex[j]; - switch c { + c2 := hex[j]; + switch c2 { case '0'..'9', 'a'..'z', 'A'..'Z': // Okay case: diff --git a/core/encoding/json/types.odin b/core/encoding/json/types.odin index 6973d3dc5..036fe50b4 100644 --- a/core/encoding/json/types.odin +++ b/core/encoding/json/types.odin @@ -1,7 +1,5 @@ package json -import "core:strconv" - Specification :: enum { JSON, JSON5, diff --git a/core/strconv/strconv.odin b/core/strconv/strconv.odin index 0b1f10f6c..0a48ce68b 100644 --- a/core/strconv/strconv.odin +++ b/core/strconv/strconv.odin @@ -230,8 +230,8 @@ quote :: proc(buf: []byte, s: string) -> string { write_byte(buf, &i, digits[s[0]>>4]); write_byte(buf, &i, digits[s[0]&0xf]); } - s := quote_rune(buf[i:], r); - i += len(s); + s2 := quote_rune(buf[i:], r); + i += len(s2); } write_byte(buf, &i, c); return string(buf[:i]); From 76a2807b56a9c0a40c66915d5b77cf537ad376f2 Mon Sep 17 00:00:00 2001 From: Kevin Watters Date: Tue, 26 Mar 2019 11:20:49 -0400 Subject: [PATCH 2/3] Remove unused import from demo.odin. --- examples/demo/demo.odin | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/demo/demo.odin b/examples/demo/demo.odin index efce9299a..dd7590d01 100644 --- a/examples/demo/demo.odin +++ b/examples/demo/demo.odin @@ -5,7 +5,6 @@ import "core:mem" import "core:os" when os.OS == "windows" { - import "core:runtime" import "core:thread" } From 62f5eb5bca8810a622491179039bc7c382b33995 Mon Sep 17 00:00:00 2001 From: Kevin Watters Date: Sat, 6 Apr 2019 09:19:09 -0400 Subject: [PATCH 3/3] Fix som JSON parsing bugs. - Single digit integer keys `{"a": 5}` ` Negative float keys `{"b": -42.0}` --- core/encoding/json/tokenizer.odin | 38 ++++++++++++++++--------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/core/encoding/json/tokenizer.odin b/core/encoding/json/tokenizer.odin index f9da8437e..48cbb22c0 100644 --- a/core/encoding/json/tokenizer.odin +++ b/core/encoding/json/tokenizer.odin @@ -68,12 +68,12 @@ next_rune :: proc(t: ^Tokenizer) -> rune #no_bounds_check { get_token :: proc(t: ^Tokenizer) -> (token: Token, err: Error) { skip_digits :: proc(t: ^Tokenizer) { for t.offset < len(t.data) { - next_rune(t); if '0' <= t.r && t.r <= '9' { // Okay } else { return; } + next_rune(t); } } skip_hex_digits :: proc(t: ^Tokenizer) { @@ -158,6 +158,7 @@ get_token :: proc(t: ^Tokenizer) -> (token: Token, err: Error) { skip_whitespace(t); token.pos = t.pos; + token.kind = Kind.Invalid; curr_rune := t.r; @@ -213,23 +214,6 @@ get_token :: proc(t: ^Tokenizer) -> (token: Token, err: Error) { } fallthrough; - case '.': - err = Error.Illegal_Character; - if t.spec == Specification.JSON5 { // Allow leading decimal point - skip_digits(t); - if t.r == 'e' || t.r == 'E' { - switch r := next_rune(t); r { - case '+', '-': - next_rune(t); - } - skip_digits(t); - } - str := string(t.data[token.offset:t.offset]); - if !is_valid_number(str, t.spec) { - err = Error.Invalid_Number; - } - } - case '0'..'9': token.kind = Kind.Integer; if t.spec == Specification.JSON5 { // Hexadecimal Numbers @@ -241,6 +225,7 @@ get_token :: proc(t: ^Tokenizer) -> (token: Token, err: Error) { } skip_digits(t); + if t.r == '.' { token.kind = Kind.Float; next_rune(t); @@ -259,6 +244,23 @@ get_token :: proc(t: ^Tokenizer) -> (token: Token, err: Error) { err = Error.Invalid_Number; } + case '.': + err = Error.Illegal_Character; + if t.spec == Specification.JSON5 { // Allow leading decimal point + skip_digits(t); + if t.r == 'e' || t.r == 'E' { + switch r := next_rune(t); r { + case '+', '-': + next_rune(t); + } + skip_digits(t); + } + str := string(t.data[token.offset:t.offset]); + if !is_valid_number(str, t.spec) { + err = Error.Invalid_Number; + } + } + case '\'': err = Error.Illegal_Character;