diff --git a/.github/workflows/security.yaml b/.github/workflows/security.yaml index f9d56ae6b8..82edb83552 100644 --- a/.github/workflows/security.yaml +++ b/.github/workflows/security.yaml @@ -72,7 +72,7 @@ jobs: with: distribution: "goreleaser-pro" version: "2.3.2" - args: "release --clean --split --snapshot --single-target --skip=chocolatey" + args: "release --clean --split --snapshot --single-target" env: GORELEASER_KEY: "${{ secrets.GORELEASER_KEY }}" - name: "Obtain container image to scan" diff --git a/pkg/composableschemadsl/dslshape/dslshape.go b/pkg/composableschemadsl/dslshape/dslshape.go index 2421f59690..1d5a480165 100644 --- a/pkg/composableschemadsl/dslshape/dslshape.go +++ b/pkg/composableschemadsl/dslshape/dslshape.go @@ -35,6 +35,8 @@ const ( NodeTypeNilExpression // A nil keyword NodeTypeCaveatTypeReference // A type reference for a caveat parameter. + + NodeTypeImport ) const ( @@ -188,4 +190,12 @@ const ( // NodeExpressionPredicateLeftExpr = "left-expr" NodeExpressionPredicateRightExpr = "right-expr" + + // + // NodeTypeImport + // + // TODO: still need to figure out what form this should take - full path? relative path? + NodeImportPredicateSource = "import-source" + NodeImportPredicatePathSegment = "path-segment" + NodeImportPredicateDefinitionName = "imported-definition" ) diff --git a/pkg/composableschemadsl/dslshape/zz_generated.nodetype_string.go b/pkg/composableschemadsl/dslshape/zz_generated.nodetype_string.go index 3567416c6b..125fba8abc 100644 --- a/pkg/composableschemadsl/dslshape/zz_generated.nodetype_string.go +++ b/pkg/composableschemadsl/dslshape/zz_generated.nodetype_string.go @@ -27,11 +27,12 @@ func _() { _ = x[NodeTypeIdentifier-16] _ = x[NodeTypeNilExpression-17] _ = x[NodeTypeCaveatTypeReference-18] + _ = x[NodeTypeImport-19] } -const _NodeType_name = "NodeTypeErrorNodeTypeFileNodeTypeCommentNodeTypeDefinitionNodeTypeCaveatDefinitionNodeTypeCaveatParameterNodeTypeCaveatExpressionNodeTypeRelationNodeTypePermissionNodeTypeTypeReferenceNodeTypeSpecificTypeReferenceNodeTypeCaveatReferenceNodeTypeUnionExpressionNodeTypeIntersectExpressionNodeTypeExclusionExpressionNodeTypeArrowExpressionNodeTypeIdentifierNodeTypeNilExpressionNodeTypeCaveatTypeReference" +const _NodeType_name = "NodeTypeErrorNodeTypeFileNodeTypeCommentNodeTypeDefinitionNodeTypeCaveatDefinitionNodeTypeCaveatParameterNodeTypeCaveatExpressionNodeTypeRelationNodeTypePermissionNodeTypeTypeReferenceNodeTypeSpecificTypeReferenceNodeTypeCaveatReferenceNodeTypeUnionExpressionNodeTypeIntersectExpressionNodeTypeExclusionExpressionNodeTypeArrowExpressionNodeTypeIdentifierNodeTypeNilExpressionNodeTypeCaveatTypeReferenceNodeTypeImport" -var _NodeType_index = [...]uint16{0, 13, 25, 40, 58, 82, 105, 129, 145, 163, 184, 213, 236, 259, 286, 313, 336, 354, 375, 402} +var _NodeType_index = [...]uint16{0, 13, 25, 40, 58, 82, 105, 129, 145, 163, 184, 213, 236, 259, 286, 313, 336, 354, 375, 402, 416} func (i NodeType) String() string { if i < 0 || i >= NodeType(len(_NodeType_index)-1) { diff --git a/pkg/composableschemadsl/lexer/lex_def.go b/pkg/composableschemadsl/lexer/lex_def.go index a297352019..de178c3662 100644 --- a/pkg/composableschemadsl/lexer/lex_def.go +++ b/pkg/composableschemadsl/lexer/lex_def.go @@ -78,6 +78,8 @@ var keywords = map[string]struct{}{ "permission": {}, "nil": {}, "with": {}, + "from": {}, + "import": {}, } // IsKeyword returns whether the specified input string is a reserved keyword. diff --git a/pkg/composableschemadsl/parser/parser.go b/pkg/composableschemadsl/parser/parser.go index 8c2b14298f..1cc1b2a863 100644 --- a/pkg/composableschemadsl/parser/parser.go +++ b/pkg/composableschemadsl/parser/parser.go @@ -62,6 +62,9 @@ Loop: case p.isKeyword("caveat"): rootNode.Connect(dslshape.NodePredicateChild, p.consumeCaveat()) + case p.isKeyword("from"): + rootNode.Connect(dslshape.NodePredicateChild, p.consumeImport()) + default: p.emitErrorf("Unexpected token at root level: %v", p.currentToken.Kind) break Loop @@ -574,6 +577,20 @@ func (p *sourceParser) tryConsumeIdentifierLiteral() (AstNode, bool) { return identNode, true } +// consumeIdentifierLiteral is similar to the above, but attempts and errors +// rather than checking the token type beforehand +func (p *sourceParser) consumeIdentifierLiteral() (AstNode, bool) { + identNode := p.startNode(dslshape.NodeTypeIdentifier) + defer p.mustFinishNode() + + identifier, ok := p.consumeIdentifier() + if !ok { + return identNode, false + } + identNode.MustDecorate(dslshape.NodeIdentiferPredicateValue, identifier) + return identNode, true +} + func (p *sourceParser) tryConsumeNilExpression() (AstNode, bool) { if !p.isKeyword("nil") { return nil, false @@ -584,3 +601,58 @@ func (p *sourceParser) tryConsumeNilExpression() (AstNode, bool) { defer p.mustFinishNode() return node, true } + +func (p *sourceParser) consumeImport() AstNode { + importNode := p.startNode(dslshape.NodeTypeImport) + defer p.mustFinishNode() + + // from ... + // NOTE: error handling isn't necessary here because this function is only + // invoked if the `from` keyword is found in the function above. + p.consumeKeyword("from") + + // Consume alternating periods and identifiers + for { + if _, ok := p.consume(lexer.TokenTypePeriod); !ok { + return importNode + } + + segmentNode, ok := p.consumeIdentifierLiteral() + // We connect the node so that the error information is retained, then break the loop + // so that we aren't continuing to attempt to consume. + importNode.Connect(dslshape.NodeImportPredicatePathSegment, segmentNode) + if !ok { + break + } + + if !p.isToken(lexer.TokenTypePeriod) { + // If we don't have a period as our next token, we move + // to the next step of parsing. + break + } + } + + if ok := p.consumeKeyword("import"); !ok { + return importNode + } + + // Consume alternating identifiers and commas until we reach the end of the import statement + for { + definitionNode, ok := p.consumeIdentifierLiteral() + // We connect the node so that the error information is retained, then break the loop + // so that we aren't continuing to attempt to consume. + importNode.Connect(dslshape.NodeImportPredicateDefinitionName, definitionNode) + if !ok { + break + } + + if _, ok := p.tryConsumeStatementTerminator(); ok { + break + } + if _, ok := p.consume(lexer.TokenTypeComma); !ok { + return importNode + } + } + + return importNode +} diff --git a/pkg/composableschemadsl/parser/parser_test.go b/pkg/composableschemadsl/parser/parser_test.go index c14dcfb5e9..066e95408c 100644 --- a/pkg/composableschemadsl/parser/parser_test.go +++ b/pkg/composableschemadsl/parser/parser_test.go @@ -122,6 +122,13 @@ func TestParser(t *testing.T) { {"arrow illegal operations test", "arrowillegalops"}, {"arrow illegal function test", "arrowillegalfunc"}, {"caveat with keyword parameter test", "caveatwithkeywordparam"}, + {"local imports test", "localimport"}, + {"local imports with keyword in import path test", "localimport_import_path_with_keyword"}, + {"local imports with keyword in identifiers test", "localimport_keyword_in_identifiers"}, + {"local imports with malformed identifiers set test", "localimport_malformed_identifier_set"}, + {"local imports with malformed import path test", "localimport_malformed_import_path"}, + {"local imports with path missing leading period test", "localimport_path_missing_leading_period"}, + {"local imports with typo in import separator test", "localimport_typo_in_import_separator"}, } for _, test := range parserTests { diff --git a/pkg/composableschemadsl/parser/tests/localimport.zed b/pkg/composableschemadsl/parser/tests/localimport.zed new file mode 100644 index 0000000000..43f3c04786 --- /dev/null +++ b/pkg/composableschemadsl/parser/tests/localimport.zed @@ -0,0 +1,7 @@ +from .path.to.user import user, persona + +definition resource { + relation user: user + relation persona: persona + permission view = user + persona +} diff --git a/pkg/composableschemadsl/parser/tests/localimport.zed.expected b/pkg/composableschemadsl/parser/tests/localimport.zed.expected new file mode 100644 index 0000000000..34ff6ac77a --- /dev/null +++ b/pkg/composableschemadsl/parser/tests/localimport.zed.expected @@ -0,0 +1,96 @@ +NodeTypeFile + end-rune = 155 + input-source = local imports test + start-rune = 0 + child-node => + NodeTypeImport + end-rune = 39 + input-source = local imports test + start-rune = 0 + imported-definition => + NodeTypeIdentifier + end-rune = 29 + identifier-value = user + input-source = local imports test + start-rune = 26 + NodeTypeIdentifier + end-rune = 38 + identifier-value = persona + input-source = local imports test + start-rune = 32 + path-segment => + NodeTypeIdentifier + end-rune = 9 + identifier-value = path + input-source = local imports test + start-rune = 6 + NodeTypeIdentifier + end-rune = 12 + identifier-value = to + input-source = local imports test + start-rune = 11 + NodeTypeIdentifier + end-rune = 17 + identifier-value = user + input-source = local imports test + start-rune = 14 + NodeTypeDefinition + definition-name = resource + end-rune = 154 + input-source = local imports test + start-rune = 41 + child-node => + NodeTypeRelation + end-rune = 85 + input-source = local imports test + relation-name = user + start-rune = 67 + allowed-types => + NodeTypeTypeReference + end-rune = 85 + input-source = local imports test + start-rune = 82 + type-ref-type => + NodeTypeSpecificTypeReference + end-rune = 85 + input-source = local imports test + start-rune = 82 + type-name = user + NodeTypeRelation + end-rune = 115 + input-source = local imports test + relation-name = persona + start-rune = 91 + allowed-types => + NodeTypeTypeReference + end-rune = 115 + input-source = local imports test + start-rune = 109 + type-ref-type => + NodeTypeSpecificTypeReference + end-rune = 115 + input-source = local imports test + start-rune = 109 + type-name = persona + NodeTypePermission + end-rune = 152 + input-source = local imports test + relation-name = view + start-rune = 121 + compute-expression => + NodeTypeUnionExpression + end-rune = 152 + input-source = local imports test + start-rune = 139 + left-expr => + NodeTypeIdentifier + end-rune = 142 + identifier-value = user + input-source = local imports test + start-rune = 139 + right-expr => + NodeTypeIdentifier + end-rune = 152 + identifier-value = persona + input-source = local imports test + start-rune = 146 \ No newline at end of file diff --git a/pkg/composableschemadsl/parser/tests/localimport_import_path_with_keyword.zed b/pkg/composableschemadsl/parser/tests/localimport_import_path_with_keyword.zed new file mode 100644 index 0000000000..0cd749f17e --- /dev/null +++ b/pkg/composableschemadsl/parser/tests/localimport_import_path_with_keyword.zed @@ -0,0 +1,7 @@ +from .path.definition.user import user, persona + +definition resource { + relation user: user + relation persona: persona + permission view = user + persona +} diff --git a/pkg/composableschemadsl/parser/tests/localimport_import_path_with_keyword.zed.expected b/pkg/composableschemadsl/parser/tests/localimport_import_path_with_keyword.zed.expected new file mode 100644 index 0000000000..3eaa12515d --- /dev/null +++ b/pkg/composableschemadsl/parser/tests/localimport_import_path_with_keyword.zed.expected @@ -0,0 +1,50 @@ +NodeTypeFile + end-rune = 20 + input-source = local imports with keyword in import path test + start-rune = 0 + child-node => + NodeTypeImport + end-rune = 10 + input-source = local imports with keyword in import path test + start-rune = 0 + child-node => + NodeTypeError + end-rune = 10 + error-message = Expected keyword import, found token TokenTypeKeyword + error-source = definition + input-source = local imports with keyword in import path test + start-rune = 11 + path-segment => + NodeTypeIdentifier + end-rune = 9 + identifier-value = path + input-source = local imports with keyword in import path test + start-rune = 6 + NodeTypeIdentifier + end-rune = 10 + input-source = local imports with keyword in import path test + start-rune = 11 + child-node => + NodeTypeError + end-rune = 10 + error-message = Expected identifier, found token TokenTypeKeyword + error-source = definition + input-source = local imports with keyword in import path test + start-rune = 11 + NodeTypeDefinition + end-rune = 20 + input-source = local imports with keyword in import path test + start-rune = 11 + child-node => + NodeTypeError + end-rune = 20 + error-message = Expected identifier, found token TokenTypePeriod + error-source = . + input-source = local imports with keyword in import path test + start-rune = 21 + NodeTypeError + end-rune = 20 + error-message = Unexpected token at root level: TokenTypePeriod + error-source = . + input-source = local imports with keyword in import path test + start-rune = 21 \ No newline at end of file diff --git a/pkg/composableschemadsl/parser/tests/localimport_keyword_in_identifiers.zed b/pkg/composableschemadsl/parser/tests/localimport_keyword_in_identifiers.zed new file mode 100644 index 0000000000..4c2e87c804 --- /dev/null +++ b/pkg/composableschemadsl/parser/tests/localimport_keyword_in_identifiers.zed @@ -0,0 +1,7 @@ +from .path.to.user import user, caveat + +definition resource { + relation user: user + relation persona: persona + permission view = user + persona +} diff --git a/pkg/composableschemadsl/parser/tests/localimport_keyword_in_identifiers.zed.expected b/pkg/composableschemadsl/parser/tests/localimport_keyword_in_identifiers.zed.expected new file mode 100644 index 0000000000..068371eeea --- /dev/null +++ b/pkg/composableschemadsl/parser/tests/localimport_keyword_in_identifiers.zed.expected @@ -0,0 +1,114 @@ +NodeTypeFile + end-rune = 154 + input-source = local imports with keyword in identifiers test + start-rune = 0 + child-node => + NodeTypeImport + end-rune = 30 + input-source = local imports with keyword in identifiers test + start-rune = 0 + imported-definition => + NodeTypeIdentifier + end-rune = 29 + identifier-value = user + input-source = local imports with keyword in identifiers test + start-rune = 26 + NodeTypeIdentifier + end-rune = 30 + input-source = local imports with keyword in identifiers test + start-rune = 32 + child-node => + NodeTypeError + end-rune = 30 + error-message = Expected identifier, found token TokenTypeKeyword + error-source = caveat + input-source = local imports with keyword in identifiers test + start-rune = 32 + path-segment => + NodeTypeIdentifier + end-rune = 9 + identifier-value = path + input-source = local imports with keyword in identifiers test + start-rune = 6 + NodeTypeIdentifier + end-rune = 12 + identifier-value = to + input-source = local imports with keyword in identifiers test + start-rune = 11 + NodeTypeIdentifier + end-rune = 17 + identifier-value = user + input-source = local imports with keyword in identifiers test + start-rune = 14 + NodeTypeCaveatDefinition + end-rune = 37 + input-source = local imports with keyword in identifiers test + start-rune = 32 + child-node => + NodeTypeError + end-rune = 37 + error-message = Expected identifier, found token TokenTypeSyntheticSemicolon + error-source = + + input-source = local imports with keyword in identifiers test + start-rune = 38 + NodeTypeDefinition + definition-name = resource + end-rune = 153 + input-source = local imports with keyword in identifiers test + start-rune = 40 + child-node => + NodeTypeRelation + end-rune = 84 + input-source = local imports with keyword in identifiers test + relation-name = user + start-rune = 66 + allowed-types => + NodeTypeTypeReference + end-rune = 84 + input-source = local imports with keyword in identifiers test + start-rune = 81 + type-ref-type => + NodeTypeSpecificTypeReference + end-rune = 84 + input-source = local imports with keyword in identifiers test + start-rune = 81 + type-name = user + NodeTypeRelation + end-rune = 114 + input-source = local imports with keyword in identifiers test + relation-name = persona + start-rune = 90 + allowed-types => + NodeTypeTypeReference + end-rune = 114 + input-source = local imports with keyword in identifiers test + start-rune = 108 + type-ref-type => + NodeTypeSpecificTypeReference + end-rune = 114 + input-source = local imports with keyword in identifiers test + start-rune = 108 + type-name = persona + NodeTypePermission + end-rune = 151 + input-source = local imports with keyword in identifiers test + relation-name = view + start-rune = 120 + compute-expression => + NodeTypeUnionExpression + end-rune = 151 + input-source = local imports with keyword in identifiers test + start-rune = 138 + left-expr => + NodeTypeIdentifier + end-rune = 141 + identifier-value = user + input-source = local imports with keyword in identifiers test + start-rune = 138 + right-expr => + NodeTypeIdentifier + end-rune = 151 + identifier-value = persona + input-source = local imports with keyword in identifiers test + start-rune = 145 \ No newline at end of file diff --git a/pkg/composableschemadsl/parser/tests/localimport_malformed_identifier_set.zed b/pkg/composableschemadsl/parser/tests/localimport_malformed_identifier_set.zed new file mode 100644 index 0000000000..b3b46b1d28 --- /dev/null +++ b/pkg/composableschemadsl/parser/tests/localimport_malformed_identifier_set.zed @@ -0,0 +1,7 @@ +from .path.to.user import user, + +definition resource { + relation user: user + relation persona: persona + permission view = user + persona +} diff --git a/pkg/composableschemadsl/parser/tests/localimport_malformed_identifier_set.zed.expected b/pkg/composableschemadsl/parser/tests/localimport_malformed_identifier_set.zed.expected new file mode 100644 index 0000000000..7ef947d008 --- /dev/null +++ b/pkg/composableschemadsl/parser/tests/localimport_malformed_identifier_set.zed.expected @@ -0,0 +1,102 @@ +NodeTypeFile + end-rune = 147 + input-source = local imports with malformed identifiers set test + start-rune = 0 + child-node => + NodeTypeImport + end-rune = 30 + input-source = local imports with malformed identifiers set test + start-rune = 0 + imported-definition => + NodeTypeIdentifier + end-rune = 29 + identifier-value = user + input-source = local imports with malformed identifiers set test + start-rune = 26 + NodeTypeIdentifier + end-rune = 30 + input-source = local imports with malformed identifiers set test + start-rune = 33 + child-node => + NodeTypeError + end-rune = 30 + error-message = Expected identifier, found token TokenTypeKeyword + error-source = definition + input-source = local imports with malformed identifiers set test + start-rune = 33 + path-segment => + NodeTypeIdentifier + end-rune = 9 + identifier-value = path + input-source = local imports with malformed identifiers set test + start-rune = 6 + NodeTypeIdentifier + end-rune = 12 + identifier-value = to + input-source = local imports with malformed identifiers set test + start-rune = 11 + NodeTypeIdentifier + end-rune = 17 + identifier-value = user + input-source = local imports with malformed identifiers set test + start-rune = 14 + NodeTypeDefinition + definition-name = resource + end-rune = 146 + input-source = local imports with malformed identifiers set test + start-rune = 33 + child-node => + NodeTypeRelation + end-rune = 77 + input-source = local imports with malformed identifiers set test + relation-name = user + start-rune = 59 + allowed-types => + NodeTypeTypeReference + end-rune = 77 + input-source = local imports with malformed identifiers set test + start-rune = 74 + type-ref-type => + NodeTypeSpecificTypeReference + end-rune = 77 + input-source = local imports with malformed identifiers set test + start-rune = 74 + type-name = user + NodeTypeRelation + end-rune = 107 + input-source = local imports with malformed identifiers set test + relation-name = persona + start-rune = 83 + allowed-types => + NodeTypeTypeReference + end-rune = 107 + input-source = local imports with malformed identifiers set test + start-rune = 101 + type-ref-type => + NodeTypeSpecificTypeReference + end-rune = 107 + input-source = local imports with malformed identifiers set test + start-rune = 101 + type-name = persona + NodeTypePermission + end-rune = 144 + input-source = local imports with malformed identifiers set test + relation-name = view + start-rune = 113 + compute-expression => + NodeTypeUnionExpression + end-rune = 144 + input-source = local imports with malformed identifiers set test + start-rune = 131 + left-expr => + NodeTypeIdentifier + end-rune = 134 + identifier-value = user + input-source = local imports with malformed identifiers set test + start-rune = 131 + right-expr => + NodeTypeIdentifier + end-rune = 144 + identifier-value = persona + input-source = local imports with malformed identifiers set test + start-rune = 138 \ No newline at end of file diff --git a/pkg/composableschemadsl/parser/tests/localimport_malformed_import_path.zed b/pkg/composableschemadsl/parser/tests/localimport_malformed_import_path.zed new file mode 100644 index 0000000000..e15bb6713f --- /dev/null +++ b/pkg/composableschemadsl/parser/tests/localimport_malformed_import_path.zed @@ -0,0 +1,7 @@ +from .path.to. import user, persona + +definition resource { + relation user: user + relation persona: persona + permission view = user + persona +} diff --git a/pkg/composableschemadsl/parser/tests/localimport_malformed_import_path.zed.expected b/pkg/composableschemadsl/parser/tests/localimport_malformed_import_path.zed.expected new file mode 100644 index 0000000000..d7bf922abe --- /dev/null +++ b/pkg/composableschemadsl/parser/tests/localimport_malformed_import_path.zed.expected @@ -0,0 +1,102 @@ +NodeTypeFile + end-rune = 151 + input-source = local imports with malformed import path test + start-rune = 0 + child-node => + NodeTypeImport + end-rune = 35 + input-source = local imports with malformed import path test + start-rune = 0 + imported-definition => + NodeTypeIdentifier + end-rune = 25 + identifier-value = user + input-source = local imports with malformed import path test + start-rune = 22 + NodeTypeIdentifier + end-rune = 34 + identifier-value = persona + input-source = local imports with malformed import path test + start-rune = 28 + path-segment => + NodeTypeIdentifier + end-rune = 9 + identifier-value = path + input-source = local imports with malformed import path test + start-rune = 6 + NodeTypeIdentifier + end-rune = 12 + identifier-value = to + input-source = local imports with malformed import path test + start-rune = 11 + NodeTypeIdentifier + end-rune = 13 + input-source = local imports with malformed import path test + start-rune = 15 + child-node => + NodeTypeError + end-rune = 13 + error-message = Expected identifier, found token TokenTypeKeyword + error-source = import + input-source = local imports with malformed import path test + start-rune = 15 + NodeTypeDefinition + definition-name = resource + end-rune = 150 + input-source = local imports with malformed import path test + start-rune = 37 + child-node => + NodeTypeRelation + end-rune = 81 + input-source = local imports with malformed import path test + relation-name = user + start-rune = 63 + allowed-types => + NodeTypeTypeReference + end-rune = 81 + input-source = local imports with malformed import path test + start-rune = 78 + type-ref-type => + NodeTypeSpecificTypeReference + end-rune = 81 + input-source = local imports with malformed import path test + start-rune = 78 + type-name = user + NodeTypeRelation + end-rune = 111 + input-source = local imports with malformed import path test + relation-name = persona + start-rune = 87 + allowed-types => + NodeTypeTypeReference + end-rune = 111 + input-source = local imports with malformed import path test + start-rune = 105 + type-ref-type => + NodeTypeSpecificTypeReference + end-rune = 111 + input-source = local imports with malformed import path test + start-rune = 105 + type-name = persona + NodeTypePermission + end-rune = 148 + input-source = local imports with malformed import path test + relation-name = view + start-rune = 117 + compute-expression => + NodeTypeUnionExpression + end-rune = 148 + input-source = local imports with malformed import path test + start-rune = 135 + left-expr => + NodeTypeIdentifier + end-rune = 138 + identifier-value = user + input-source = local imports with malformed import path test + start-rune = 135 + right-expr => + NodeTypeIdentifier + end-rune = 148 + identifier-value = persona + input-source = local imports with malformed import path test + start-rune = 142 \ No newline at end of file diff --git a/pkg/composableschemadsl/parser/tests/localimport_path_missing_leading_period.zed b/pkg/composableschemadsl/parser/tests/localimport_path_missing_leading_period.zed new file mode 100644 index 0000000000..45ddc27060 --- /dev/null +++ b/pkg/composableschemadsl/parser/tests/localimport_path_missing_leading_period.zed @@ -0,0 +1,7 @@ +from path.to.user import user, persona + +definition resource { + relation user: user + relation persona: persona + permission view = user + persona +} diff --git a/pkg/composableschemadsl/parser/tests/localimport_path_missing_leading_period.zed.expected b/pkg/composableschemadsl/parser/tests/localimport_path_missing_leading_period.zed.expected new file mode 100644 index 0000000000..1638642b68 --- /dev/null +++ b/pkg/composableschemadsl/parser/tests/localimport_path_missing_leading_period.zed.expected @@ -0,0 +1,22 @@ +NodeTypeFile + end-rune = 3 + input-source = local imports with path missing leading period test + start-rune = 0 + child-node => + NodeTypeImport + end-rune = 3 + input-source = local imports with path missing leading period test + start-rune = 0 + child-node => + NodeTypeError + end-rune = 3 + error-message = Expected one of: [TokenTypePeriod], found: TokenTypeIdentifier + error-source = path + input-source = local imports with path missing leading period test + start-rune = 5 + NodeTypeError + end-rune = 3 + error-message = Unexpected token at root level: TokenTypeIdentifier + error-source = path + input-source = local imports with path missing leading period test + start-rune = 5 \ No newline at end of file diff --git a/pkg/composableschemadsl/parser/tests/localimport_typo_in_import_separator.zed b/pkg/composableschemadsl/parser/tests/localimport_typo_in_import_separator.zed new file mode 100644 index 0000000000..79817cba19 --- /dev/null +++ b/pkg/composableschemadsl/parser/tests/localimport_typo_in_import_separator.zed @@ -0,0 +1,7 @@ +from .path.to.user impoort user, persona + +definition resource { + relation user: user + relation persona: persona + permission view = user + persona +} diff --git a/pkg/composableschemadsl/parser/tests/localimport_typo_in_import_separator.zed.expected b/pkg/composableschemadsl/parser/tests/localimport_typo_in_import_separator.zed.expected new file mode 100644 index 0000000000..8271c8c14e --- /dev/null +++ b/pkg/composableschemadsl/parser/tests/localimport_typo_in_import_separator.zed.expected @@ -0,0 +1,38 @@ +NodeTypeFile + end-rune = 17 + input-source = local imports with typo in import separator test + start-rune = 0 + child-node => + NodeTypeImport + end-rune = 17 + input-source = local imports with typo in import separator test + start-rune = 0 + child-node => + NodeTypeError + end-rune = 17 + error-message = Expected keyword import, found token TokenTypeIdentifier + error-source = impoort + input-source = local imports with typo in import separator test + start-rune = 19 + path-segment => + NodeTypeIdentifier + end-rune = 9 + identifier-value = path + input-source = local imports with typo in import separator test + start-rune = 6 + NodeTypeIdentifier + end-rune = 12 + identifier-value = to + input-source = local imports with typo in import separator test + start-rune = 11 + NodeTypeIdentifier + end-rune = 17 + identifier-value = user + input-source = local imports with typo in import separator test + start-rune = 14 + NodeTypeError + end-rune = 17 + error-message = Unexpected token at root level: TokenTypeIdentifier + error-source = impoort + input-source = local imports with typo in import separator test + start-rune = 19 \ No newline at end of file