From 081d83454f96a7050c3f451048fb07d5204f839f Mon Sep 17 00:00:00 2001 From: Patrik Date: Wed, 16 Nov 2022 15:07:16 +0100 Subject: [PATCH] feat: allow quoting object keys in OPL --- internal/schema/parser.go | 8 ++++---- internal/schema/parser_test.go | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/schema/parser.go b/internal/schema/parser.go index 3795d15b1..0ea022644 100644 --- a/internal/schema/parser.go +++ b/internal/schema/parser.go @@ -195,7 +195,7 @@ func (p *parser) parseRelated() { switch item := p.next(); item.Typ { case itemBraceRight: return - case itemIdentifier: + case itemIdentifier, itemStringLiteral: relation := item.Val var types []ast.RelationType p.match(":") @@ -216,7 +216,7 @@ func (p *parser) parseRelated() { Types: types, }) default: - p.addFatal(item, "expected identifier or '}', got %q", item.Val) + p.addFatal(item, "expected identifier or '}', got %s %q", item.Typ.String(), item.Val) return } } @@ -258,7 +258,7 @@ func (p *parser) parsePermits() { case itemBraceRight: return - case itemIdentifier: + case itemIdentifier, itemStringLiteral: permission := item.Val p.match( ":", "(", "ctx", optional(":", "Context"), ")", @@ -276,7 +276,7 @@ func (p *parser) parsePermits() { }) default: - p.addFatal(item, "expected identifier or '}', got %q", item.Val) + p.addFatal(item, "expected identifier or '}', got %s %q", item.Typ.String(), item.Val) return } } diff --git a/internal/schema/parser_test.go b/internal/schema/parser_test.go index 40ee9fe3f..c00d94527 100644 --- a/internal/schema/parser_test.go +++ b/internal/schema/parser_test.go @@ -90,7 +90,7 @@ var parserTestCases = []struct { related: { parents: (File | Folder)[] viewers: (User | SubjectSet)[] - owners: (User | SubjectSet)[] + "owners": (User | SubjectSet)[] siblings: File[] } @@ -107,7 +107,7 @@ var parserTestCases = []struct { this.related.viewers.includes(ctx.subject) ) || this.related.owners.includes(ctx.subject), - edit: (ctx: Context) => this.related.owners.includes(ctx.subject), + 'edit': (ctx: Context) => this.related.owners.includes(ctx.subject), not: (ctx: Context) => !this.related.owners.includes(ctx.subject),