77/* eslint-disable @typescript-eslint/no-empty-interface */
88import { AstNode , AstReflection , Reference , isAstNode , TypeMetaData } from 'langium' ;
99
10- export type Expression = ArrayExpr | BinaryExpr | EnumMemberExpr | InvocationExpr | LiteralExpr | ReferenceExpr | UnaryExpr ;
10+ export type AbstractDeclaration = Attribute | DataModel | DataSource | Enum | Function ;
11+
12+ export const AbstractDeclaration = 'AbstractDeclaration' ;
13+
14+ export function isAbstractDeclaration ( item : unknown ) : item is AbstractDeclaration {
15+ return reflection . isInstance ( item , AbstractDeclaration ) ;
16+ }
17+
18+ export type Expression = ArrayExpr | BinaryExpr | InvocationExpr | LiteralExpr | ReferenceExpr | UnaryExpr ;
1119
1220export const Expression = 'Expression' ;
1321
1422export function isExpression ( item : unknown ) : item is Expression {
1523 return reflection . isInstance ( item , Expression ) ;
1624}
1725
18- export type ReferenceTarget = DataModelField | Function | FunctionParam ;
26+ export type QualifiedName = string ;
27+
28+ export type ReferenceTarget = DataModelField | EnumField | Function | FunctionParam ;
1929
2030export const ReferenceTarget = 'ReferenceTarget' ;
2131
@@ -94,8 +104,8 @@ export function isDataModelAttribute(item: unknown): item is DataModelAttribute
94104export interface DataModelField extends AstNode {
95105 readonly $container : DataModel ;
96106 attributes : Array < DataModelFieldAttribute >
97- fieldType : DataModelFieldType
98107 name : string
108+ type : DataModelFieldType
99109}
100110
101111export const DataModelField = 'DataModelField' ;
@@ -168,7 +178,7 @@ export function isEnum(item: unknown): item is Enum {
168178
169179export interface EnumField extends AstNode {
170180 readonly $container : Enum ;
171- value : string
181+ name : string
172182}
173183
174184export const EnumField = 'EnumField' ;
@@ -177,18 +187,6 @@ export function isEnumField(item: unknown): item is EnumField {
177187 return reflection . isInstance ( item , EnumField ) ;
178188}
179189
180- export interface EnumMemberExpr extends AstNode {
181- readonly $container : ArrayExpr | BinaryExpr | DataModelAttribute | DataModelFieldAttribute | DataSourceField | Function | InvocationExpr | UnaryExpr ;
182- decl : Reference < Enum >
183- member : string
184- }
185-
186- export const EnumMemberExpr = 'EnumMemberExpr' ;
187-
188- export function isEnumMemberExpr ( item : unknown ) : item is EnumMemberExpr {
189- return reflection . isInstance ( item , EnumMemberExpr ) ;
190- }
191-
192190export interface Function extends AstNode {
193191 readonly $container : Model ;
194192 expression : Expression
@@ -205,6 +203,7 @@ export function isFunction(item: unknown): item is Function {
205203export interface FunctionParam extends AstNode {
206204 readonly $container : Function ;
207205 name : string
206+ type : FunctionParamType
208207}
209208
210209export const FunctionParam = 'FunctionParam' ;
@@ -213,6 +212,19 @@ export function isFunctionParam(item: unknown): item is FunctionParam {
213212 return reflection . isInstance ( item , FunctionParam ) ;
214213}
215214
215+ export interface FunctionParamType extends AstNode {
216+ readonly $container : FunctionParam ;
217+ array : boolean
218+ reference ?: Reference < TypeDeclaration >
219+ type ?: 'Boolean' | 'DateTime' | 'Float' | 'Int' | 'JSON' | 'String'
220+ }
221+
222+ export const FunctionParamType = 'FunctionParamType' ;
223+
224+ export function isFunctionParamType ( item : unknown ) : item is FunctionParamType {
225+ return reflection . isInstance ( item , FunctionParamType ) ;
226+ }
227+
216228export interface InvocationExpr extends AstNode {
217229 readonly $container : ArrayExpr | BinaryExpr | DataModelAttribute | DataModelFieldAttribute | DataSourceField | Function | InvocationExpr | UnaryExpr ;
218230 args : Array < Expression >
@@ -237,11 +249,7 @@ export function isLiteralExpr(item: unknown): item is LiteralExpr {
237249}
238250
239251export interface Model extends AstNode {
240- attributes : Array < Attribute >
241- datasources : Array < DataSource >
242- enums : Array < Enum >
243- functions : Array < Function >
244- models : Array < DataModel >
252+ declarations : Array < AbstractDeclaration >
245253}
246254
247255export const Model = 'Model' ;
@@ -273,14 +281,14 @@ export function isUnaryExpr(item: unknown): item is UnaryExpr {
273281 return reflection . isInstance ( item , UnaryExpr ) ;
274282}
275283
276- export type ZModelAstType = 'ArrayExpr' | 'Attribute' | 'BinaryExpr' | 'DataModel' | 'DataModelAttribute' | 'DataModelField' | 'DataModelFieldAttribute' | 'DataModelFieldType' | 'DataSource' | 'DataSourceField' | 'Enum' | 'EnumField' | 'EnumMemberExpr ' | 'Expression ' | 'Function ' | 'FunctionParam ' | 'InvocationExpr' | 'LiteralExpr' | 'Model' | 'ReferenceExpr' | 'ReferenceTarget' | 'TypeDeclaration' | 'UnaryExpr' ;
284+ export type ZModelAstType = 'AbstractDeclaration' | ' ArrayExpr' | 'Attribute' | 'BinaryExpr' | 'DataModel' | 'DataModelAttribute' | 'DataModelField' | 'DataModelFieldAttribute' | 'DataModelFieldType' | 'DataSource' | 'DataSourceField' | 'Enum' | 'EnumField' | 'Expression ' | 'Function ' | 'FunctionParam ' | 'FunctionParamType ' | 'InvocationExpr' | 'LiteralExpr' | 'Model' | 'ReferenceExpr' | 'ReferenceTarget' | 'TypeDeclaration' | 'UnaryExpr' ;
277285
278- export type ZModelAstReference = 'DataModelAttribute:decl' | 'DataModelFieldAttribute:decl' | 'DataModelFieldType:reference' | 'EnumMemberExpr:decl ' | 'ReferenceExpr:target' ;
286+ export type ZModelAstReference = 'DataModelAttribute:decl' | 'DataModelFieldAttribute:decl' | 'DataModelFieldType:reference' | 'FunctionParamType:reference ' | 'ReferenceExpr:target' ;
279287
280288export class ZModelAstReflection implements AstReflection {
281289
282290 getAllTypes ( ) : string [ ] {
283- return [ 'ArrayExpr' , 'Attribute' , 'BinaryExpr' , 'DataModel' , 'DataModelAttribute' , 'DataModelField' , 'DataModelFieldAttribute' , 'DataModelFieldType' , 'DataSource' , 'DataSourceField' , 'Enum' , 'EnumField' , 'EnumMemberExpr ' , 'Expression ' , 'Function ' , 'FunctionParam ' , 'InvocationExpr' , 'LiteralExpr' , 'Model' , 'ReferenceExpr' , 'ReferenceTarget' , 'TypeDeclaration' , 'UnaryExpr' ] ;
291+ return [ 'AbstractDeclaration' , ' ArrayExpr', 'Attribute' , 'BinaryExpr' , 'DataModel' , 'DataModelAttribute' , 'DataModelField' , 'DataModelFieldAttribute' , 'DataModelFieldType' , 'DataSource' , 'DataSourceField' , 'Enum' , 'EnumField' , 'Expression ' , 'Function ' , 'FunctionParam ' , 'FunctionParamType ' , 'InvocationExpr' , 'LiteralExpr' , 'Model' , 'ReferenceExpr' , 'ReferenceTarget' , 'TypeDeclaration' , 'UnaryExpr' ] ;
284292 }
285293
286294 isInstance ( node : unknown , type : string ) : boolean {
@@ -294,22 +302,28 @@ export class ZModelAstReflection implements AstReflection {
294302 switch ( subtype ) {
295303 case ArrayExpr :
296304 case BinaryExpr :
297- case EnumMemberExpr :
298305 case InvocationExpr :
299306 case LiteralExpr :
300307 case ReferenceExpr :
301308 case UnaryExpr : {
302309 return this . isSubtype ( Expression , supertype ) ;
303310 }
311+ case Attribute :
312+ case DataSource : {
313+ return this . isSubtype ( AbstractDeclaration , supertype ) ;
314+ }
304315 case DataModel :
305316 case Enum : {
306- return this . isSubtype ( TypeDeclaration , supertype ) ;
317+ return this . isSubtype ( AbstractDeclaration , supertype ) || this . isSubtype ( TypeDeclaration , supertype ) ;
307318 }
308319 case DataModelField :
309- case Function :
320+ case EnumField :
310321 case FunctionParam : {
311322 return this . isSubtype ( ReferenceTarget , supertype ) ;
312323 }
324+ case Function : {
325+ return this . isSubtype ( AbstractDeclaration , supertype ) || this . isSubtype ( ReferenceTarget , supertype ) ;
326+ }
313327 default : {
314328 return false ;
315329 }
@@ -327,8 +341,8 @@ export class ZModelAstReflection implements AstReflection {
327341 case 'DataModelFieldType:reference' : {
328342 return TypeDeclaration ;
329343 }
330- case 'EnumMemberExpr:decl ' : {
331- return Enum ;
344+ case 'FunctionParamType:reference ' : {
345+ return TypeDeclaration ;
332346 }
333347 case 'ReferenceExpr:target' : {
334348 return ReferenceTarget ;
@@ -415,6 +429,14 @@ export class ZModelAstReflection implements AstReflection {
415429 ]
416430 } ;
417431 }
432+ case 'FunctionParamType' : {
433+ return {
434+ name : 'FunctionParamType' ,
435+ mandatory : [
436+ { name : 'array' , type : 'boolean' }
437+ ]
438+ } ;
439+ }
418440 case 'InvocationExpr' : {
419441 return {
420442 name : 'InvocationExpr' ,
@@ -427,11 +449,7 @@ export class ZModelAstReflection implements AstReflection {
427449 return {
428450 name : 'Model' ,
429451 mandatory : [
430- { name : 'attributes' , type : 'array' } ,
431- { name : 'datasources' , type : 'array' } ,
432- { name : 'enums' , type : 'array' } ,
433- { name : 'functions' , type : 'array' } ,
434- { name : 'models' , type : 'array' }
452+ { name : 'declarations' , type : 'array' }
435453 ]
436454 } ;
437455 }
0 commit comments