Merge pull request #918 from quantified-uncertainty/squiggle-record-syntax

the last property of a record can have a following comma
This commit is contained in:
Ozzie Gooen 2022-07-30 13:26:12 -07:00 committed by GitHub
commit b23dbc1c8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -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", () => {

View File

@ -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]; }