Add alias flag for allowing bytes
This commit is contained in:
114
src/ir.ts
114
src/ir.ts
@ -36,17 +36,17 @@ export interface EnumDefinition {
|
||||
export type ServiceFunctionDecorators = {
|
||||
description: string;
|
||||
parameters: {
|
||||
name:string;
|
||||
name: string;
|
||||
description: string;
|
||||
}[];
|
||||
returns: string;
|
||||
}
|
||||
};
|
||||
|
||||
export interface ServiceFunctionParamsDefinition {
|
||||
name: string;
|
||||
inputs: { type: string; name: string, array: boolean }[];
|
||||
return: { type: string, array: boolean } | undefined;
|
||||
decorators: ServiceFunctionDecorators
|
||||
inputs: { type: string; name: string; array: boolean }[];
|
||||
return: { type: string; array: boolean } | undefined;
|
||||
decorators: ServiceFunctionDecorators;
|
||||
}
|
||||
export type ServiceFunctionDefinition = ServiceFunctionParamsDefinition;
|
||||
|
||||
@ -62,8 +62,8 @@ export type Step = [
|
||||
];
|
||||
|
||||
export type IR = {
|
||||
options: { [key:string]: string},
|
||||
steps: Step[]
|
||||
options: { [key: string]: string };
|
||||
steps: Step[];
|
||||
};
|
||||
|
||||
export default function get_ir(parsed: Parsed): IR {
|
||||
@ -101,7 +101,10 @@ export default function get_ir(parsed: Parsed): IR {
|
||||
}
|
||||
|
||||
if (defined.indexOf(field.fieldtype) < 0) {
|
||||
if (builtin.indexOf(field.fieldtype) < 0 && field.fieldtype !== statement.name) {
|
||||
if (
|
||||
builtin.indexOf(field.fieldtype) < 0 &&
|
||||
field.fieldtype !== statement.name
|
||||
) {
|
||||
throw new IRError(
|
||||
field,
|
||||
`Type ${field.fieldtype} is not defined!`
|
||||
@ -112,11 +115,7 @@ export default function get_ir(parsed: Parsed): IR {
|
||||
depends.push(field.fieldtype);
|
||||
}
|
||||
|
||||
if (
|
||||
field.map &&
|
||||
field.map !== "number" &&
|
||||
field.map !== "string"
|
||||
) {
|
||||
if (field.map && field.map !== "number" && field.map !== "string") {
|
||||
throw new IRError(
|
||||
field,
|
||||
`Type ${field.map} is not valid as map key!`
|
||||
@ -200,7 +199,10 @@ export default function get_ir(parsed: Parsed): IR {
|
||||
if (!depends.some((a) => a === fnc.return_type.type))
|
||||
depends.push(fnc.return_type.type);
|
||||
} else {
|
||||
if (fnc.return_type.type !== "void" && builtin.indexOf(fnc.return_type.type) < 0) {
|
||||
if (
|
||||
fnc.return_type.type !== "void" &&
|
||||
builtin.indexOf(fnc.return_type.type) < 0
|
||||
) {
|
||||
throw new IRError(
|
||||
fnc,
|
||||
`Type ${fnc.return_type.type} is not defined`
|
||||
@ -225,51 +227,73 @@ export default function get_ir(parsed: Parsed): IR {
|
||||
|
||||
let decorators = {} as ServiceFunctionDecorators;
|
||||
|
||||
fnc.decorators.forEach((values, key)=>{
|
||||
for(const val of values) {
|
||||
switch(key) {
|
||||
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!`);
|
||||
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;
|
||||
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!`);
|
||||
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}!`);
|
||||
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!`);
|
||||
throw new IRError(
|
||||
fnc,
|
||||
`Decorator ${key} is not a valid decorator!`
|
||||
);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
return {
|
||||
name: fnc.name,
|
||||
inputs: fnc.inputs,
|
||||
return: fnc.return_type,
|
||||
decorators
|
||||
decorators,
|
||||
} as ServiceFunctionDefinition;
|
||||
});
|
||||
|
||||
@ -281,9 +305,13 @@ export default function get_ir(parsed: Parsed): IR {
|
||||
functions,
|
||||
} as ServiceDefinition,
|
||||
]);
|
||||
} else if(statement.type == "define") {
|
||||
} else if (statement.type == "define") {
|
||||
options[statement.key] = statement.value;
|
||||
if(statement.key == "use_messagepack" && statement.value == "true") {
|
||||
if (
|
||||
(statement.key == "use_messagepack" ||
|
||||
statement.key == "allow_bytes") &&
|
||||
statement.value == "true"
|
||||
) {
|
||||
builtin.push("bytes");
|
||||
}
|
||||
} else {
|
||||
@ -293,6 +321,6 @@ export default function get_ir(parsed: Parsed): IR {
|
||||
|
||||
return {
|
||||
options,
|
||||
steps
|
||||
steps,
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user