Skip to content

Commit 2e15dfb

Browse files
authored
fix: allow "view" and "import" as identifier (#750)
1 parent 43322e1 commit 2e15dfb

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

packages/language/src/generated/ast.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ export function isReferenceTarget(item: unknown): item is ReferenceTarget {
9494
return reflection.isInstance(item, ReferenceTarget);
9595
}
9696

97-
export type RegularID = 'abstract' | 'attribute' | 'datasource' | 'enum' | 'in' | 'model' | 'plugin' | 'sort' | string;
97+
export type RegularID = 'abstract' | 'attribute' | 'datasource' | 'enum' | 'import' | 'in' | 'model' | 'plugin' | 'sort' | 'view' | string;
9898

9999
export function isRegularID(item: unknown): item is RegularID {
100-
return item === 'model' || item === 'enum' || item === 'attribute' || item === 'datasource' || item === 'plugin' || item === 'abstract' || item === 'in' || item === 'sort' || (typeof item === 'string' && (/[_a-zA-Z][\w_]*/.test(item)));
100+
return item === 'model' || item === 'enum' || item === 'attribute' || item === 'datasource' || item === 'plugin' || item === 'abstract' || item === 'in' || item === 'sort' || item === 'view' || item === 'import' || (typeof item === 'string' && (/[_a-zA-Z][\w_]*/.test(item)));
101101
}
102102

103103
export type TypeDeclaration = DataModel | Enum;

packages/language/src/generated/grammar.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2771,6 +2771,14 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
27712771
{
27722772
"$type": "Keyword",
27732773
"value": "sort"
2774+
},
2775+
{
2776+
"$type": "Keyword",
2777+
"value": "view"
2778+
},
2779+
{
2780+
"$type": "Keyword",
2781+
"value": "import"
27742782
}
27752783
]
27762784
},

packages/language/src/zmodel.langium

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ QualifiedName returns string:
229229
// https://github.com/langium/langium/discussions/1012
230230
RegularID returns string:
231231
// include keywords that we'd like to work as ID in most places
232-
ID | 'model' | 'enum' | 'attribute' | 'datasource' | 'plugin' | 'abstract' | 'in' | 'sort';
232+
ID | 'model' | 'enum' | 'attribute' | 'datasource' | 'plugin' | 'abstract' | 'in' | 'sort' | 'view' | 'import';
233233

234234
// internal attribute
235235
InternalAttributeName returns string:
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { loadSchema } from '@zenstackhq/testtools';
2+
3+
describe('Regression: issue 735', () => {
4+
it('regression', async () => {
5+
await loadSchema(
6+
`
7+
model MyModel {
8+
id String @id @default(cuid())
9+
view String
10+
import Int
11+
}
12+
13+
model view {
14+
id String @id @default(cuid())
15+
name String
16+
}
17+
`,
18+
{ pushDb: false }
19+
);
20+
});
21+
});

0 commit comments

Comments
 (0)