Skip to content

Commit

Permalink
feat: add limited support for mixed operators (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
adriantam authored Dec 11, 2023
2 parents 779e682 + 41d9bc8 commit b996e0f
Show file tree
Hide file tree
Showing 27 changed files with 3,698 additions and 1,149 deletions.
26 changes: 23 additions & 3 deletions OpenFGAParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,32 @@ modelHeader: (multiLineComment NEWLINE)? MODEL NEWLINE SCHEMA WHITESPACE schemaV
typeDefs: typeDef*;
typeDef: (NEWLINE multiLineComment)? NEWLINE TYPE WHITESPACE typeName=IDENTIFIER (NEWLINE RELATIONS relationDeclaration+)?;

relationDeclaration: NEWLINE DEFINE WHITESPACE relationName WHITESPACE? COLON WHITESPACE? relationDef;
// Relation definitions
relationDeclaration: NEWLINE DEFINE WHITESPACE relationName WHITESPACE? COLON WHITESPACE? (relationDef);
relationName: IDENTIFIER;
relationDef: (relationDefDirectAssignment | relationDefGrouping) (relationDefPartials)?;
relationDefPartials: (WHITESPACE OR WHITESPACE relationDefGrouping)+ | (WHITESPACE AND WHITESPACE relationDefGrouping)+ | (WHITESPACE BUT_NOT WHITESPACE relationDefGrouping)+;

relationDef: (relationDefDirectAssignment | relationDefGrouping | relationRecurse) (relationDefPartials)?;
relationDefNoDirect: (relationDefGrouping | relationRecurseNoDirect) (relationDefPartials)?;

relationDefPartials:
(WHITESPACE OR WHITESPACE (relationDefGrouping | relationRecurseNoDirect))+
| (WHITESPACE AND WHITESPACE (relationDefGrouping | relationRecurseNoDirect))+
| (WHITESPACE BUT_NOT WHITESPACE (relationDefGrouping | relationRecurseNoDirect));

relationDefGrouping: relationDefRewrite;

relationRecurse:
LPAREN WHITESPACE* (
relationDef |
relationRecurseNoDirect
) WHITESPACE* RPAREN;

relationRecurseNoDirect:
LPAREN WHITESPACE* (
relationDefNoDirect |
relationRecurseNoDirect
) WHITESPACE* RPAREN;

relationDefDirectAssignment: LBRACKET WHITESPACE? relationDefTypeRestriction WHITESPACE? (COMMA WHITESPACE? relationDefTypeRestriction WHITESPACE?)* RPRACKET;
relationDefRewrite: rewriteComputedusersetName=IDENTIFIER (WHITESPACE FROM WHITESPACE rewriteTuplesetName=IDENTIFIER)?;

Expand Down
2 changes: 1 addition & 1 deletion pkg/go/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
var ErrUnsupportedJSON = errors.New("json not currently supported by dsl")

func UnsupportedDSLNestingError(typeName string, relationName string) error {
return fmt.Errorf("the '%s' relation under the '%s' type has mixed operators which are not supported by the OpenFGA DSL syntax yet", relationName, typeName)
return fmt.Errorf("the '%s' relation definition under the '%s' type is not supported by the OpenFGA DSL syntax yet", relationName, typeName)
}

func ConditionNameDoesntMatchError(conditionName string, conditionNestedName string) error {
Expand Down
5 changes: 4 additions & 1 deletion pkg/go/gen/OpenFGAParser.interp

Large diffs are not rendered by default.

1,794 changes: 1,301 additions & 493 deletions pkg/go/gen/openfga_parser.go

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions pkg/go/gen/openfgaparser_base_listener.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions pkg/go/gen/openfgaparser_listener.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/go/transformer/dsltojson.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ func (l *OpenFgaDslListener) EnterRelationDefPartials(ctx *parser.RelationDefPar
l.currentRelation.Operator = RELATION_DEFINITION_OPERATOR_OR
} else if len(ctx.AllAND()) > 0 {
l.currentRelation.Operator = RELATION_DEFINITION_OPERATOR_AND
} else if len(ctx.AllBUT_NOT()) > 0 {
} else if ctx.BUT_NOT() != nil {
l.currentRelation.Operator = RELATION_DEFINITION_OPERATOR_BUT_NOT
}
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/js/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## v0.2.0-beta.6

### [v0.2.0-beta.6](https://github.com/openfga/language/releases/tag/vv0.2.0-beta.3...v0.2.0-beta.4) (2023-12-11)

last commit: 8b692a44e937beae8693cc155b205ffc5b732fbe

Added:
- Initial limited support for mixing operators [#107](https://github.com/openfga/language/pull/107)

## v0.2.0-beta.4

### [v0.2.0-beta.4](https://github.com/openfga/language/releases/tag/vv0.2.0-beta.3...v0.2.0-beta.4) (2023-10-04)
Expand Down
2 changes: 1 addition & 1 deletion pkg/js/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export class UnsupportedDSLNestingError extends Error {
public relationName: string,
) {
super(
`the '${relationName}' relation under the '${typeName}' type has mixed operators which are not supported by the OpenFGA DSL syntax yet`,
`the '${relationName}' relation definition under the '${typeName}' type is not supported by the OpenFGA DSL syntax yet`,
);
}
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/js/gen/OpenFGAParser.interp

Large diffs are not rendered by default.

Loading

0 comments on commit b996e0f

Please sign in to comment.