Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add composable schema test syntax parsing #2133

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion pkg/composableschemadsl/compiler/development_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func TestPositionToAstNode(t *testing.T) {
line: 2,
column: 6,
expected: []dslshape.NodeType{
dslshape.NodeTypeCaveatExpression,
dslshape.NodeTypeOpaqueBraceExpression,
dslshape.NodeTypeCaveatDefinition,
dslshape.NodeTypeFile,
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/composableschemadsl/compiler/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,12 @@ func translateCaveatDefinition(tctx translationContext, defNode *dslNode) (*core
}

// caveat expression.
expressionStringNode, err := defNode.Lookup(dslshape.NodeCaveatDefinitionPredicateExpession)
expressionStringNode, err := defNode.Lookup(dslshape.NodeOpaqueBraceExpressionPredicateExpression)
if err != nil {
return nil, defNode.ErrorWithSourcef(definitionName, "invalid expression: %w", err)
}

expressionString, err := expressionStringNode.GetString(dslshape.NodeCaveatExpressionPredicateExpression)
expressionString, err := expressionStringNode.GetString(dslshape.NodeOpaqueBraceExpressionPredicateExpression)
if err != nil {
return nil, defNode.ErrorWithSourcef(expressionString, "invalid expression: %w", err)
}
Expand Down
34 changes: 34 additions & 0 deletions pkg/composableschemadsl/dslshape/dslshape.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:generate go run golang.org/x/tools/cmd/stringer -type=NodeType -output zz_generated.nodetype_string.go

Check failure on line 1 in pkg/composableschemadsl/dslshape/dslshape.go

View workflow job for this annotation

GitHub Actions / Lint Go

Please run go run mage.go lint:go. diff --git a/pkg/composableschemadsl/dslshape/dslshape.go b/pkg/composableschemadsl/dslshape/dslshape.go index 34255a0..bb9edfc 100644 --- a/pkg/composableschemadsl/dslshape/dslshape.go +++ b/pkg/composableschemadsl/dslshape/dslshape.go @@ -216,10 +216,10 @@ const ( NodeTestPredicateName = "test-name" - NodeTestPredicateSubject = "subject" - NodeTestPredicateObject = "object" - NodeTestPredicateRelation = "relation" - NodeTestPredicatePermission = "permission" + NodeTestPredicateSubject = "subject" + NodeTestPredicateObject = "object" + NodeTestPredicateRelation = "relation" + NodeTestPredicatePermission = "permission" NodeTestPredicateAssertionType = "assertion-type" NodeTestPredicateCaveatName = "caveat-name" NodeTestPredicateCaveatContext = "caveat-context"

// Package dslshape defines the types representing the structure of schema DSL.
package dslshape
Expand Down Expand Up @@ -37,6 +37,21 @@
NodeTypeCaveatTypeReference // A type reference for a caveat parameter.

NodeTypeImport

// A balanced brace-enclosed expression. Represents both caveat CELs and caveat JSON context.
NodeTypeOpaqueBraceExpression

NodeTypeTest
NodeTypeTestRelations
NodeTypeTestRelation
NodeTypeTestObject
NodeTypeTestPermission
NodeTypeTestNegativePermission
NodeTypeTestAssertions
NodeTypeTestAssertion
NodeTypeTestExpectedRelations
NodeTypeTestExpectedRelation
NodeTypeTestExpectedRelationSource
)

const (
Expand Down Expand Up @@ -198,4 +213,23 @@
NodeImportPredicateSource = "import-source"
NodeImportPredicatePathSegment = "path-segment"
NodeImportPredicateDefinitionName = "imported-definition"

NodeTestPredicateName = "test-name"

NodeTestPredicateSubject = "subject"
NodeTestPredicateObject = "object"
NodeTestPredicateRelation = "relation"
NodeTestPredicatePermission = "permission"
NodeTestPredicateAssertionType = "assertion-type"
NodeTestPredicateCaveatName = "caveat-name"
NodeTestPredicateCaveatContext = "caveat-context"

NodeTestObjectPredicateObjectType = "object-type"
NodeTestObjectPredicateObjectID = "object-id"
// Used for both positive and negative permissions
NodeTestRelationPermissionPredicateName = "permission-name"

NodeTestExpectedRelationSourcePredicateCaveatAnnotation = "caveat-annotation"

NodeOpaqueBraceExpressionPredicateExpression = "expression"
)
7 changes: 7 additions & 0 deletions pkg/composableschemadsl/lexer/lex_def.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ var keywords = map[string]struct{}{
"import": {},
"all": {},
"any": {},
// Test keywords
"test": {},
"relationships": {},
"assertions": {},
"expected": {},
"is": {},
"of": {},
}

// IsKeyword returns whether the specified input string is a reserved keyword.
Expand Down
Loading
Loading