Skip to content

Commit

Permalink
fix: supporting using type names as reference target as well
Browse files Browse the repository at this point in the history
  • Loading branch information
ymc9 committed May 20, 2024
1 parent 5a13d8b commit d17a85c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/language/src/generated/grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
"terminal": {
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@46"
"$ref": "#/rules@47"
},
"arguments": []
},
Expand Down
2 changes: 1 addition & 1 deletion packages/language/src/zmodel.langium
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ NullExpr:
value='null';

ReferenceExpr:
target=[ReferenceTarget:RegularID] ('(' ReferenceArgList ')')?;
target=[ReferenceTarget:RegularIDWithTypeNames] ('(' ReferenceArgList ')')?;

fragment ReferenceArgList:
args+=ReferenceArg (',' args+=ReferenceArg)*;
Expand Down
18 changes: 18 additions & 0 deletions packages/schema/tests/schema/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,24 @@ describe('Parsing Tests', () => {
expect((attrVal.value as ReferenceExpr).target.ref?.name).toBe('USER');
});

it('enum fields named with type name', async () => {
const content = `
enum MyEnum {
DateTime
Int
String
}
model User {
id String @id
role MyEnum @default(DateTime)
@@allow('all', role == String)
}
`;
await loadModel(content);
});

it('enum dup name resolve', async () => {
const content = `
datasource db {
Expand Down

0 comments on commit d17a85c

Please sign in to comment.