From 4c21aa902e43e515c07c881285f9a1fbf3ae0d85 Mon Sep 17 00:00:00 2001 From: Umur Ozkul Date: Sat, 30 Jul 2022 22:14:16 +0200 Subject: [PATCH] the last property of a record can have a following comma --- .../squiggle-lang/__tests__/Reducer/Reducer_test.res | 9 +++++++++ .../Reducer_Peggy/Reducer_Peggy_GeneratedParser.peggy | 6 +++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/squiggle-lang/__tests__/Reducer/Reducer_test.res b/packages/squiggle-lang/__tests__/Reducer/Reducer_test.res index 39f387a1..dc403e7d 100644 --- a/packages/squiggle-lang/__tests__/Reducer/Reducer_test.res +++ b/packages/squiggle-lang/__tests__/Reducer/Reducer_test.res @@ -27,6 +27,15 @@ describe("eval", () => { test("index", () => expectEvalToBe("r = {a: 1}; r.a", "Ok(1)")) test("index", () => expectEvalToBe("r = {a: 1}; r.b", "Error(Record property not found: b)")) testEvalError("{a: 1}.b") // invalid syntax + test("always the same property ending", () => + expectEvalToBe( + `{ + a: 1, + b: 2, + }`, + "Ok({a: 1,b: 2})", + ) + ) }) describe("multi-line", () => { diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/Reducer_Peggy_GeneratedParser.peggy b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/Reducer_Peggy_GeneratedParser.peggy index dfd3eb45..15837da4 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/Reducer_Peggy_GeneratedParser.peggy +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/Reducer_Peggy_GeneratedParser.peggy @@ -277,9 +277,13 @@ arrayConstructor 'array' { return [head, ...tail]; } recordConstructor 'record' - = '{' _nl args:array_recordArguments _nl '}' + = '{' _nl args:array_recordArguments _nl end_of_record { return h.constructRecord(args); } + end_of_record + = '}' + / ',' _nl '}' + array_recordArguments = head:keyValuePair tail:(_ ',' _nl @keyValuePair)* { return [head, ...tail]; }