Adding Decorators for comments
This commit is contained in:
53
src/ir.ts
53
src/ir.ts
@ -33,10 +33,20 @@ export interface EnumDefinition {
|
||||
values: EnumValueDefinition[];
|
||||
}
|
||||
|
||||
export type ServiceFunctionDecorators = {
|
||||
description: string;
|
||||
parameters: {
|
||||
name:string;
|
||||
description: string;
|
||||
}[];
|
||||
returns: string;
|
||||
}
|
||||
|
||||
export interface ServiceFunctionParamsDefinition {
|
||||
name: string;
|
||||
inputs: { type: string; name: string }[];
|
||||
return: string | undefined;
|
||||
decorators: ServiceFunctionDecorators
|
||||
}
|
||||
export type ServiceFunctionDefinition = ServiceFunctionParamsDefinition;
|
||||
|
||||
@ -208,10 +218,53 @@ export default function get_ir(parsed: Parsed): IR {
|
||||
}
|
||||
}
|
||||
|
||||
let decorators = {} as ServiceFunctionDecorators;
|
||||
|
||||
fnc.decorators.forEach((values, key)=>{
|
||||
for(const val of values) {
|
||||
switch(key) {
|
||||
case "Description":
|
||||
if(decorators.description)
|
||||
throw new IRError(fnc, `Decorator 'Description' can only be used once!`);
|
||||
if(val.length != 1)
|
||||
throw new IRError(fnc, `Decorator 'Description' requires exactly one parameter!`);
|
||||
decorators.description = val[0];
|
||||
break;
|
||||
case "Returns":
|
||||
if(decorators.returns)
|
||||
throw new IRError(fnc, `Decorator 'Returns' can only be used once!`);
|
||||
if(val.length != 1)
|
||||
throw new IRError(fnc, `Decorator 'Returns' requires exactly one parameter!`);
|
||||
decorators.returns = val[0];
|
||||
break;
|
||||
case "Param":
|
||||
if(!decorators.parameters)
|
||||
decorators.parameters = [];
|
||||
if(val.length != 2)
|
||||
throw new IRError(fnc, `Decorator 'Param' requires exactly two parameters!`);
|
||||
const [name, description] = val;
|
||||
if(!fnc.inputs.find(e=>e.name == name))
|
||||
throw new IRError(fnc, `Decorator 'Param' requires the first param to equal the name of a function parameter!`);
|
||||
if(decorators.parameters.find(e=>e.name == name))
|
||||
throw new IRError(fnc, `Decorator 'Param' has already been set for the parameter ${name}!`);
|
||||
|
||||
decorators.parameters.push({
|
||||
name,
|
||||
description,
|
||||
})
|
||||
break;
|
||||
default:
|
||||
throw new IRError(fnc, `Decorator ${key} is not a valid decorator!`);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
return {
|
||||
name: fnc.name,
|
||||
inputs: fnc.inputs,
|
||||
return: fnc.return_type,
|
||||
decorators
|
||||
} as ServiceFunctionDefinition;
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user