Post public code/Raw

Used in Post public code. // Read and parse entered code const fs = require("fs");

const code = fs.readFileSync("code.txt").toString.split("\n");

// Variables var out = []; var logs = []; var d = ""; var olr = []; var mtr = [];

var params = []; var module = ""; var command = ""; var params = [];

const posmodules = [ "sys", ] // Preinstalled modules var installed = [ "sys", ]; // Configs const displayerrors = true;

// General functions function log(msg) { d = new Date; logs.push(`${d.getHours}:${d.getMinutes}:${d.getSeconds}: ${msg}`); }

function push(msg) { // out.push(msg); console.log(msg); log(`Added text ${msg} into output prompt.`); }

function dispLines { push("---"); log("Displayed some lines with displiens.") }

function error(msg) { if (displayerrors) { dispLines; push(`Error at line ${i + 1}:\n ${msg}`); log(`ERROR at line ${i + 1}: ${msg}`); dispLines; } }

// Operator helper functions function getType(msg) { if (msg == "none" || msg == "NN") { return "none"; } else if (msg.startsWith("\"") && msg.endsWith("\"")) { return "str"; } else if (msg.startsWith("'") && msg.endsWith("'")) { return "varInput"; } else if (isNaN(msg)) { return "invalid"; } else { return "int"; } }

function remvStrQuotes(msg) { return msg.substring(1,msg.length - 1); }

function requiresParams(params,params2,params3) { return "Coming soon! Sorry." }

// Single-line code function runOneLine(cur) { olr = []; if (cur.replace(" ","").length < 1) { log("Blank line has been passed over.") } else if (cur.startsWith("#")) { log("Comment has been passed over.") } else if (cur.replace(" ","").includes(".")) { params = cur.split("."); module = params[0]; command = params[1]; params.shift; params.shift; log(`Module of this line is ${module}, and command is ${command}. Length of params is ${params.length}.`)

if (installed.includes(module)) { if (module == "sys") { if (command == "print") { if (getType(params[0]) == "str") { push(remvStrQuotes(params[0])); } else if (getType(params[0]) != "varInput") { error(`Positional parameter "1" of sys.print must be type str, not the given ${getType(params[0])}`) }       } else if (command == "print-checktype") { push(`${params[0]} is a ${getType(params[0])}`); } else if (command == "clearmlr") { mlr = []; }     }    } else if (posmodules.includes(module)) { error(`Module "${module}" is not installed.`); } else { error(`Module "${module}" is not installed and doesn't exist.`); } } else { error("Unexpected undotted command."); } }

// Introduction text dispLines push("Welcome to the Post (PostOnJS) compiler! Post is a simple but extensive programming language built on top many programming languages. This one, Post, is built on top of JavaScript.") dispLines push("To enter in code for Post to execute, go inside this repl's code, click on the code.txt file, and edit the text there. Then, click Run, and watch your code get ran by Post!") dispLines push("You may also go to docs.md inside the repl's files to see the official documentation of Post. That's it!") dispLines push("The output of the code entered into code.txt is shown below.") dispLines

// Main loop for (i = 0; i < code.length; i++) { runOneLine(code[i]); } dispLines