2021-09-19 01:14:32 +02:00
var _ _extends = ( this && this . _ _extends ) || ( function ( ) {
var extendStatics = function ( d , b ) {
extendStatics = Object . setPrototypeOf ||
( { _ _proto _ _ : [ ] } instanceof Array && function ( d , b ) { d . _ _proto _ _ = b ; } ) ||
function ( d , b ) { for ( var p in b ) if ( b . hasOwnProperty ( p ) ) d [ p ] = b [ p ] ; } ;
return extendStatics ( d , b ) ;
} ;
return function ( d , b ) {
extendStatics ( d , b ) ;
function _ _ ( ) { this . constructor = d ; }
d . prototype = b === null ? Object . create ( b ) : ( _ _ . prototype = b . prototype , new _ _ ( ) ) ;
} ;
} ) ( ) ;
/ *
This file is part of » bacterio - plankton : base « .
Copyright 2016 - 2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : base « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : base « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : base « . If not , see < http : //www.gnu.org/licenses/>.
* /
// }
/ *
This file is part of » bacterio - plankton : base « .
Copyright 2016 - 2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : base « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : base « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : base « . If not , see < http : //www.gnu.org/licenses/>.
* /
/ * *
* @ author fenris
* /
/*export*/ function pseudopointer _null ( ) {
return {
"value" : null
} ;
}
/ * *
* @ author fenris
* /
/*export*/ function pseudopointer _make ( value ) {
return {
"value" : value
} ;
}
/ * *
* @ author fenris
* /
/*export*/ function pseudopointer _isset ( pseudopointer ) {
return ( pseudopointer . value != null ) ;
}
/ * *
* @ author fenris
* /
/*export*/ function pseudopointer _read ( pseudopointer ) {
if ( pseudopointer . value != null ) {
return pseudopointer . value ;
}
else {
var message = "nullpointer dereferencation" ;
throw ( new Error ( message ) ) ;
}
}
/ * *
* @ author fenris
* /
/*export*/ function pseudopointer _write ( pseudopointer , value ) {
pseudopointer . value = value ;
}
/ *
This file is part of » bacterio - plankton : base « .
Copyright 2016 - 2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : base « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : base « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : base « . If not , see < http : //www.gnu.org/licenses/>.
* /
;
var lib _base ;
( function ( lib _base ) {
/ * *
* @ author fenris
* /
function environment ( ) {
var entries = [
{
"id" : "web" ,
"name" : "Web" ,
"predicate" : function ( ) { return ( typeof ( document ) !== "undefined" ) ; } ,
} ,
{
"id" : "node" ,
"name" : "Node.js" ,
"predicate" : function ( ) { return ( typeof ( process ) !== "undefined" ) ; } ,
} ,
{
"id" : "rhino" ,
"name" : "Rhino" ,
"predicate" : function ( ) { return ( typeof ( java ) !== "undefined" ) ; } ,
} ,
{
"id" : "webworker" ,
"name" : "WebWorker" ,
"predicate" : function ( ) { return ( typeof ( self [ "WorkerNavigator" ] ) !== "undefined" ) ; }
}
] ;
var id ;
var found = entries . some ( function ( entry ) {
if ( entry . predicate ( ) ) {
id = entry . id ;
return true ;
}
else {
return false ;
}
} ) ;
if ( found ) {
return id ;
}
else {
throw ( new Error ( "unknown environment" ) ) ;
}
}
lib _base . environment = environment ;
} ) ( lib _base || ( lib _base = { } ) ) ;
/ *
This file is part of » bacterio - plankton : base « .
Copyright 2016 - 2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : base « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : base « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : base « . If not , see < http : //www.gnu.org/licenses/>.
* /
/ * *
* @ author fenris
* /
var instance _verbosity = 0 ;
/ * *
* @ author fenris
* /
function instance _collate ( value1 , value2 ) {
if ( typeof ( value1 ) === "object" ) {
if ( value1 == null ) {
return ( value2 == null ) ;
}
else {
if ( "_collate" in value1 ) {
return value1 [ "_collate" ] ( value2 ) ;
}
else {
throw ( new Error ( "[collate]" + " " + "object has no such method" ) ) ;
}
}
}
else {
if ( instance _verbosity >= 1 ) {
lib _log . warn ( "[collate]" + " " + "primitive value; using default implementation" ) ;
}
return ( value1 === value2 ) ;
}
}
/ * *
* @ author fenris
* /
function instance _compare ( value1 , value2 ) {
if ( typeof ( value1 ) === "object" ) {
if ( "_compare" in value1 ) {
return value1 [ "_compare" ] ( value2 ) ;
}
else {
throw ( new Error ( "[compare]" + " " + "object has no such method" ) ) ;
}
}
else {
if ( instance _verbosity >= 1 ) {
lib _log . warn ( "[compare]" + " " + "primitive value; using default implementation" ) ;
}
return ( value1 <= value2 ) ;
}
}
/ * *
* @ author fenris
* /
function instance _clone ( value ) {
if ( typeof ( value ) === "object" ) {
if ( "_clone" in value ) {
return value [ "_clone" ] ( ) ;
}
else {
throw ( new Error ( "[clone]" + " " + "object has no such method" ) ) ;
}
}
else {
if ( instance _verbosity >= 1 ) {
lib _log . warn ( "[clone]" + " " + "primitive value; using default implementation" ) ;
}
return value ;
}
}
/ * *
* @ desc the ability to generate a string out of the element , which identifies it to a high degree
* @ author fenris
* /
function instance _hash ( value ) {
if ( typeof ( value ) === "object" ) {
if ( "_hash" in value ) {
return value [ "_hash" ] ( ) ;
}
else {
throw ( new Error ( "[hash]" + " " + "object has no such method" ) ) ;
}
}
else {
if ( instance _verbosity >= 1 ) {
lib _log . warn ( "[hash]" + " " + "primitive value; using default implementation" ) ;
}
return String ( value ) ;
}
}
/ * *
* @ desc the ability to map the element to a textual representation ( most likely not injective )
* @ author fenris
* /
function instance _show ( value ) {
if ( typeof ( value ) === "object" ) {
if ( value == null ) {
return "NULL" ;
}
else {
if ( "_show" in value ) {
return value [ "_show" ] ( ) ;
}
else {
// throw (new Error("[show]" + " " + "object has no such method"));
return JSON . stringify ( value ) ;
}
}
}
else {
if ( instance _verbosity >= 1 ) {
lib _log . warn ( "[show]" + " " + "primitive value; using default implementation" ) ;
}
return String ( value ) ;
}
}
/ *
This file is part of » bacterio - plankton : base « .
Copyright 2016 - 2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : base « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : base « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : base « . If not , see < http : //www.gnu.org/licenses/>.
* /
/ * *
* @ todo outsource to dedicated plankton - lib
* /
var lib _log ;
( function ( lib _log ) {
/ * *
* @ author fenris
* /
function log ( ) {
var args = [ ] ;
for ( var _i = 0 ; _i < arguments . length ; _i ++ ) {
args [ _i ] = arguments [ _i ] ;
}
/*window.*/ console . log . apply ( console , args ) ;
}
lib _log . log = log ;
/ * *
* @ author fenris
* /
function info ( ) {
var args = [ ] ;
for ( var _i = 0 ; _i < arguments . length ; _i ++ ) {
args [ _i ] = arguments [ _i ] ;
}
/*window.*/ console . info . apply ( console , args ) ;
}
lib _log . info = info ;
/ * *
* @ author fenris
* /
function warn ( ) {
var args = [ ] ;
for ( var _i = 0 ; _i < arguments . length ; _i ++ ) {
args [ _i ] = arguments [ _i ] ;
}
/*window.*/ console . warn . apply ( console , args ) ;
}
lib _log . warn = warn ;
/ * *
* @ author fenris
* /
function error ( ) {
var args = [ ] ;
for ( var _i = 0 ; _i < arguments . length ; _i ++ ) {
args [ _i ] = arguments [ _i ] ;
}
/*window.*/ console . error . apply ( console , args ) ;
}
lib _log . error = error ;
} ) ( lib _log || ( lib _log = { } ) ) ;
/ *
This file is part of » bacterio - plankton : base « .
Copyright 2016 - 2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : base « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : base « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : base « . If not , see < http : //www.gnu.org/licenses/>.
* /
/ * *
* @ author frac
* /
var class _observer = /** @class */ ( function ( ) {
/ * *
* @ author frac
* /
function class _observer ( ) {
this . counter = 0 ;
this . actions = { } ;
this . buffer = [ ] ;
}
/ * *
* @ author frac
* /
class _observer . prototype . empty = function ( ) {
return ( Object . keys ( this . actions ) . length == 0 ) ;
} ;
/ * *
* @ author frac
* /
class _observer . prototype . flush = function ( ) {
this . actions = { } ;
} ;
/ * *
* @ author frac
* /
class _observer . prototype . set = function ( id , action ) {
this . actions [ id ] = action ;
} ;
/ * *
* @ author frac
* /
class _observer . prototype . del = function ( id ) {
delete this . actions [ id ] ;
} ;
/ * *
* @ author frac
* /
class _observer . prototype . add = function ( action ) {
this . set ( ( this . counter ++ ) . toString ( ) , action ) ;
} ;
/ * *
* @ author frac
* /
class _observer . prototype . notify = function ( information , delayed ) {
var _this = this ;
if ( information === void 0 ) { information = { } ; }
if ( delayed === void 0 ) { delayed = false ; }
if ( delayed ) {
this . buffer . push ( information ) ;
}
else {
Object . keys ( this . actions ) . forEach ( function ( id ) { return _this . actions [ id ] ( information ) ; } ) ;
}
} ;
/ * *
* @ author frac
* /
class _observer . prototype . rollout = function ( ) {
var _this = this ;
this . buffer . forEach ( function ( information ) { return _this . notify ( information , false ) ; } ) ;
this . buffer = [ ] ;
} ;
return class _observer ;
} ( ) ) ;
/ * *
* @ author frac
* /
/ *
export interface interface _readable < type _value > {
| * *
* @ author frac
* |
read ( ) : type _executor < type _value , Error > ;
}
* /
/ * *
* @ author frac
* /
/ *
export interface interface _writeable < type _value > {
| * *
* @ author frac
* |
write ( value : type _value ) : type _executor < void , Error > ;
}
* /
/ *
This file is part of » bacterio - plankton : base « .
Copyright 2016 - 2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : base « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : base « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : base « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _maybe ;
( function ( lib _maybe ) {
/ * *
* @ author fenris
* /
function make _nothing ( ) {
return {
"kind" : "nothing" ,
"parameters" : { }
} ;
}
lib _maybe . make _nothing = make _nothing ;
/ * *
* @ author fenris
* /
function make _just ( value ) {
return {
"kind" : "just" ,
"parameters" : {
"value" : value
}
} ;
}
lib _maybe . make _just = make _just ;
/ * *
* @ author fenris
* /
function is _nothing ( maybe ) {
return ( maybe . kind === "nothing" ) ;
}
lib _maybe . is _nothing = is _nothing ;
/ * *
* @ author fenris
* /
function is _just ( maybe ) {
return ( maybe . kind === "just" ) ;
}
lib _maybe . is _just = is _just ;
/ * *
* @ author fenris
* /
function cull ( maybe ) {
if ( ! is _just ( maybe ) ) {
var message = "cull from nothing" ;
throw ( new Error ( message ) ) ;
}
else {
var value = maybe . parameters [ "value" ] ;
return value ;
}
}
lib _maybe . cull = cull ;
/ * *
* @ author fenris
* /
function propagate ( maybe , function _ ) {
if ( ! is _just ( maybe ) ) {
}
else {
var value = maybe . parameters [ "value" ] ;
var maybe _ = function _ ( value ) ;
return maybe _ ;
}
}
lib _maybe . propagate = propagate ;
} ) ( lib _maybe || ( lib _maybe = { } ) ) ;
/ * *
* @ author fenris
* /
/*export*/ var class _maybe = /** @class */ ( function ( ) {
function class _maybe ( ) {
}
/ * *
* @ desc whether the wrapper is nothing
* @ author fenris
* /
class _maybe . prototype . is _nothing = function ( ) {
throw ( new Error ( "not implemented: class_maybe.is_nothing" ) ) ;
} ;
/ * *
* @ desc whether the wrapper is just
* @ author fenris
* /
class _maybe . prototype . is _just = function ( ) {
throw ( new Error ( "not implemented: class_maybe.is_just" ) ) ;
} ;
/ * *
* @ desc return the value , stored in the maybe - wrapper
* @ author fenris
* /
class _maybe . prototype . cull = function ( ) {
throw ( new Error ( "not implemented: class_maybe.cull" ) ) ;
} ;
/ * *
* @ author fenris
* /
class _maybe . prototype . toString = function ( ) {
throw ( new Error ( "not implemented: class_maybe.cull" ) ) ;
} ;
/ * *
* @ author fenris
* /
class _maybe . prototype . distinguish = function ( action _just , action _nothing ) {
if ( action _nothing === void 0 ) { action _nothing = function ( ) { } ; }
throw ( new Error ( "not implemented: class_maybe.distinguish" ) ) ;
} ;
/ * *
* @ author fenris
* /
class _maybe . prototype . propagate = function ( action ) {
throw ( new Error ( "not implemented: class_maybe.propagate" ) ) ;
} ;
/ * *
* @ desc [ implementation ]
* @ author fenris
* /
class _maybe . prototype . _show = function ( ) {
return this . toString ( ) ;
} ;
return class _maybe ;
} ( ) ) ;
/ * *
* @ author fenris
* /
/*export*/ var class _nothing = /** @class */ ( function ( _super ) {
_ _extends ( class _nothing , _super ) ;
/ * *
* @ author fenris
* /
function class _nothing ( reason ) {
if ( reason === void 0 ) { reason = null ; }
var _this = _super . call ( this ) || this ;
_this . reason = reason ;
return _this ;
}
/ * *
* @ author fenris
* /
class _nothing . prototype . is _nothing = function ( ) {
return true ;
} ;
/ * *
* @ author fenris
* /
class _nothing . prototype . is _just = function ( ) {
return false ;
} ;
/ * *
* @ author fenris
* /
class _nothing . prototype . cull = function ( ) {
var message = "you shouldn't cull a nothing-value …" ;
lib _log . warn ( message ) ;
return null ;
} ;
/ * *
* @ author fenris
* /
class _nothing . prototype . toString = function ( ) {
return "<\u00B7>" ;
} ;
/ * *
* @ author fenris
* /
class _nothing . prototype . reason _get = function ( ) {
var content = ( ( this . reason == null ) ? "·" : this . reason ) ;
return "<- " + content + " ->" ;
} ;
/ * *
* @ author fenris
* /
class _nothing . prototype . distinguish = function ( action _just , action _nothing ) {
if ( action _nothing === void 0 ) { action _nothing = function ( ) { } ; }
action _nothing ( this . reason ) ;
} ;
/ * *
* @ author fenris
* /
class _nothing . prototype . propagate = function ( action ) {
return ( new class _nothing ( this . reason ) ) ;
} ;
return class _nothing ;
} ( class _maybe ) ) ;
/ * *
* @ author fenris
* /
/*export*/ var class _just = /** @class */ ( function ( _super ) {
_ _extends ( class _just , _super ) ;
/ * *
* @ author fenris
* /
function class _just ( value ) {
var _this = _super . call ( this ) || this ;
_this . value = value ;
return _this ;
}
/ * *
* @ author fenris
* /
class _just . prototype . is _nothing = function ( ) {
return false ;
} ;
/ * *
* @ author fenris
* /
class _just . prototype . is _just = function ( ) {
return true ;
} ;
/ * *
* @ author fenris
* /
class _just . prototype . cull = function ( ) {
return this . value ;
} ;
/ * *
* @ author fenris
* /
class _just . prototype . toString = function ( ) {
var content = instance _show ( this . value ) ;
return "<+ " + content + " +>" ;
} ;
/ * *
* @ author fenris
* /
class _just . prototype . distinguish = function ( action _just , action _nothing ) {
if ( action _nothing === void 0 ) { action _nothing = function ( ) { } ; }
action _just ( this . value ) ;
} ;
/ * *
* @ author fenris
* /
class _just . prototype . propagate = function ( action ) {
return action ( this . value ) ;
} ;
return class _just ;
} ( class _maybe ) ) ;
/ *
This file is part of » bacterio - plankton : base « .
Copyright 2016 - 2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : base « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : base « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : base « . If not , see < http : //www.gnu.org/licenses/>.
* /
/ * *
* @ author frac
* /
var class _error = /** @class */ ( function ( _super ) {
_ _extends ( class _error , _super ) ;
/ * *
* @ author frac
* /
function class _error ( message , suberrors ) {
if ( suberrors === void 0 ) { suberrors = [ ] ; }
var _this = _super . call ( this , message ) || this ;
_this . suberrors = suberrors ;
_this . mess = message ;
return _this ;
}
/ * *
* @ override
* @ author frac
* /
class _error . prototype . toString = function ( ) {
return ( /*super.toString()*/ this . mess + " " + ( "[" + this . suberrors . map ( function ( x ) { return x . toString ( ) ; } ) . join ( "," ) + "]" ) ) ;
} ;
return class _error ;
} ( Error ) ) ;
var _ _extends = ( this && this . _ _extends ) || ( function ( ) {
var extendStatics = function ( d , b ) {
extendStatics = Object . setPrototypeOf ||
( { _ _proto _ _ : [ ] } instanceof Array && function ( d , b ) { d . _ _proto _ _ = b ; } ) ||
function ( d , b ) { for ( var p in b ) if ( b . hasOwnProperty ( p ) ) d [ p ] = b [ p ] ; } ;
return extendStatics ( d , b ) ;
} ;
return function ( d , b ) {
extendStatics ( d , b ) ;
function _ _ ( ) { this . constructor = d ; }
d . prototype = b === null ? Object . create ( b ) : ( _ _ . prototype = b . prototype , new _ _ ( ) ) ;
} ;
} ) ( ) ;
/ *
This file is part of » bacterio - plankton : log « .
Copyright 2016 - 2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : log « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : lang « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : lang « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var log ;
( function ( log ) {
/ * *
* /
var enum _level ;
( function ( enum _level ) {
enum _level [ enum _level [ "debug" ] = 0 ] = "debug" ;
enum _level [ enum _level [ "info" ] = 1 ] = "info" ;
enum _level [ enum _level [ "notice" ] = 2 ] = "notice" ;
enum _level [ enum _level [ "warning" ] = 3 ] = "warning" ;
enum _level [ enum _level [ "error" ] = 4 ] = "error" ;
} ) ( enum _level = log . enum _level || ( log . enum _level = { } ) ) ;
;
/ * *
* /
function level _order ( level1 , level2 ) {
return ( level1 <= level2 ) ;
}
log . level _order = level _order ;
/ * *
* /
function level _show ( level ) {
switch ( level ) {
case enum _level . debug : return "debug" ;
case enum _level . info : return "info" ;
case enum _level . notice : return "notice" ;
case enum _level . warning : return "warning" ;
case enum _level . error : return "error" ;
default : return "(unknown)" ;
}
}
log . level _show = level _show ;
} ) ( log = lib _plankton . log || ( lib _plankton . log = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : log « .
Copyright 2016 - 2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : log « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : lang « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : lang « . If not , see < http : //www.gnu.org/licenses/>.
* /
/ * *
* @ deprecated
* @ todo remove
* /
var lib _log ;
( function ( lib _log ) {
/ * *
* @ author fenris
* /
/*export*/ var level _stack = [ 0 ] ;
function level _push ( level ) { level _stack . push ( level ) ; }
lib _log . level _push = level _push ;
function level _pop ( ) { if ( level _stack . length > 1 ) {
level _stack . pop ( ) ;
} }
lib _log . level _pop = level _pop ;
function level _get ( ) { return level _stack . slice ( - 1 ) [ 0 ] ; }
/ *
export function level _inc ( ) : void { level _push ( level _get ( ) + 1 ) ; }
export function level _dec ( ) : void { level _push ( level _get ( ) - 1 ) ; }
* /
/ * *
* @ author fenris
* /
var indent _stack = [ 0 ] ;
function indent _push ( indent ) { indent _stack . push ( indent ) ; }
lib _log . indent _push = indent _push ;
function indent _pop ( ) { if ( indent _stack . length > 1 ) {
indent _stack . pop ( ) ;
} }
lib _log . indent _pop = indent _pop ;
function indent _get ( ) { return level _stack . slice ( - 1 ) [ 0 ] ; }
function indent _inc ( ) { level _push ( level _get ( ) + 1 ) ; }
lib _log . indent _inc = indent _inc ;
function indent _dec ( ) { level _push ( level _get ( ) - 1 ) ; }
lib _log . indent _dec = indent _dec ;
/ * *
* @ author fenris
* /
function write ( _a ) {
var message = _a [ "message" ] , _b = _a [ "type" ] , type = _b === void 0 ? null : _b , _c = _a [ "prefix" ] , prefix = _c === void 0 ? null : _c , _d = _a [ "level" ] , level = _d === void 0 ? 0 : _d , _e = _a [ "indent" ] , indent = _e === void 0 ? 0 : _e ;
var entry = {
"level" : ( ( type === null )
? lib _plankton . log . enum _level . info
: {
"debug" : lib _plankton . log . enum _level . debug ,
"info" : lib _plankton . log . enum _level . info ,
"notice" : lib _plankton . log . enum _level . notice ,
"warning" : lib _plankton . log . enum _level . warning ,
"error" : lib _plankton . log . enum _level . error
} [ type ] ) ,
"incident" : message ,
"details" : {
"prefix" : prefix ,
"level" : level ,
"indent" : indent
}
} ;
lib _plankton . log . add ( entry ) ;
}
lib _log . write = write ;
} ) ( lib _log || ( lib _log = { } ) ) ;
/ *
This file is part of » bacterio - plankton : log « .
Copyright 2016 - 2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : log « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : lang « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : lang « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var log ;
( function ( log ) {
/ * *
* /
var class _channel = /** @class */ ( function ( ) {
function class _channel ( ) {
}
return class _channel ;
} ( ) ) ;
log . class _channel = class _channel ;
} ) ( log = lib _plankton . log || ( lib _plankton . log = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : log « .
Copyright 2016 - 2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : log « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : lang « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : lang « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var log ;
( function ( log ) {
/ * *
* /
var class _channel _console = /** @class */ ( function ( _super ) {
_ _extends ( class _channel _console , _super ) ;
function class _channel _console ( ) {
return _super !== null && _super . apply ( this , arguments ) || this ;
}
/ * *
* /
class _channel _console . prototype . add = function ( entry ) {
console . log ( ( "<" + ( new Date ( Date . now ( ) ) ) . toISOString ( ) . slice ( 0 , 19 ) + ">" )
+
" "
+
( "[" + log . level _show ( entry . level ) + "]" )
+
" "
+
( "" + entry . incident + "" )
+
": "
+
JSON . stringify ( entry . details , undefined , " " ) ) ;
} ;
return class _channel _console ;
} ( log . class _channel ) ) ;
log . class _channel _console = class _channel _console ;
} ) ( log = lib _plankton . log || ( lib _plankton . log = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : log « .
Copyright 2016 - 2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : log « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : lang « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : lang « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var log ;
( function ( log ) {
/ * *
* /
var class _channel _notify = /** @class */ ( function ( _super ) {
_ _extends ( class _channel _notify , _super ) ;
function class _channel _notify ( ) {
return _super !== null && _super . apply ( this , arguments ) || this ;
}
/ * *
* /
class _channel _notify . prototype . add = function ( entry ) {
var nm _child _process = require ( "child_process" ) ;
var command = ( "notify-send"
+
" "
+
( "'"
+
( "[" + log . level _show ( entry . level ) + "]" )
+
" "
+
entry . incident
+
"'" )
+
" "
+
( "'"
+
( Object . keys ( entry . details )
. map ( function ( key ) { return ( key + ": " + JSON . stringify ( entry . details [ key ] ) ) ; } )
. join ( "\n" ) )
+
"'" ) ) ;
nm _child _process . exec ( command , function ( error , stdout , stderr ) {
// do noting
} ) ;
} ;
return class _channel _notify ;
} ( log . class _channel ) ) ;
log . class _channel _notify = class _channel _notify ;
} ) ( log = lib _plankton . log || ( lib _plankton . log = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : log « .
Copyright 2016 - 2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : log « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : lang « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : lang « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var log ;
( function ( log ) {
/ * *
* /
var class _channel _minlevel = /** @class */ ( function ( _super ) {
_ _extends ( class _channel _minlevel , _super ) ;
/ * *
* /
function class _channel _minlevel ( core , threshold ) {
var _this = _super . call ( this ) || this ;
_this . core = core ;
_this . threshold = threshold ;
return _this ;
}
/ * *
* /
class _channel _minlevel . prototype . add = function ( entry ) {
if ( log . level _order ( this . threshold , entry . level ) ) {
this . core . add ( entry ) ;
}
} ;
return class _channel _minlevel ;
} ( log . class _channel ) ) ;
log . class _channel _minlevel = class _channel _minlevel ;
} ) ( log = lib _plankton . log || ( lib _plankton . log = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : log « .
Copyright 2016 - 2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : log « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : lang « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : lang « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var log ;
( function ( log ) {
/ * *
* /
function translate _level ( level _string ) {
return {
"debug" : log . enum _level . debug ,
"info" : log . enum _level . info ,
"notice" : log . enum _level . notice ,
"warning" : log . enum _level . warning ,
"error" : log . enum _level . error
} [ level _string ] ;
}
/ * *
* /
function channel _make ( description ) {
var _a , _b ;
switch ( description . kind ) {
default : {
throw ( new Error ( "unhandled log channel kind: " + description . kind ) ) ;
break ;
}
case "console" : {
return ( new log . class _channel _minlevel ( new log . class _channel _console ( ) , translate _level ( ( _a = description . data [ "threshold" ] ) !== null && _a !== void 0 ? _a : "debug" ) ) ) ;
break ;
}
case "notify" : {
return ( new log . class _channel _minlevel ( new log . class _channel _notify ( ) , translate _level ( ( _b = description . data [ "threshold" ] ) !== null && _b !== void 0 ? _b : "debug" ) ) ) ;
break ;
}
}
}
log . channel _make = channel _make ;
} ) ( log = lib _plankton . log || ( lib _plankton . log = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : log « .
Copyright 2016 - 2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : log « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : lang « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : lang « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var log ;
( function ( log ) {
/ * *
* /
var _channel _stack = null ;
/ * *
* /
function conf _default ( ) {
return [
new log . class _channel _minlevel ( new log . class _channel _console ( ) , log . enum _level . notice ) ,
new log . class _channel _minlevel ( new log . class _channel _notify ( ) , log . enum _level . error ) ,
] ;
}
log . conf _default = conf _default ;
/ * *
* /
function conf _push ( channels ) {
if ( _channel _stack === null ) {
_channel _stack = [ ] ;
}
_channel _stack . push ( channels ) ;
}
log . conf _push = conf _push ;
/ * *
* /
function conf _pop ( ) {
if ( _channel _stack . length > 0 ) {
_channel _stack . pop ( ) ;
}
else {
// do nothing
}
}
log . conf _pop = conf _pop ;
/ * *
* /
function setup ( ) {
if ( _channel _stack === null ) {
_channel _stack = [ ] ;
conf _push ( conf _default ( ) ) ;
}
else {
// do nothing
}
}
log . setup = setup ;
/ * *
* /
function add ( entry ) {
setup ( ) ;
_channel _stack . slice ( - 1 ) [ 0 ] . forEach ( function ( channel ) { return channel . add ( entry ) ; } ) ;
}
log . add = add ;
/ * *
* /
function debug ( incident , details ) {
if ( details === void 0 ) { details = { } ; }
add ( { "level" : log . enum _level . debug , "incident" : incident , "details" : details } ) ;
}
log . debug = debug ;
/ * *
* /
function info ( incident , details ) {
if ( details === void 0 ) { details = { } ; }
add ( { "level" : log . enum _level . info , "incident" : incident , "details" : details } ) ;
}
log . info = info ;
/ * *
* /
function notice ( incident , details ) {
if ( details === void 0 ) { details = { } ; }
add ( { "level" : log . enum _level . notice , "incident" : incident , "details" : details } ) ;
}
log . notice = notice ;
/ * *
* /
function warning ( incident , details ) {
if ( details === void 0 ) { details = { } ; }
add ( { "level" : log . enum _level . warning , "incident" : incident , "details" : details } ) ;
}
log . warning = warning ;
/ * *
* /
function error ( incident , details ) {
if ( details === void 0 ) { details = { } ; }
add ( { "level" : log . enum _level . error , "incident" : incident , "details" : details } ) ;
}
log . error = error ;
} ) ( log = lib _plankton . log || ( lib _plankton . log = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : args « .
Copyright 2016 - 2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : args « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : args « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : args « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _args ;
( function ( lib _args ) {
/ * *
* /
var enum _environment ;
( function ( enum _environment ) {
enum _environment [ "cli" ] = "cli" ;
enum _environment [ "url" ] = "url" ;
} ) ( enum _environment = lib _args . enum _environment || ( lib _args . enum _environment = { } ) ) ;
;
/ * *
* /
var enum _kind ;
( function ( enum _kind ) {
enum _kind [ "positional" ] = "positional" ;
enum _kind [ "volatile" ] = "volatile" ;
} ) ( enum _kind = lib _args . enum _kind || ( lib _args . enum _kind = { } ) ) ;
;
/ * *
* /
var enum _type ;
( function ( enum _type ) {
enum _type [ "boolean" ] = "boolean" ;
enum _type [ "integer" ] = "int" ;
enum _type [ "float" ] = "float" ;
enum _type [ "string" ] = "string" ;
} ) ( enum _type = lib _args . enum _type || ( lib _args . enum _type = { } ) ) ;
;
/ * *
* /
var enum _mode ;
( function ( enum _mode ) {
enum _mode [ "replace" ] = "replace" ;
enum _mode [ "accumulate" ] = "accumulate" ;
} ) ( enum _mode = lib _args . enum _mode || ( lib _args . enum _mode = { } ) ) ;
;
} ) ( lib _args || ( lib _args = { } ) ) ;
/ *
This file is part of » bacterio - plankton : args « .
Copyright 2016 - 2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : args « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : args « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : args « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _args ;
( function ( lib _args ) {
/ * *
* @ author fenris
* /
var class _argument = /** @class */ ( function ( ) {
/ * *
* @ author fenris
* /
function class _argument ( _a ) {
var name = _a [ "name" ] , _b = _a [ "type" ] , type = _b === void 0 ? lib _args . enum _type . string : _b , _c = _a [ "kind" ] , kind = _c === void 0 ? lib _args . enum _kind . positional : _c , _d = _a [ "mode" ] , mode = _d === void 0 ? lib _args . enum _mode . replace : _d , _e = _a [ "default" ] , default _ = _e === void 0 ? null : _e , _f = _a [ "info" ] , info = _f === void 0 ? null : _f , _g = _a [ "parameters" ] , parameters = _g === void 0 ? { } : _g , _h = _a [ "hidden" ] , hidden = _h === void 0 ? false : _h ;
this . name = name ;
this . type = type ;
this . kind = kind ;
this . mode = mode ;
this . default _ = default _ ;
this . info = info ;
this . parameters = parameters ;
this . hidden = hidden ;
if ( ! this . check ( ) ) {
throw ( new Error ( "invalid argument-setup" ) ) ;
}
}
/ * *
* @ author fenris
* /
class _argument . positional = function ( _a ) {
var name = _a [ "name" ] , _b = _a [ "type" ] , type = _b === void 0 ? lib _args . enum _type . string : _b , _c = _a [ "mode" ] , mode = _c === void 0 ? lib _args . enum _mode . replace : _c , _d = _a [ "default" ] , default _ = _d === void 0 ? null : _d , _e = _a [ "info" ] , info = _e === void 0 ? null : _e , _f = _a [ "hidden" ] , hidden = _f === void 0 ? false : _f , index = _a [ "index" ] ;
return ( new class _argument ( {
"name" : name ,
"kind" : lib _args . enum _kind . positional ,
"type" : type ,
"mode" : mode ,
"default" : default _ ,
"info" : info ,
"hidden" : hidden ,
"parameters" : {
"index" : index
}
} ) ) ;
} ;
/ * *
* @ author fenris
* /
class _argument . volatile = function ( _a ) {
var name = _a [ "name" ] , _b = _a [ "type" ] , type = _b === void 0 ? lib _args . enum _type . string : _b , _c = _a [ "mode" ] , mode = _c === void 0 ? lib _args . enum _mode . replace : _c , _d = _a [ "default" ] , default _ = _d === void 0 ? null : _d , _e = _a [ "info" ] , info = _e === void 0 ? null : _e , _f = _a [ "hidden" ] , hidden = _f === void 0 ? false : _f , indicators _short = _a [ "indicators_short" ] , indicators _long = _a [ "indicators_long" ] ;
return ( new class _argument ( {
"name" : name ,
"kind" : lib _args . enum _kind . volatile ,
"type" : type ,
"mode" : mode ,
"default" : default _ ,
"info" : info ,
"hidden" : hidden ,
"parameters" : {
"indicators_short" : indicators _short ,
"indicators_long" : indicators _long
}
} ) ) ;
} ;
/ * *
* @ author fenris
* /
class _argument . prototype . check = function ( ) {
var _this = this ;
return [
function ( ) { return ( ( ! ( _this . kind == lib _args . enum _kind . volatile ) )
||
( ( "indicators_long" in _this . parameters )
&&
( _this . parameters [ "indicators_long" ] [ "length" ] >= 0 ) ) ) ; } ,
] . every ( function ( condition ) { return condition ( ) ; } ) ;
} ;
/ * *
* @ author fenris
* /
class _argument . prototype . name _get = function ( ) {
return this . name ;
} ;
/ * *
* @ author fenris
* /
class _argument . prototype . kind _get = function ( ) {
return this . kind ;
} ;
/ * *
* @ author fenris
* /
class _argument . prototype . type _get = function ( ) {
return this . type ;
} ;
/ * *
* @ author fenris
* /
class _argument . prototype . mode _get = function ( ) {
return this . mode ;
} ;
/ * *
* @ author fenris
* /
class _argument . prototype . default _get = function ( ) {
return this . default _ ;
} ;
/ * *
* @ author fenris
* /
class _argument . prototype . parameters _get = function ( ) {
return this . parameters ;
} ;
/ * *
* @ author fenris
* /
class _argument . prototype . hidden _get = function ( ) {
return this . hidden ;
} ;
/ * *
* @ author fenris
* /
class _argument . prototype . toString = function ( ) {
return "<" + this . name + ">" ;
} ;
/ * *
* @ author fenris
* /
class _argument . prototype . indicator _main = function ( ) {
if ( this . kind === lib _args . enum _kind . volatile ) {
return this . parameters [ "indicators_long" ] [ 0 ] ;
}
else {
return null ;
}
} ;
/ * *
* @ author fenris
* /
class _argument . prototype . pattern _value = function ( ) {
switch ( this . type ) {
case lib _args . enum _type . boolean : {
return "false|true" ;
break ;
}
case lib _args . enum _type . integer : {
return "[0-9]+" ;
break ;
}
case lib _args . enum _type . float : {
return "\\d*(?:\\.\\d+)?" ;
break ;
}
case lib _args . enum _type . string : {
return "\\S+" ;
break ;
}
default : {
throw ( new Error ( "unhandled type " + this . type ) ) ;
break ;
}
}
} ;
/ * *
* @ author fenris
* /
class _argument . prototype . extract = function ( raw ) {
switch ( this . type ) {
case lib _args . enum _type . boolean : {
return ( raw != "false" ) ;
break ;
}
case lib _args . enum _type . integer : {
return parseInt ( raw ) ;
break ;
}
case lib _args . enum _type . float : {
return parseFloat ( raw ) ;
break ;
}
case lib _args . enum _type . string : {
return raw ;
break ;
}
default : {
throw ( new Error ( "unhandled type " + this . type ) ) ;
break ;
}
}
} ;
/ * *
* @ author fenris
* /
class _argument . prototype . assign = function ( data , target , raw ) {
var value = this . extract ( raw ) ;
switch ( this . mode ) {
case lib _args . enum _mode . replace : {
data [ target ] = value ;
break ;
}
case lib _args . enum _mode . accumulate : {
/ *
if ( ! ( this . name in data ) ) {
data [ this . name ] = [ ] ;
}
* /
data [ target ] . push ( value ) ;
break ;
}
default : {
throw ( new Error ( "unhandled mode " + this . mode ) ) ;
}
}
} ;
/ * *
* @ author fenris
* /
class _argument . prototype . make = function ( data , target ) {
var value = data [ target ] ;
return value . toString ( ) ;
} ;
/ * *
* @ author fenris
* /
class _argument . prototype . generate _help = function ( ) {
var _this = this ;
var _a , _b , _c , _d ;
var output = "" ;
{
switch ( this . kind ) {
case lib _args . enum _kind . positional : {
var line = "" ;
line += "\t" ;
line += "<" + this . name + ">" ;
line += "\n" ;
output += line ;
}
case lib _args . enum _kind . volatile : {
var line = "" ;
line += "\t" ;
if ( this . type === lib _args . enum _type . boolean ) {
line += ( [ ]
. concat ( ( ( _a = this . parameters [ "indicators_short" ] ) !== null && _a !== void 0 ? _a : [ ] ) . map ( function ( indicator ) { return ( "-" + indicator ) ; } ) )
. concat ( ( ( _b = this . parameters [ "indicators_long" ] ) !== null && _b !== void 0 ? _b : [ ] ) . map ( function ( indicator ) { return ( "--" + indicator ) ; } ) )
. join ( " | " ) ) ;
}
else {
line += ( [ ]
. concat ( ( ( _c = this . parameters [ "indicators_short" ] ) !== null && _c !== void 0 ? _c : [ ] ) . map ( function ( indicator ) { return ( "-" + indicator + " " + ( "<" + _this . name + ">" ) ) ; } ) )
. concat ( ( ( _d = this . parameters [ "indicators_long" ] ) !== null && _d !== void 0 ? _d : [ ] ) . map ( function ( indicator ) { return ( "--" + indicator + "=" + ( "<" + _this . name + ">" ) ) ; } ) )
. join ( " | " ) ) ;
}
line += "\n" ;
output += line ;
}
}
}
{
var line = "" ;
line += "\t\t" ;
var infotext = ( ( this . info == null ) ? "(no info available)" : this . info ) ;
line += infotext ;
if ( ( this . type != "boolean" ) && ( this . default _ != null ) ) {
line += "; default: " + this . default _ . toString ( ) ;
}
line += "\n" ;
output += line ;
}
return output ;
} ;
return class _argument ;
} ( ) ) ;
lib _args . class _argument = class _argument ;
} ) ( lib _args || ( lib _args = { } ) ) ;
/ *
This file is part of » bacterio - plankton : args « .
Copyright 2016 - 2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : args « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : args « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : args « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _args ;
( function ( lib _args ) {
/ * *
* @ author fenris
* /
var settings = {
"environment" : {
"cli" : {
"symbols" : {
"delimiter" : " " ,
"prefix" : "--" ,
"assignment" : "="
}
} ,
"url" : {
"symbols" : {
"delimiter" : "&" ,
"prefix" : "" ,
"assignment" : "="
}
}
}
} ;
/ * *
* @ author fenris
* /
lib _args . verbosity = 0 ;
/ * *
* @ author fenris
* @ todo check validity
* /
var class _handler = /** @class */ ( function ( ) {
/ * *
* @ author fenris
* /
function class _handler ( arguments _ ) {
this . arguments _ = arguments _ ;
}
/ * *
* @ author fenris
* /
class _handler . prototype . filter = function ( kind ) {
var arguments _ = { } ;
for ( var _i = 0 , _a = Object . entries ( this . arguments _ ) ; _i < _a . length ; _i ++ ) {
var _b = _a [ _i ] , name = _b [ 0 ] , argument = _b [ 1 ] ;
if ( argument . kind _get ( ) == kind ) {
arguments _ [ name ] = argument ;
}
}
return arguments _ ;
} ;
/ * *
* @ author fenris
* /
class _handler . prototype . read = function ( environment , input , data ) {
var _this = this ;
if ( data === void 0 ) { data = { } ; }
switch ( environment ) {
case lib _args . enum _environment . cli :
case lib _args . enum _environment . url : {
// default values
{
for ( var _i = 0 , _a = Object . entries ( this . arguments _ ) ; _i < _a . length ; _i ++ ) {
var _b = _a [ _i ] , name = _b [ 0 ] , argument = _b [ 1 ] ;
data [ name ] = argument . default _get ( ) ;
}
}
// preprocessing
{
// short indicators (lil hacky ...)
{
if ( environment == lib _args . enum _environment . cli ) {
for ( var _c = 0 , _d = Object . entries ( this . filter ( lib _args . enum _kind . volatile ) ) ; _c < _d . length ; _c ++ ) {
var _e = _d [ _c ] , name = _e [ 0 ] , argument = _e [ 1 ] ;
// console.info(argument.parameters_get()["indicators_short"].join("|"));
var pattern _from = "" ;
{
pattern _from += "(?:^|" + settings [ "environment" ] [ environment ] [ "symbols" ] [ "delimiter" ] + ")" ;
pattern _from += "-" + argument . parameters _get ( ) [ "indicators_short" ] . join ( "|" ) ;
pattern _from += "(?:$|" + settings [ "environment" ] [ environment ] [ "symbols" ] [ "delimiter" ] + ")" ;
}
var pattern _to = "" ;
{
pattern _to += settings [ "environment" ] [ environment ] [ "symbols" ] [ "delimiter" ] ;
pattern _to += settings [ "environment" ] [ environment ] [ "symbols" ] [ "prefix" ] ;
pattern _to += argument . indicator _main ( ) ;
if ( argument . type _get ( ) == lib _args . enum _type . boolean ) {
pattern _to += settings [ "environment" ] [ environment ] [ "symbols" ] [ "delimiter" ] ;
}
else {
pattern _to += settings [ "environment" ] [ environment ] [ "symbols" ] [ "assignment" ] ;
}
}
var result = input . replace ( new RegExp ( pattern _from , "g" ) , pattern _to ) ;
lib _plankton . log . debug ( "lib_args:read:replacing" , {
"pattern_from" : pattern _from ,
"pattern_to" : pattern _to ,
"input" : input ,
"result" : result
} ) ;
input = result ;
}
}
}
lib _plankton . log . debug ( "lib_args:read:current_input" , {
"input" : input
} ) ;
}
// parsing
{
var parts = input
. split ( settings [ "environment" ] [ environment ] [ "symbols" ] [ "delimiter" ] )
. filter ( function ( x ) { return ( x != "" ) ; } ) ;
var index _expected _1 = 0 ;
parts . forEach ( function ( part ) {
lib _plankton . log . debug ( "lib_args:read:analyzing" , {
"part" : part
} ) ;
var found = [
function ( ) {
lib _plankton . log . debug ( "lib_args:read:probing_as_volatile" , {
"part" : part
} ) ;
for ( var _i = 0 , _a = Object . entries ( _this . filter ( lib _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 ( )
} ) ;
var pattern = "" ;
{
var pattern _front = "" ;
pattern _front += "" + settings [ "environment" ] [ environment ] [ "symbols" ] [ "prefix" ] ;
pattern _front += "(?:" + argument . parameters _get ( ) [ "indicators_long" ] . join ( "|" ) + ")" ;
pattern += pattern _front ;
}
{
var pattern _back = "" ;
pattern _back += "" + settings [ "environment" ] [ environment ] [ "symbols" ] [ "assignment" ] ;
pattern _back += "(" + argument . pattern _value ( ) + ")" ;
if ( argument . type _get ( ) == lib _args . enum _type . boolean ) {
pattern _back = "(?:" + pattern _back + ")?" ;
}
pattern += pattern _back ;
}
lib _plankton . log . debug ( "lib_args:read:probing_as_volatile: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
} ) ;
if ( matching == null ) {
// do nothing
}
else {
argument . assign ( data , name , matching [ 1 ] ) ;
return true ;
}
}
return false ;
} ,
function ( ) {
lib _plankton . log . debug ( "lib_args:read:probing_as_positional" , {
"part" : part
} ) ;
var positional = _this . filter ( lib _args . enum _kind . positional ) ;
for ( var _i = 0 , _a = Object . entries ( positional ) ; _i < _a . length ; _i ++ ) {
var _b = _a [ _i ] , name = _b [ 0 ] , argument = _b [ 1 ] ;
if ( argument . parameters _get ( ) [ 'index' ] !== index _expected _1 ) {
// do nothing
}
else {
lib _plankton . log . debug ( "lib_args:read:probing_as_positional:trying" , {
"part" : part ,
"argument" : argument . toString ( )
} ) ;
var pattern = "" ;
{
var pattern _back = "" ;
pattern _back += "(" + argument . pattern _value ( ) + ")" ;
pattern += pattern _back ;
}
lib _plankton . log . debug ( "lib_args:read:probing_as_positional: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
} ) ;
if ( matching == null ) {
return false ;
}
else {
argument . assign ( data , name , matching [ 1 ] ) ;
index _expected _1 += 1 ;
return true ;
}
}
}
return false ;
} ,
] . some ( function ( x ) { return x ( ) ; } ) ;
if ( ! found ) {
lib _plankton . log . warning ( "lib_args:read:could_not_parse" , {
"part" : part
} ) ;
}
} ) ;
}
return data ;
break ;
}
default : {
throw ( new Error ( "unhandled environment " + environment ) ) ;
break ;
}
}
} ;
/ * *
* @ author fenris
* @ todo handle if the data object doesn ' t have the required field or the type is wrong or sth .
* /
class _handler . prototype . write = function ( environment , data ) {
switch ( environment ) {
case lib _args . enum _environment . cli : {
return ( ( [ ]
. concat ( Object . entries ( this . filter ( lib _args . enum _kind . volatile ) ) . map ( function ( _a ) {
var name = _a [ 0 ] , argument = _a [ 1 ] ;
var values ;
switch ( argument . mode _get ( ) ) {
case lib _args . enum _mode . replace : {
values = [ data [ argument . name _get ( ) ] ] ;
break ;
}
case lib _args . enum _mode . accumulate : {
values = data [ argument . name _get ( ) ] ;
break ;
}
}
return ( values
. map ( function ( value ) { return ( ( settings [ "environment" ] [ environment ] [ "symbols" ] [ "prefix" ]
+
argument . parameters _get ( ) [ "indicators_long" ] [ 0 ] )
+
( settings [ "environment" ] [ environment ] [ "symbols" ] [ "assignment" ]
+
value . toString ( ) ) ) ; } )
. join ( " " ) ) ;
} ) )
. concat ( Object . entries ( this . filter ( lib _args . enum _kind . positional ) ) . map ( function ( _a ) {
var name = _a [ 0 ] , argument = _a [ 1 ] ;
var raw = "" ;
{
var raw _back = "" ;
raw _back += argument . make ( data , name ) ;
raw += raw _back ;
}
return raw ;
} ) ) )
. join ( settings [ "environment" ] [ environment ] [ "symbols" ] [ "delimiter" ] ) ) ;
break ;
}
default : {
throw ( new Error ( "unhandled environment " + environment ) ) ;
break ;
}
}
} ;
/ * *
* @ desc manpage - like info - sheet
* @ author fenris
* /
class _handler . prototype . generate _help = function ( _a ) {
var _b = _a [ "programname" ] , programname = _b === void 0 ? null : _b , _c = _a [ "author" ] , author = _c === void 0 ? null : _c , _d = _a [ "description" ] , description = _d === void 0 ? null : _d , _e = _a [ "executable" ] , executable = _e === void 0 ? null : _e ;
var environment = lib _args . enum _environment . cli ;
var output = "" ;
{
var section = "" ;
{
var line = "" ;
line += "" ;
line += "INFO" ;
line += "\n" ;
section += line ;
}
{
var line = "" ;
line += "\t" ;
line += programname + " -- " + description ;
line += "\n" ;
section += line ;
}
section += "\n" ;
output += section ;
}
{
if ( author != null ) {
var section = "" ;
{
var line = "" ;
line += "" ;
line += "AUTHOR" ;
line += "\n" ;
section += line ;
}
{
var line = "" ;
line += "\t" ;
line += "" + author ;
line += "\n" ;
section += line ;
}
section += "\n" ;
output += section ;
}
}
{
var section = "" ;
{
var line = "" ;
line += "" ;
line += "SYNOPSIS" ;
line += "\n" ;
section += line ;
}
{
var line = "" ;
line += "\t" ;
line += executable ;
line += settings [ "environment" ] [ environment ] [ "symbols" ] [ "delimiter" ] ;
line += Object . entries ( this . filter ( lib _args . enum _kind . positional ) )
. map ( function ( _a ) {
var name = _a [ 0 ] , argument = _a [ 1 ] ;
var part = "" ;
part += "<" + argument . name _get ( ) + ">" ;
return part ;
} )
. join ( settings [ "environment" ] [ environment ] [ "symbols" ] [ "delimiter" ] ) ;
line += settings [ "environment" ] [ environment ] [ "symbols" ] [ "delimiter" ] ;
line += Object . entries ( this . filter ( lib _args . enum _kind . volatile ) )
. filter ( function ( _a ) {
var name = _a [ 0 ] , argument = _a [ 1 ] ;
return ( ! argument . hidden _get ( ) ) ;
} )
. map ( function ( _a ) {
var name = _a [ 0 ] , argument = _a [ 1 ] ;
var part = "" ;
// part += settings["environment"][environment]["symbols"]["prefix"];
part += "-" ;
part += argument . parameters _get ( ) [ "indicators_short" ] [ 0 ] ;
if ( argument . type _get ( ) != "boolean" ) {
/ *
part += settings [ "environment" ] [ environment ] [ "symbols" ] [ "assignment" ] ;
part += ` < ${ argument . name _get ( ) } > ` ;
* /
part += " " ;
part += "<" + argument . name _get ( ) + ">" ;
}
part = "[" + part + "]" ;
return part ;
} )
. join ( settings [ "environment" ] [ environment ] [ "symbols" ] [ "delimiter" ] ) ;
line += "\n" ;
section += line ;
}
section += "\n" ;
output += section ;
}
{
var section = "" ;
{
var line = "" ;
line += "" ;
line += "OPTIONS" ;
line += "\n" ;
section += line ;
}
{
section += ( Object . entries ( this . arguments _ )
. filter ( function ( _a ) {
var name = _a [ 0 ] , argument = _a [ 1 ] ;
return ( ! argument . hidden _get ( ) ) ;
} )
. map ( function ( _a ) {
var name = _a [ 0 ] , argument = _a [ 1 ] ;
return argument . generate _help ( ) ;
} )
. join ( "\n" ) ) ;
}
section += "\n" ;
output += section ;
}
return output ;
} ;
return class _handler ;
} ( ) ) ;
lib _args . class _handler = class _handler ;
} ) ( lib _args || ( lib _args = { } ) ) ;
/ *
2021-09-19 01:57:14 +02:00
This file is part of » bacterio - plankton : file « .
2021-09-19 01:14:32 +02:00
Copyright 2016 - 2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
2021-09-19 01:57:14 +02:00
» bacterio - plankton : file « is free software : you can redistribute it and / or modify
2021-09-19 01:14:32 +02:00
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
2021-09-19 01:57:14 +02:00
» bacterio - plankton : file « is distributed in the hope that it will be useful ,
2021-09-19 01:14:32 +02:00
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
2021-09-19 01:57:14 +02:00
along with » bacterio - plankton : file « . If not , see < http : //www.gnu.org/licenses/>.
2021-09-19 01:14:32 +02:00
* /
2021-09-19 01:57:14 +02:00
var lib _plankton ;
( function ( lib _plankton ) {
var file ;
( function ( file ) {
2021-09-19 01:14:32 +02:00
/ * *
* @ author fenris
* /
2021-09-19 01:57:14 +02:00
function read ( path ) {
var nm _fs = require ( "fs" ) ;
return ( new Promise ( function ( resolve , reject ) {
nm _fs . readFile ( path , {
"encoding" : "utf8" ,
"flag" : "r"
} , function ( error , content ) {
if ( error == null ) {
resolve ( content ) ;
}
else {
reject ( error ) ;
}
} ) ;
} ) ) ;
2021-09-19 01:14:32 +02:00
}
2021-09-19 01:57:14 +02:00
file . read = read ;
2021-09-19 01:14:32 +02:00
/ * *
* @ author fenris
* /
2021-09-19 01:57:14 +02:00
function read _stdin ( ) {
return ( new Promise ( function ( resolve , reject ) {
var input _raw = "" ;
process . stdin . setEncoding ( "utf8" ) ;
process . stdin . on ( "readable" , function ( ) {
var chunk ;
while ( ( chunk = process . stdin . read ( ) ) !== null ) {
input _raw += chunk ;
}
2021-09-19 01:14:32 +02:00
} ) ;
2021-09-19 01:57:14 +02:00
process . stdin . on ( "end" , function ( ) {
resolve ( input _raw ) ;
2021-09-19 01:14:32 +02:00
} ) ;
2021-09-19 01:57:14 +02:00
} ) ) ;
2021-09-19 01:14:32 +02:00
}
2021-09-19 01:57:14 +02:00
file . read _stdin = read _stdin ;
/ * *
* @ author fenris
* /
function write ( path , content ) {
var nm _fs = require ( "fs" ) ;
return ( new Promise ( function ( resolve , reject ) {
nm _fs . writeFile ( path , content , {
"encoding" : "utf8" ,
"flag" : "w"
} , function ( error ) {
if ( error == null ) {
resolve ( undefined ) ;
}
else {
reject ( error ) ;
}
} ) ;
} ) ) ;
2021-09-19 01:14:32 +02:00
}
2021-09-19 01:57:14 +02:00
file . write = write ;
} ) ( file = lib _plankton . file || ( lib _plankton . file = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
2021-09-19 01:14:32 +02:00
/ *
This file is part of » bacterio - plankton : observer « .
Copyright 2016 - 2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : observer « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : observer « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : observer « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _observer ;
( function ( lib _observer ) {
/ * *
* @ author fenris
* /
function make ( _a ) {
var _b = _a === void 0 ? { } : _a , _c = _b [ "force_registration" ] , force _registration = _c === void 0 ? false : _c , _d = _b [ "no_attendants_warn_do" ] , no _attendants _warn _do = _d === void 0 ? false : _d , _e = _b [ "no_attendants_warn_action" ] , no _attendants _warn _action = _e === void 0 ? ( function ( eventname ) { return console . warn ( "no attendants for event '" + eventname + "'" ) ; } ) : _e ;
return {
"actions" : { } ,
"force_registration" : force _registration ,
"no_attendants_warn_do" : no _attendants _warn _do ,
"no_attendants_warn_action" : no _attendants _warn _action ,
} ;
}
lib _observer . make = make ;
/ * *
* @ author fenris
* /
function present ( observer , eventname ) {
return ( observer . actions . hasOwnProperty ( eventname ) ) ;
}
/ * *
* @ author fenris
* /
function register ( observer , eventname ) {
if ( ! present ( observer , eventname ) ) {
observer . actions [ eventname ] = [ ] ;
}
else {
// do nothing
// warn that it is already registered?
}
}
lib _observer . register = register ;
/ * *
* @ author fenris
* /
function attend ( observer , eventname , action ) {
if ( ! present ( observer , eventname ) ) {
if ( observer . force _registration ) {
throw ( new Error ( "no event '" + eventname + "'" ) ) ;
}
else {
register ( observer , eventname ) ;
}
}
else {
// do nothing
}
observer . actions [ eventname ] . push ( action ) ;
}
lib _observer . attend = attend ;
/ * *
* @ author fenris
* /
function notify ( observer , eventname , data ) {
if ( ! present ( observer , eventname ) ) {
if ( observer . force _registration ) {
throw ( new Error ( "no event '" + eventname + "'" ) ) ;
}
else {
register ( observer , eventname ) ;
}
}
else {
if ( observer . no _attendants _warn _do ) {
if ( observer . actions [ eventname ] . length <= 0 ) {
observer . no _attendants _warn _action ( eventname ) ;
}
else {
// do nothing
}
}
else {
// do nothing
}
observer . actions [ eventname ]
. forEach ( function ( action ) {
action ( data ) ;
} ) ;
}
}
lib _observer . notify = notify ;
} ) ( lib _observer || ( lib _observer = { } ) ) ;
/ *
This file is part of » bacterio - plankton : lang « .
Copyright 2016 - 2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : lang « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : lang « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : lang « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var lang ;
( function ( lang ) {
/ * *
* @ author fenris
* /
function sequence ( length ) {
return ( ( length > 0 ) ? sequence ( length - 1 ) . concat ( [ length - 1 ] ) : [ ] ) ;
}
/ * *
* @ author fenris
* /
function find ( word , part , equality , /*= instance_collate*/ right _to _left = false ) {
let result = - 1 ;
let found = sequence ( word . length - part . length + 1 ) . some ( function ( position ) {
let position _ = ( right _to _left
? ( word . length - part . length - position )
: ( position ) ) ;
let matches = sequence ( part . length ) . every ( index => equality ( word [ position _ + index ] , part [ index ] ) ) ;
if ( matches ) {
result = position _ ;
return true ;
}
else {
return false ;
}
} ) ;
return result ;
}
lang . find = find ;
} ) ( lang = lib _plankton . lang || ( lib _plankton . lang = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : lang « .
Copyright 2016 - 2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : lang « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : lang « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : lang « . If not , see < http : //www.gnu.org/licenses/>.
* /
/ *
This file is part of » bacterio - plankton : lang « .
Copyright 2016 - 2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : lang « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : lang « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : lang « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var lang ;
( function ( lang ) {
/ * *
* @ author fenris
* /
class class _symbol _terminal {
/ * *
* @ desc [ constructor ]
* @ author fenris
* /
constructor ( terminal , equality _terminal = ( ( x , y ) => ( x == y ) ) ) {
this . terminal = terminal ;
this . equality _terminal = equality _terminal ;
}
/ * *
* @ author fenris
* /
terminal _get ( ) {
return this . terminal ;
}
/ * *
* @ override
* @ author fenris
* /
equals ( symbol ) {
if ( symbol instanceof class _symbol _terminal ) {
let symbol _terminal = ( symbol ) ;
return this . equality _terminal ( this . terminal , symbol _terminal . terminal ) ;
}
else {
return false ;
}
}
/ * *
* @ override
* @ author fenris
* /
toString ( ) {
return JSON . stringify ( this ) ;
}
/ * *
* @ author fenris
* /
static tree _generic ( terminal ) {
return ( new lib _plankton . lang . class _symbol _terminal ( terminal ) ) ;
}
/ * *
* @ author fenris
* /
static tree _default ( terminal ) {
return ( new lib _plankton . lang . class _symbol _terminal ( terminal ) ) ;
}
}
lang . class _symbol _terminal = class _symbol _terminal ;
} ) ( lang = lib _plankton . lang || ( lib _plankton . lang = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : lang « .
Copyright 2016 - 2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : lang « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : lang « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : lang « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var lang ;
( function ( lang ) {
/ * *
* @ author fenris
* /
class class _symbol _variable {
/ * *
* @ desc [ constructor ]
* @ author fenris
* /
constructor ( variable , meaning = undefined ) {
this . variable = variable ;
this . meaning = meaning ;
}
/ * *
* @ desc [ accessor ] [ getter ]
* @ author fenris
* /
variable _get ( ) {
return this . variable ;
}
/ * *
* @ desc [ accessor ] [ getter ]
* @ author fenris
* /
meaning _get ( ) {
return this . meaning ;
}
/ * *
* @ override
* @ author fenris
* /
equals ( symbol ) {
if ( symbol instanceof class _symbol _variable ) {
let symbol _variable = ( symbol ) ;
return ( this . variable == symbol _variable . variable ) ;
}
else {
return false ;
}
}
/ * *
* @ override
* @ author fenris
* /
toString ( ) {
return JSON . stringify ( this ) ;
}
/ * *
* @ author fenris
* /
static tree _generic ( variable ) {
return ( new lib _plankton . lang . class _symbol _variable ( variable ) ) ;
}
/ * *
* @ author fenris
* /
static tree _default ( variable ) {
return ( new lib _plankton . lang . class _symbol _variable ( variable ) ) ;
}
}
lang . class _symbol _variable = class _symbol _variable ;
} ) ( lang = lib _plankton . lang || ( lib _plankton . lang = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : lang « .
Copyright 2016 - 2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : lang « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : lang « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : lang « . If not , see < http : //www.gnu.org/licenses/>.
* /
/ *
This file is part of » bacterio - plankton : lang « .
Copyright 2016 - 2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : lang « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : lang « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : lang « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var lang ;
( function ( lang ) {
/ * *
* @ author fenris
* /
function lexerrule _make ( search , construct ) {
let observer = lib _observer . make ( ) ;
lib _observer . register ( observer , "start" ) ;
lib _observer . register ( observer , "message_sequence" ) ;
lib _observer . register ( observer , "maximum_reached" ) ;
lib _observer . attend ( observer , "start" , ( { "rule" : rule } ) => {
lib _plankton . log . debug ( "lang:lexer:run:current_rule" , {
"rule" : lexerrule _show ( rule ) ,
} ) ;
} ) ;
lib _observer . attend ( observer , "message_sequence" , ( { "tokens" : tokens } ) => {
lib _plankton . log . debug ( "lang:lexer:run:current_sequence" , {
"tokens" : tokens ,
} ) ;
} ) ;
lib _observer . attend ( observer , "maximum_reached" , ( ) => {
lib _plankton . log . warning ( "lang:lexer:run:maximum_reached" , { } ) ;
} ) ;
return {
"search" : search ,
"construct" : construct ,
"observer" : observer ,
} ;
}
lang . lexerrule _make = lexerrule _make ;
/ * *
* @ author fenris
* @ todo schön machen ? is aber vermutlich gar nicht möglich : /
* /
function lexerrule _show ( rule ) {
return "(nicht darstellbar)" ;
}
lang . lexerrule _show = lexerrule _show ;
/ * *
* @ author fenris
* /
function lexerrule _apply ( rule , tokens ) {
/ * *
* @ todo Wert sollte konfigurierbar sein
* /
let maximum = ( 1 << 10 ) ;
lib _observer . notify ( rule . observer , "start" , { "rule" : rule } ) ;
let offset = 0 ;
// process _all_ occurences
while ( true ) {
lib _observer . notify ( rule . observer , "message_sequence" , { "tokens" : tokens } ) ;
if ( maximum -- <= 0 ) {
lib _observer . notify ( rule . observer , "maximum_reached" , { } ) ;
break ;
}
let found = tokens . slice ( offset ) . some ( function ( token _old , index ) {
if ( token _old . terminal . is _just ( ) ) {
return false ;
}
else {
let result = rule . search ( token _old . sequence ) ;
if ( ! result . found ) {
return false ;
}
else {
// der Ersatz für den Platz von "token_old"
let tokens _new = [ ] ;
// die Zeichen des alten Tokens, die vor der Übereinstimmung stehen
{
let nonempty = ( result . data . position > 0 ) ;
if ( nonempty ) {
let sequence = token _old . sequence . slice ( 0 , result . data . position ) ;
tokens _new . push ( {
"sequence" : sequence ,
"terminal" : new class _nothing ( ) ,
} ) ;
}
}
// die Zeichen der Übereinstimmung
{
let sequence = token _old . sequence . slice ( result . data . position , result . data . position + result . data . length ) ;
let terminals = rule . construct ( sequence ) ;
terminals . forEach ( ( terminal ) => {
tokens _new . push ( {
"sequence" : null ,
"terminal" : new class _just ( terminal ) ,
} ) ;
} ) ;
}
// die Zeichen des alten Tokens, die hinter der Übereinstimmung stehen
{
let nonempty = ( result . data . position + result . data . length < token _old . sequence . length ) ;
if ( nonempty ) {
let sequence = token _old . sequence . slice ( result . data . position + result . data . length / * ,
token _old . sequence . length * / ) ;
tokens _new . push ( {
"sequence" : sequence ,
"terminal" : new class _nothing ( ) ,
} ) ;
}
}
/ *
console . log ( "-- offset_old: " , offset ) ;
console . log ( "-- index: " , index ) ;
console . log ( "-- token_old: " , token _old ) ;
offset += index ;
console . log ( "-- offset_new: " , offset ) ;
* /
tokens = [ ]
. concat ( tokens . slice ( 0 , index ) )
. concat ( tokens _new )
. concat ( tokens . slice ( index + 1 ) ) ;
return true ;
}
}
} ) ;
if ( ! found ) {
break ;
}
}
return tokens ;
}
lang . lexerrule _apply = lexerrule _apply ;
/ * *
* @ author fenris
* /
function lexerrule _pass ( ) {
return lexerrule _make ( ( part ) => ( { "found" : true , "data" : { "position" : 0 , "length" : 1 } } ) , ( part ) => part ) ;
}
lang . lexerrule _pass = lexerrule _pass ;
/ * *
* @ author fenris
* /
function lexerrule _pattern _generic ( rule _raw ) {
let regexp = new RegExp ( rule _raw . pattern ) ;
return lexerrule _make ( ( part ) => {
const part _ = part . join ( "" ) ;
// console.log(`searching for '${regexp.toString()}' in '${part_}' ...`);
const match _ = regexp . exec ( part _ ) ;
// console.log(`... result: `, match_);
if ( match _ == null ) {
return { "found" : false } ;
}
else {
return { "found" : true , "data" : { "position" : match _ . index , "length" : match _ [ 0 ] . length } } ;
}
} , rule _raw . construct ) ;
}
lang . lexerrule _pattern _generic = lexerrule _pattern _generic ;
/ * *
* @ author fenris
* /
function lexerrule _pattern _ignore ( pattern ) {
return ( lexerrule _pattern _generic ( {
"pattern" : pattern ,
"construct" : tokens => [ ]
} ) ) ;
}
lang . lexerrule _pattern _ignore = lexerrule _pattern _ignore ;
/ * *
* @ author fenris
* /
function lexerrule _pattern _void ( pattern , id ) {
return ( lexerrule _pattern _generic ( {
"pattern" : pattern ,
"construct" : tokens => [ { "id" : id , "data" : { } } ] ,
} ) ) ;
}
lang . lexerrule _pattern _void = lexerrule _pattern _void ;
/ * *
* @ author fenris
* /
function lexerrule _pattern _boolean ( pattern , id , value ) {
return ( lexerrule _pattern _generic ( {
"pattern" : pattern ,
"construct" : tokens => [ { "id" : id , "data" : { "value" : value } } ] ,
} ) ) ;
}
lang . lexerrule _pattern _boolean = lexerrule _pattern _boolean ;
/ * *
* @ author fenris
* /
function lexerrule _pattern _int ( pattern , id ) {
return ( lexerrule _pattern _generic ( {
"pattern" : pattern ,
"construct" : tokens => [ { "id" : id , "data" : { "value" : parseInt ( tokens . join ( "" ) ) } } ] ,
} ) ) ;
}
lang . lexerrule _pattern _int = lexerrule _pattern _int ;
/ * *
* @ author fenris
* /
function lexerrule _pattern _float ( pattern , id ) {
return ( lexerrule _pattern _generic ( {
"pattern" : pattern ,
"construct" : tokens => [ { "id" : id , "data" : { "value" : parseFloat ( tokens . join ( "" ) ) } } ] ,
} ) ) ;
}
lang . lexerrule _pattern _float = lexerrule _pattern _float ;
/ * *
* @ author fenris
* /
function lexerrule _pattern _string ( pattern , id ) {
return ( lexerrule _pattern _generic ( {
"pattern" : pattern ,
"construct" : tokens => [ { "id" : id , "data" : { "value" : tokens . join ( "" ) } } ] ,
} ) ) ;
}
lang . lexerrule _pattern _string = lexerrule _pattern _string ;
} ) ( lang = lib _plankton . lang || ( lib _plankton . lang = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : lang « .
Copyright 2016 - 2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : lang « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : lang « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : lang « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var lang ;
( function ( lang ) {
/ *
-- input
[ ( "0 & !0" , — ) ]
-- ws
[ ( "0" , — ) , ( "& !0" , — ) ]
[ ( "0" , — ) , ( "&" , — ) , ( "!0" , — ) ]
-- const
[ ( "0" , < false > ) , ( "&" , — ) , ( "!0" , — ) ]
[ ( "0" , < false > ) , ( "&" , — ) , ( "!" , — ) , ( "0" , < false > ) ]
-- not
[ ( "0" , < false > ) , ( "&" , — ) , ( "!" , < not > ) , ( "0" , < false > ) ]
-- and
[ ( "0" , < false > ) , ( "&" , < and > ) , ( "!" , < not > ) , ( "0" , < false > ) ]
* /
/ * *
* @ author fenris
* /
function lexer _dumb _make ( rules ) {
let observer = lib _observer . make ( ) ;
lib _observer . register ( observer , "start" ) ;
lib _observer . register ( observer , "fail" ) ;
lib _observer . attend ( observer , "start" , ( { "input" : input } ) => {
lib _plankton . log . info ( "lib_plankton.lang:lexer:run:begin" , {
"input" : input ,
} ) ;
} ) ;
lib _observer . attend ( observer , "fail" , ( { "open" : open } ) => {
lib _plankton . log . warning ( "lib_plankton.lang:lexer:run:fail" , {
"sequence" : open . map ( token => String ( token . sequence ) ) ,
} ) ;
} ) ;
return {
"rules" : rules ,
"observer" : observer ,
} ;
}
lang . lexer _dumb _make = lexer _dumb _make ;
/ * *
* @ author fenris
* /
function lexer _dumb _run ( subject , input , configuration = {
"use_reduce" : false ,
} ) {
lib _observer . notify ( subject . observer , "start" , { "input" : input } ) ;
let tokens ;
if ( configuration . use _reduce ) {
tokens = subject . rules . reduce ( ( tokens , rule ) => lang . lexerrule _apply ( rule , tokens ) , [
{
"sequence" : input ,
"terminal" : new class _nothing ( ) ,
}
] ) ;
}
else {
tokens = [
{
"sequence" : input ,
"terminal" : new class _nothing ( ) ,
}
] ;
subject . rules . forEach ( ( rule ) => ( tokens = lang . lexerrule _apply ( rule , tokens ) ) ) ;
}
let open = tokens . filter ( token => token . terminal . is _nothing ( ) ) ;
if ( open . length > 0 ) {
lib _observer . notify ( subject . observer , "fail" , { "open" : open } ) ;
throw ( new Error ( "failed" ) ) ;
}
else {
return tokens . map ( token => token . terminal . cull ( ) ) ;
}
}
lang . lexer _dumb _run = lexer _dumb _run ;
/ * *
* @ author fenris
* /
function lexer _dumb _pass ( ) {
return lexer _dumb _make ( [
lang . lexerrule _pass ( ) ,
] ) ;
}
lang . lexer _dumb _pass = lexer _dumb _pass ;
} ) ( lang = lib _plankton . lang || ( lib _plankton . lang = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : lang « .
Copyright 2016 - 2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : lang « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : lang « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : lang « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var lang ;
( function ( lang ) {
/ * *
* @ author fenris
* /
class class _lexerrule {
/ * *
* @ author fenris
* /
constructor ( subject ) {
this . subject = subject ;
}
/ * *
* @ author fenris
* /
static construct ( { "search" : search , "construct" : construct , } ) {
let subject = lang . lexerrule _make ( search , construct ) ;
return ( new class _lexerrule ( subject ) ) ;
}
/ * *
* @ author fenris
* /
subject _get ( ) {
return this . subject ;
}
/ * *
* @ author fenris
* /
search ( part ) {
return this . subject . search ( part ) ;
}
/ * *
* @ author fenris
* /
construct ( part ) {
return this . subject . construct ( part ) ;
}
/ * *
* @ author fenris
* /
static pass ( ) {
return ( new class _lexerrule ( lang . lexerrule _pass ( ) ) ) ;
}
/ * *
* @ author fenris
* /
static pattern _generic ( rule _raw ) {
return ( new class _lexerrule ( lang . lexerrule _pattern _generic ( rule _raw ) ) ) ;
}
/ * *
* @ author fenris
* /
static pattern _ignore ( pattern ) {
return ( new class _lexerrule ( lang . lexerrule _pattern _ignore ( pattern ) ) ) ;
}
/ * *
* @ author fenris
* /
static pattern _void ( pattern , id ) {
return ( new class _lexerrule ( lang . lexerrule _pattern _void ( pattern , id ) ) ) ;
}
/ * *
* @ author fenris
* /
static pattern _boolean ( pattern , id , value ) {
return ( new class _lexerrule ( lang . lexerrule _pattern _boolean ( pattern , id , value ) ) ) ;
}
/ * *
* @ author fenris
* /
static pattern _int ( pattern , id ) {
return ( new class _lexerrule ( lang . lexerrule _pattern _int ( pattern , id ) ) ) ;
}
/ * *
* @ author fenris
* /
static pattern _float ( pattern , id ) {
return ( new class _lexerrule ( lang . lexerrule _pattern _float ( pattern , id ) ) ) ;
}
/ * *
* @ author fenris
* /
static pattern _string ( pattern , id ) {
return ( new class _lexerrule ( lang . lexerrule _pattern _string ( pattern , id ) ) ) ;
}
}
lang . class _lexerrule = class _lexerrule ;
/ * *
* @ author fenris
* /
class class _lexer _dumb {
/ * *
* @ author fenris
* /
constructor ( subject ) {
this . subject = subject ;
}
/ * *
* @ author fenris
* /
static construct ( rules ) {
const subject = lang . lexer _dumb _make ( rules . map ( rule => rule . subject _get ( ) ) ) ;
return ( new class _lexer _dumb ( subject ) ) ;
}
/ * *
* @ author fenris
* /
run ( input ) {
return lang . lexer _dumb _run ( this . subject , input ) ;
}
/ * *
* @ author fenris
* /
static pass ( ) {
return ( new class _lexer _dumb ( lang . lexer _dumb _pass ( ) ) ) ;
}
}
lang . class _lexer _dumb = class _lexer _dumb ;
} ) ( lang = lib _plankton . lang || ( lib _plankton . lang = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : lang « .
Copyright 2016 - 2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : lang « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : lang « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : lang « . If not , see < http : //www.gnu.org/licenses/>.
* /
/ *
This file is part of » bacterio - plankton : lang « .
Copyright 2016 - 2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : lang « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : lang « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : lang « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var lang ;
( function ( lang ) {
/ * *
* @ desc [ constructor ]
* @ author fenris
* /
function parserrule _make ( { "premise" : premise , "conclusion" : conclusion , "construct" : construct , "right_to_left" : right _to _left = false , } ) {
return {
"premise" : premise ,
"conclusion" : conclusion ,
"construct" : construct ,
"right_to_left" : right _to _left ,
} ;
}
lang . parserrule _make = parserrule _make ;
/ * *
* @ author fenris
* /
function parserrule _check ( parserrule , sequence ) {
let position = lang . find ( sequence , parserrule . conclusion , ( x , y ) => x . equals ( y ) , parserrule . right _to _left ) ;
return position ;
}
lang . parserrule _check = parserrule _check ;
/ * *
* @ author fenris
* /
function parserrule _construct ( parserrule , args , terminals ) {
return parserrule . construct ( args , terminals ) ;
}
lang . parserrule _construct = parserrule _construct ;
} ) ( lang = lib _plankton . lang || ( lib _plankton . lang = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : lang « .
Copyright 2016 - 2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : lang « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : lang « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : lang « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var lang ;
( function ( lang ) {
/ * *
* @ author fenris
* /
function parser _dumb _make ( start , rules , equality _terminal = ( ( x , y ) => ( x == y ) ) ) {
let observer = lib _observer . make ( ) ;
lib _observer . register ( observer , "start" ) ;
lib _observer . register ( observer , "message_sequence" ) ;
lib _observer . register ( observer , "use_rule" ) ;
lib _observer . register ( observer , "fail" ) ;
lib _observer . attend ( observer , "start" , ( { "input" : input } ) => {
lib _plankton . log . info ( "lib_plankton.lang:parser:run:begin" , {
"input" : input
} ) ;
} ) ;
lib _observer . attend ( observer , "message_sequence" , ( { "sequence" : sequence } ) => {
lib _plankton . log . debug ( "lib_plankton.lang:parser:run:current_sequence" , {
"tokens" : sequence ,
} ) ;
} ) ;
lib _observer . attend ( observer , "use_rule" , ( { "rule" : rule , "conclusion" : conclusion } ) => {
lib _plankton . log . debug ( "lib_plankton.lang:parser:run:using_the_following_rule" , {
"conclusion" : conclusion . map ( symbol => symbol . toString ( ) ) ,
"premise" : rule . premise . toString ( ) ,
} ) ;
} ) ;
lib _observer . attend ( observer , "fail" , ( { "sequence" : sequence } ) => {
lib _plankton . log . error ( "lib_plankton.lang:parser:run:failed" , {
"last_sequence" : sequence ,
} ) ;
} ) ;
return {
"start" : start ,
"rules" : rules ,
"equality_terminal" : equality _terminal ,
"observer" : observer ,
} ;
}
lang . parser _dumb _make = parser _dumb _make ;
/ * *
* @ override
* @ author fenris
* /
function parser _dumb _run ( parser _dumb , input , target _variable ) {
if ( target _variable === undefined ) {
target _variable = parser _dumb . start ;
}
lib _observer . notify ( parser _dumb . observer , "start" , { "input" : input } ) ;
let maximum = ( 1 << 10 ) ;
let current = ( input
. map ( ( terminal ) => {
return ( new lang . class _symbol _terminal ( terminal , parser _dumb . equality _terminal ) ) ;
} ) ) ;
while ( true ) {
lib _observer . notify ( parser _dumb . observer , "message_sequence" , { "sequence" : current } ) ;
if ( maximum -- <= 0 ) {
break ;
}
const found = parser _dumb . rules . some ( function ( rule , index ) {
let conclusion = rule . conclusion ;
let position = lang . parserrule _check ( rule , current ) ;
if ( position >= 0 ) {
lib _observer . notify ( parser _dumb . observer , "use_rule" , { "rule" : rule , "conclusion" : conclusion } ) ;
let terminals = ( current
. slice ( position , position + conclusion . length )
. filter ( x => ( x instanceof lang . class _symbol _terminal /*<type_terminal, type_variable, type_meaning>*/ ) )
. map ( element => ( element ) . terminal _get ( ) ) ) ;
let args = ( current
. slice ( position , position + conclusion . length )
. filter ( x => ( x instanceof lang . class _symbol _variable /*<type_terminal, type_variable, type_meaning>*/ ) )
. map ( element => ( element ) . meaning _get ( ) ) ) ;
let meaning = rule . construct ( args , terminals ) ;
let symbol = ( new lang . class _symbol _variable ( rule . premise , meaning ) ) ;
current = ( [ ]
. concat ( current . slice ( 0 , position ) )
. concat ( [ symbol ] )
. concat ( current . slice ( position + conclusion . length ) ) ) ;
return true ;
}
else {
return false ;
}
} ) ;
if ( ! found ) {
break ;
}
}
if ( ( current . length == 1 )
&&
( current [ 0 ] instanceof lang . class _symbol _variable /*<type_terminal, type_variable, type_meaning>*/ )
&&
( ( current [ 0 ] ) . variable _get ( ) === target _variable ) ) {
return ( current [ 0 ] ) . meaning _get ( ) ;
}
else {
lib _observer . notify ( parser _dumb . observer , "fail" , { "sequence" : current } ) ;
/ *
console . warn ( "--" , "parsing failed" ) ;
console . info ( "--" , "last sequence was:" ) ; current . forEach ( element => console . info ( element ) ) ;
* /
// return null;
throw ( new Error ( "parsing failed" ) ) ;
}
}
lang . parser _dumb _run = parser _dumb _run ;
/ * *
* @ author fenris
* /
function parser _dumb _tree ( start , rules _raw , equality _terminal = ( ( x , y ) => ( x == y ) ) ) {
return ( parser _dumb _make ( start , rules _raw . map ( ( rule _raw ) => {
return ( lang . parserrule _make ( {
"premise" : rule _raw . premise ,
"conclusion" : rule _raw . conclusion ,
"construct" : ( args , tokens ) => {
return {
"label" : rule _raw . label ,
"value" : tokens ,
"children" : args ,
} ;
} ,
"right_to_left" : rule _raw . right _to _left ,
} ) ) ;
} ) , equality _terminal ) ) ;
}
lang . parser _dumb _tree = parser _dumb _tree ;
} ) ( lang = lib _plankton . lang || ( lib _plankton . lang = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : lang « .
Copyright 2016 - 2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : lang « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : lang « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : lang « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var lang ;
( function ( lang ) {
/ * *
* @ author fenris
* /
class class _parserrule {
/ * *
* @ desc [ constructor ]
* @ author fenris
* /
constructor ( subject ) {
this . subject = subject ;
}
/ * *
* @ desc [ constructor ]
* @ author fenris
* /
static construct ( { "premise" : premise , "conclusion" : conclusion , "construct" : construct , "right_to_left" : right _to _left = false , } ) {
return ( new class _parserrule ( {
"premise" : premise ,
"conclusion" : conclusion ,
"construct" : construct ,
"right_to_left" : right _to _left ,
} ) ) ;
}
/ * *
* @ desc [ accessor ] [ getter ]
* @ author fenris
* /
subject _get ( ) {
return this . subject ;
}
/ * *
* @ desc [ accessor ] [ getter ]
* @ author fenris
* /
premise _get ( ) {
return this . subject . premise ;
}
/ * *
* @ desc [ accessor ] [ getter ]
* @ author fenris
* /
conclusion _get ( ) {
return this . subject . conclusion ;
}
/ * *
* @ desc [ accessor ]
* @ author fenris
* /
check ( sequence ) {
return ( lang . parserrule _check ( this . subject , sequence ) ) ;
}
/ * *
* @ desc [ accessor ]
* @ author fenris
* /
construct ( args , terminals ) {
return ( lang . parserrule _construct ( this . subject , args , terminals ) ) ;
}
}
lang . class _parserrule = class _parserrule ;
/ * *
* @ author fenris
* @ todo fatal error on empty conclusion
* /
class class _parser _dumb {
/ * *
* @ author fenris
* /
constructor ( subject ) {
this . subject = subject ;
}
/ * *
* @ author fenris
* /
static construct ( start , rules , equality _terminal = ( ( x , y ) => ( x == y ) ) ) {
const subject = lang . parser _dumb _make ( start , rules . map ( rule => rule . subject _get ( ) ) , equality _terminal ) ;
return ( new class _parser _dumb ( subject ) ) ;
}
/ * *
* @ override
* @ author fenris
* /
run ( input , target _variable ) {
return lang . parser _dumb _run ( this . subject , input , target _variable ) ;
}
/ * *
* @ author fenris
* /
static tree ( start , rules _raw , equality _terminal = ( ( x , y ) => ( x == y ) ) ) {
return ( new class _parser _dumb ( lang . parser _dumb _tree ( start , rules _raw , equality _terminal ) ) ) ;
}
}
lang . class _parser _dumb = class _parser _dumb ;
} ) ( lang = lib _plankton . lang || ( lib _plankton . lang = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : lang « .
Copyright 2016 - 2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : lang « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : lang « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : lang « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var lang ;
( function ( lang ) {
/ * *
* @ author fenris
* /
function reader _run ( lexer _run , parser _run , input , target _variable ) {
const syntax = lexer _run ( input ) ;
lib _plankton . log . info ( "lib_plankton.lang:reader:syntax" , {
"syntax" : syntax ,
} ) ;
const semantics = parser _run ( syntax , target _variable ) ;
lib _plankton . log . info ( "lib_plankton.lang:reader:semantics" , {
"semantics" : semantics ,
} ) ;
return semantics ;
}
lang . reader _run = reader _run ;
/ * *
* @ author fenris
* /
function reader _default ( { "lexer_rules" : lexer _rules , "parser_start" : parser _start , "parser_rules" : parser _rules , } ) {
return ( new lib _plankton . lang . class _reader ( lang . class _lexer _dumb . construct ( lexer _rules ) , lang . class _parser _dumb . tree ( parser _start , parser _rules , ( x , y ) => ( x . id == y . id ) ) ) ) ;
}
lang . reader _default = reader _default ;
/ * *
* @ author fenris
* /
2022-03-20 21:42:17 +01:00
function default _raw _v1 ( { "lexer_rules" : lexer _rules , "parser_start" : parser _start , "parser_rules" : parser _rules , } ) {
return ( reader _default ( {
2021-09-19 01:14:32 +02:00
"lexer_rules" : lexer _rules . map ( ( lexerrule _raw ) => {
switch ( lexerrule _raw . type ) {
case "ignore" : {
return lang . class _lexerrule . pattern _ignore ( lexerrule _raw . parameters [ "pattern" ] ) ;
break ;
}
case "void" : {
return lang . class _lexerrule . pattern _void ( lexerrule _raw . parameters [ "pattern" ] , lexerrule _raw . parameters [ "id" ] ) ;
break ;
}
case "boolean" : {
return lang . class _lexerrule . pattern _boolean ( lexerrule _raw . parameters [ "pattern" ] , lexerrule _raw . parameters [ "id" ] , lexerrule _raw . parameters [ "value" ] ) ;
break ;
}
case "int" : {
return lang . class _lexerrule . pattern _int ( lexerrule _raw . parameters [ "pattern" ] , lexerrule _raw . parameters [ "id" ] ) ;
break ;
}
case "float" : {
return lang . class _lexerrule . pattern _float ( lexerrule _raw . parameters [ "pattern" ] , lexerrule _raw . parameters [ "id" ] ) ;
break ;
}
case "string" : {
return lang . class _lexerrule . pattern _string ( lexerrule _raw . parameters [ "pattern" ] , lexerrule _raw . parameters [ "id" ] ) ;
break ;
}
default : {
throw ( new Error ( ` unhandled type for raw lexer-rule ' ${ lexerrule _raw . type } ' ` ) ) ;
break ;
}
}
} ) ,
"parser_start" : parser _start ,
"parser_rules" : parser _rules . map ( ( parserrule _raw ) => {
return ( {
"label" : parserrule _raw . label ,
"premise" : parserrule _raw . premise ,
"conclusion" : parserrule _raw . conclusion . map ( entry => {
switch ( entry . type ) {
case "terminal" : {
return ( new lib _plankton . lang . class _symbol _terminal ( { "id" : entry . parameters [ "id" ] } ) ) ;
break ;
}
case "variable" : {
return ( new lib _plankton . lang . class _symbol _variable ( entry . parameters [ "id" ] ) ) ;
break ;
}
default : {
throw ( new Error ( ` unhandled type for raw parser-rule ' ${ entry . type } ' ` ) ) ;
break ;
}
}
} ) ,
"right_to_left" : parserrule _raw . right _to _left ,
} ) ;
} ) ,
} ) ) ;
}
2022-03-20 21:42:17 +01:00
/ * *
* @ author fenris
* /
function default _raw _v2 ( { "lexer_rules" : lexer _rules , "parser_start" : parser _start , "parser_rules" : parser _rules , } ) {
return default _raw _v1 ( {
"lexer_rules" : lexer _rules . map ( ( rule ) => {
if ( rule [ "name" ] === null ) {
return {
"type" : "ignore" ,
"parameters" : {
"pattern" : rule [ "pattern" ] ,
}
} ;
}
else {
return {
"type" : ( ( rule [ "pass" ] === true )
? "string"
: "void" ) ,
"parameters" : {
"pattern" : rule [ "pattern" ] ,
"id" : rule [ "name" ] ,
}
} ;
}
} ) ,
"parser_start" : parser _start ,
"parser_rules" : parser _rules ,
} ) ;
}
/ * *
* @ author fenris
* /
function default _raw ( input ) {
switch ( input [ "version" ] ) {
default :
case "1" :
{
return default _raw _v1 ( input ) ;
break ;
}
case "2" :
{
return default _raw _v2 ( input ) ;
break ;
}
}
}
2021-09-19 01:14:32 +02:00
lang . default _raw = default _raw ;
} ) ( lang = lib _plankton . lang || ( lib _plankton . lang = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : lang « .
Copyright 2016 - 2021 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : lang « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : lang « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : lang « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var lang ;
( function ( lang ) {
/ * *
* @ author fenris
* /
class class _reader {
/ * *
* @ author fenris
* /
constructor ( lexer , parser ) {
this . lexer = lexer ;
this . parser = parser ;
}
/ * *
* @ desc [ accessor ] yes , it ' s really just lexing and parsing
* @ author fenris
* /
run ( input , target _variable ) {
/ *
const syntax : Array < type _terminal > = this . lexer . run ( input ) ;
lib _plankton . log . info (
"lang:reader:syntax" ,
{
"syntax" : syntax ,
}
) ;
const semantics : type _result = this . parser . run ( syntax , target _variable ) ;
lib _plankton . log . info (
"lang:reader:semantics" ,
{
"semantics" : semantics ,
}
) ;
return semantics ;
* /
return lang . reader _run ( ( input ) => this . lexer . run ( input ) , ( input , target _variable ) => this . parser . run ( input , target _variable ) , input , target _variable ) ;
}
/ * *
* @ author fenris
* /
static default ( { "lexer_rules" : lexer _rules , "parser_start" : parser _start , "parser_rules" : parser _rules , } ) {
return ( new lib _plankton . lang . class _reader ( lang . class _lexer _dumb . construct ( lexer _rules ) , lang . class _parser _dumb . tree ( parser _start , parser _rules , ( x , y ) => ( x . id == y . id ) ) ) ) ;
}
/ * *
* @ author fenris
* /
2022-03-20 21:42:17 +01:00
static default _raw ( input ) {
return lang . default _raw ( input ) ;
2021-09-19 01:14:32 +02:00
}
}
lang . class _reader = class _reader ;
} ) ( lang = lib _plankton . lang || ( lib _plankton . lang = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;