1912 lines
59 KiB
TypeScript
1912 lines
59 KiB
TypeScript
/**
|
|
* @author fenris
|
|
*/
|
|
declare type int = number;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
declare type float = number;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
declare type type_time = {
|
|
hours: int;
|
|
minutes: int;
|
|
seconds: int;
|
|
};
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
declare type type_pseudopointer<type_value> = {
|
|
value: type_value;
|
|
};
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
declare function pseudopointer_null<type_value>(): type_pseudopointer<type_value>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
declare function pseudopointer_make<type_value>(value: type_value): type_pseudopointer<type_value>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
declare function pseudopointer_isset<type_value>(pseudopointer: type_pseudopointer<type_value>): boolean;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
declare function pseudopointer_read<type_value>(pseudopointer: type_pseudopointer<type_value>): type_value;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
declare function pseudopointer_write<type_value>(pseudopointer: type_pseudopointer<type_value>, value: type_value): void;
|
|
declare var process: any;
|
|
declare var require: any;
|
|
declare class Buffer {
|
|
constructor(x: string, modifier?: string);
|
|
toString(modifier?: string): string;
|
|
}
|
|
declare var java: any;
|
|
declare module lib_base {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function environment(): string;
|
|
}
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
declare var instance_verbosity: int;
|
|
/**
|
|
* @desc the ability to check for equality with another element of the same domain
|
|
* @author fenris
|
|
*/
|
|
interface interface_collatable<type_value> {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
_collate(value: type_value): boolean;
|
|
}
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
declare function instance_collate<type_value>(value1: type_value, value2: type_value): boolean;
|
|
/**
|
|
* @desc the ability to compare with another element of the same domain for determining if the first is "smaller than or equal to" the latter
|
|
* @author fenris
|
|
*/
|
|
interface interface_comparable<type_value> {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
_compare(value: type_value): boolean;
|
|
}
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
declare function instance_compare<type_value>(value1: type_value, value2: type_value): boolean;
|
|
/**
|
|
* @desc the ability to create an exact copy
|
|
* @author fenris
|
|
*/
|
|
interface interface_cloneable<type_value> {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
_clone(): type_value;
|
|
}
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
declare function instance_clone<type_value>(value: type_value): type_value;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
interface interface_hashable {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
_hash(): string;
|
|
}
|
|
/**
|
|
* @desc the ability to generate a string out of the element, which identifies it to a high degree
|
|
* @author fenris
|
|
*/
|
|
declare function instance_hash<type_value>(value: type_value): string;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
interface interface_showable {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
_show(): string;
|
|
}
|
|
/**
|
|
* @desc the ability to map the element to a textual representation (most likely not injective)
|
|
* @author fenris
|
|
*/
|
|
declare function instance_show<type_value>(value: type_value): string;
|
|
/**
|
|
* @todo outsource to dedicated plankton-lib
|
|
*/
|
|
declare module lib_log {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function log(...args: Array<any>): void;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function info(...args: Array<any>): void;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function warn(...args: Array<any>): void;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function error(...args: Array<any>): void;
|
|
}
|
|
/**
|
|
* @author frac
|
|
*/
|
|
interface interface_decorator<type_core> {
|
|
/**
|
|
* @author frac
|
|
*/
|
|
core: type_core;
|
|
}
|
|
/**
|
|
* @author frac
|
|
*/
|
|
declare class class_observer {
|
|
/**
|
|
* @author frac
|
|
*/
|
|
protected counter: int;
|
|
/**
|
|
* @author frac
|
|
*/
|
|
protected actions: {
|
|
[id: string]: (information: Object) => void;
|
|
};
|
|
/**
|
|
* @author frac
|
|
*/
|
|
protected buffer: Array<Object>;
|
|
/**
|
|
* @author frac
|
|
*/
|
|
constructor();
|
|
/**
|
|
* @author frac
|
|
*/
|
|
empty(): boolean;
|
|
/**
|
|
* @author frac
|
|
*/
|
|
flush(): void;
|
|
/**
|
|
* @author frac
|
|
*/
|
|
set(id: string, action: (information: Object) => void): void;
|
|
/**
|
|
* @author frac
|
|
*/
|
|
del(id: string): void;
|
|
/**
|
|
* @author frac
|
|
*/
|
|
add(action: (information: Object) => void): void;
|
|
/**
|
|
* @author frac
|
|
*/
|
|
notify(information?: Object, delayed?: boolean): void;
|
|
/**
|
|
* @author frac
|
|
*/
|
|
rollout(): void;
|
|
}
|
|
/**
|
|
* @author frac
|
|
*/
|
|
/**
|
|
* @author frac
|
|
*/
|
|
declare module lib_maybe {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
type type_maybe<type_value> = {
|
|
kind: string;
|
|
parameters: Object;
|
|
};
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function make_nothing<type_value>(): type_maybe<type_value>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function make_just<type_value>(value: type_value): type_maybe<type_value>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function is_nothing<type_value>(maybe: type_maybe<type_value>): boolean;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function is_just<type_value>(maybe: type_maybe<type_value>): boolean;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function cull<type_value>(maybe: type_maybe<type_value>): type_value;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function propagate<type_value, type_value_>(maybe: type_maybe<type_value>, function_: (value: type_value) => type_maybe<type_value_>): type_maybe<type_value_>;
|
|
}
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
declare class class_maybe<type_value> implements interface_showable {
|
|
/**
|
|
* @desc whether the wrapper is nothing
|
|
* @author fenris
|
|
*/
|
|
is_nothing(): boolean;
|
|
/**
|
|
* @desc whether the wrapper is just
|
|
* @author fenris
|
|
*/
|
|
is_just(): boolean;
|
|
/**
|
|
* @desc return the value, stored in the maybe-wrapper
|
|
* @author fenris
|
|
*/
|
|
cull(): type_value;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
toString(): string;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
distinguish(action_just: (value?: type_value) => void, action_nothing?: (reason?: string) => void): void;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
propagate<type_value_>(action: (value: type_value) => class_maybe<type_value_>): class_maybe<type_value_>;
|
|
/**
|
|
* @desc [implementation]
|
|
* @author fenris
|
|
*/
|
|
_show(): string;
|
|
}
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
declare class class_nothing<type_value> extends class_maybe<type_value> {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
private reason;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
constructor(reason?: string);
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
is_nothing(): boolean;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
is_just(): boolean;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
cull(): type_value;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
toString(): string;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
reason_get(): string;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
distinguish(action_just: (value?: type_value) => void, action_nothing?: (reason?: string) => void): void;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
propagate<type_value_>(action: (value: type_value) => class_maybe<type_value_>): class_maybe<type_value_>;
|
|
}
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
declare class class_just<type_value> extends class_maybe<type_value> {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
private value;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
constructor(value: type_value);
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
is_nothing(): boolean;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
is_just(): boolean;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
cull(): type_value;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
toString(): string;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
distinguish(action_just: (value?: type_value) => void, action_nothing?: (reason?: string) => void): void;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
propagate<type_value_>(action: (value: type_value) => class_maybe<type_value_>): class_maybe<type_value_>;
|
|
}
|
|
/**
|
|
* @author frac
|
|
*/
|
|
declare class class_error extends Error {
|
|
/**
|
|
* @author frac
|
|
*/
|
|
protected suberrors: Array<Error>;
|
|
/**
|
|
* @author frac
|
|
*/
|
|
protected mess: string;
|
|
/**
|
|
* @author frac
|
|
*/
|
|
constructor(message: string, suberrors?: Array<Error>);
|
|
/**
|
|
* @override
|
|
* @author frac
|
|
*/
|
|
toString(): string;
|
|
}
|
|
declare module lib_call {
|
|
/**
|
|
* @desc hacked class for postfix function application
|
|
* @author fenris
|
|
*/
|
|
class class_valuewrapper<type_value> {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
protected value: type_value;
|
|
/**
|
|
* @desc [constructor]
|
|
* @author fenris
|
|
*/
|
|
constructor(value: type_value);
|
|
/**
|
|
* @desc [accessor] applies a function and returns a new valuewrapper
|
|
* @author fenris
|
|
*/
|
|
pass<type_value_>(function_: (value: type_value) => type_value_): class_valuewrapper<type_value_>;
|
|
/**
|
|
* @desc [accessor] gives the wrapped value
|
|
* @author fenris
|
|
*/
|
|
extract(): type_value;
|
|
}
|
|
/**
|
|
* @desc shortcut for constructing a valuewrapper-object
|
|
* @author fenris
|
|
*/
|
|
function vw<type_value>(value: type_value): class_valuewrapper<type_value>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function use<type_input, type_output>(input: type_input, function_: (input: type_input) => type_output): type_output;
|
|
/**
|
|
* @desc just the identity; useful for some callbacks etc.
|
|
* @author fenris
|
|
*/
|
|
function id<type_value>(x: type_value): type_value;
|
|
/**
|
|
* @desc composes two functions (i.e. returns a function that return the result of the successive execution of both input-functions)
|
|
* @param {function} function_f
|
|
* @param {function} function_g
|
|
* @author fenris
|
|
*/
|
|
function compose<type_x, type_y, type_z>(function_f: (type_x: any) => type_y, function_g: (type_y: any) => type_z): (value: type_x) => type_z;
|
|
/**
|
|
* @desc transforms a function with sequential input into a function with leveled input; example: add(2,3) = curryfy(add)(2)(3)
|
|
* @param {function} f
|
|
* @param {int} n (don't set manually)
|
|
* @return {function} the currified version of the in put function
|
|
* @author fenris
|
|
*/
|
|
function curryfy(f: Function, n?: int): Function;
|
|
}
|
|
declare module lib_call {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
type type_executor<type_result, type_reason> = ((resolve: (result?: type_result) => any, reject?: (reason?: type_reason) => void) => void);
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function executor_resolve<type_result, type_reason>(result: type_result): type_executor<type_result, type_reason>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function executor_reject<type_result, type_reason>(reason: type_reason): type_executor<type_result, type_reason>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function executor_transform<type_result_from, type_error_from, type_result_to, type_error_to>(executor: type_executor<type_result_from, type_error_from>, transform_result: (result_from: type_result_from) => type_result_to, transform_reason: (error_from: type_error_from) => type_error_to): type_executor<type_result_to, type_error_to>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function executor_transform_default<type_result_from, type_result_to>(executor: type_executor<type_result_from, Error>, transform_result: (result_from: type_result_from) => type_result_to, wrap_string?: string): type_executor<type_result_to, Error>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function executor_compose_sequential<type_result_first, type_result_second, type_reason>(first: type_executor<type_result_first, type_reason>, second: (result: type_result_first) => type_executor<type_result_second, type_reason>): type_executor<type_result_second, type_reason>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function executor_chain<type_state, type_error>(state: type_state, executors: Array<(state: type_state) => type_executor<type_state, type_error>>): type_executor<type_state, type_error>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function executor_first<type_result, type_reason>(executors: Array<type_executor<type_result, type_reason>>): type_executor<type_result, Array<type_reason>>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function executor_condense<type_element>(executors: Array<type_executor<type_element, Error>>): type_executor<Array<type_element>, Error>;
|
|
/**
|
|
* @author fenris
|
|
* @deprecated use condense
|
|
*/
|
|
function executor_filter<type_element>(executors: Array<type_executor<type_element, Error>>, predicate: (element: type_element) => boolean): type_executor<Array<type_element>, Error>;
|
|
/**
|
|
* @author fenris
|
|
* @deprecated use condense
|
|
*/
|
|
function executor_map<type_element1, type_element2>(executors: Array<type_executor<type_element1, Error>>, transformator: (element1: type_element1) => type_element2): type_executor<Array<type_element2>, Error>;
|
|
/**
|
|
* @author fenris
|
|
* @deprecated use condense
|
|
*/
|
|
function executor_reduce<type_element, type_result>(executors: Array<type_executor<type_element, Error>>, initial: type_result, accumulator: (result: type_result, element: type_element) => type_result): type_executor<type_result, Error>;
|
|
}
|
|
declare module lib_call {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
type type_promise<type_result, type_reason> = Promise<type_result>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function promise_reject<type_result, type_reason>(reason: type_reason): type_promise<type_result, type_reason>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function promise_resolve<type_result, type_reason>(result: type_result): type_promise<type_result, type_reason>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function promise_make<type_result, type_reason>(executor: (resolve: (result?: type_result) => void, reject: (reason?: type_reason) => void) => void): type_promise<type_result, type_reason>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function promise_then_close<type_result, type_reason>(promise: type_promise<type_result, type_reason>, resolver: (result: type_result) => void, rejector: (reason: type_reason) => void): void;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function promise_then_append<type_result, type_reason, type_result_>(promise: type_promise<type_result, type_reason>, resolver: (result: type_result) => type_promise<type_result_, type_reason>, rejector?: (reason: type_reason) => type_promise<type_result_, type_reason>): type_promise<type_result_, type_result>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function promise_all<type_result, type_reason>(promises: Array<type_promise<type_result, type_reason>>): type_promise<Array<type_result>, type_reason>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function promise_chain<type_result, type_reason>(promises: Array<(input: type_result) => type_promise<type_result, type_reason>>, start?: type_result): type_promise<type_result, type_reason>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function promise_condense<type_element, type_reason>(promises: Array<() => type_promise<type_element, type_reason>>): type_promise<Array<type_element>, type_reason>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function promise_group<type_reason>(promises: {
|
|
[name: string]: () => type_promise<any, type_reason>;
|
|
}, serial?: boolean): type_promise<{
|
|
[name: string]: any;
|
|
}, type_reason>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function promise_wrap<type_result_inner, type_result_outer, type_reason>(promise: type_promise<type_result_inner, type_reason>, transformator_result: (reason: type_result_inner) => type_result_outer, transformator_reason?: (reason: type_reason) => type_reason): type_promise<type_result_outer, type_reason>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function promise_show<type_result, type_reason>(label: string): (result: type_result) => type_promise<type_result, type_reason>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function promise_log<type_result, type_reason>(result: type_result): (result: type_result) => type_promise<type_result, type_reason>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function promise_attach<type_reason>(state: {
|
|
[name: string]: any;
|
|
}, promise: type_promise<any, type_reason>, name: string): type_promise<{
|
|
[name: string]: any;
|
|
}, type_reason>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function promise_delay<type_result, type_reason>(promise: type_promise<type_result, type_reason>, delay: int): type_promise<type_result, type_reason>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function promise_to_executor<type_result, type_reason>(promise: type_promise<type_result, type_reason>): type_executor<type_result, type_reason>;
|
|
}
|
|
declare module lib_call {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
type type_initializer_state = int;
|
|
const initializer_state_initial: type_initializer_state;
|
|
const initializer_state_waiting: type_initializer_state;
|
|
const initializer_state_successful: type_initializer_state;
|
|
const initializer_state_failed: type_initializer_state;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
type type_initializer<type_result, type_reason> = {
|
|
fetcher: () => type_promise<type_result, type_reason>;
|
|
state?: type_initializer_state;
|
|
queue: Array<{
|
|
resolve: (result?: type_result) => void;
|
|
reject: (reason?: type_reason) => void;
|
|
}>;
|
|
result?: type_result;
|
|
reason?: type_reason;
|
|
};
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function initializer_make<type_result, type_reason>(fetcher: () => type_promise<type_result, type_reason>): type_initializer<type_result, type_reason>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function initializer_reset<type_result, type_reason>(subject: type_initializer<type_result, type_reason>): void;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function initializer_state<type_result, type_reason>(subject: type_initializer<type_result, type_reason>): type_initializer_state;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function initializer_get<type_result, type_reason>(subject: type_initializer<type_result, type_reason>): type_promise<type_result, type_reason>;
|
|
}
|
|
declare module lib_call {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
type type_deferral<type_input, type_output> = {
|
|
representation: (input: type_input) => Promise<type_output>;
|
|
};
|
|
/**
|
|
* @author fenris
|
|
* @desc activates the deferral and handles its output according to a given procedure
|
|
* @param {(value : type_value)=>void} procedure a function which receives the output of the deferral as argument
|
|
*/
|
|
function deferral_use<type_input, type_output>(deferral: type_deferral<type_input, type_output>, input: type_input, procedure: (output: type_output) => void): void;
|
|
/**
|
|
* @author fenris
|
|
* @desc creates a deferral-subject (similar to "new Promise", where "convey" reflects "resolve"/"reject")
|
|
*/
|
|
function deferral_make<type_input, type_output>(handler: (input: type_input, convey: (output: type_output) => void) => void): type_deferral<type_input, type_output>;
|
|
/**
|
|
* @author fenris
|
|
* @desc wraps a simple function into a deferral (similar to "Promise.resolve"/"Promise.reject")
|
|
*/
|
|
function deferral_wrap<type_input, type_output>(function_: (input: type_input) => type_output): type_deferral<type_input, type_output>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function deferral_id<type_value>(): type_deferral<type_value, type_value>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function deferral_const<type_value>(value: type_value): type_deferral<type_value, type_value>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function deferral_delay<type_output>(output: type_output, delay: int): type_deferral<any, type_output>;
|
|
/**
|
|
* @author fenris
|
|
* @desc connects two deferrals to form a new one; the output of the first is taken as input for the second
|
|
* (similar to "Promise.then" when passing a function which returns a new promise)
|
|
* @param {type_deferral<type_value1>} first a simple deferral
|
|
* @param {(value1 : type_value1)=>type_deferral<type_value2>} second a function depending from a value returning a deferral
|
|
*/
|
|
function deferral_compose_serial<type_input, type_between, type_output>(first: type_deferral<type_input, type_between>, second: type_deferral<type_between, type_output>): type_deferral<type_input, type_output>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function deferral_compose_parallel<type_input, type_output_left, type_output_right>({ "left": deferral_left, "right": deferral_right, }: {
|
|
left: type_deferral<type_input, type_output_left>;
|
|
right: type_deferral<type_input, type_output_right>;
|
|
}): type_deferral<type_input, {
|
|
left: type_output_left;
|
|
right: type_output_right;
|
|
}>;
|
|
/**
|
|
* @author fenris
|
|
* @desc repeatedly applied serial composition
|
|
*/
|
|
function deferral_chain<type_value>(members: Array<type_deferral<type_value, type_value>>): type_deferral<type_value, type_value>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
}
|
|
declare module lib_call {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
class class_deferral<type_input, type_output> {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
private subject;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
private constructor();
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
private static _cram;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
private static _tear;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
static make<type_input, type_output>(handler: (input: type_input, convey: (value: type_output) => void) => void): class_deferral<type_input, type_output>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
use(input: type_input, procedure: (value: type_output) => void): void;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
compose_serial<type_output_>(second: class_deferral<type_output, type_output_>): class_deferral<type_input, type_output_>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
static chain<type_value>(members: Array<class_deferral<type_value, type_value>>): class_deferral<type_value, type_value>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
static wrap<type_input, type_output>(function_: (input: type_input) => type_output): class_deferral<type_input, type_output>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
static const_<type_value>(value: type_value): class_deferral<type_value, type_value>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
static delay<type_output>(output: type_output, delay: int): class_deferral<any, type_output>;
|
|
}
|
|
}
|
|
declare module lib_call {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function timeout(function_: () => void, delay: int): int;
|
|
/**
|
|
* @desc a definition for a value being "defined"
|
|
* @author neuc
|
|
*/
|
|
function is_def<type_value>(obj: type_value, null_is_valid?: boolean): boolean;
|
|
/**
|
|
* @desc returns the value if set and, when a type is specified, if the type is correct, if not return default_value
|
|
* @author neuc
|
|
*/
|
|
function def_val(value: any, default_value: any, type?: string, null_is_valid?: boolean): any;
|
|
/**
|
|
* @desc just the empty function; useful for some callbacks etc.
|
|
* @author fenris
|
|
*/
|
|
function nothing(): void;
|
|
/**
|
|
* @desc outputs
|
|
* @author fenris
|
|
*/
|
|
function output(...args: Array<any>): void;
|
|
/**
|
|
* @desc converts the "arguments"-map into an array
|
|
* @param {Object} args
|
|
* @author fenris
|
|
*/
|
|
function args2list(args: any): Array<any>;
|
|
/**
|
|
* @desc provides the call for an attribute of a class as a regular function
|
|
* @param {string} name the name of the attribute
|
|
* @return {*}
|
|
* @author fenris
|
|
*/
|
|
function attribute<type_object, type_attribute>(name: string): (object: type_object) => type_attribute;
|
|
/**
|
|
* @desc provides a method of a class as a regular function
|
|
* @param {string} name the name of the method
|
|
* @return {function}
|
|
* @author fenris
|
|
*/
|
|
function method<type_object, type_output>(name: string): (object: type_object) => type_output;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
type type_unival = {
|
|
kind: string;
|
|
data?: any;
|
|
};
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function distinguish(unival: type_unival, handlers: {
|
|
[kind: string]: (data?: any) => any;
|
|
}, fallback?: (unival?: type_unival) => any): any;
|
|
}
|
|
declare namespace lib_plankton.log {
|
|
/**
|
|
*/
|
|
enum enum_level {
|
|
debug = 0,
|
|
info = 1,
|
|
notice = 2,
|
|
warning = 3,
|
|
error = 4
|
|
}
|
|
/**
|
|
*/
|
|
function level_order(level1: enum_level, level2: enum_level): boolean;
|
|
/**
|
|
*/
|
|
function level_show(level: enum_level): string;
|
|
/**
|
|
*/
|
|
type type_entry = {
|
|
level: enum_level;
|
|
incident: string;
|
|
details: {
|
|
[name: string]: any;
|
|
};
|
|
};
|
|
}
|
|
/**
|
|
* @deprecated
|
|
* @todo remove
|
|
*/
|
|
declare module lib_log {
|
|
function level_push(level: int): void;
|
|
function level_pop(): void;
|
|
function indent_push(indent: int): void;
|
|
function indent_pop(): void;
|
|
function indent_inc(): void;
|
|
function indent_dec(): void;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function write({ "message": message, "type": type, "prefix": prefix, "level": level, "indent": indent, }: {
|
|
message?: string;
|
|
type?: string;
|
|
prefix?: string;
|
|
level?: int;
|
|
indent?: int;
|
|
}): void;
|
|
}
|
|
declare namespace lib_plankton.log {
|
|
/**
|
|
*/
|
|
abstract class class_channel {
|
|
/**
|
|
*/
|
|
abstract add(entry: type_entry): void;
|
|
}
|
|
}
|
|
declare namespace lib_plankton.log {
|
|
/**
|
|
*/
|
|
class class_channel_console extends class_channel {
|
|
/**
|
|
*/
|
|
add(entry: type_entry): void;
|
|
}
|
|
}
|
|
declare namespace lib_plankton.log {
|
|
/**
|
|
*/
|
|
class class_channel_notify extends class_channel {
|
|
/**
|
|
*/
|
|
add(entry: type_entry): void;
|
|
}
|
|
}
|
|
declare namespace lib_plankton.log {
|
|
/**
|
|
*/
|
|
class class_channel_minlevel extends class_channel {
|
|
/**
|
|
*/
|
|
private core;
|
|
/**
|
|
*/
|
|
private threshold;
|
|
/**
|
|
*/
|
|
constructor(core: class_channel, threshold: enum_level);
|
|
/**
|
|
*/
|
|
add(entry: type_entry): void;
|
|
}
|
|
}
|
|
declare namespace lib_plankton.log {
|
|
/**
|
|
*/
|
|
function channel_make(description: {
|
|
kind: string;
|
|
data?: {
|
|
[key: string]: any;
|
|
};
|
|
}): class_channel;
|
|
}
|
|
declare namespace lib_plankton.log {
|
|
/**
|
|
*/
|
|
function conf_default(): Array<class_channel>;
|
|
/**
|
|
*/
|
|
function conf_push(channels: Array<class_channel>): void;
|
|
/**
|
|
*/
|
|
function conf_pop(): void;
|
|
/**
|
|
*/
|
|
function setup(): void;
|
|
/**
|
|
*/
|
|
function add(entry: type_entry): void;
|
|
/**
|
|
*/
|
|
function debug(incident: string, details?: {
|
|
[name: string]: any;
|
|
}): void;
|
|
/**
|
|
*/
|
|
function info(incident: string, details?: {
|
|
[name: string]: any;
|
|
}): void;
|
|
/**
|
|
*/
|
|
function notice(incident: string, details?: {
|
|
[name: string]: any;
|
|
}): void;
|
|
/**
|
|
*/
|
|
function warning(incident: string, details?: {
|
|
[name: string]: any;
|
|
}): void;
|
|
/**
|
|
*/
|
|
function error(incident: string, details?: {
|
|
[name: string]: any;
|
|
}): void;
|
|
}
|
|
declare namespace lib_args {
|
|
/**
|
|
*/
|
|
enum enum_environment {
|
|
cli = "cli",
|
|
url = "url"
|
|
}
|
|
/**
|
|
*/
|
|
enum enum_kind {
|
|
positional = "positional",
|
|
volatile = "volatile"
|
|
}
|
|
/**
|
|
*/
|
|
enum enum_type {
|
|
boolean = "boolean",
|
|
integer = "int",
|
|
float = "float",
|
|
string = "string"
|
|
}
|
|
/**
|
|
*/
|
|
enum enum_mode {
|
|
replace = "replace",
|
|
accumulate = "accumulate"
|
|
}
|
|
}
|
|
declare module lib_args {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
class class_argument {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
protected name: string;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
protected kind: enum_kind;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
protected type: enum_type;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
protected mode: enum_mode;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
protected default_: any;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
protected info: string;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
protected parameters: Object;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
protected hidden: boolean;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
constructor({ "name": name, "type": type, "kind": kind, "mode": mode, "default": default_, "info": info, "parameters": parameters, "hidden": hidden, }: {
|
|
name: string;
|
|
type?: enum_type;
|
|
kind?: enum_kind;
|
|
mode?: enum_mode;
|
|
default?: any;
|
|
info?: string;
|
|
parameters?: Object;
|
|
hidden?: boolean;
|
|
});
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
static positional({ "name": name, "type": type, "mode": mode, "default": default_, "info": info, "hidden": hidden, "index": index, }: {
|
|
name: string;
|
|
type?: enum_type;
|
|
mode?: enum_mode;
|
|
default?: any;
|
|
info?: string;
|
|
hidden?: boolean;
|
|
index: int;
|
|
}): class_argument;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
static volatile({ "name": name, "type": type, "mode": mode, "default": default_, "info": info, "hidden": hidden, "indicators_short": indicators_short, "indicators_long": indicators_long, }: {
|
|
name: string;
|
|
type?: enum_type;
|
|
mode?: enum_mode;
|
|
default?: any;
|
|
info?: string;
|
|
hidden?: boolean;
|
|
indicators_short: Array<string>;
|
|
indicators_long: Array<string>;
|
|
}): class_argument;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
check(): boolean;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
name_get(): string;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
kind_get(): enum_kind;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
type_get(): enum_type;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
mode_get(): enum_mode;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
default_get(): any;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
parameters_get(): Object;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
hidden_get(): boolean;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
toString(): string;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
indicator_main(): string;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
pattern_value(): string;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
extract(raw: string): any;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
assign(data: Object, target: string, raw: string): void;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
make(data: Object, target: string): string;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
generate_help(): string;
|
|
}
|
|
}
|
|
declare module lib_args {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
var verbosity: int;
|
|
/**
|
|
* @author fenris
|
|
* @todo check validity
|
|
*/
|
|
class class_handler {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
protected arguments_: {
|
|
[name: string]: class_argument;
|
|
};
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
constructor(arguments_: {
|
|
[name: string]: class_argument;
|
|
});
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
filter(kind: enum_kind): {
|
|
[name: string]: class_argument;
|
|
};
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
read(environment: enum_environment, input: string, data?: {
|
|
[name: string]: any;
|
|
}): {
|
|
[name: string]: any;
|
|
};
|
|
/**
|
|
* @author fenris
|
|
* @todo handle if the data object doesn't have the required field or the type is wrong or sth.
|
|
*/
|
|
write(environment: enum_environment, data: {
|
|
[name: string]: any;
|
|
}): string;
|
|
/**
|
|
* @desc manpage-like info-sheet
|
|
* @author fenris
|
|
*/
|
|
generate_help({ "programname": programname, "author": author, "description": description, "executable": executable, }: {
|
|
programname?: string;
|
|
author?: string;
|
|
description?: string;
|
|
executable?: string;
|
|
}): string;
|
|
}
|
|
}
|
|
declare module lib_client {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
type type_subject = {
|
|
host: string;
|
|
port: int;
|
|
verbosity: int;
|
|
};
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function make(host: string, port: int, verbosity?: int): type_subject;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function query(subject: type_subject, input: string): Promise<string>;
|
|
}
|
|
declare module lib_client {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
class class_client {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
protected subject: type_subject;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
constructor(host: string, port: int, verbosity: int);
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
query(input: string): Promise<string>;
|
|
}
|
|
}
|
|
declare module lib_file {
|
|
/**
|
|
* @author fenris,maspr
|
|
* @todo clear up if http(s)-handling belongs here or not ...
|
|
*/
|
|
function read_promise(path: string): lib_call.type_promise<string, Error>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function write_promise(path: string, content: string): lib_call.type_promise<void, Error>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function read_stdin(): Promise<string>;
|
|
}
|
|
declare module lib_file {
|
|
/**
|
|
* @author fenris
|
|
* @deprecated lib_file shouldn't care for code stuff; use a combination of lib_file and lib_code instead
|
|
*/
|
|
function read_json_promise(path: string): lib_call.type_promise<any, Error>;
|
|
/**
|
|
* @author fenris
|
|
* @deprecated lib_file shouldn't care for code stuff; use a combination of lib_file and lib_code instead
|
|
*/
|
|
function write_json_promise(path: string, data: any): lib_call.type_promise<void, Error>;
|
|
/**
|
|
* @author fenris
|
|
* @deprecated use promises instead of executors
|
|
*/
|
|
function read_executor(path: string): lib_call.type_executor<string, Error>;
|
|
/**
|
|
* @author fenris
|
|
* @deprecated use promises instead of executors
|
|
*/
|
|
function write_executor(path: string, content: string): lib_call.type_executor<void, Error>;
|
|
/**
|
|
* @author fenris
|
|
* @deprecated lib_file shouldn't care for code stuff; use a combination of lib_file and lib_code instead
|
|
* @deprecated use promises instead of executors
|
|
*/
|
|
function read_json_executor(path: string): lib_call.type_executor<any, Error>;
|
|
/**
|
|
* @author fenris
|
|
* @deprecated lib_file shouldn't care for code stuff; use a combination of lib_file and lib_code instead
|
|
* @deprecated use promises instead of executors
|
|
*/
|
|
function write_json_executor(path: string, data: any): lib_call.type_executor<void, Error>;
|
|
/**
|
|
* @desc reads a file
|
|
* @author fenris
|
|
* @todo replace with promise version
|
|
*/
|
|
function read(path: string): lib_call.type_executor<string, Error>;
|
|
/**
|
|
* @desc writes a file
|
|
* @author fenris
|
|
* @todo replace with promise version
|
|
*/
|
|
function write(path: string, content: string): lib_call.type_executor<void, Error>;
|
|
/**
|
|
* @desc reads a json file
|
|
* @author fenris
|
|
* @deprecated lib_file shouldn't care for code stuff; use a combination of lib_file and lib_code instead
|
|
*/
|
|
function read_json(path: string): lib_call.type_executor<any, Error>;
|
|
/**
|
|
* @desc writes a json file
|
|
* @author fenris
|
|
* @deprecated lib_file shouldn't care for code stuff; use a combination of lib_file and lib_code instead
|
|
*/
|
|
function write_json(path: string, data: any): lib_call.type_executor<void, Error>;
|
|
}
|
|
declare module lib_observer {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
type type_eventname = string;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
type type_data = any;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
type type_action = (data: type_data) => void;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
type type_observer = {
|
|
actions: {
|
|
[eventname: string]: Array<type_action>;
|
|
};
|
|
force_registration: boolean;
|
|
no_attendants_warn_do: boolean;
|
|
no_attendants_warn_action: (eventname: type_eventname) => void;
|
|
};
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function make({ "force_registration": force_registration, "no_attendants_warn_do": no_attendants_warn_do, "no_attendants_warn_action": no_attendants_warn_action, }?: {
|
|
force_registration?: boolean;
|
|
no_attendants_warn_do?: boolean;
|
|
no_attendants_warn_action?: (eventname: type_eventname) => void;
|
|
}): type_observer;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function register(observer: type_observer, eventname: type_eventname): void;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function attend(observer: type_observer, eventname: type_eventname, action: type_action): void;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function notify(observer: type_observer, eventname: type_eventname, data: type_data): void;
|
|
}
|
|
declare namespace lib_plankton.lang {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
type char = string;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
type type_terminal_default = {
|
|
id: string;
|
|
data?: Object;
|
|
};
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function find<type_x, type_y>(word: Array<type_x>, part: Array<type_y>, equality: (x: type_x, y: type_y) => boolean, /*= instance_collate*/ right_to_left?: boolean): int;
|
|
}
|
|
declare namespace lib_plankton.lang {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
interface interface_symbol<type_terminal, type_variable, type_meaning> {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
equals(symbol: interface_symbol<type_terminal, type_variable, type_meaning>): boolean;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
toString(): string;
|
|
}
|
|
}
|
|
declare namespace lib_plankton.lang {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
class class_symbol_terminal<type_terminal, type_variable, type_meaning> implements interface_symbol<type_terminal, type_variable, type_meaning> {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
protected terminal: type_terminal;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
protected equality_terminal: (x: type_terminal, y: type_terminal) => boolean;
|
|
/**
|
|
* @desc [constructor]
|
|
* @author fenris
|
|
*/
|
|
constructor(terminal: type_terminal, equality_terminal?: (x: type_terminal, y: type_terminal) => boolean);
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
terminal_get(): type_terminal;
|
|
/**
|
|
* @override
|
|
* @author fenris
|
|
*/
|
|
equals(symbol: interface_symbol<type_terminal, type_variable, type_meaning>): boolean;
|
|
/**
|
|
* @override
|
|
* @author fenris
|
|
*/
|
|
toString(): string;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
static tree_generic<type_terminal, type_variable>(terminal: type_terminal): class_symbol_terminal<type_terminal, type_variable, type_tree<type_terminal>>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
static tree_default(terminal: type_terminal_default): class_symbol_terminal<type_terminal_default, string, type_tree<type_terminal_default>>;
|
|
}
|
|
}
|
|
declare namespace lib_plankton.lang {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
class class_symbol_variable<type_terminal, type_variable, type_meaning> implements interface_symbol<type_terminal, type_variable, type_meaning> {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
protected variable: type_variable;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
protected meaning: type_meaning;
|
|
/**
|
|
* @desc [constructor]
|
|
* @author fenris
|
|
*/
|
|
constructor(variable: type_variable, meaning?: type_meaning);
|
|
/**
|
|
* @desc [accessor] [getter]
|
|
* @author fenris
|
|
*/
|
|
variable_get(): type_variable;
|
|
/**
|
|
* @desc [accessor] [getter]
|
|
* @author fenris
|
|
*/
|
|
meaning_get(): type_meaning;
|
|
/**
|
|
* @override
|
|
* @author fenris
|
|
*/
|
|
equals(symbol: interface_symbol<type_terminal, type_variable, type_meaning>): boolean;
|
|
/**
|
|
* @override
|
|
* @author fenris
|
|
*/
|
|
toString(): string;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
static tree_generic<type_terminal, type_variable>(variable: type_variable): class_symbol_variable<type_terminal, type_variable, type_tree<type_terminal>>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
static tree_default(variable: string): class_symbol_variable<type_terminal_default, string, type_tree<type_terminal_default>>;
|
|
}
|
|
}
|
|
declare namespace lib_plankton.lang {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
interface interface_lexer<type_character, type_terminal> {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
run(input: Array<type_character>): Array<type_terminal>;
|
|
}
|
|
}
|
|
declare namespace lib_plankton.lang {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
type type_token<type_character, type_terminal> = {
|
|
sequence: Array<type_character>;
|
|
terminal: class_maybe<type_terminal>;
|
|
};
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
type type_lexerrule<type_character, type_terminal> = {
|
|
search: (part: Array<type_character>) => {
|
|
found: boolean;
|
|
data?: {
|
|
position?: int;
|
|
length?: int;
|
|
};
|
|
};
|
|
construct: (part: Array<type_character>) => Array<type_terminal>;
|
|
observer: lib_observer.type_observer;
|
|
};
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function lexerrule_make<type_character, type_terminal>(search: (part: Array<type_character>) => {
|
|
found: boolean;
|
|
data?: {
|
|
position?: int;
|
|
length?: int;
|
|
};
|
|
}, construct: (part: Array<type_character>) => Array<type_terminal>): type_lexerrule<type_character, type_terminal>;
|
|
/**
|
|
* @author fenris
|
|
* @todo schön machen? is aber vermutlich gar nicht möglich :/
|
|
*/
|
|
function lexerrule_show<type_character, type_terminal>(rule: type_lexerrule<type_character, type_terminal>): string;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function lexerrule_apply<type_character, type_terminal>(rule: type_lexerrule<type_character, type_terminal>, tokens: Array<type_token<type_character, type_terminal>>): Array<type_token<type_character, type_terminal>>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function lexerrule_pass<type_character>(): type_lexerrule<type_character, type_character>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function lexerrule_pattern_generic(rule_raw: {
|
|
pattern: string;
|
|
construct: (part: Array<char>) => Array<type_terminal_default>;
|
|
}): type_lexerrule<char, type_terminal_default>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function lexerrule_pattern_ignore(pattern: string): type_lexerrule<char, type_terminal_default>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function lexerrule_pattern_void(pattern: string, id: string): type_lexerrule<char, type_terminal_default>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function lexerrule_pattern_boolean(pattern: string, id: string, value: boolean): type_lexerrule<char, type_terminal_default>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function lexerrule_pattern_int(pattern: string, id: string): type_lexerrule<char, type_terminal_default>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function lexerrule_pattern_float(pattern: string, id: string): type_lexerrule<char, type_terminal_default>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function lexerrule_pattern_string(pattern: string, id: string): type_lexerrule<char, type_terminal_default>;
|
|
}
|
|
declare namespace lib_plankton.lang {
|
|
/**
|
|
* @author fenris
|
|
* @todo warn on prefix-detection
|
|
* @todo after rule application don't start from the beginning but from the last position
|
|
*/
|
|
type type_lexer_dumb<type_character, type_terminal> = {
|
|
rules: Array<type_lexerrule<type_character, type_terminal>>;
|
|
observer: lib_observer.type_observer;
|
|
};
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function lexer_dumb_make<type_character, type_terminal>(rules: Array<type_lexerrule<type_character, type_terminal>>): type_lexer_dumb<type_character, type_terminal>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function lexer_dumb_run<type_character, type_terminal>(subject: type_lexer_dumb<type_character, type_terminal>, input: Array<type_character>, configuration?: {
|
|
use_reduce?: boolean;
|
|
}): Array<type_terminal>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function lexer_dumb_pass<type_character>(): type_lexer_dumb<type_character, type_character>;
|
|
}
|
|
declare namespace lib_plankton.lang {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
class class_lexerrule<type_character, type_terminal> {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
protected subject: type_lexerrule<type_character, type_terminal>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
constructor(subject: type_lexerrule<type_character, type_terminal>);
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
static construct<type_character, type_terminal>({ "search": search, "construct": construct, }: {
|
|
search: (part: Array<type_character>) => {
|
|
found: boolean;
|
|
data?: {
|
|
position?: int;
|
|
length?: int;
|
|
};
|
|
};
|
|
construct: (part: Array<type_character>) => Array<type_terminal>;
|
|
}): class_lexerrule<type_character, type_terminal>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
subject_get(): type_lexerrule<type_character, type_terminal>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
search(part: Array<type_character>): {
|
|
found: boolean;
|
|
data?: {
|
|
position?: int;
|
|
length?: int;
|
|
};
|
|
};
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
construct(part: Array<type_character>): Array<type_terminal>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
static pass<type_character>(): class_lexerrule<type_character, type_character>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
static pattern_generic(rule_raw: {
|
|
pattern: string;
|
|
construct: (part: Array<char>) => Array<type_terminal_default>;
|
|
}): class_lexerrule<char, type_terminal_default>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
static pattern_ignore(pattern: string): class_lexerrule<char, type_terminal_default>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
static pattern_void(pattern: string, id: string): class_lexerrule<char, type_terminal_default>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
static pattern_boolean(pattern: string, id: string, value: boolean): class_lexerrule<char, type_terminal_default>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
static pattern_int(pattern: string, id: string): class_lexerrule<char, type_terminal_default>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
static pattern_float(pattern: string, id: string): class_lexerrule<char, type_terminal_default>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
static pattern_string(pattern: string, id: string): class_lexerrule<char, type_terminal_default>;
|
|
}
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
class class_lexer_dumb<type_character, type_terminal> implements interface_lexer<type_character, type_terminal> {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
protected subject: type_lexer_dumb<type_character, type_terminal>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
constructor(subject: type_lexer_dumb<type_character, type_terminal>);
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
static construct<type_character, type_terminal>(rules: Array<class_lexerrule<type_character, type_terminal>>): class_lexer_dumb<type_character, type_terminal>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
run(input: Array<type_character>): Array<type_terminal>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
static pass<type_character>(): class_lexer_dumb<type_character, type_character>;
|
|
}
|
|
}
|
|
declare namespace lib_plankton.lang {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
interface interface_parser<type_terminal, type_variable, type_meaning> {
|
|
/**
|
|
* @param input the input sequence to parse
|
|
* @param target_variable if not passed, this value should fall back to the start symbol of the grammar
|
|
* @author fenris
|
|
*/
|
|
run(input: Array<type_terminal>, target_variable?: type_variable): type_meaning;
|
|
}
|
|
}
|
|
declare namespace lib_plankton.lang {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
type type_tree<type_terminal> = {
|
|
label?: string;
|
|
value: Array<type_terminal>;
|
|
children: Array<type_tree<type_terminal>>;
|
|
};
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
type type_parserrule<type_terminal, type_variable, type_meaning> = {
|
|
premise: type_variable;
|
|
conclusion: Array<interface_symbol<type_terminal, type_variable, type_meaning>>;
|
|
construct: (args: Array<type_meaning>, terminals: Array<type_terminal>) => type_meaning;
|
|
right_to_left: boolean;
|
|
};
|
|
/**
|
|
* @desc [constructor]
|
|
* @author fenris
|
|
*/
|
|
function parserrule_make<type_terminal, type_variable, type_meaning>({ "premise": premise, "conclusion": conclusion, "construct": construct, "right_to_left": right_to_left, }: {
|
|
premise: type_variable;
|
|
conclusion: Array<interface_symbol<type_terminal, type_variable, type_meaning>>;
|
|
construct: (args: Array<type_meaning>, terminals: Array<type_terminal>) => type_meaning;
|
|
right_to_left?: boolean;
|
|
}): {
|
|
premise: type_variable;
|
|
conclusion: interface_symbol<type_terminal, type_variable, type_meaning>[];
|
|
construct: (args: type_meaning[], terminals: type_terminal[]) => type_meaning;
|
|
right_to_left: boolean;
|
|
};
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function parserrule_check<type_terminal, type_variable, type_meaning>(parserrule: type_parserrule<type_terminal, type_variable, type_meaning>, sequence: Array<interface_symbol<type_terminal, type_variable, type_meaning>>): int;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function parserrule_construct<type_terminal, type_variable, type_meaning>(parserrule: type_parserrule<type_terminal, type_variable, type_meaning>, args: Array<type_meaning>, terminals: Array<type_terminal>): type_meaning;
|
|
}
|
|
declare namespace lib_plankton.lang {
|
|
/**
|
|
* @author fenris
|
|
* @todo fatal error on empty conclusion
|
|
*/
|
|
type type_parser_dumb<type_terminal, type_variable, type_meaning> = {
|
|
start: type_variable;
|
|
rules: Array<type_parserrule<type_terminal, type_variable, type_meaning>>;
|
|
equality_terminal: (x: type_terminal, y: type_terminal) => boolean;
|
|
observer: lib_observer.type_observer;
|
|
};
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function parser_dumb_make<type_terminal, type_variable, type_meaning>(start: type_variable, rules: Array<type_parserrule<type_terminal, type_variable, type_meaning>>, equality_terminal?: (x: type_terminal, y: type_terminal) => boolean): type_parser_dumb<type_terminal, type_variable, type_meaning>;
|
|
/**
|
|
* @override
|
|
* @author fenris
|
|
*/
|
|
function parser_dumb_run<type_terminal, type_variable, type_meaning>(parser_dumb: type_parser_dumb<type_terminal, type_variable, type_meaning>, input: Array<type_terminal>, target_variable?: type_variable): type_meaning;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function parser_dumb_tree<type_terminal, type_variable>(start: type_variable, rules_raw: Array<{
|
|
premise: type_variable;
|
|
conclusion: Array<interface_symbol<type_terminal, type_variable, type_tree<type_terminal>>>;
|
|
label?: string;
|
|
right_to_left?: boolean;
|
|
}>, equality_terminal?: (x: type_terminal, y: type_terminal) => boolean): type_parser_dumb<type_terminal, type_variable, type_tree<type_terminal>>;
|
|
}
|
|
declare namespace lib_plankton.lang {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
class class_parserrule<type_terminal, type_variable, type_meaning> {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
protected subject: type_parserrule<type_terminal, type_variable, type_meaning>;
|
|
/**
|
|
* @desc [constructor]
|
|
* @author fenris
|
|
*/
|
|
private constructor();
|
|
/**
|
|
* @desc [constructor]
|
|
* @author fenris
|
|
*/
|
|
static construct<type_terminal, type_variable, type_meaning>({ "premise": premise, "conclusion": conclusion, "construct": construct, "right_to_left": right_to_left, }: {
|
|
premise: type_variable;
|
|
conclusion: Array<interface_symbol<type_terminal, type_variable, type_meaning>>;
|
|
construct: (args: Array<type_meaning>, terminals: Array<type_terminal>) => type_meaning;
|
|
right_to_left?: boolean;
|
|
}): class_parserrule<type_terminal, type_variable, type_meaning>;
|
|
/**
|
|
* @desc [accessor] [getter]
|
|
* @author fenris
|
|
*/
|
|
subject_get(): type_parserrule<type_terminal, type_variable, type_meaning>;
|
|
/**
|
|
* @desc [accessor] [getter]
|
|
* @author fenris
|
|
*/
|
|
premise_get(): type_variable;
|
|
/**
|
|
* @desc [accessor] [getter]
|
|
* @author fenris
|
|
*/
|
|
conclusion_get(): Array<interface_symbol<type_terminal, type_variable, type_meaning>>;
|
|
/**
|
|
* @desc [accessor]
|
|
* @author fenris
|
|
*/
|
|
check(sequence: Array<interface_symbol<type_terminal, type_variable, type_meaning>>): int;
|
|
/**
|
|
* @desc [accessor]
|
|
* @author fenris
|
|
*/
|
|
construct(args: Array<type_meaning>, terminals: Array<type_terminal>): type_meaning;
|
|
}
|
|
/**
|
|
* @author fenris
|
|
* @todo fatal error on empty conclusion
|
|
*/
|
|
class class_parser_dumb<type_terminal, type_variable, type_meaning> implements interface_parser<type_terminal, type_variable, type_meaning> {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
protected subject: type_parser_dumb<type_terminal, type_variable, type_meaning>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
private constructor();
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
static construct<type_terminal, type_variable, type_meaning>(start: type_variable, rules: Array<class_parserrule<type_terminal, type_variable, type_meaning>>, equality_terminal?: (x: type_terminal, y: type_terminal) => boolean): class_parser_dumb<type_terminal, type_variable, type_meaning>;
|
|
/**
|
|
* @override
|
|
* @author fenris
|
|
*/
|
|
run(input: Array<type_terminal>, target_variable?: type_variable): type_meaning;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
static tree<type_terminal, type_variable>(start: type_variable, rules_raw: Array<{
|
|
premise: type_variable;
|
|
conclusion: Array<interface_symbol<type_terminal, type_variable, type_tree<type_terminal>>>;
|
|
label?: string;
|
|
right_to_left?: boolean;
|
|
}>, equality_terminal?: (x: type_terminal, y: type_terminal) => boolean): class_parser_dumb<type_terminal, type_variable, type_tree<type_terminal>>;
|
|
}
|
|
}
|
|
declare namespace lib_plankton.lang {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function reader_run<type_character, type_terminal, type_variable, type_meaning>(lexer_run: (input: Array<type_character>) => Array<type_terminal>, parser_run: (input: Array<type_terminal>, target_variable?: type_variable) => type_meaning, input: Array<type_character>, target_variable?: type_variable): type_meaning;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
type type_parser_rule_default = {
|
|
premise: string;
|
|
conclusion: Array<interface_symbol<type_terminal_default, string, type_tree<type_terminal_default>>>;
|
|
label?: string;
|
|
right_to_left?: boolean;
|
|
};
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function reader_default({ "lexer_rules": lexer_rules, "parser_start": parser_start, "parser_rules": parser_rules, }: {
|
|
lexer_rules: Array<class_lexerrule<char, type_terminal_default>>;
|
|
parser_start: string;
|
|
parser_rules: Array<type_parser_rule_default>;
|
|
}): class_reader<char, type_terminal_default, string, type_tree<type_terminal_default>>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
type type_raw_parser_rule = {
|
|
premise: string;
|
|
conclusion: Array<{
|
|
type: string;
|
|
parameters?: Object;
|
|
}>;
|
|
label?: string;
|
|
right_to_left?: boolean;
|
|
};
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
function default_raw({ "lexer_rules": lexer_rules, "parser_start": parser_start, "parser_rules": parser_rules, }: {
|
|
lexer_rules: Array<{
|
|
type: string;
|
|
parameters?: Object;
|
|
}>;
|
|
parser_start: string;
|
|
parser_rules: Array<type_raw_parser_rule>;
|
|
}): class_reader<char, type_terminal_default, string, type_tree<type_terminal_default>>;
|
|
}
|
|
declare namespace lib_plankton.lang {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
class class_reader<type_character, type_terminal, type_variable, type_result> {
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
protected lexer: interface_lexer<type_character, type_terminal>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
protected parser: interface_parser<type_terminal, type_variable, type_result>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
constructor(lexer: interface_lexer<type_character, type_terminal>, parser: interface_parser<type_terminal, type_variable, type_result>);
|
|
/**
|
|
* @desc [accessor] yes, it's really just lexing and parsing
|
|
* @author fenris
|
|
*/
|
|
run(input: Array<type_character>, target_variable?: type_variable): type_result;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
static default({ "lexer_rules": lexer_rules, "parser_start": parser_start, "parser_rules": parser_rules, }: {
|
|
lexer_rules: Array<class_lexerrule<char, type_terminal_default>>;
|
|
parser_start: string;
|
|
parser_rules: Array<{
|
|
premise: string;
|
|
conclusion: Array<interface_symbol<type_terminal_default, string, type_tree<type_terminal_default>>>;
|
|
label?: string;
|
|
right_to_left?: boolean;
|
|
}>;
|
|
}): class_reader<char, type_terminal_default, string, type_tree<type_terminal_default>>;
|
|
/**
|
|
* @author fenris
|
|
*/
|
|
static default_raw({ "lexer_rules": lexer_rules, "parser_start": parser_start, "parser_rules": parser_rules, }: {
|
|
lexer_rules: Array<{
|
|
type: string;
|
|
parameters?: Object;
|
|
}>;
|
|
parser_start: string;
|
|
parser_rules: Array<{
|
|
premise: string;
|
|
conclusion: Array<{
|
|
type: string;
|
|
parameters?: Object;
|
|
}>;
|
|
label?: string;
|
|
right_to_left?: boolean;
|
|
}>;
|
|
}): class_reader<char, type_terminal_default, string, type_tree<type_terminal_default>>;
|
|
}
|
|
}
|