0
0
This repository has been archived on 2024-05-25. You can view files and clone it, but cannot push or open issues or pull requests.
legacy-code/juicescript.js

96 lines
1.8 KiB
JavaScript
Raw Normal View History

2022-09-01 19:05:37 +02:00
/*! Juicescript.js v1.0.0-a | (c) DrMaxNix 2022 | juice.drmaxnix.de */
2022-09-01 17:45:31 +02:00
2022-09-06 13:34:32 +02:00
/////////////////////////
// M A I N C L A S S //
/////////////////////////
2022-09-01 17:45:31 +02:00
class Juicescript {
/*
CONSTRUCTOR: Return new juicescript parser with OPTIONS
*/
constructor(options){
// STORE CALLBACKS //
// save
if(options.callback !== undefined){
this.callback = options.callback;
}
// check if all have been set
if(!(this.callback.stdout instanceof Function)){
throw "invalid stdout callback";
}
if(!(this.callback.stderr instanceof Function)){
throw "invalid stderr callback";
}
2022-09-06 13:34:32 +02:00
// GET IO ADAPTER //
this.io = new Juicescript_io(this.callback);
2022-09-01 17:45:31 +02:00
}
2022-09-01 19:31:19 +02:00
/*
Parse given PROGRAM-STRING and store syntax tree
*/
parse(program_string){
2022-09-06 13:34:32 +02:00
2022-09-01 19:31:19 +02:00
}
2022-09-01 17:45:31 +02:00
2022-09-01 19:31:19 +02:00
// DEBUG STUFFS //
2022-09-01 17:45:31 +02:00
run(){
2022-09-06 13:34:32 +02:00
this.io.stdout("stdout text");
this.io.stderr.debug("This debug is a test");
this.io.stderr.info("This info is a test");
this.io.stderr.warning("This warning is a test");
this.io.stderr.error("This error is a test");
}
}
/////////////////////////////////
// I N P U T / O U T P U T //
/////////////////////////////////
class Juicescript_io {
/*
CONSTRUCTOR: Return new juicescript io adapter with CALLBACKs
*/
constructor(callback){
// store callbacks
this.callback = callback;
2022-09-01 17:45:31 +02:00
}
2022-09-06 13:34:32 +02:00
/*
HELPER: Stdout method
*/
stdout(text){
2022-09-01 17:45:31 +02:00
this.callback.stdout(text);
}
2022-09-06 13:34:32 +02:00
/*
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");
}
}
2022-09-01 17:45:31 +02:00
}
}