diff --git a/lib/plankton/plankton.d.ts b/lib/plankton/plankton.d.ts index cffd4f0..efeda7a 100644 --- a/lib/plankton/plankton.d.ts +++ b/lib/plankton/plankton.d.ts @@ -938,6 +938,9 @@ declare namespace lib_plankton.file { * @author fenris */ function write_buffer(path: string, content: Buffer, options?: {}): Promise; + /** + */ + function delete_(path: string): Promise; } declare namespace lib_plankton.prog { /** @@ -1275,7 +1278,7 @@ declare namespace lib_plankton.prog { render_program: ((program: struct_program) => string); }; } -declare namespace lib_plankton.prog { +declare namespace lib_plankton.prog.typescript { /** */ function render_type(type: struct_type, options?: { diff --git a/lib/plankton/plankton.js b/lib/plankton/plankton.js index 4b4fa71..aca3bcc 100644 --- a/lib/plankton/plankton.js +++ b/lib/plankton/plankton.js @@ -2766,7 +2766,7 @@ var lib_plankton; return (new Promise(function (resolve, reject) { nm_fs.readFile(path, { "encoding": "utf8", - "flag": "r" + "flag": "r", }, function (error, content) { if (error == null) { resolve(content); @@ -2785,7 +2785,7 @@ var lib_plankton; var nm_fs = require("fs"); return (new Promise(function (resolve, reject) { nm_fs.readFile(path, { - "flag": "r" + "flag": "r", }, function (error, content) { if (error == null) { resolve(content); @@ -2822,13 +2822,13 @@ var lib_plankton; function write(path, content, options) { if (options === void 0) { options = {}; } options = Object.assign({ - "encoding": "utf-8" + "encoding": "utf-8", }, options); var nm_fs = require("fs"); return (new Promise(function (resolve, reject) { nm_fs.writeFile(path, content, { "encoding": options.encoding, - "flag": "w" + "flag": "w", }, function (error) { if (error == null) { resolve(undefined); @@ -2849,7 +2849,7 @@ var lib_plankton; var nm_fs = require("fs"); return (new Promise(function (resolve, reject) { nm_fs.writeFile(path, content, { - "flag": "w" + "flag": "w", }, function (error) { if (error == null) { resolve(undefined); @@ -2861,6 +2861,17 @@ var lib_plankton; })); } file.write_buffer = write_buffer; + /** + */ + function delete_(path) { + var nm_fs = require("fs"); + return (new Promise(function (resolve, reject) { + nm_fs.unlink(path, function () { + resolve(undefined); + }); + })); + } + file.delete_ = delete_; })(file = lib_plankton.file || (lib_plankton.file = {})); })(lib_plankton || (lib_plankton = {})); var __extends = (this && this.__extends) || (function () { @@ -4256,506 +4267,509 @@ var lib_plankton; (function (lib_plankton) { var prog; (function (prog) { - /** - */ - function indentation(active, level) { - return (active - ? "\t".repeat(level) - : ""); - } - /** - */ - function render_type(type, options) { - if (options === void 0) { options = {}; } - options = Object.assign({ - "indent": true, - "level": 0 - }, options); - if (type instanceof prog.struct_type_literal) { - var type_literal = type; - return lib_plankton.string.coin("{{indentation}}{{value}}", { - "indentation": indentation(options.indent, options.level), - "value": render_expression(type_literal.value, { - "level": (options.level + 1) - }) - }); + var typescript; + (function (typescript) { + /** + */ + function indentation(active, level) { + return (active + ? "\t".repeat(level) + : ""); } - else if (type instanceof prog.struct_type_any) { - var type_any = type; - return lib_plankton.string.coin("{{indentation}}any", { - "indentation": indentation(options.indent, options.level) - }); - } - else if (type instanceof prog.struct_type_void) { - var type_void = type; - return lib_plankton.string.coin("{{indentation}}void", { - "indentation": indentation(options.indent, options.level) - }); - } - else if (type instanceof prog.struct_type_boolean) { - var type_boolean = type; - return lib_plankton.string.coin("{{indentation}}boolean", { - "indentation": indentation(options.indent, options.level) - }); - } - else if (type instanceof prog.struct_type_integer) { - var type_integer = type; - return lib_plankton.string.coin("{{indentation}}number", { - "indentation": indentation(options.indent, options.level) - }); - } - else if (type instanceof prog.struct_type_string) { - var type_string = type; - return lib_plankton.string.coin("{{indentation}}string", { - "indentation": indentation(options.indent, options.level) - }); - } - else if (type instanceof prog.struct_type_list) { - var type_list = type; - return render_type(new prog.struct_type_construction("Array", [ - type_list.element, - ])); - } - else if (type instanceof prog.struct_type_map) { - var type_map = type; - return render_type(new prog.struct_type_construction("Record", [ - type_map.key, - type_map.value, - ])); - } - else if (type instanceof prog.struct_type_record) { - var type_record = type; - return lib_plankton.string.coin("{{indentation1}}{\n{{fields}}\n{{indentation2}}}", { - "indentation1": indentation(options.indent, options.level), - "indentation2": indentation(true, options.level), - "fields": (type_record.fields - .map(function (field) { return lib_plankton.string.coin("{{indentation}}{{name}} {{assignment}} {{type}}", { - "indentation": indentation(true, options.level + 1), - "name": field.name, - "assignment": (field.mandatory ? ":" : "?:"), - "type": render_type(field.type, { - "indent": false, - "level": (options.level + 1) - }) - }); }) - .join(";\n")) - }); - } - else if (type instanceof prog.struct_type_function) { - var type_function = type; - return lib_plankton.string.coin("{{indentation1}}(({{arguments}})\n{{indentation2}}=>\n{{target}})", { - "indentation1": indentation(options.indent, options.level), - "indentation2": indentation(true, options.level), - "arguments": (type_function.arguments - .map(function (argument) { return render_type(argument, { - "level": (options.level + 1) - }); }) - .join(", ")), - "target": render_type(type_function.target, { - "level": (options.level + 1) - }) - }); - } - else if (type instanceof prog.struct_type_construction) { - var type_construction = type; - return lib_plankton.string.coin("{{indentation}}{{name}}{{macro_arguments}}", { - "indentation": indentation(options.indent, options.level), - "name": type_construction.name, - "macro_arguments": ((type_construction.arguments === null) - ? "" - : lib_plankton.string.coin("<\n{{arguments}}\n{{indentation}}>", { - "indentation": indentation(true, options.level), - "arguments": (type_construction.arguments - .map(function (argument) { return render_type(argument, { - "level": (options.level + 1) - }); }) - .join(",\n")) - })) - }); - } - else if (type instanceof prog.struct_type_union) { - var type_union = type; - return lib_plankton.string.coin("{{indentation1}}(\n{{left}}\n{{indentation3}}|\n{{right}}\n{{indentation2}})", { - "indentation1": indentation(options.indent, options.level), - "indentation2": indentation(true, options.level), - "indentation3": indentation(true, options.level + 1), - "left": render_type(type_union.left, { - "level": (options.level + 1) - }), - "right": render_type(type_union.right, { - "level": (options.level + 1) - }) - }); - } - else if (type instanceof prog.struct_type_intersection) { - var type_intersection = type; - return lib_plankton.string.coin("{{indentation1}}(\n{{left}}\n{{indentation2}}&\n{{right}}\n{{indentation2}})", { - "indentation1": indentation(options.indent, options.level), - "indentation2": indentation(true, options.level + 1), - "left": render_type(type_intersection.left, { - "level": (options.level + 1) - }), - "right": render_type(type_intersection.right, { - "level": (options.level + 1) - }) - }); - } - else { - throw (new Error("unhandled type kind: " + String(type))); - } - } - prog.render_type = render_type; - /** - */ - function render_expression(expression, options) { - if (options === void 0) { options = {}; } - options = Object.assign({ - "indent": false, - "level": 0 - }, options); - if (expression instanceof prog.struct_expression_variable) { - var expression_variable = expression; - return lib_plankton.string.coin("{{indentation}}{{name}}", { - "indentation": indentation(options.indent, options.level), - "name": expression.name - }); - } - else if (expression instanceof prog.struct_expression_literal) { - var expression_literal = expression; - return lib_plankton.string.coin("{{indentation}}{{value}}", { - "indentation": indentation(options.indent, options.level), - "value": JSON.stringify(expression_literal.value) - }); - } - else if (expression instanceof prog.struct_expression_list) { - var expression_list = expression; - return lib_plankton.string.coin("{{indentation1}}[\n{{elements}}\n{{indentation2}}]", { - "indentation1": indentation(options.indent, options.level), - "indentation2": indentation(true, options.level), - "elements": (expression_list.elements - .map(function (element) { return lib_plankton.string.coin("{{indentation}}{{value}}", { - "indentation": indentation(true, options.level + 1), - "value": render_expression(element, { - "indent": false, - "level": (options.level + 1) - }) - }); }) - .join(",\n")) - }); - } - else if (expression instanceof prog.struct_expression_dict) { - var expression_dict = expression; - return lib_plankton.string.coin("{{indentation1}}{\n{{fields}}\n{{indentation2}}}", { - "indentation1": indentation(options.indent, options.level), - "indentation2": indentation(true, options.level), - "fields": (expression_dict.fields - .map(function (field) { return lib_plankton.string.coin("{{indentation}}\"{{key}}\": {{value}}", { - "indentation": indentation(true, options.level + 1), - "key": field.key, - "value": render_expression(field.value, { - "indent": false, - "level": (options.level + 1) - }) - }); }) - .join(",\n")) - }); - } - else if (expression instanceof prog.struct_expression_abstraction) { - var expression_abstraction = expression; - return lib_plankton.string.coin("{{indentation1}}{{macro_async}}function ({{arguments}}){{macro_output_type}} {\n{{body}}{{indentation2}}}", { - "indentation1": indentation(options.indent, options.level), - "indentation2": indentation(true, options.level), - "macro_async": (expression_abstraction.async_ - ? "async " - : ""), - "arguments": (expression_abstraction.arguments - .map(function (argument) { return lib_plankton.string.coin("{{name}}{{macro_type}}", { - "name": argument.name, - "macro_type": ((argument.type === null) - ? "" - : lib_plankton.string.coin(" : {{type}}", { - "type": render_type(argument.type) - })) - }); }) - .join(", ")), - "macro_output_type": ((expression_abstraction.output_type === null) - ? "" - : lib_plankton.string.coin(" : {{type}}", { - "type": render_type(expression_abstraction.output_type, { - "indent": false, - "level": (options.level + 1) - }) - })), - "body": (expression_abstraction.body - .map(function (statement) { return render_statement(statement, { - "level": (options.level + 1) - }); }) - .join("")) - }); - } - else if (expression instanceof prog.struct_expression_function_application) { - var expression_function_application = expression; - return lib_plankton.string.coin("{{indentation1}}{{name}}(\n{{arguments}}\n{{indentation2}})", { - "indentation1": indentation(options.indent, options.level), - "indentation2": indentation(true, options.level), - "name": render_expression(expression_function_application.head, { - "indent": false, - "level": (options.level + 0) - }), - "arguments": (expression_function_application.arguments - .map(function (argument) { return lib_plankton.string.coin("{{argument}}", { - "argument": render_expression(argument, { - "indent": true, - "level": (options.level + 1) - }) - }); }) - .join(",\n")) - }); - } - else if (expression instanceof prog.struct_expression_projection) { - var expression_projection = expression; - return lib_plankton.string.coin("{{indentation}}{{source}}[{{index}}]", { - "indentation": indentation(options.indent, options.level), - "source": render_expression(expression_projection.source), - "index": render_expression(expression_projection.index) - }); - } - else if (expression instanceof prog.struct_expression_fieldaccess) { - var expression_fieldaccess = expression; - return lib_plankton.string.coin("{{indentation}}{{structure}}.{{fieldname}}", { - "indentation": indentation(options.indent, options.level), - "structure": render_expression(expression_fieldaccess.structure, { - "level": (options.level + 1) - }), - "fieldname": expression_fieldaccess.fieldname - }); - } - else if (expression instanceof prog.struct_expression_operation_comparison) { - var expression_operation_comparison = expression; - return lib_plankton.string.coin("{{indentation}}({{left}} === {{right}})", { - "indentation": indentation(options.indent, options.level), - "left": render_expression(expression_operation_comparison.left, { - "indent": false, - "level": (options.level + 0) - }), - "right": render_expression(expression_operation_comparison.right, { - "indent": false, - "level": (options.level + 0) - }) - }); - } - else if (expression instanceof prog.struct_expression_await) { - var expression_await = expression; - return lib_plankton.string.coin("{{indentation}}await {{target}}", { - "indentation": indentation(options.indent, options.level), - "target": render_expression(expression_await.target, { - "indent": false, - "level": (options.level + 0) - }) - }); - } - else if (expression instanceof prog.struct_expression_cast) { - var expression_cast = expression; - return lib_plankton.string.coin("{{indentation}}({{expression}} as {{type}})", { - "indentation": indentation(options.indent, options.level), - "expression": render_expression(expression_cast.expression, { - "indent": false, - "level": (options.level + 0) - }), - "type": render_type(expression_cast.type, { - "indent": false, - "level": (options.level + 0) - }) - }); - } - else { - throw (new Error("unhandled expression: " + String(expression))); - } - } - prog.render_expression = render_expression; - /** - */ - function render_statement(statement, options) { - if (options === void 0) { options = {}; } - options = Object.assign({ - "indent": true, - "level": 0 - }, options); - if (statement instanceof prog.struct_statement_comment) { - var statement_comment = statement; - return (statement_comment.block - ? lib_plankton.string.coin("{{indentation}}/**\n{{lines}}{{indentation}} */\n", { + /** + */ + function render_type(type, options) { + if (options === void 0) { options = {}; } + options = Object.assign({ + "indent": true, + "level": 0, + }, options); + if (type instanceof prog.struct_type_literal) { + var type_literal = type; + return lib_plankton.string.coin("{{indentation}}{{value}}", { "indentation": indentation(options.indent, options.level), - "lines": (statement_comment.lines - .map(function (line) { return lib_plankton.string.coin("{{indentation}} * {{line}}\n", { - "indentation": indentation(options.indent, options.level), - "line": line - }); }) - .join("")) - }) - : lib_plankton.string.coin("{{lines}}", { - "lines": (statement_comment.lines - .map(function (line) { return lib_plankton.string.coin("{{indentation}}// {{line}}\n", { - "indentation": indentation(options.indent, options.level), - "line": line - }); }) - .join("")) - })); - } - else if (statement instanceof prog.struct_statement_block) { - var statement_block = statement; - return lib_plankton.string.coin("{{indentation}}{\n{{statements}}{{indentation}}}\n", { - "indentation": indentation(options.indent, options.level), - "statements": (statement_block.statements - .map(function (statement) { return render_statement(statement, { - "level": (options.level + 1) - }); }) - .join("")) - }); - } - else if (statement instanceof prog.struct_statement_type_definition) { - var statement_type_definition = statement; - return lib_plankton.string.coin("{{indentation}}type {{name}} = {{type}};\n", { - "indentation": indentation(options.indent, options.level), - "name": statement_type_definition.name, - "type": render_type(statement_type_definition.type, { - "indent": false, - "level": (options.level + 0) - }) - }); - } - else if (statement instanceof prog.struct_statement_declaration) { - var statement_declaration = statement; - return lib_plankton.string.coin("{{indentation}}{{kind}} {{name}}{{macro_type}}{{macro_value}};\n", { - "indentation": indentation(options.indent, options.level), - "kind": (statement_declaration.constant - ? "const" - : "let"), - "name": statement_declaration.name, - "macro_type": ((statement_declaration.type === null) - ? "" - : lib_plankton.string.coin(" : {{type}}", { - "type": render_type(statement_declaration.type, { + "value": render_expression(type_literal.value, { + "level": (options.level + 1), + }), + }); + } + else if (type instanceof prog.struct_type_any) { + var type_any = type; + return lib_plankton.string.coin("{{indentation}}any", { + "indentation": indentation(options.indent, options.level), + }); + } + else if (type instanceof prog.struct_type_void) { + var type_void = type; + return lib_plankton.string.coin("{{indentation}}void", { + "indentation": indentation(options.indent, options.level), + }); + } + else if (type instanceof prog.struct_type_boolean) { + var type_boolean = type; + return lib_plankton.string.coin("{{indentation}}boolean", { + "indentation": indentation(options.indent, options.level), + }); + } + else if (type instanceof prog.struct_type_integer) { + var type_integer = type; + return lib_plankton.string.coin("{{indentation}}number", { + "indentation": indentation(options.indent, options.level), + }); + } + else if (type instanceof prog.struct_type_string) { + var type_string = type; + return lib_plankton.string.coin("{{indentation}}string", { + "indentation": indentation(options.indent, options.level), + }); + } + else if (type instanceof prog.struct_type_list) { + var type_list = type; + return render_type(new prog.struct_type_construction("Array", [ + type_list.element, + ])); + } + else if (type instanceof prog.struct_type_map) { + var type_map = type; + return render_type(new prog.struct_type_construction("Record", [ + type_map.key, + type_map.value, + ])); + } + else if (type instanceof prog.struct_type_record) { + var type_record = type; + return lib_plankton.string.coin("{{indentation1}}{\n{{fields}}\n{{indentation2}}}", { + "indentation1": indentation(options.indent, options.level), + "indentation2": indentation(true, options.level), + "fields": (type_record.fields + .map(function (field) { return lib_plankton.string.coin("{{indentation}}{{name}} {{assignment}} {{type}}", { + "indentation": indentation(true, options.level + 1), + "name": field.name, + "assignment": (field.mandatory ? ":" : "?:"), + "type": render_type(field.type, { "indent": false, - "level": (options.level + 0) - }) - })), - "macro_value": ((statement_declaration.value === null) - ? "" - : lib_plankton.string.coin(" = {{value}}", { - "value": render_expression(statement_declaration.value, { + "level": (options.level + 1), + }), + }); }) + .join(";\n")), + }); + } + else if (type instanceof prog.struct_type_function) { + var type_function = type; + return lib_plankton.string.coin("{{indentation1}}(({{arguments}})\n{{indentation2}}=>\n{{target}})", { + "indentation1": indentation(options.indent, options.level), + "indentation2": indentation(true, options.level), + "arguments": (type_function.arguments + .map(function (argument) { return render_type(argument, { + "level": (options.level + 1), + }); }) + .join(", ")), + "target": render_type(type_function.target, { + "level": (options.level + 1), + }), + }); + } + else if (type instanceof prog.struct_type_construction) { + var type_construction = type; + return lib_plankton.string.coin("{{indentation}}{{name}}{{macro_arguments}}", { + "indentation": indentation(options.indent, options.level), + "name": type_construction.name, + "macro_arguments": ((type_construction.arguments === null) + ? "" + : lib_plankton.string.coin("<\n{{arguments}}\n{{indentation}}>", { + "indentation": indentation(true, options.level), + "arguments": (type_construction.arguments + .map(function (argument) { return render_type(argument, { + "level": (options.level + 1), + }); }) + .join(",\n")), + })), + }); + } + else if (type instanceof prog.struct_type_union) { + var type_union = type; + return lib_plankton.string.coin("{{indentation1}}(\n{{left}}\n{{indentation3}}|\n{{right}}\n{{indentation2}})", { + "indentation1": indentation(options.indent, options.level), + "indentation2": indentation(true, options.level), + "indentation3": indentation(true, options.level + 1), + "left": render_type(type_union.left, { + "level": (options.level + 1), + }), + "right": render_type(type_union.right, { + "level": (options.level + 1), + }), + }); + } + else if (type instanceof prog.struct_type_intersection) { + var type_intersection = type; + return lib_plankton.string.coin("{{indentation1}}(\n{{left}}\n{{indentation2}}&\n{{right}}\n{{indentation2}})", { + "indentation1": indentation(options.indent, options.level), + "indentation2": indentation(true, options.level + 1), + "left": render_type(type_intersection.left, { + "level": (options.level + 1), + }), + "right": render_type(type_intersection.right, { + "level": (options.level + 1), + }), + }); + } + else { + throw (new Error("unhandled type kind: " + String(type))); + } + } + typescript.render_type = render_type; + /** + */ + function render_expression(expression, options) { + if (options === void 0) { options = {}; } + options = Object.assign({ + "indent": false, + "level": 0, + }, options); + if (expression instanceof prog.struct_expression_variable) { + var expression_variable = expression; + return lib_plankton.string.coin("{{indentation}}{{name}}", { + "indentation": indentation(options.indent, options.level), + "name": expression.name, + }); + } + else if (expression instanceof prog.struct_expression_literal) { + var expression_literal = expression; + return lib_plankton.string.coin("{{indentation}}{{value}}", { + "indentation": indentation(options.indent, options.level), + "value": JSON.stringify(expression_literal.value), + }); + } + else if (expression instanceof prog.struct_expression_list) { + var expression_list = expression; + return lib_plankton.string.coin("{{indentation1}}[\n{{elements}}\n{{indentation2}}]", { + "indentation1": indentation(options.indent, options.level), + "indentation2": indentation(true, options.level), + "elements": (expression_list.elements + .map(function (element) { return lib_plankton.string.coin("{{indentation}}{{value}}", { + "indentation": indentation(true, options.level + 1), + "value": render_expression(element, { "indent": false, - "level": (options.level + 0) - }) - })) - }); - } - else if (statement instanceof prog.struct_statement_assignment) { - var statement_assignment = statement; - return lib_plankton.string.coin("{{indentation}}{{name}} = {{value}};\n", { - "indentation": indentation(options.indent, options.level), - "name": statement_assignment.name, - "value": render_expression(statement_assignment.value, { - "indent": false, - "level": (options.level + 1) - }) - }); - } - else if (statement instanceof prog.struct_statement_procedure_call) { - var statement_procedure_call = statement; - return lib_plankton.string.coin("{{indentation1}}{{name}}(\n{{arguments}}\n{{indentation2}});\n", { - "indentation1": indentation(options.indent, options.level), - "indentation2": indentation(true, options.level), - "name": render_expression(statement_procedure_call.head, { - "indent": false, - "level": (options.level + 0) - }), - "arguments": (statement_procedure_call.arguments - .map(function (argument) { return lib_plankton.string.coin("{{argument}}", { - "argument": render_expression(argument, { - "indent": true, - "level": (options.level + 1) - }) - }); }) - .join(",\n")) - }); - } - else if (statement instanceof prog.struct_statement_function_definition) { - var statement_function_definition = statement; - return lib_plankton.string.coin("{{indentation1}}{{macro_async}}function {{name}}(\n{{arguments}}\n{{indentation2}}){{macro_output_type}}\n{{indentation2}}{\n{{body}}{{indentation2}}}\n", { - "indentation1": indentation(options.indent, options.level), - "indentation2": indentation(true, options.level), - "macro_async": (statement_function_definition.async_ - ? "async " - : ""), - "name": statement_function_definition.name, - "arguments": (statement_function_definition.arguments - .map(function (argument) { return lib_plankton.string.coin("{{indentation}}{{name}}{{macro_type}}", { - "indentation": indentation(true, (options.level + 1)), - "name": argument.name, - "macro_type": ((argument.type === null) + "level": (options.level + 1), + }), + }); }) + .join(",\n")), + }); + } + else if (expression instanceof prog.struct_expression_dict) { + var expression_dict = expression; + return lib_plankton.string.coin("{{indentation1}}{\n{{fields}}\n{{indentation2}}}", { + "indentation1": indentation(options.indent, options.level), + "indentation2": indentation(true, options.level), + "fields": (expression_dict.fields + .map(function (field) { return lib_plankton.string.coin("{{indentation}}\"{{key}}\": {{value}}", { + "indentation": indentation(true, options.level + 1), + "key": field.key, + "value": render_expression(field.value, { + "indent": false, + "level": (options.level + 1), + }), + }); }) + .join(",\n")), + }); + } + else if (expression instanceof prog.struct_expression_abstraction) { + var expression_abstraction = expression; + return lib_plankton.string.coin("{{indentation1}}{{macro_async}}function ({{arguments}}){{macro_output_type}} {\n{{body}}{{indentation2}}}", { + "indentation1": indentation(options.indent, options.level), + "indentation2": indentation(true, options.level), + "macro_async": (expression_abstraction.async_ + ? "async " + : ""), + "arguments": (expression_abstraction.arguments + .map(function (argument) { return lib_plankton.string.coin("{{name}}{{macro_type}}", { + "name": argument.name, + "macro_type": ((argument.type === null) + ? "" + : lib_plankton.string.coin(" : {{type}}", { + "type": render_type(argument.type) + })), + }); }) + .join(", ")), + "macro_output_type": ((expression_abstraction.output_type === null) ? "" : lib_plankton.string.coin(" : {{type}}", { - "type": render_type(argument.type, { + "type": render_type(expression_abstraction.output_type, { "indent": false, - "level": (options.level + 2) + "level": (options.level + 1), }) - })) - }); }) - .join(",\n")), - "macro_output_type": ((statement_function_definition.output_type === null) - ? "" - : lib_plankton.string.coin(" : {{type}}", { - "type": render_type(statement_function_definition.output_type, { - "indent": false, - "level": (options.level + 0) - }) - })), - "body": (statement_function_definition.body - .map(function (statement) { return render_statement(statement, { - "indent": true, - "level": (options.level + 1) - }); }) - .join("")) - }); + })), + "body": (expression_abstraction.body + .map(function (statement) { return render_statement(statement, { + "level": (options.level + 1), + }); }) + .join("")), + }); + } + else if (expression instanceof prog.struct_expression_function_application) { + var expression_function_application = expression; + return lib_plankton.string.coin("{{indentation1}}{{name}}(\n{{arguments}}\n{{indentation2}})", { + "indentation1": indentation(options.indent, options.level), + "indentation2": indentation(true, options.level), + "name": render_expression(expression_function_application.head, { + "indent": false, + "level": (options.level + 0), + }), + "arguments": (expression_function_application.arguments + .map(function (argument) { return lib_plankton.string.coin("{{argument}}", { + "argument": render_expression(argument, { + "indent": true, + "level": (options.level + 1), + }), + }); }) + .join(",\n")), + }); + } + else if (expression instanceof prog.struct_expression_projection) { + var expression_projection = expression; + return lib_plankton.string.coin("{{indentation}}{{source}}[{{index}}]", { + "indentation": indentation(options.indent, options.level), + "source": render_expression(expression_projection.source), + "index": render_expression(expression_projection.index), + }); + } + else if (expression instanceof prog.struct_expression_fieldaccess) { + var expression_fieldaccess = expression; + return lib_plankton.string.coin("{{indentation}}{{structure}}.{{fieldname}}", { + "indentation": indentation(options.indent, options.level), + "structure": render_expression(expression_fieldaccess.structure, { + "level": (options.level + 1), + }), + "fieldname": expression_fieldaccess.fieldname, + }); + } + else if (expression instanceof prog.struct_expression_operation_comparison) { + var expression_operation_comparison = expression; + return lib_plankton.string.coin("{{indentation}}({{left}} === {{right}})", { + "indentation": indentation(options.indent, options.level), + "left": render_expression(expression_operation_comparison.left, { + "indent": false, + "level": (options.level + 0), + }), + "right": render_expression(expression_operation_comparison.right, { + "indent": false, + "level": (options.level + 0), + }), + }); + } + else if (expression instanceof prog.struct_expression_await) { + var expression_await = expression; + return lib_plankton.string.coin("{{indentation}}await {{target}}", { + "indentation": indentation(options.indent, options.level), + "target": render_expression(expression_await.target, { + "indent": false, + "level": (options.level + 0), + }), + }); + } + else if (expression instanceof prog.struct_expression_cast) { + var expression_cast = expression; + return lib_plankton.string.coin("{{indentation}}({{expression}} as {{type}})", { + "indentation": indentation(options.indent, options.level), + "expression": render_expression(expression_cast.expression, { + "indent": false, + "level": (options.level + 0), + }), + "type": render_type(expression_cast.type, { + "indent": false, + "level": (options.level + 0), + }), + }); + } + else { + throw (new Error("unhandled expression: " + String(expression))); + } } - else if (statement instanceof prog.struct_statement_return) { - var statement_return = statement; - return lib_plankton.string.coin("{{indentation}}return {{expression}};\n", { - "indentation": indentation(options.indent, options.level), - "expression": render_expression(statement_return.expression, { - "indent": false, - "level": (options.level + 0) - }) - }); + typescript.render_expression = render_expression; + /** + */ + function render_statement(statement, options) { + if (options === void 0) { options = {}; } + options = Object.assign({ + "indent": true, + "level": 0, + }, options); + if (statement instanceof prog.struct_statement_comment) { + var statement_comment = statement; + return (statement_comment.block + ? lib_plankton.string.coin("{{indentation}}/**\n{{lines}}{{indentation}} */\n", { + "indentation": indentation(options.indent, options.level), + "lines": (statement_comment.lines + .map(function (line) { return lib_plankton.string.coin("{{indentation}} * {{line}}\n", { + "indentation": indentation(options.indent, options.level), + "line": line, + }); }) + .join("")), + }) + : lib_plankton.string.coin("{{lines}}", { + "lines": (statement_comment.lines + .map(function (line) { return lib_plankton.string.coin("{{indentation}}// {{line}}\n", { + "indentation": indentation(options.indent, options.level), + "line": line, + }); }) + .join("")), + })); + } + else if (statement instanceof prog.struct_statement_block) { + var statement_block = statement; + return lib_plankton.string.coin("{{indentation}}{\n{{statements}}{{indentation}}}\n", { + "indentation": indentation(options.indent, options.level), + "statements": (statement_block.statements + .map(function (statement) { return render_statement(statement, { + "level": (options.level + 1), + }); }) + .join("")), + }); + } + else if (statement instanceof prog.struct_statement_type_definition) { + var statement_type_definition = statement; + return lib_plankton.string.coin("{{indentation}}type {{name}} = {{type}};\n", { + "indentation": indentation(options.indent, options.level), + "name": statement_type_definition.name, + "type": render_type(statement_type_definition.type, { + "indent": false, + "level": (options.level + 0), + }), + }); + } + else if (statement instanceof prog.struct_statement_declaration) { + var statement_declaration = statement; + return lib_plankton.string.coin("{{indentation}}{{kind}} {{name}}{{macro_type}}{{macro_value}};\n", { + "indentation": indentation(options.indent, options.level), + "kind": (statement_declaration.constant + ? "const" + : "let"), + "name": statement_declaration.name, + "macro_type": ((statement_declaration.type === null) + ? "" + : lib_plankton.string.coin(" : {{type}}", { + "type": render_type(statement_declaration.type, { + "indent": false, + "level": (options.level + 0), + }), + })), + "macro_value": ((statement_declaration.value === null) + ? "" + : lib_plankton.string.coin(" = {{value}}", { + "value": render_expression(statement_declaration.value, { + "indent": false, + "level": (options.level + 0), + }), + })), + }); + } + else if (statement instanceof prog.struct_statement_assignment) { + var statement_assignment = statement; + return lib_plankton.string.coin("{{indentation}}{{name}} = {{value}};\n", { + "indentation": indentation(options.indent, options.level), + "name": statement_assignment.name, + "value": render_expression(statement_assignment.value, { + "indent": false, + "level": (options.level + 1), + }), + }); + } + else if (statement instanceof prog.struct_statement_procedure_call) { + var statement_procedure_call = statement; + return lib_plankton.string.coin("{{indentation1}}{{name}}(\n{{arguments}}\n{{indentation2}});\n", { + "indentation1": indentation(options.indent, options.level), + "indentation2": indentation(true, options.level), + "name": render_expression(statement_procedure_call.head, { + "indent": false, + "level": (options.level + 0), + }), + "arguments": (statement_procedure_call.arguments + .map(function (argument) { return lib_plankton.string.coin("{{argument}}", { + "argument": render_expression(argument, { + "indent": true, + "level": (options.level + 1), + }), + }); }) + .join(",\n")), + }); + } + else if (statement instanceof prog.struct_statement_function_definition) { + var statement_function_definition = statement; + return lib_plankton.string.coin("{{indentation1}}{{macro_async}}function {{name}}(\n{{arguments}}\n{{indentation2}}){{macro_output_type}}\n{{indentation2}}{\n{{body}}{{indentation2}}}\n", { + "indentation1": indentation(options.indent, options.level), + "indentation2": indentation(true, options.level), + "macro_async": (statement_function_definition.async_ + ? "async " + : ""), + "name": statement_function_definition.name, + "arguments": (statement_function_definition.arguments + .map(function (argument) { return lib_plankton.string.coin("{{indentation}}{{name}}{{macro_type}}", { + "indentation": indentation(true, (options.level + 1)), + "name": argument.name, + "macro_type": ((argument.type === null) + ? "" + : lib_plankton.string.coin(" : {{type}}", { + "type": render_type(argument.type, { + "indent": false, + "level": (options.level + 2), + }) + })), + }); }) + .join(",\n")), + "macro_output_type": ((statement_function_definition.output_type === null) + ? "" + : lib_plankton.string.coin(" : {{type}}", { + "type": render_type(statement_function_definition.output_type, { + "indent": false, + "level": (options.level + 0), + }) + })), + "body": (statement_function_definition.body + .map(function (statement) { return render_statement(statement, { + "indent": true, + "level": (options.level + 1), + }); }) + .join("")), + }); + } + else if (statement instanceof prog.struct_statement_return) { + var statement_return = statement; + return lib_plankton.string.coin("{{indentation}}return {{expression}};\n", { + "indentation": indentation(options.indent, options.level), + "expression": render_expression(statement_return.expression, { + "indent": false, + "level": (options.level + 0), + }), + }); + } + else { + throw (new Error("unhandled statement: " + (statement.constructor.name))); + } } - else { - throw (new Error("unhandled statement: " + (statement.constructor.name))); + typescript.render_statement = render_statement; + /** + */ + function render_program(program) { + return (program.statements + .map(function (statement) { return render_statement(statement, { + "indent": true, + "level": 0, + }); }) + .join("\n")); } - } - prog.render_statement = render_statement; - /** - */ - function render_program(program) { - return (program.statements - .map(function (statement) { return render_statement(statement, { - "indent": true, - "level": 0 - }); }) - .join("\n")); - } - prog.render_program = render_program; - /** - */ - function output_typescript() { - return { - "render_expression": render_expression, - "render_type": render_type, - "render_statement": render_statement, - "render_program": render_program - }; - } - prog.output_typescript = output_typescript; + typescript.render_program = render_program; + /** + */ + function output_typescript() { + return { + "render_expression": render_expression, + "render_type": render_type, + "render_statement": render_statement, + "render_program": render_program, + }; + } + typescript.output_typescript = output_typescript; + })(typescript = prog.typescript || (prog.typescript = {})); })(prog = lib_plankton.prog || (lib_plankton.prog = {})); })(lib_plankton || (lib_plankton = {})); /* @@ -4881,8 +4895,8 @@ var lib_plankton; "info": info, "hidden": hidden, "parameters": { - "index": index - } + "index": index, + }, })); }; /** @@ -4900,8 +4914,8 @@ var lib_plankton; "hidden": hidden, "parameters": { "indicators_short": indicators_short, - "indicators_long": indicators_long - } + "indicators_long": indicators_long, + }, })); }; /** @@ -5147,17 +5161,17 @@ var lib_plankton; "symbols": { "delimiter": " ", "prefix": "--", - "assignment": "=" - } + "assignment": "=", + }, }, "url": { "symbols": { "delimiter": "&", "prefix": "", - "assignment": "=" + "assignment": "=", } } - } + }, }; /** * @author fenris @@ -5234,14 +5248,14 @@ var lib_plankton; "pattern_from": pattern_from, "pattern_to": pattern_to, "input": input, - "result": result + "result": result, }); input = result; } } } lib_plankton.log.debug("lib_args:read:current_input", { - "input": input + "input": input, }); } // parsing @@ -5252,18 +5266,18 @@ var lib_plankton; var index_expected_1 = 0; parts.forEach(function (part) { lib_plankton.log.debug("lib_args:read:analyzing", { - "part": part + "part": part, }); var found = [ function () { lib_plankton.log.debug("lib_args:read:probing_as_volatile", { - "part": part + "part": part, }); for (var _i = 0, _a = Object.entries(_this.filter(args.enum_kind.volatile)); _i < _a.length; _i++) { var _b = _a[_i], name = _b[0], argument = _b[1]; lib_plankton.log.debug("lib_args:read:probing_as_volatile:trying", { "part": part, - "argument": argument.toString() + "argument": argument.toString(), }); var pattern = ""; { @@ -5282,12 +5296,12 @@ var lib_plankton; pattern += pattern_back; } lib_plankton.log.debug("lib_args:read:probing_as_volatile:pattern", { - "pattern": pattern + "pattern": pattern, }); var regexp = new RegExp(pattern); var matching = regexp.exec(part); lib_plankton.log.debug("lib_args:read:probing_as_volatile:matching", { - "matching": matching + "matching": matching, }); if (matching == null) { // do nothing @@ -5301,7 +5315,7 @@ var lib_plankton; }, function () { lib_plankton.log.debug("lib_args:read:probing_as_positional", { - "part": part + "part": part, }); var positional = _this.filter(args.enum_kind.positional); for (var _i = 0, _a = Object.entries(positional); _i < _a.length; _i++) { @@ -5312,7 +5326,7 @@ var lib_plankton; else { lib_plankton.log.debug("lib_args:read:probing_as_positional:trying", { "part": part, - "argument": argument.toString() + "argument": argument.toString(), }); var pattern = ""; { @@ -5321,12 +5335,12 @@ var lib_plankton; pattern += pattern_back; } lib_plankton.log.debug("lib_args:read:probing_as_positional:pattern", { - "pattern": pattern + "pattern": pattern, }); var regexp = new RegExp(pattern); var matching = regexp.exec(part); lib_plankton.log.debug("lib_args:read:probing_as_positional:matching", { - "matching": matching + "matching": matching, }); if (matching == null) { return false; @@ -5343,7 +5357,7 @@ var lib_plankton; ].some(function (x) { return x(); }); if (!found) { lib_plankton.log.warning("lib_args:read:could_not_parse", { - "part": part + "part": part, }); } });