Checking in compiled version

This commit is contained in:
K35 2022-01-01 18:55:27 +00:00
parent 4e389dc472
commit a8f49d117d

View File

@ -6988,6 +6988,7 @@ var matcher = [
regexMatcher(/^#.+/, "comment"),
regexMatcher(/^".*?"/, "string"),
regexMatcher(/^(type|enum|import|service)\b/, "keyword"),
regexMatcher(/^\@/, "at"),
regexMatcher(/^\:/, "colon"),
regexMatcher(/^\;/, "semicolon"),
regexMatcher(/^\,/, "comma"),
@ -7160,7 +7161,29 @@ function parse(tokens, file) {
location: { file, idx }
};
};
const parseServiceFunction = (notification) => {
const parseFunctionDecorator = (decorators = /* @__PURE__ */ new Map()) => {
const idx = eatToken("@");
const [decorator] = eatText();
eatToken("(");
let args = [];
let first = true;
while (currentToken.value !== ")") {
if (first) {
first = false;
} else {
eatToken(",");
}
checkTypes("string");
args.push(currentToken.value.slice(1, -1));
eatToken();
}
eatToken(")");
let dec = decorators.get(decorator) || [];
dec.push(args);
decorators.set(decorator, dec);
return decorators;
};
const parseServiceFunction = (decorators, notification) => {
const [name, idx] = eatText();
eatToken("(");
let input_streaming = void 0;
@ -7191,7 +7214,8 @@ function parse(tokens, file) {
idx
},
inputs,
return_type
return_type,
decorators
};
};
const parseServiceStatement = () => {
@ -7199,13 +7223,17 @@ function parse(tokens, file) {
let [name] = eatText();
eatToken("{");
let functions = [];
while (currentToken.type === "text") {
while (currentToken.type !== "curly_close") {
let decorators = /* @__PURE__ */ new Map();
while (currentToken.type == "at") {
parseFunctionDecorator(decorators);
}
let notification = false;
if (currentToken.value == "notification") {
eatText();
notification = true;
}
functions.push(parseServiceFunction(notification));
functions.push(parseServiceFunction(decorators, notification));
}
eatToken("}");
return {
@ -7356,10 +7384,49 @@ function get_ir(parsed) {
}
}
}
let decorators = {};
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
return: fnc.return_type,
decorators
};
});
steps.push([
@ -7741,6 +7808,8 @@ var NodeJSTypescriptTarget = class extends TypescriptTarget {
};
// src/process.ts
var CatchedError = class extends Error {
};
var log2 = (0, import_debug2.default)("app");
var Targets = /* @__PURE__ */ new Map();
Targets.set("ts-esm", ESMTypescriptTarget);
@ -7784,7 +7853,7 @@ function printError(err, file, idx) {
console.error(" ", err.message);
log2(err.stack);
}
function processFile(ctx, file) {
function processFile(ctx, file, root = false) {
file = Path2.resolve(file);
if (ctx.processedFiles.has(file)) {
log2("Skipping file %s since it has already be processed", file);
@ -7814,12 +7883,17 @@ function processFile(ctx, file) {
} catch (err) {
if (err instanceof TokenizerError) {
printError(err, file, err.index);
if (!root)
throw new CatchedError();
} else if (err instanceof ParserError) {
printError(err, file, err.token.startIdx);
if (!root)
throw new CatchedError();
} else if (root && err instanceof CatchedError) {
return null;
} else {
throw err;
}
return null;
}
}
function startCompile(options) {
@ -7831,15 +7905,24 @@ function startCompile(options) {
if (options.input.endsWith(".json")) {
ir = JSON.parse(FS2.readFileSync(options.input, "utf-8"));
} else {
const parsed = processFile(ctx, options.input);
const parsed = processFile(ctx, options.input, true);
if (!parsed)
throw new Error("Error compiling: Parse output is undefined!");
ir = get_ir(parsed);
process.exit(1);
try {
ir = get_ir(parsed);
} catch (err) {
if (err instanceof IRError) {
printError(err, err.statement.location.file, err.statement.location.idx);
process.exit(1);
} else {
throw err;
}
}
}
if (!ir)
throw new Error("Error compiling: Cannot get IR");
if (options.emitDefinitions) {
FS2.writeFileSync(options.emitDefinitions, JSON.stringify(ir));
FS2.writeFileSync(options.emitDefinitions, JSON.stringify(ir, void 0, 3));
}
if (options.targets.length <= 0) {
console.log(import_chalk.default.yellow("WARNING:"), "No targets selected!");