diff options
| author | gingerBill <bill@gingerbill.org> | 2019-01-06 22:25:02 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2019-01-06 22:25:02 +0000 |
| commit | 08598b9425ebaf06805cbf9b2fb09acbc29a3a64 (patch) | |
| tree | 435182aaf09aca0068d8ae54591140064732cc55 /core/encoding/json | |
| parent | 6295f6747fbbeeb849c2334c489d774051d78f6e (diff) | |
Support NaN and Infinity for JSON5
Diffstat (limited to 'core/encoding/json')
| -rw-r--r-- | core/encoding/json/parser.odin | 22 | ||||
| -rw-r--r-- | core/encoding/json/validator.odin | 30 |
2 files changed, 38 insertions, 14 deletions
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: - advance_token(p); - return true; - case Kind.False: + case Null, False, True: advance_token(p); return true; - case Kind.True: + case Integer, Float: 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; |