übertragung
This commit is contained in:
commit
7cdfe72c79
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
temp/
|
||||
build/
|
||||
tools/
|
||||
|
||||
53
project.json
Normal file
53
project.json
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
{
|
||||
"name": "type2",
|
||||
"version": "0.0.1",
|
||||
"dependencies": [
|
||||
"../plankton/lang/project.json"
|
||||
],
|
||||
"roottask": {
|
||||
"name": "link",
|
||||
"type": "schwamm-apply",
|
||||
"parameters": {
|
||||
"path": "build/schwamm.json",
|
||||
"outputs": {
|
||||
"logic-impl": "build/type2.js"
|
||||
}
|
||||
},
|
||||
"sub": [
|
||||
{
|
||||
"name": "build",
|
||||
"type": "schwamm-create",
|
||||
"parameters": {
|
||||
"includes": [
|
||||
"../plankton/lang/build/schwamm.json"
|
||||
],
|
||||
"adhoc": {
|
||||
"logic-decl": [
|
||||
"temp/unlinked-logic-decl.d.ts"
|
||||
],
|
||||
"logic-impl": [
|
||||
"temp/unlinked-logic-impl.js"
|
||||
]
|
||||
},
|
||||
"output": "build/schwamm.json"
|
||||
},
|
||||
"sub": [
|
||||
{
|
||||
"name": "logic",
|
||||
"type": "typescript",
|
||||
"parameters": {
|
||||
"allowUnreachableCode": true,
|
||||
"inputs": [
|
||||
"source/base.ts",
|
||||
"source/type2.ts"
|
||||
],
|
||||
"declaration": "temp/unlinked-logic-decl.d.ts",
|
||||
"output": "temp/unlinked-logic-impl.js"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
79
source/base.ts
Normal file
79
source/base.ts
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
type char = string;
|
||||
|
||||
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
declare var require : (path : string)=>any;
|
||||
|
||||
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
declare var process : any;
|
||||
|
||||
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
declare class Buffer
|
||||
{
|
||||
public toString() : string;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
declare class Promise<type_result, type_reason>
|
||||
{
|
||||
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
public constructor
|
||||
(
|
||||
executor : (resolve : (result ?: type_result)=>void, reject ?: (reason ?: type_reason)=>void)=>void
|
||||
)
|
||||
;
|
||||
|
||||
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
public then<type_result_, type_reason_>
|
||||
(
|
||||
onFulfilled : (result : type_result)=>any,
|
||||
onRejected ?: (reason : type_reason)=>any
|
||||
)
|
||||
: Promise<type_result_, type_reason_>
|
||||
;
|
||||
|
||||
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
public catch<type_result_, type_reason_>
|
||||
(
|
||||
onRejected : (reason : type_reason)=>any
|
||||
)
|
||||
: Promise<type_result_, type_reason_>
|
||||
;
|
||||
|
||||
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
public static resolve<type_result, type_reason>
|
||||
(
|
||||
result : type_result
|
||||
)
|
||||
: Promise<type_result, type_reason>
|
||||
;
|
||||
|
||||
}
|
||||
|
||||
190
source/type2.ts
Normal file
190
source/type2.ts
Normal file
|
|
@ -0,0 +1,190 @@
|
|||
|
||||
///<reference path="../../lang/build/logic-decl.d.ts"/>
|
||||
|
||||
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
type type_myreader = lib_lang.class_reader<char, lib_lang.type_terminal_default, string, lib_lang.type_tree<lib_lang.type_terminal_default>>;
|
||||
|
||||
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
var generate_reader : (path : string)=>Promise<type_myreader, Error> =
|
||||
path => Promise.resolve<string, Error>(path)
|
||||
.then<Buffer, Error>
|
||||
(
|
||||
path => new Promise<Buffer, Error>
|
||||
(
|
||||
(resolve, reject) =>
|
||||
{
|
||||
let _fs = require("fs");
|
||||
_fs.readFile
|
||||
(
|
||||
path,
|
||||
{
|
||||
"encoding": "utf8",
|
||||
"flag": "r",
|
||||
},
|
||||
(error, buffer) =>
|
||||
{
|
||||
if (error == null)
|
||||
{
|
||||
resolve(buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
reject(error);
|
||||
}
|
||||
}
|
||||
)
|
||||
;
|
||||
}
|
||||
)
|
||||
)
|
||||
.then<any, Error>
|
||||
(
|
||||
buffer => new Promise<any, Error>
|
||||
(
|
||||
(resolve, reject) =>
|
||||
{
|
||||
resolve(JSON.parse(buffer.toString()));
|
||||
}
|
||||
)
|
||||
)
|
||||
.then<type_myreader, Error>
|
||||
(
|
||||
data => new Promise<type_myreader, Error>
|
||||
(
|
||||
(resolve, reject) =>
|
||||
{
|
||||
resolve(lib_lang.class_reader.default_raw(data));
|
||||
}
|
||||
)
|
||||
)
|
||||
;
|
||||
|
||||
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
var transform_arguments : (args : Array<string>)=>Promise<{path ?: string; input ?: Array<char>;}, Error> =
|
||||
args => Promise.resolve<{path ?: string; input ?: Array<char>;}, Error>({})
|
||||
.then<{path ?: string; input ?: Array<char>;}, Error>
|
||||
(
|
||||
parameters => new Promise<{path ?: string; input ?: Array<char>;}, Error>
|
||||
(
|
||||
(resolve, reject) =>
|
||||
{
|
||||
let path : string;
|
||||
path = ((args.length >= 1) ? args.shift() : null);
|
||||
if (path == null)
|
||||
{
|
||||
reject(new Error("no path specified"));
|
||||
}
|
||||
else
|
||||
{
|
||||
resolve({"path": path, "input": parameters.input});
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
.then<{path ?: string; input ?: Array<char>;}, Error>
|
||||
(
|
||||
parameters => new Promise<{path ?: string; input ?: Array<char>;}, Error>
|
||||
(
|
||||
(resolve, reject) =>
|
||||
{
|
||||
let input : Array<char>;
|
||||
let input_raw : string = args.join(" ");
|
||||
if (input_raw == "")
|
||||
{
|
||||
reject(new Error("no input given"));
|
||||
}
|
||||
else
|
||||
{
|
||||
input = input_raw.split("");
|
||||
resolve({"path": parameters.path, "input": input});
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
;
|
||||
|
||||
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
var main : (args : Array<string>)=>Promise<void, Error> =
|
||||
args => Promise.resolve<void, Error>(undefined)
|
||||
.then<{path ?: string; input ?: Array<char>;}, Error>
|
||||
(
|
||||
_ => transform_arguments(args)
|
||||
)
|
||||
.then<{parameters : {path ?: string; input ?: Array<char>;}; reader : type_myreader;}, Error>
|
||||
(
|
||||
parameters => generate_reader(parameters.path)
|
||||
.then<{parameters : {path ?: string; input ?: Array<char>;}; reader : type_myreader;}, Error>
|
||||
(
|
||||
reader => new Promise<{parameters : {path ?: string; input ?: Array<char>;}; reader : type_myreader;}, Error>
|
||||
(
|
||||
(resolve_, reject_) =>
|
||||
{
|
||||
resolve_({"parameters": parameters, "reader": reader});
|
||||
}
|
||||
)
|
||||
)
|
||||
)
|
||||
.then<lib_lang.type_tree<lib_lang.type_terminal_default>, Error>
|
||||
(
|
||||
vars => new Promise<lib_lang.type_tree<lib_lang.type_terminal_default>, Error>
|
||||
(
|
||||
(resolve, reject) =>
|
||||
{
|
||||
lib_log.level_push(1);
|
||||
let result : lib_lang.type_tree<lib_lang.type_terminal_default> = vars.reader.run(vars.parameters.input);
|
||||
lib_log.level_pop();
|
||||
if (result == null)
|
||||
{
|
||||
reject(new Error("didn't work"));
|
||||
}
|
||||
else
|
||||
{
|
||||
resolve(result);
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
.then<void, Error>
|
||||
(
|
||||
result => new Promise<void, Error>
|
||||
(
|
||||
(resolve, reject) =>
|
||||
{
|
||||
console.info(JSON.stringify(result, undefined, "\t"));
|
||||
resolve(undefined);
|
||||
}
|
||||
)
|
||||
)
|
||||
;
|
||||
|
||||
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
main(process.argv.slice(2))
|
||||
.then
|
||||
(
|
||||
output =>
|
||||
{
|
||||
// console.info("--", "done:", output);
|
||||
}
|
||||
,
|
||||
error =>
|
||||
{
|
||||
console.error("--", "failed:", error);
|
||||
}
|
||||
)
|
||||
;
|
||||
|
||||
Loading…
Reference in a new issue