diff --git a/core/encoding/json/parser.odin b/core/encoding/json/parser.odin index 2c7d79465..aa041ba5e 100644 --- a/core/encoding/json/parser.odin +++ b/core/encoding/json/parser.odin @@ -93,6 +93,28 @@ parse_value :: proc(p: ^Parser) -> (value: Value, err: Error) { case Kind.Open_Bracket: return parse_array(p); + + case: + if p.spec == Specification.JSON5 { + switch token.kind { + case Kind.Infinity: + inf: u64 = 0x7ff0000000000000; + if token.text[0] == '-' { + inf = 0xfff0000000000000; + } + value.value = transmute(f64)inf; + advance_token(p); + return; + case Kind.NaN: + nan: u64 = 0x7ff7ffffffffffff; + if token.text[0] == '-' { + nan = 0xfff7ffffffffffff; + } + value.value = transmute(f64)nan; + advance_token(p); + return; + } + } } err = Error.Unexpected_Token; diff --git a/core/encoding/json/validator.odin b/core/encoding/json/validator.odin index aa49364ec..332716e24 100644 --- a/core/encoding/json/validator.odin +++ b/core/encoding/json/validator.odin @@ -90,31 +90,33 @@ validate_array :: proc(p: ^Parser) -> bool { validate_value :: proc(p: ^Parser) -> bool { token := p.curr_token; + + using Kind; switch token.kind { - case Kind.Null: + case Null, False, True: advance_token(p); return true; - case Kind.False: + case Integer, Float: advance_token(p); return true; - case Kind.True: - advance_token(p); - return true; - case Kind.Integer: - advance_token(p); - return true; - case Kind.Float: - advance_token(p); - return true; - case Kind.String: + case String: advance_token(p); return is_valid_string_literal(token.text, p.spec); - case Kind.Open_Brace: + case Open_Brace: return validate_object(p); - case Kind.Open_Bracket: + case Open_Bracket: return validate_array(p); + + case: + if p.spec == Specification.JSON5 { + switch token.kind { + case Infinity, NaN: + advance_token(p); + return true; + } + } } return false;