🎨 move io to own class
This commit is contained in:
parent
e9c448f56f
commit
2db86a2c4f
@ -1,5 +1,9 @@
|
|||||||
/*! Juicescript.js v1.0.0-a | (c) DrMaxNix 2022 | juice.drmaxnix.de */
|
/*! Juicescript.js v1.0.0-a | (c) DrMaxNix 2022 | juice.drmaxnix.de */
|
||||||
|
|
||||||
|
/////////////////////////
|
||||||
|
// M A I N C L A S S //
|
||||||
|
/////////////////////////
|
||||||
|
|
||||||
class Juicescript {
|
class Juicescript {
|
||||||
/*
|
/*
|
||||||
CONSTRUCTOR: Return new juicescript parser with OPTIONS
|
CONSTRUCTOR: Return new juicescript parser with OPTIONS
|
||||||
@ -18,15 +22,17 @@ class Juicescript {
|
|||||||
if(!(this.callback.stderr instanceof Function)){
|
if(!(this.callback.stderr instanceof Function)){
|
||||||
throw "invalid stderr callback";
|
throw "invalid stderr callback";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// GET IO ADAPTER //
|
||||||
|
this.io = new Juicescript_io(this.callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Parse given PROGRAM-STRING and store syntax tree
|
Parse given PROGRAM-STRING and store syntax tree
|
||||||
*/
|
*/
|
||||||
parse(program_string){
|
parse(program_string){
|
||||||
// DEVIDE INTO LINES //
|
|
||||||
var line_list = program_string.split("\n");
|
|
||||||
/**/console.log(line_list);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -35,30 +41,55 @@ class Juicescript {
|
|||||||
|
|
||||||
// DEBUG STUFFS //
|
// DEBUG STUFFS //
|
||||||
run(){
|
run(){
|
||||||
//this.io_stdout("stdout text");
|
this.io.stdout("stdout text");
|
||||||
//this.io_stderr_debug("This debug is a test");
|
this.io.stderr.debug("This debug is a test");
|
||||||
//this.io_stderr_info("This info is a test");
|
this.io.stderr.info("This info is a test");
|
||||||
//this.io_stderr_warning("This warning is a test");
|
this.io.stderr.warning("This warning is a test");
|
||||||
//this.io_stderr_error("This error is a test");
|
this.io.stderr.error("This error is a test");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
io_stdout(text){
|
|
||||||
this.callback.stdout(text);
|
/////////////////////////////////
|
||||||
}
|
// I N P U T / O U T P U T //
|
||||||
io_stderr_debug(text){
|
/////////////////////////////////
|
||||||
this.callback.stderr("[DEBUG] " + text, "debug");
|
|
||||||
}
|
class Juicescript_io {
|
||||||
io_stderr_info(text){
|
/*
|
||||||
this.callback.stderr("[INFO ] " + text, "info");
|
CONSTRUCTOR: Return new juicescript io adapter with CALLBACKs
|
||||||
}
|
*/
|
||||||
io_stderr_warning(text){
|
constructor(callback){
|
||||||
this.callback.stderr("[WARN ] " + text, "warning");
|
// store callbacks
|
||||||
}
|
this.callback = callback;
|
||||||
io_stderr_error(text){
|
}
|
||||||
this.callback.stderr("[ERROR] " + text, "error");
|
|
||||||
|
/*
|
||||||
|
HELPER: Stdout method
|
||||||
|
*/
|
||||||
|
stdout(text){
|
||||||
|
this.callback.stdout(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
GETTER: Return stderr method collection
|
||||||
|
*/
|
||||||
|
get stderr(){
|
||||||
|
return {
|
||||||
|
debug: (text) => {
|
||||||
|
this.callback.stderr("[DEBUG] " + text, "debug");
|
||||||
|
},
|
||||||
|
info: (text) => {
|
||||||
|
this.callback.stderr("[INFO ] " + text, "info");
|
||||||
|
},
|
||||||
|
warning: (text) => {
|
||||||
|
this.callback.stderr("[WARN ] " + text, "warning");
|
||||||
|
},
|
||||||
|
error: (text) => {
|
||||||
|
this.callback.stderr("[ERROR] " + text, "error");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user