commit e8ac6ea44ea58db723977d9603a894aa7baf03aa
parent 187426a322cc9db5d49f35a162890a5f20d76fbc
Author: Sebastian <sebastian@sebsite.pw>
Date: Sat, 14 May 2022 22:46:20 -0400
encoding::json: disallow trailing comma
Signed-off-by: Sebastian <sebastian@sebsite.pw>
Diffstat:
1 file changed, 16 insertions(+), 9 deletions(-)
diff --git a/encoding/json/load.ha b/encoding/json/load.ha
@@ -37,15 +37,15 @@ fn _load(lexer: *lexer) (value | error) = {
fn _load_array(lexer: *lexer) (value | error) = {
let array: []value = [];
- for (true) {
- let tok = mustscan(lexer)?;
- match (tok) {
- case arrayend =>
- break;
- case =>
- unlex(lexer, tok);
- };
+ let tok = mustscan(lexer)?;
+ match (tok) {
+ case arrayend =>
+ return array;
+ case =>
+ unlex(lexer, tok);
+ };
+ for (true) {
append(array, _load(lexer)?);
tok = mustscan(lexer)?;
@@ -60,12 +60,19 @@ fn _load_array(lexer: *lexer) (value | error) = {
fn _load_obj(lexer: *lexer) (value | error) = {
let obj = newobject();
+ let tok = mustscan(lexer)?;
+ match (tok) {
+ case objend =>
+ return obj;
+ case =>
+ unlex(lexer, tok);
+ };
+
for (true) {
let tok = mustscan(lexer)?;
const key = match (tok) {
case let s: str =>
yield strings::dup(s);
- case objend => break;
case => return invalid;
};
defer free(key);