@@ -15,16 +15,14 @@ export function isAbstractDeclaration(item: unknown): item is AbstractDeclaratio
1515 return reflection . isInstance ( item , AbstractDeclaration ) ;
1616}
1717
18- export type Expression = ArrayExpr | BinaryExpr | InvocationExpr | LiteralExpr | MemberAccessExpr | ReferenceExpr | UnaryExpr ;
18+ export type Expression = ArrayExpr | BinaryExpr | InvocationExpr | LiteralExpr | MemberAccessExpr | ReferenceExpr | ThisExpr | UnaryExpr ;
1919
2020export const Expression = 'Expression' ;
2121
2222export function isExpression ( item : unknown ) : item is Expression {
2323 return reflection . isInstance ( item , Expression ) ;
2424}
2525
26- export type QualifiedName = string ;
27-
2826export type ReferenceTarget = DataModelField | EnumField | FunctionParam ;
2927
3028export const ReferenceTarget = 'ReferenceTarget' ;
@@ -55,6 +53,7 @@ export function isArrayExpr(item: unknown): item is ArrayExpr {
5553export interface Attribute extends AstNode {
5654 readonly $container : Model ;
5755 name : string
56+ params : Array < FunctionParam >
5857}
5958
6059export const Attribute = 'Attribute' ;
@@ -66,7 +65,7 @@ export function isAttribute(item: unknown): item is Attribute {
6665export interface BinaryExpr extends AstNode {
6766 readonly $container : ArrayExpr | BinaryExpr | DataModelAttribute | DataModelFieldAttribute | DataSourceField | Function | InvocationExpr | MemberAccessExpr | UnaryExpr ;
6867 left : Expression
69- operator : '!=' | '&&' | '*' | '+' | '-' | '/' | '<' | '<=' | '==' | '>' | '>=' | '||'
68+ operator : '!' | '! =' | '&&' | '*' | '+' | '-' | '/' | '<' | '<=' | '==' | '>' | '>=' | '? ' | '||'
7069 right : Expression
7170}
7271
@@ -189,9 +188,10 @@ export function isEnumField(item: unknown): item is EnumField {
189188
190189export interface Function extends AstNode {
191190 readonly $container : Model ;
192- expression : Expression
191+ expression ? : Expression
193192 name : string
194193 params : Array < FunctionParam >
194+ returnType : FunctionParamType
195195}
196196
197197export const Function = 'Function' ;
@@ -201,7 +201,7 @@ export function isFunction(item: unknown): item is Function {
201201}
202202
203203export interface FunctionParam extends AstNode {
204- readonly $container : Function ;
204+ readonly $container : Attribute | Function ;
205205 name : string
206206 type : FunctionParamType
207207}
@@ -213,7 +213,7 @@ export function isFunctionParam(item: unknown): item is FunctionParam {
213213}
214214
215215export interface FunctionParamType extends AstNode {
216- readonly $container : FunctionParam ;
216+ readonly $container : Function | FunctionParam ;
217217 array : boolean
218218 reference ?: Reference < TypeDeclaration >
219219 type ?: 'Boolean' | 'DateTime' | 'Int' | 'JSON' | 'String'
@@ -281,6 +281,17 @@ export function isReferenceExpr(item: unknown): item is ReferenceExpr {
281281 return reflection . isInstance ( item , ReferenceExpr ) ;
282282}
283283
284+ export interface ThisExpr extends AstNode {
285+ readonly $container : ArrayExpr | BinaryExpr | DataModelAttribute | DataModelFieldAttribute | DataSourceField | Function | InvocationExpr | MemberAccessExpr | UnaryExpr ;
286+ value : string
287+ }
288+
289+ export const ThisExpr = 'ThisExpr' ;
290+
291+ export function isThisExpr ( item : unknown ) : item is ThisExpr {
292+ return reflection . isInstance ( item , ThisExpr ) ;
293+ }
294+
284295export interface UnaryExpr extends AstNode {
285296 readonly $container : ArrayExpr | BinaryExpr | DataModelAttribute | DataModelFieldAttribute | DataSourceField | Function | InvocationExpr | MemberAccessExpr | UnaryExpr ;
286297 arg : Expression
@@ -293,14 +304,14 @@ export function isUnaryExpr(item: unknown): item is UnaryExpr {
293304 return reflection . isInstance ( item , UnaryExpr ) ;
294305}
295306
296- export type ZModelAstType = 'AbstractDeclaration' | 'ArrayExpr' | 'Attribute' | 'BinaryExpr' | 'DataModel' | 'DataModelAttribute' | 'DataModelField' | 'DataModelFieldAttribute' | 'DataModelFieldType' | 'DataSource' | 'DataSourceField' | 'Enum' | 'EnumField' | 'Expression' | 'Function' | 'FunctionParam' | 'FunctionParamType' | 'InvocationExpr' | 'LiteralExpr' | 'MemberAccessExpr' | 'Model' | 'ReferenceExpr' | 'ReferenceTarget' | 'TypeDeclaration' | 'UnaryExpr' ;
307+ export type ZModelAstType = 'AbstractDeclaration' | 'ArrayExpr' | 'Attribute' | 'BinaryExpr' | 'DataModel' | 'DataModelAttribute' | 'DataModelField' | 'DataModelFieldAttribute' | 'DataModelFieldType' | 'DataSource' | 'DataSourceField' | 'Enum' | 'EnumField' | 'Expression' | 'Function' | 'FunctionParam' | 'FunctionParamType' | 'InvocationExpr' | 'LiteralExpr' | 'MemberAccessExpr' | 'Model' | 'ReferenceExpr' | 'ReferenceTarget' | 'ThisExpr' | ' TypeDeclaration' | 'UnaryExpr' ;
297308
298309export type ZModelAstReference = 'DataModelAttribute:decl' | 'DataModelFieldAttribute:decl' | 'DataModelFieldType:reference' | 'FunctionParamType:reference' | 'InvocationExpr:function' | 'MemberAccessExpr:member' | 'ReferenceExpr:target' ;
299310
300311export class ZModelAstReflection implements AstReflection {
301312
302313 getAllTypes ( ) : string [ ] {
303- return [ 'AbstractDeclaration' , 'ArrayExpr' , 'Attribute' , 'BinaryExpr' , 'DataModel' , 'DataModelAttribute' , 'DataModelField' , 'DataModelFieldAttribute' , 'DataModelFieldType' , 'DataSource' , 'DataSourceField' , 'Enum' , 'EnumField' , 'Expression' , 'Function' , 'FunctionParam' , 'FunctionParamType' , 'InvocationExpr' , 'LiteralExpr' , 'MemberAccessExpr' , 'Model' , 'ReferenceExpr' , 'ReferenceTarget' , 'TypeDeclaration' , 'UnaryExpr' ] ;
314+ return [ 'AbstractDeclaration' , 'ArrayExpr' , 'Attribute' , 'BinaryExpr' , 'DataModel' , 'DataModelAttribute' , 'DataModelField' , 'DataModelFieldAttribute' , 'DataModelFieldType' , 'DataSource' , 'DataSourceField' , 'Enum' , 'EnumField' , 'Expression' , 'Function' , 'FunctionParam' , 'FunctionParamType' , 'InvocationExpr' , 'LiteralExpr' , 'MemberAccessExpr' , 'Model' , 'ReferenceExpr' , 'ReferenceTarget' , 'ThisExpr' , ' TypeDeclaration', 'UnaryExpr' ] ;
304315 }
305316
306317 isInstance ( node : unknown , type : string ) : boolean {
@@ -318,6 +329,7 @@ export class ZModelAstReflection implements AstReflection {
318329 case LiteralExpr :
319330 case MemberAccessExpr :
320331 case ReferenceExpr :
332+ case ThisExpr :
321333 case UnaryExpr : {
322334 return this . isSubtype ( Expression , supertype ) ;
323335 }
@@ -380,6 +392,14 @@ export class ZModelAstReflection implements AstReflection {
380392 ]
381393 } ;
382394 }
395+ case 'Attribute' : {
396+ return {
397+ name : 'Attribute' ,
398+ mandatory : [
399+ { name : 'params' , type : 'array' }
400+ ]
401+ } ;
402+ }
383403 case 'DataModel' : {
384404 return {
385405 name : 'DataModel' ,
0 commit comments