diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..ba7d7e0 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,4 @@ +/docs +.vscode +.github +/node_modules diff --git a/package.json b/package.json index 8c9162f..f878540 100644 --- a/package.json +++ b/package.json @@ -9,8 +9,8 @@ "test": "jest", "coverage": "node_modules/.bin/jest --coverage", "link": "npm link", - "lint": "eslint ./ --color", - "lint:fix": "eslint ./ --fix" + "lint": "eslint ./src --color", + "lint:fix": "eslint ./src --fix" }, "devDependencies": { "eslint": "5.9.0", diff --git a/src/environment.js b/src/environment.js index 9bdadc8..96a0ed1 100644 --- a/src/environment.js +++ b/src/environment.js @@ -1,13 +1,12 @@ const helperIseDeclarations = require("./helperise/registeredHelperIse.js"); class Environment { - - constructor() { + constructor () { this.vars = {}; this.iseDeclarations = {}; } - setJeki(scope, name, value) { + setJeki (scope, name, value) { if (this.vars[scope] == undefined) { this.vars[scope] = {}; } @@ -15,12 +14,11 @@ class Environment { this.vars[scope][name] = value; } - getJeki(scope, name) { - if (this.vars[scope] != undefined) - return this.vars[scope][name]; + getJeki (scope, name) { + if (this.vars[scope] != undefined) { return this.vars[scope][name]; } } - setIse(scope, iseName, iseNode) { + setIse (scope, iseName, iseNode) { if (this.iseDeclarations[scope] == undefined) { this.iseDeclarations[scope] = {}; } @@ -28,25 +26,25 @@ class Environment { this.iseDeclarations[scope][iseName] = iseNode; } - getIse(scope, iseName) { + getIse (scope, iseName) { if (this.iseDeclarations[scope] != undefined) { return this.iseDeclarations[scope][iseName]; } } - isExistHelperIse(iseName) { + isExistHelperIse (iseName) { return helperIseDeclarations[iseName] != undefined; } - runHelperIse(iseName, iseArgs) { + runHelperIse (iseName, iseArgs) { if (this.isExistHelperIse(iseName)) { return helperIseDeclarations[iseName](iseArgs); } } - sope(value) { + sope (value) { console.log(value); } } -module.exports = Environment; \ No newline at end of file +module.exports = Environment; diff --git a/src/helperise/array_helpers/ka.js b/src/helperise/array_helpers/ka.js index aa98fb9..d967b3b 100644 --- a/src/helperise/array_helpers/ka.js +++ b/src/helperise/array_helpers/ka.js @@ -1,13 +1,13 @@ -//Get array length -function ka(args) { +// Get array length +function ka (args) { if (args instanceof Array) { - const [param] = args; + const [param, ] = args; if (param instanceof Array) return param.length; - throw new Error (`Invalid param given to helper ise ka.`); - } - - throw new Error('Yorlang system error'); + throw new Error("Invalid param given to helper ise ka."); + } + + throw new Error("Yorlang system error"); } -module.exports = ka; \ No newline at end of file +module.exports = ka; diff --git a/src/helperise/input_output/tesibi.js b/src/helperise/input_output/tesibi.js index 57760c7..5f6d668 100644 --- a/src/helperise/input_output/tesibi.js +++ b/src/helperise/input_output/tesibi.js @@ -1,18 +1,18 @@ -const readlineSync = require('readline-sync'); +const readlineSync = require("readline-sync"); -//Takes command line input -function teSibi(args) { +// Takes command line input +function teSibi (args) { if (args instanceof Array) { - const [param] = args; - if (typeof param === "string"){ + const [param, ] = args; + if (typeof param === "string") { const input = readlineSync.question(param); return parseFloat(input) || input; - } + } - throw new Error (`Invalid param given to helper ise teSibi.`); - } - - throw new Error('Yorlang system error'); + throw new Error("Invalid param given to helper ise teSibi."); + } + + throw new Error("Yorlang system error"); } -module.exports = teSibi; \ No newline at end of file +module.exports = teSibi; diff --git a/src/helperise/registeredHelperIse.js b/src/helperise/registeredHelperIse.js index 8e4a57a..cf54ce7 100644 --- a/src/helperise/registeredHelperIse.js +++ b/src/helperise/registeredHelperIse.js @@ -4,4 +4,4 @@ helperIseDeclarations["siLetaNla"] = require("./string_helpers/si_leta_nla.js"); helperIseDeclarations["siLetaKekere"] = require("./string_helpers/si_leta_kekere.js"); helperIseDeclarations["teSibi"] = require("./input_output/tesibi.js"); -module.exports = helperIseDeclarations; \ No newline at end of file +module.exports = helperIseDeclarations; diff --git a/src/helperise/string_helpers/si_leta_kekere.js b/src/helperise/string_helpers/si_leta_kekere.js index 7fbeda8..6ff2acf 100644 --- a/src/helperise/string_helpers/si_leta_kekere.js +++ b/src/helperise/string_helpers/si_leta_kekere.js @@ -1,13 +1,13 @@ -//Convert String to lower case -function siLetaKekere(args) { +// Convert String to lower case +function siLetaKekere (args) { if (args instanceof Array) { - const [param] = args; + const [param, ] = args; if (typeof param === "string") return param.toLowerCase(); - throw new Error (`Invalid param given to helper ise síLẹ́tàkékeré.`); - } - - throw new Error('Yorlang system error'); + throw new Error("Invalid param given to helper ise síLẹ́tàkékeré."); + } + + throw new Error("Yorlang system error"); } -module.exports = siLetaKekere; \ No newline at end of file +module.exports = siLetaKekere; diff --git a/src/helperise/string_helpers/si_leta_nla.js b/src/helperise/string_helpers/si_leta_nla.js index b5d04f9..020ec05 100644 --- a/src/helperise/string_helpers/si_leta_nla.js +++ b/src/helperise/string_helpers/si_leta_nla.js @@ -1,13 +1,13 @@ -//Convert String to upper case -function siLetaNla(args) { +// Convert String to upper case +function siLetaNla (args) { if (args instanceof Array) { - const [param] = args; + const [param, ] = args; if (typeof param === "string") return param.toUpperCase(); - throw new Error (`Invalid param given to helper ise síLẹ́tàŃlá.`); - } - - throw new Error('Yorlang system error'); + throw new Error("Invalid param given to helper ise síLẹ́tàŃlá."); + } + + throw new Error("Yorlang system error"); } -module.exports = siLetaNla; \ No newline at end of file +module.exports = siLetaNla; diff --git a/src/inputstream.js b/src/inputstream.js index bd370d8..431eb0f 100644 --- a/src/inputstream.js +++ b/src/inputstream.js @@ -2,8 +2,7 @@ const constants = require("./constants.js"); const fs = require("fs"); class InputStream { - - constructor(fileName) { + constructor (fileName) { this.code = this.readProgramFile(fileName); this.line = 1; this.column = 0; @@ -11,18 +10,18 @@ class InputStream { this.yorlangFileName = fileName; } - readProgramFile(fileName) { + readProgramFile (fileName) { try { - return fs.readFileSync(process.cwd() +"/"+ fileName, 'utf8'); + return fs.readFileSync(process.cwd() + "/" + fileName, "utf8"); } catch (e) { throw new Error(`Could not read file: ${fileName}`); } } - //return the next value and also discard it from the stream - next() { + // return the next value and also discard it from the stream + next () { const character = this.code.charAt(this.position++); - + if (character === constants.SYM.NEW_LINE) { this.column = 0; this.line++; } else { @@ -32,22 +31,22 @@ class InputStream { return character; } - //return the next value without discarding it from the stream - peek() { + // return the next value without discarding it from the stream + peek () { return this.code.charAt(this.position); } - throwError(msg) { + throwError (msg) { throw new Error(`There's an error at line ${this.line} near column ${this.column} in file ${this.yorlangFileName} :\n ${msg}`); } - isEndOfFile() { + isEndOfFile () { return this.peek() == ""; } - isNotEndOfFile() { + isNotEndOfFile () { return this.peek() != ""; } } -module.exports = InputStream; \ No newline at end of file +module.exports = InputStream; diff --git a/src/interpreters/helpers/woke_helper.js b/src/interpreters/helpers/woke_helper.js index adf4131..5af8ede 100644 --- a/src/interpreters/helpers/woke_helper.js +++ b/src/interpreters/helpers/woke_helper.js @@ -1,10 +1,10 @@ const constants = require("../../constants.js"); -class WokeHelper { - static isWokeVariable(context, tiName) { +class WokeHelper { + static isWokeVariable (context, tiName) { const wokeList = context.environment().getJeki(context.getCurrentScope(), constants.KW.WOKE); return wokeList != undefined && wokeList.indexOf(tiName) != -1; } } -module.exports = WokeHelper; \ No newline at end of file +module.exports = WokeHelper; diff --git a/src/interpreters/ibase.js b/src/interpreters/ibase.js index 045879d..2ce5ee3 100644 --- a/src/interpreters/ibase.js +++ b/src/interpreters/ibase.js @@ -1,14 +1,13 @@ class IBase { - - constructor() { + constructor () { if (this.constructor == IBase) { throw new Error("Cannot instantiate abstract class IBase"); } } - interpreteNode(node) { - throw new Error(`Class of type IBase must implement interpreteNode()`); + interpreteNode (node) { + throw new Error("Class of type IBase must implement interpreteNode()"); } } -module.exports = IBase; \ No newline at end of file +module.exports = IBase; diff --git a/src/interpreters/inodeand.js b/src/interpreters/inodeand.js index f9e9a3c..dc20321 100644 --- a/src/interpreters/inodeand.js +++ b/src/interpreters/inodeand.js @@ -2,11 +2,10 @@ const IBase = require("./ibase.js"); const constants = require("../constants.js"); class INodeAnd extends IBase { - - interpreteNode(node) { + interpreteNode (node) { return this.evaluateNode(node.left) !== constants.KW.IRO && this.evaluateNode(node.right) !== constants.KW.IRO - ? constants.KW.OOTO : constants.KW.IRO; + ? constants.KW.OOTO : constants.KW.IRO; } } -module.exports = new INodeAnd(); \ No newline at end of file +module.exports = new INodeAnd(); diff --git a/src/interpreters/inodearray.js b/src/interpreters/inodearray.js index 238f256..80cb7e0 100644 --- a/src/interpreters/inodearray.js +++ b/src/interpreters/inodearray.js @@ -1,7 +1,6 @@ const IBase = require("./ibase.js"); class INodeArray extends IBase { - - interpreteNode(arrayNode) { + interpreteNode (arrayNode) { const arr = []; arrayNode.body.forEach(arrayItemNode => { @@ -12,4 +11,4 @@ class INodeArray extends IBase { } } -module.exports = new INodeArray(); \ No newline at end of file +module.exports = new INodeArray(); diff --git a/src/interpreters/inodearrayelem.js b/src/interpreters/inodearrayelem.js index 5fe88d8..8ebab93 100644 --- a/src/interpreters/inodearrayelem.js +++ b/src/interpreters/inodearrayelem.js @@ -2,21 +2,20 @@ const IBase = require("./ibase.js"); const contansts = require("../constants.js"); class INodeArrayElement extends IBase { - - interpreteNode(node) { - const jekiNode = {name: node.name, operation: contansts.GET_JEKI} + interpreteNode (node) { + const jekiNode = { name: node.name, operation: contansts.GET_JEKI, }; const arrayLiteral = this.evaluateNode(jekiNode); - + return INodeArrayElement.getArrayElement(this, node, arrayLiteral); } - static getArrayElement(context, node, arrayLiteral) { - let arrayElement, isOnedimensionalArray = true; + static getArrayElement (context, node, arrayLiteral) { + let arrayElement; let isOnedimensionalArray = true; - node.indexNodes.map(indexNode => { //if this callback run more than once, then the array is multi-dimensional + node.indexNodes.map(indexNode => { // if this callback run more than once, then the array is multi-dimensional const index = context.evaluateNode(indexNode); - if (typeof index == "number") { + if (typeof index === "number") { arrayElement = (isOnedimensionalArray) ? arrayLiteral[index] : arrayElement[index]; isOnedimensionalArray = false; } else { @@ -30,4 +29,4 @@ class INodeArrayElement extends IBase { } } -module.exports = new INodeArrayElement(); \ No newline at end of file +module.exports = new INodeArrayElement(); diff --git a/src/interpreters/inodecallise.js b/src/interpreters/inodecallise.js index 41fb064..7bc4ff4 100644 --- a/src/interpreters/inodecallise.js +++ b/src/interpreters/inodecallise.js @@ -2,26 +2,24 @@ const IBase = require("./ibase.js"); const constants = require("../constants.js"); class INodeCallIse extends IBase { - - interpreteNode(node) { + interpreteNode (node) { const iseNode = INodeCallIse.getIseNode(this, node.name); if (iseNode == null) { - if (this.environment().isExistHelperIse(node.name)) - return this.environment().runHelperIse(node.name, INodeCallIse.getIseHelperParams(this, node.paramValues)); - - this.throwError(`Ise ${node.name} is undefined`) + if (this.environment().isExistHelperIse(node.name)) { return this.environment().runHelperIse(node.name, INodeCallIse.getIseHelperParams(this, node.paramValues)); } + + this.throwError(`Ise ${node.name} is undefined`); } this.pushToScopeStack(iseNode.name); INodeCallIse.setIseNodeParam(this, iseNode.paramTokens, node.paramValues); - const returnedValue = INodeCallIse.runIseNodeBody(this, iseNode.body); + const returnedValue = INodeCallIse.runIseNodeBody(this, iseNode.body); this.popFromScopeStack(); - return returnedValue; //return the value that is returned by an encountered pada statement within an ise body + return returnedValue; // return the value that is returned by an encountered pada statement within an ise body } - static getIseNode(context, iseName) { + static getIseNode (context, iseName) { for (let index = context.scopeStack().length - 1; index >= 0; index--) { if (context.environment().getIse(context.scopeStack()[index], iseName) != undefined) { return context.environment().getIse(context.scopeStack()[index], iseName); @@ -30,7 +28,7 @@ class INodeCallIse extends IBase { return null; } - static getIseHelperParams(context, paramNodeList) { + static getIseHelperParams (context, paramNodeList) { const params = []; paramNodeList.forEach(paramNode => { params.push(context.evaluateNode(paramNode)); @@ -38,13 +36,13 @@ class INodeCallIse extends IBase { return params; } - static setIseNodeParam(context, iseNodeParamTokens, iseNodeParamValues) { + static setIseNodeParam (context, iseNodeParamTokens, iseNodeParamValues) { for (let i = 0; i < iseNodeParamTokens.length; i++) { context.environment().setJeki(context.getCurrentScope(), iseNodeParamTokens[i].value, context.evaluateNode(iseNodeParamValues[i])); } } - static runIseNodeBody(context, iseNodeBody) { + static runIseNodeBody (context, iseNodeBody) { for (let i = 0; i < iseNodeBody.length; i++) { const returnedValue = context.evaluateNode(iseNodeBody[i]); if (returnedValue != undefined) return returnedValue; @@ -52,4 +50,4 @@ class INodeCallIse extends IBase { } } -module.exports = new INodeCallIse(); \ No newline at end of file +module.exports = new INodeCallIse(); diff --git a/src/interpreters/inodedivide.js b/src/interpreters/inodedivide.js index b82375c..843f59c 100644 --- a/src/interpreters/inodedivide.js +++ b/src/interpreters/inodedivide.js @@ -1,14 +1,13 @@ const IBase = require("./ibase.js"); class INodeDivide extends IBase { - - interpreteNode(node) { - const leftNodeValue = this.evaluateNode(node.left) + interpreteNode (node) { + const leftNodeValue = this.evaluateNode(node.left); const rightNodeValue = this.evaluateNode(node.right); if (rightNodeValue === 0) this.throwError("YorlangArithmeticException - cannot divide by zero"); - + return leftNodeValue / rightNodeValue; } } -module.exports = new INodeDivide(); \ No newline at end of file +module.exports = new INodeDivide(); diff --git a/src/interpreters/inodeequals.js b/src/interpreters/inodeequals.js index bbdd77a..fbde8d7 100644 --- a/src/interpreters/inodeequals.js +++ b/src/interpreters/inodeequals.js @@ -2,10 +2,9 @@ const IBase = require("./ibase.js"); const constants = require("../constants.js"); class INodeEquals extends IBase { - - interpreteNode(node) { + interpreteNode (node) { return this.evaluateNode(node.left) === this.evaluateNode(node.right) ? constants.KW.OOTO : constants.KW.IRO; } } -module.exports = new INodeEquals(); \ No newline at end of file +module.exports = new INodeEquals(); diff --git a/src/interpreters/inodefun.js b/src/interpreters/inodefun.js index 48ab0b2..ff68660 100644 --- a/src/interpreters/inodefun.js +++ b/src/interpreters/inodefun.js @@ -2,8 +2,7 @@ const IBase = require("./ibase.js"); const constants = require("../constants.js"); class INodeFun extends IBase { - - interpreteNode(node) { + interpreteNode (node) { this.evaluateNode(node.init); while (this.evaluateNode(node.condition) !== constants.KW.IRO) { @@ -11,11 +10,11 @@ class INodeFun extends IBase { const returnedValue = this.evaluateNode(node.body[i]); if (returnedValue === constants.KW.KURO) return; if (returnedValue != undefined) return returnedValue; - } - + } + this.evaluateNode(node.increment); } } } -module.exports = new INodeFun(); \ No newline at end of file +module.exports = new INodeFun(); diff --git a/src/interpreters/inodegbewole.js b/src/interpreters/inodegbewole.js index e22512b..47f21ae 100644 --- a/src/interpreters/inodegbewole.js +++ b/src/interpreters/inodegbewole.js @@ -4,12 +4,11 @@ const Lexer = require("../lexer.js"); const InputStream = require("../inputstream.js"); class INodeGbeWole extends IBase { - - interpreteNode(node) { + interpreteNode (node) { const fileName = this.evaluateNode(node.path); const parser = new Parser(new Lexer(new InputStream(fileName))); - this.interpreteImportedProgram(parser); + this.interpreteImportedProgram(parser); } } -module.exports = new INodeGbeWole(); \ No newline at end of file +module.exports = new INodeGbeWole(); diff --git a/src/interpreters/inodegetjeki.js b/src/interpreters/inodegetjeki.js index 62fc1ec..6660f3c 100644 --- a/src/interpreters/inodegetjeki.js +++ b/src/interpreters/inodegetjeki.js @@ -2,8 +2,7 @@ const IBase = require("./ibase.js"); const WokeHelper = require("./helpers/woke_helper.js"); class INodeGetJeki extends IBase { - - interpreteNode(node) { + interpreteNode (node) { for (let index = INodeGetJeki.getTopIndex(this, node.name); index >= 0; index--) { if (this.environment().getJeki(this.scopeStack()[index], node.name) != undefined) { return this.environment().getJeki(this.scopeStack()[index], node.name); @@ -13,15 +12,13 @@ class INodeGetJeki extends IBase { this.throwError(`Variable ${node.name} is undefined`); } - static getTopIndex(context, tiName) { + static getTopIndex (context, tiName) { if (WokeHelper.isWokeVariable(context, tiName)) { return context.scopeStack().length - 2; - } + } return context.scopeStack().length - 1; } - - } -module.exports = new INodeGetJeki(); \ No newline at end of file +module.exports = new INodeGetJeki(); diff --git a/src/interpreters/inodegthan.js b/src/interpreters/inodegthan.js index 8f09c14..509a221 100644 --- a/src/interpreters/inodegthan.js +++ b/src/interpreters/inodegthan.js @@ -2,10 +2,9 @@ const IBase = require("./ibase.js"); const constants = require("../constants.js"); class INodeGThan extends IBase { - - interpreteNode(node) { + interpreteNode (node) { return this.evaluateNode(node.left) > this.evaluateNode(node.right) ? constants.KW.OOTO : constants.KW.IRO; } } -module.exports = new INodeGThan(); \ No newline at end of file +module.exports = new INodeGThan(); diff --git a/src/interpreters/inodegthanoreq.js b/src/interpreters/inodegthanoreq.js index 1950949..e98a0ea 100644 --- a/src/interpreters/inodegthanoreq.js +++ b/src/interpreters/inodegthanoreq.js @@ -2,10 +2,9 @@ const IBase = require("./ibase.js"); const constants = require("../constants.js"); class INodeGThanOrEq extends IBase { - - interpreteNode(node) { + interpreteNode (node) { return this.evaluateNode(node.left) >= this.evaluateNode(node.right) ? constants.KW.OOTO : constants.KW.IRO; } } -module.exports = new INodeGThanOrEq(); \ No newline at end of file +module.exports = new INodeGThanOrEq(); diff --git a/src/interpreters/inodeise.js b/src/interpreters/inodeise.js index a3de4ee..1e0ad90 100644 --- a/src/interpreters/inodeise.js +++ b/src/interpreters/inodeise.js @@ -1,13 +1,11 @@ const IBase = require("./ibase.js"); class INodeIse extends IBase { - - interpreteNode(node) { - if (this.environment().getIse(this.getCurrentScope(), node.name) != undefined) - this.throwError(`Ise with name ${node.name} already exists within the ${this.getCurrentScope()} scope`); + interpreteNode (node) { + if (this.environment().getIse(this.getCurrentScope(), node.name) != undefined) { this.throwError(`Ise with name ${node.name} already exists within the ${this.getCurrentScope()} scope`); } this.environment().setIse(this.getCurrentScope(), node.name, node); } } -module.exports = new INodeIse(); \ No newline at end of file +module.exports = new INodeIse(); diff --git a/src/interpreters/inodejeki.js b/src/interpreters/inodejeki.js index ef39e8c..bcc4089 100644 --- a/src/interpreters/inodejeki.js +++ b/src/interpreters/inodejeki.js @@ -3,22 +3,21 @@ const constants = require("../constants.js"); const WokeHelper = require("./helpers/woke_helper.js"); class INodeJeki extends IBase { - - interpreteNode(node) { + interpreteNode (node) { if (node.left.operation === constants.ARRAY_ELEM) { - INodeJeki.setArrayElement(this, node); + INodeJeki.setArrayElement(this, node); return; } if (WokeHelper.isWokeVariable(this, node.left)) { - INodeJeki.setWokeVariable(this, node); + INodeJeki.setWokeVariable(this, node); return; } - + this.environment().setJeki(this.getCurrentScope(), node.left, INodeJeki.getValue(this, node.right)); } - static setWokeVariable(context, node) { + static setWokeVariable (context, node) { const topIndex = context.scopeStack().length - 2; for (let index = topIndex; index >= 0; index--) { @@ -28,19 +27,19 @@ class INodeJeki extends IBase { } } - static setArrayElement(context, node) { //this also caters for setting multi-dimensional array element + static setArrayElement (context, node) { // this also caters for setting multi-dimensional array element let arrayLiteral = INodeJeki.getArrayLiteral(context, node); for (let i = 0; i < node.left.indexNodes.length; i++) { const arrayIndex = context.evaluateNode(node.left.indexNodes[i]); - if (arrayIndex === "" && i == node.left.indexNodes.length - 1) { - //push right node to the last location in the array when index is empty + if (arrayIndex === "" && i == node.left.indexNodes.length - 1) { + // push right node to the last location in the array when index is empty arrayLiteral.push(context.evaluateNode(node.right)); return; } - if (typeof arrayIndex == "number") { + if (typeof arrayIndex === "number") { if (!(Array.isArray(arrayLiteral[arrayIndex])) && (i < node.left.indexNodes.length - 1)) { context.throwError(`Cannot set invalid array element for array : ${node.left.name}`); } @@ -54,20 +53,20 @@ class INodeJeki extends IBase { } } else { context.throwError(`Typeof index given for array ${node.name} must be a number`); - } + } }; } - static getArrayLiteral(context, node) { - const jekiNode = { name: node.left.name, operation: constants.GET_JEKI }; + static getArrayLiteral (context, node) { + const jekiNode = { name: node.left.name, operation: constants.GET_JEKI, }; return context.evaluateNode(jekiNode); } - static getValue(context, node) { + static getValue (context, node) { const value = context.evaluateNode(node); if (value == undefined) context.throwError(`Cannot set value undefined to variable ${node.left}`); return value; } } -module.exports = new INodeJeki(); \ No newline at end of file +module.exports = new INodeJeki(); diff --git a/src/interpreters/inodekuro.js b/src/interpreters/inodekuro.js index f80ed03..6515d15 100644 --- a/src/interpreters/inodekuro.js +++ b/src/interpreters/inodekuro.js @@ -2,10 +2,9 @@ const IBase = require("./ibase.js"); const constants = require("../constants.js"); class INodeKuro extends IBase { - - interpreteNode(node) { + interpreteNode (node) { return constants.KW.KURO; } } -module.exports = new INodeKuro(); \ No newline at end of file +module.exports = new INodeKuro(); diff --git a/src/interpreters/inodelthan.js b/src/interpreters/inodelthan.js index c1946b6..cb05d19 100644 --- a/src/interpreters/inodelthan.js +++ b/src/interpreters/inodelthan.js @@ -2,10 +2,9 @@ const IBase = require("./ibase.js"); const constants = require("../constants.js"); class INodeLThan extends IBase { - - interpreteNode(node) { + interpreteNode (node) { return this.evaluateNode(node.left) < this.evaluateNode(node.right) ? constants.KW.OOTO : constants.KW.IRO; } } -module.exports = new INodeLThan(); \ No newline at end of file +module.exports = new INodeLThan(); diff --git a/src/interpreters/inodelthanoreq.js b/src/interpreters/inodelthanoreq.js index 792264b..5bcf045 100644 --- a/src/interpreters/inodelthanoreq.js +++ b/src/interpreters/inodelthanoreq.js @@ -2,10 +2,9 @@ const IBase = require("./ibase.js"); const constants = require("../constants.js"); class INodeLThanOrEq extends IBase { - - interpreteNode(node) { + interpreteNode (node) { return this.evaluateNode(node.left) <= this.evaluateNode(node.right) ? constants.KW.OOTO : constants.KW.IRO; } } -module.exports = new INodeLThanOrEq(); \ No newline at end of file +module.exports = new INodeLThanOrEq(); diff --git a/src/interpreters/inodeminus.js b/src/interpreters/inodeminus.js index d363436..318821f 100644 --- a/src/interpreters/inodeminus.js +++ b/src/interpreters/inodeminus.js @@ -1,10 +1,9 @@ const IBase = require("./ibase.js"); class INodeMinus extends IBase { - - interpreteNode(node) { + interpreteNode (node) { return this.evaluateNode(node.left) - this.evaluateNode(node.right); } } -module.exports = new INodeMinus(); \ No newline at end of file +module.exports = new INodeMinus(); diff --git a/src/interpreters/inodemultiply.js b/src/interpreters/inodemultiply.js index 885a6c1..3d55737 100644 --- a/src/interpreters/inodemultiply.js +++ b/src/interpreters/inodemultiply.js @@ -1,10 +1,9 @@ const IBase = require("./ibase.js"); class INodeMultiply extends IBase { - - interpreteNode(node) { + interpreteNode (node) { return this.evaluateNode(node.left) * this.evaluateNode(node.right); } } -module.exports = new INodeMultiply(); \ No newline at end of file +module.exports = new INodeMultiply(); diff --git a/src/interpreters/inodenigbati.js b/src/interpreters/inodenigbati.js index 0e45fb0..ac04b9f 100644 --- a/src/interpreters/inodenigbati.js +++ b/src/interpreters/inodenigbati.js @@ -2,16 +2,15 @@ const IBase = require("./ibase.js"); const constants = require("../constants.js"); class INodeNigbati extends IBase { - - interpreteNode(node) { + interpreteNode (node) { while (this.evaluateNode(node.condition) !== constants.KW.IRO) { for (let i = 0; i < node.body.length; i++) { const returnedValue = this.evaluateNode(node.body[i]); if (returnedValue === constants.KW.KURO) return; if (returnedValue != undefined) return returnedValue; - } + } } } } -module.exports = new INodeNigbati(); \ No newline at end of file +module.exports = new INodeNigbati(); diff --git a/src/interpreters/inodenoteq.js b/src/interpreters/inodenoteq.js index 7eaa2cd..2ea0f8e 100644 --- a/src/interpreters/inodenoteq.js +++ b/src/interpreters/inodenoteq.js @@ -2,10 +2,9 @@ const IBase = require("./ibase.js"); const constants = require("../constants.js"); class INodeNotEq extends IBase { - - interpreteNode(node) { + interpreteNode (node) { return this.evaluateNode(node.left) !== this.evaluateNode(node.right) ? constants.KW.OOTO : constants.KW.IRO; } } -module.exports = new INodeNotEq(); \ No newline at end of file +module.exports = new INodeNotEq(); diff --git a/src/interpreters/inodenotoperator.js b/src/interpreters/inodenotoperator.js index 1532a7e..a72b937 100644 --- a/src/interpreters/inodenotoperator.js +++ b/src/interpreters/inodenotoperator.js @@ -2,10 +2,9 @@ const IBase = require("./ibase.js"); const constants = require("../constants.js"); class INodeNotOperator extends IBase { - - interpreteNode(node) { + interpreteNode (node) { return (this.evaluateNode(node.body) === constants.KW.IRO) ? constants.KW.OOTO : constants.KW.IRO; } } -module.exports = new INodeNotOperator(); \ No newline at end of file +module.exports = new INodeNotOperator(); diff --git a/src/interpreters/inodeor.js b/src/interpreters/inodeor.js index 8dff17b..9f91f0c 100644 --- a/src/interpreters/inodeor.js +++ b/src/interpreters/inodeor.js @@ -2,11 +2,10 @@ const IBase = require("./ibase.js"); const constants = require("../constants.js"); class INodeOr extends IBase { - - interpreteNode(node) { + interpreteNode (node) { return this.evaluateNode(node.left) !== (constants.KW.IRO) || this.evaluateNode(node.right) !== constants.KW.IRO - ? constants.KW.OOTO : constants.KW.IRO; + ? constants.KW.OOTO : constants.KW.IRO; } } -module.exports = new INodeOr(); \ No newline at end of file +module.exports = new INodeOr(); diff --git a/src/interpreters/inodepada.js b/src/interpreters/inodepada.js index 41ca36f..21207e9 100644 --- a/src/interpreters/inodepada.js +++ b/src/interpreters/inodepada.js @@ -1,10 +1,9 @@ const IBase = require("./ibase.js"); class INodePada extends IBase { - - interpreteNode(node) { + interpreteNode (node) { return this.evaluateNode(node.body); } } -module.exports = new INodePada(); \ No newline at end of file +module.exports = new INodePada(); diff --git a/src/interpreters/inodeplus.js b/src/interpreters/inodeplus.js index 0f034e0..93532db 100644 --- a/src/interpreters/inodeplus.js +++ b/src/interpreters/inodeplus.js @@ -1,10 +1,9 @@ const IBase = require("./ibase.js"); class INodePlus extends IBase { - - interpreteNode(node) { + interpreteNode (node) { return this.evaluateNode(node.left) + this.evaluateNode(node.right); } } -module.exports = new INodePlus(); \ No newline at end of file +module.exports = new INodePlus(); diff --git a/src/interpreters/inoderemainder.js b/src/interpreters/inoderemainder.js index d139a66..51d7335 100644 --- a/src/interpreters/inoderemainder.js +++ b/src/interpreters/inoderemainder.js @@ -1,10 +1,9 @@ const IBase = require("./ibase.js"); class INodeRemainder extends IBase { - - interpreteNode(node) { + interpreteNode (node) { return this.evaluateNode(node.left) % this.evaluateNode(node.right); } } -module.exports = new INodeRemainder(); \ No newline at end of file +module.exports = new INodeRemainder(); diff --git a/src/interpreters/inodese.js b/src/interpreters/inodese.js index 2df42cb..921afdd 100644 --- a/src/interpreters/inodese.js +++ b/src/interpreters/inodese.js @@ -2,8 +2,7 @@ const IBase = require("./ibase.js"); const constants = require("../constants.js"); class INodeSe extends IBase { - - interpreteNode(node) { + interpreteNode (node) { if (this.evaluateNode(node.condition) !== constants.KW.IRO) { return INodeSe.runBody(this, node.then); } else if (node.else != undefined) { @@ -11,15 +10,15 @@ class INodeSe extends IBase { } } - static runBody(context, body) { - //It is expected to be a 'tabi se' block when body is not an instance of an array + static runBody (context, body) { + // It is expected to be a 'tabi se' block when body is not an instance of an array if (!(body instanceof Array)) context.evaluateNode(body); for (let i = 0; i < body.length; i++) { const returnedValue = context.evaluateNode(body[i]); - if (returnedValue != undefined) return returnedValue; //it's an ise pada value or kuro statement + if (returnedValue != undefined) return returnedValue; // it's an ise pada value or kuro statement } } } -module.exports = new INodeSe(); \ No newline at end of file +module.exports = new INodeSe(); diff --git a/src/interpreters/inodesope.js b/src/interpreters/inodesope.js index 9edd310..a9472b9 100644 --- a/src/interpreters/inodesope.js +++ b/src/interpreters/inodesope.js @@ -1,10 +1,9 @@ const IBase = require("./ibase.js"); class INodeSope extends IBase { - - interpreteNode(node) { + interpreteNode (node) { this.environment().sope(this.evaluateNode(node.body)); } } -module.exports = new INodeSope(); \ No newline at end of file +module.exports = new INodeSope(); diff --git a/src/interpreters/inodewoke.js b/src/interpreters/inodewoke.js index 6e15736..d7c8354 100644 --- a/src/interpreters/inodewoke.js +++ b/src/interpreters/inodewoke.js @@ -2,8 +2,7 @@ const IBase = require("./ibase.js"); const constants = require("../constants.js"); class INodeWoke extends IBase { - - interpreteNode(node) { + interpreteNode (node) { let woke = this.environment().getJeki(this.getCurrentScope(), constants.KW.WOKE); if (woke == undefined) woke = node.varNames; @@ -13,4 +12,4 @@ class INodeWoke extends IBase { } } -module.exports = new INodeWoke(); \ No newline at end of file +module.exports = new INodeWoke(); diff --git a/src/interpreters/inodeyi.js b/src/interpreters/inodeyi.js index d39c294..98d8406 100644 --- a/src/interpreters/inodeyi.js +++ b/src/interpreters/inodeyi.js @@ -1,8 +1,7 @@ const IBase = require("./ibase.js"); class INodeYi extends IBase { - - interpreteNode(node) { + interpreteNode (node) { const yivalue = this.evaluateNode(node.yivalue); for (let IRUIndex = 0; IRUIndex < node.yibody.length; IRUIndex++) { @@ -17,25 +16,25 @@ class INodeYi extends IBase { } } - static isIRUValueMatchYiValue(context, IRUvalueNode, yivalue) { + static isIRUValueMatchYiValue (context, IRUvalueNode, yivalue) { return context.evaluateNode(IRUvalueNode) === yivalue; } - static runMatchedIRUBody(context, IRUBody) { + static runMatchedIRUBody (context, IRUBody) { for (let i = 0; i < IRUBody.length; i++) { context.evaluateNode(IRUBody[i]); } } - static canRunPadasi(IRUIndex, node) { + static canRunPadasi (IRUIndex, node) { return (IRUIndex === node.yibody.length - 1) && (node.padasi != undefined); } - static runPadasi(context, padasi) { + static runPadasi (context, padasi) { for (let padasiIndex = 0; padasiIndex < padasi.length; padasiIndex++) { context.evaluateNode(padasi[padasiIndex]); } } } -module.exports = new INodeYi(); \ No newline at end of file +module.exports = new INodeYi(); diff --git a/src/interpreters/interpreters.js b/src/interpreters/interpreters.js index da77514..92ca7dc 100644 --- a/src/interpreters/interpreters.js +++ b/src/interpreters/interpreters.js @@ -33,4 +33,4 @@ interpreters[constants.GET_JEKI] = require("./inodegetjeki.js"); interpreters[constants.ARRAY] = require("./inodearray.js"); interpreters[constants.ARRAY_ELEM] = require("./inodearrayelem.js"); -module.exports = interpreters; \ No newline at end of file +module.exports = interpreters; diff --git a/src/interpreters/maininterpreter.js b/src/interpreters/maininterpreter.js index 6ba9db5..26692dd 100644 --- a/src/interpreters/maininterpreter.js +++ b/src/interpreters/maininterpreter.js @@ -3,22 +3,21 @@ const constants = require("../constants.js"); const IBase = require("./ibase.js"); class MainInterpreter { - - constructor(environment, parser) { + constructor (environment, parser) { this.environment = () => environment; this.parser = () => parser; this.initScopeStack(); } - initScopeStack() { - const _scopeStack = ["global"]; + initScopeStack () { + const _scopeStack = ["global", ]; this.getCurrentScope = () => _scopeStack[_scopeStack.length - 1]; - this.scopeStack = () => [..._scopeStack]; + this.scopeStack = () => [..._scopeStack, ]; this.pushToScopeStack = (scope) => _scopeStack.push(scope); this.popFromScopeStack = () => _scopeStack.pop(); } - getLeafValue(leaf) { + getLeafValue (leaf) { if (leaf.value != null) { return leaf.value; } @@ -26,10 +25,10 @@ class MainInterpreter { return null; } - evaluateNode(node) { + evaluateNode (node) { const leafValue = this.getLeafValue(node); if (leafValue == null) { - const interpreter = registeredInterpreters[node.operation]; + const interpreter = registeredInterpreters[node.operation]; if (interpreter instanceof IBase) return interpreter.interpreteNode.call(this, node); else this.throwError(`Interpreter must be of type IBase: ${node.operation}`); } @@ -37,11 +36,11 @@ class MainInterpreter { return leafValue; } - throwError(msg) { + throwError (msg) { this.parser().throwError(msg); } - interpreteProgram() { + interpreteProgram () { this.parser().pushToBlockTypeStack(constants.PROGRAM); while (this.parser().isNotEndOfFile()) { this.evaluateNode(this.parser().parseAst()); @@ -49,9 +48,9 @@ class MainInterpreter { this.parser().popBlockTypeStack(); } - interpreteImportedProgram(parser) { + interpreteImportedProgram (parser) { new MainInterpreter(this.environment(), parser).interpreteProgram(); } } -module.exports = MainInterpreter; \ No newline at end of file +module.exports = MainInterpreter; diff --git a/src/lexer.js b/src/lexer.js index 78a91ce..b5b3231 100644 --- a/src/lexer.js +++ b/src/lexer.js @@ -1,37 +1,36 @@ const constants = require("./constants.js"); class Lexer { - - constructor(inputStream) { + constructor (inputStream) { this.inputStream = inputStream; this.currentToken = null; } - isWhiteSpace(ws) { + isWhiteSpace (ws) { return constants.LIST.WHITESPACES.indexOf(ws) >= 0; } - isPunctuation(punc) { + isPunctuation (punc) { return constants.LIST.PUNCTUATIONS.indexOf(punc) >= 0; } - isIdentifier(id) { + isIdentifier (id) { return constants.REGEX.IDENTIFIER.test(id); } - isOperator(op) { + isOperator (op) { return constants.LIST.OPERATORS.indexOf(op) >= 0; } - isKeyword(kw) { + isKeyword (kw) { return constants.LIST.KEYWORDS.indexOf(kw) >= 0; } - isDigit(dig) { - return constants.REGEX.DIGIT.test(dig); + isDigit (dig) { + return constants.REGEX.DIGIT.test(dig); } - readWhile(predicate) { + readWhile (predicate) { let str = ""; while (this.inputStream.isNotEndOfFile() && predicate(this.inputStream.peek())) { @@ -41,56 +40,54 @@ class Lexer { return str; } - readString() { + readString () { const stringEnd = constants.SYM.STR_QUOTE; - this.inputStream.next(); //needed to skip the opening quote symbol '"' + this.inputStream.next(); // needed to skip the opening quote symbol '"' const str = this.readWhile((ch) => { - return (ch == stringEnd) ? false : true; + return ch != stringEnd; }); - if (this.inputStream.peek() == stringEnd) - this.inputStream.next(); //needed to skip the closing quote symbol '"' - else - this.throwError(`Expecting '${stringEnd}' but found unexpected char`); + if (this.inputStream.peek() == stringEnd) { this.inputStream.next(); } // needed to skip the closing quote symbol '"' + else { this.throwError(`Expecting '${stringEnd}' but found unexpected char`); } - return { type: constants.STRING, value: str }; + return { type: constants.STRING, value: str, }; } - readIdentifier() { + readIdentifier () { const identifier = this.getIdentifierWithoutAccentMarks(this.readWhile(this.isIdentifier)); - + return { - type: this.isKeyword(identifier) ? constants.KEYWORD : constants.VARIABLE, - value: identifier + type: this.isKeyword(identifier) ? constants.KEYWORD : constants.VARIABLE, + value: identifier, }; } - getIdentifierWithoutAccentMarks(identifier) { - return identifier.normalize('NFD').replace(/[\u0300-\u036f]/g, ""); + getIdentifierWithoutAccentMarks (identifier) { + return identifier.normalize("NFD").replace(/[\u0300-\u036f]/g, ""); } - readNumber() { + readNumber () { let hasDot = false; const num = this.readWhile((ch) => { if (ch == constants.SYM.PERIOD) { - if(hasDot) return false; + if (hasDot) return false; hasDot = true; return true; } - return this.isDigit(ch) + return this.isDigit(ch); }); - return { type: constants.NUMBER, value: parseFloat(num) }; + return { type: constants.NUMBER, value: parseFloat(num), }; } - skipComments() { + skipComments () { this.readWhile((ch) => { return ch != constants.SYM.NEW_LINE; }); - this.inputStream.next(); //skips the "\n" symbol + this.inputStream.next(); // skips the "\n" symbol } - readNext() { + readNext () { this.readWhile(this.isWhiteSpace); if (this.inputStream.isEndOfFile()) return null; @@ -102,36 +99,36 @@ class Lexer { if (ch == constants.SYM.STR_QUOTE) return this.readString(); if (this.isDigit(ch)) return this.readNumber(); if (this.isIdentifier(ch)) return this.readIdentifier(); - if (this.isPunctuation(ch)) return { type: constants.PUNCTUATION, value: this.inputStream.next() } - if (this.isOperator(ch)) return { type: constants.OPERATOR, value: this.readWhile(this.isOperator) } + if (this.isPunctuation(ch)) return { type: constants.PUNCTUATION, value: this.inputStream.next(), }; + if (this.isOperator(ch)) return { type: constants.OPERATOR, value: this.readWhile(this.isOperator), }; this.throwError(`Cant handle character '${ch}'`); } - peek() { + peek () { return this.current || (this.current = this.readNext()); } - //The next function dosent always call readNext() - //because it might have been peeked before - //(in which case readNext() was already called and the inputstream has advanced) - next() { + // The next function dosent always call readNext() + // because it might have been peeked before + // (in which case readNext() was already called and the inputstream has advanced) + next () { const token = this.current; this.current = null; return token || this.readNext(); } - isEndOfFile() { + isEndOfFile () { return this.peek() == null; } - isNotEndOfFile() { + isNotEndOfFile () { return this.peek() != null; } - throwError(msg) { + throwError (msg) { this.inputStream.throwError(msg); } } -module.exports = Lexer; \ No newline at end of file +module.exports = Lexer; diff --git a/src/parsers/basenode.js b/src/parsers/basenode.js index 5851e6f..ba1fb93 100644 --- a/src/parsers/basenode.js +++ b/src/parsers/basenode.js @@ -1,15 +1,14 @@ class BaseNode { - - //Make BaseNode act like an interface. - constructor() { + // Make BaseNode act like an interface. + constructor () { if (this.constructor == BaseNode) { throw new Error("Cannot instantiate abstract class BaseNode"); } } - getNode() { - throw new Error(`Class of type BaseNode must implement getNode()`); + getNode () { + throw new Error("Class of type BaseNode must implement getNode()"); } } -module.exports = BaseNode; \ No newline at end of file +module.exports = BaseNode; diff --git a/src/parsers/keywordnodes/kwnodegbewole.js b/src/parsers/keywordnodes/kwnodegbewole.js index 8b743d2..09b114f 100644 --- a/src/parsers/keywordnodes/kwnodegbewole.js +++ b/src/parsers/keywordnodes/kwnodegbewole.js @@ -4,23 +4,21 @@ const leafnl = require("../nodeLiterals/leafnl.js"); const path = require("path"); class KwNodeGbeWole extends BaseNode { - - getNode() { + getNode () { this.skipKeyword(constants.KW.GBE_WOLE); - const node = {}; + const node = {}; node.operation = constants.KW.GBE_WOLE; - + if (this.lexer().peek().type == constants.STRING) { node.path = leafnl.getNode.call(this); - if (path.extname(node.path.value) != constants.YL_EXT) - this.throwError("Invalid yorlang file. Expected file with .yl extension"); + if (path.extname(node.path.value) != constants.YL_EXT) { this.throwError("Invalid yorlang file. Expected file with .yl extension"); } this.skipPunctuation(constants.SYM.STATEMENT_TERMINATOR); return node; } - + this.lexer().throwError(`${constants.KW.GBE_WOLE} expects a string.`); } } -module.exports = new KwNodeGbeWole(); \ No newline at end of file +module.exports = new KwNodeGbeWole(); diff --git a/src/parsers/keywordnodes/kwnodeise.js b/src/parsers/keywordnodes/kwnodeise.js index 4bd4c3f..aaaf665 100644 --- a/src/parsers/keywordnodes/kwnodeise.js +++ b/src/parsers/keywordnodes/kwnodeise.js @@ -2,28 +2,27 @@ const constants = require("../../constants.js"); const BaseNode = require("../basenode.js"); class KwNodeIse extends BaseNode { - - getNode() { + getNode () { if (KwNodeIse.isExpectedIseDeclaration(this)) { return KwNodeIse.getParsedIseNode(this); } - - this.throwError("Cannot create a yorlang function within a non function block"); + + this.throwError("Cannot create a yorlang function within a non function block"); } - static isExpectedIseDeclaration(context) { - return context.getBlockTypeStack().length == 0 || context.peekBlockTypeStack() === constants.PROGRAM - || context.peekBlockTypeStack() === constants.KW.ISE; + static isExpectedIseDeclaration (context) { + return context.getBlockTypeStack().length == 0 || context.peekBlockTypeStack() === constants.PROGRAM || + context.peekBlockTypeStack() === constants.KW.ISE; } - static getParsedIseNode(context) { + static getParsedIseNode (context) { context.skipKeyword(constants.KW.ISE); return { operation: constants.KW.ISE, name: context.parseVarname(), - paramTokens: context.parseDelimited( - constants.SYM.L_BRACKET , constants.SYM.R_BRACKET, constants.SYM.COMMA, + paramTokens: context.parseDelimited( + constants.SYM.L_BRACKET, constants.SYM.R_BRACKET, constants.SYM.COMMA, context.getTokenThatSatisfiesPredicate.bind(context), (token) => token.type === constants.VARIABLE ), body: context.parseBlock(constants.KW.ISE), @@ -31,4 +30,4 @@ class KwNodeIse extends BaseNode { } } -module.exports = new KwNodeIse(); \ No newline at end of file +module.exports = new KwNodeIse(); diff --git a/src/parsers/keywordnodes/kwnodekuro.js b/src/parsers/keywordnodes/kwnodekuro.js index ac6b0ab..0a50294 100644 --- a/src/parsers/keywordnodes/kwnodekuro.js +++ b/src/parsers/keywordnodes/kwnodekuro.js @@ -2,8 +2,7 @@ const constants = require("../../constants.js"); const BaseNode = require("../basenode.js"); class KwNodeKuro extends BaseNode { - - getNode() { + getNode () { if (KwNodeKuro.isExpectedKuroStatement(this)) { return KwNodeKuro.getParsedKuroNode(this); } @@ -11,12 +10,12 @@ class KwNodeKuro extends BaseNode { this.throwError("Yorlang Kuro keyword not expected"); } - static isExpectedKuroStatement(context) { + static isExpectedKuroStatement (context) { return context.getBlockTypeStack().indexOf(constants.KW.FUN) >= 0 || context.getBlockTypeStack().indexOf(constants.KW.NIGBATI) >= 0; } - static getParsedKuroNode(context) { + static getParsedKuroNode (context) { const node = {}; node.operation = context.lexer().next().value; context.skipPunctuation(constants.SYM.STATEMENT_TERMINATOR); @@ -25,4 +24,4 @@ class KwNodeKuro extends BaseNode { } } -module.exports = new KwNodeKuro(); \ No newline at end of file +module.exports = new KwNodeKuro(); diff --git a/src/parsers/keywordnodes/kwnodenigbati.js b/src/parsers/keywordnodes/kwnodenigbati.js index 6248992..b570703 100644 --- a/src/parsers/keywordnodes/kwnodenigbati.js +++ b/src/parsers/keywordnodes/kwnodenigbati.js @@ -3,23 +3,22 @@ const BaseNode = require("../basenode.js"); const bracketExpressionNl = require("../nodeLiterals/bracketexpressionnl.js"); class KwNodeNigbati extends BaseNode { - - constructor() { + constructor () { super(); if (!(bracketExpressionNl instanceof BaseNode)) { throw new Error("Dependency bracketExpressionNl must be of type BaseNode"); - } + } } - getNode() { + getNode () { this.skipKeyword(constants.KW.NIGBATI); return { operation: constants.KW.NIGBATI, condition: bracketExpressionNl.getNode.call(this, false), - body: this.parseBlock(constants.KW.NIGBATI) + body: this.parseBlock(constants.KW.NIGBATI), }; } } -module.exports = new KwNodeNigbati(); \ No newline at end of file +module.exports = new KwNodeNigbati(); diff --git a/src/parsers/keywordnodes/kwnodepada.js b/src/parsers/keywordnodes/kwnodepada.js index 8df4b48..102038d 100644 --- a/src/parsers/keywordnodes/kwnodepada.js +++ b/src/parsers/keywordnodes/kwnodepada.js @@ -2,20 +2,19 @@ const constants = require("../../constants.js"); const BaseNode = require("../basenode.js"); class KwNodePada extends BaseNode { - - getNode() { + getNode () { if (KwNodePada.isExpectedPadaStatement(this)) { return KwNodePada.getParsedPadaNode(this); } - + this.throwError("Yorlang pada keyword not expected in a non function(ise) block"); } - static isExpectedPadaStatement(context) { - return context.getBlockTypeStack().indexOf(constants.KW.ISE) >= 0 + static isExpectedPadaStatement (context) { + return context.getBlockTypeStack().indexOf(constants.KW.ISE) >= 0; } - static getParsedPadaNode(context) { + static getParsedPadaNode (context) { context.skipKeyword(constants.KW.PADA); const node = {}; node.operation = constants.KW.PADA; @@ -26,4 +25,4 @@ class KwNodePada extends BaseNode { } } -module.exports = new KwNodePada(); \ No newline at end of file +module.exports = new KwNodePada(); diff --git a/src/parsers/keywordnodes/kwnodes.js b/src/parsers/keywordnodes/kwnodes.js index c73dfe1..b90d79c 100644 --- a/src/parsers/keywordnodes/kwnodes.js +++ b/src/parsers/keywordnodes/kwnodes.js @@ -13,4 +13,4 @@ KwNodes[constants.KW.YI] = require("./kwnodeyi.js"); KwNodes[constants.KW.GBE_WOLE] = require("./kwnodegbewole.js"); KwNodes[constants.KW.WOKE] = require("./kwnodewoke.js"); -module.exports = KwNodes; \ No newline at end of file +module.exports = KwNodes; diff --git a/src/parsers/keywordnodes/kwnodese.js b/src/parsers/keywordnodes/kwnodese.js index 8200a01..8aed3f0 100644 --- a/src/parsers/keywordnodes/kwnodese.js +++ b/src/parsers/keywordnodes/kwnodese.js @@ -2,18 +2,17 @@ const constants = require("../../constants.js"); const BaseNode = require("../basenode.js"); const bracketExpressionNl = require("../nodeLiterals/bracketexpressionnl.js"); class KwNodeSe extends BaseNode { - - constructor() { - super() + constructor () { + super(); if (!(bracketExpressionNl instanceof BaseNode)) { throw new Error("Dependency brackExpressionNl must be of type BaseNode"); - } + } } - getNode() { + getNode () { this.skipKeyword(constants.KW.SE); - const node = {}; + const node = {}; node.operation = constants.KW.SE; node.condition = bracketExpressionNl.getNode.call(this, false); node.then = this.parseBlock(constants.KW.SE); @@ -25,16 +24,15 @@ class KwNodeSe extends BaseNode { return node; } - static getTabiNode(context) { + static getTabiNode (context) { context.skipKeyword(constants.KW.TABI); - if (context.isNextTokenKeyword(constants.KW.SE)) { //cater for 'tabi se' block + if (context.isNextTokenKeyword(constants.KW.SE)) { // cater for 'tabi se' block return new KwNodeSe().getNode.call(context); } return context.parseBlock(constants.KW.TABI); } - } -module.exports = new KwNodeSe(); \ No newline at end of file +module.exports = new KwNodeSe(); diff --git a/src/parsers/keywordnodes/kwnodesope.js b/src/parsers/keywordnodes/kwnodesope.js index f27922d..13ead24 100644 --- a/src/parsers/keywordnodes/kwnodesope.js +++ b/src/parsers/keywordnodes/kwnodesope.js @@ -2,8 +2,7 @@ const constants = require("../../constants.js"); const BaseNode = require("../basenode.js"); class KwNodeSope extends BaseNode { - - getNode() { + getNode () { this.skipKeyword(constants.KW.SOPE); const node = {}; node.operation = constants.KW.SOPE; @@ -14,4 +13,4 @@ class KwNodeSope extends BaseNode { } } -module.exports = new KwNodeSope(); \ No newline at end of file +module.exports = new KwNodeSope(); diff --git a/src/parsers/keywordnodes/kwnodewoke.js b/src/parsers/keywordnodes/kwnodewoke.js index 9259def..50df0fc 100644 --- a/src/parsers/keywordnodes/kwnodewoke.js +++ b/src/parsers/keywordnodes/kwnodewoke.js @@ -2,20 +2,19 @@ const constants = require("../../constants.js"); const BaseNode = require("../basenode.js"); class KwNodeWoke extends BaseNode { - - getNode() { + getNode () { if (KwNodeWoke.isExpectedWokeStatement(this)) { return KwNodeWoke.getParsedWokeNode(this); } - + this.throwError("Yorlang woke keyword not expected in a non function(ise) block"); } - static isExpectedWokeStatement(context) { - return context.getBlockTypeStack().indexOf(constants.KW.ISE) >= 0 + static isExpectedWokeStatement (context) { + return context.getBlockTypeStack().indexOf(constants.KW.ISE) >= 0; } - static getParsedWokeNode(context) { + static getParsedWokeNode (context) { context.skipKeyword(constants.KW.WOKE); const node = {}; node.operation = constants.KW.WOKE; @@ -25,7 +24,7 @@ class KwNodeWoke extends BaseNode { return node; } - static getWokeVarNames(context) { + static getWokeVarNames (context) { const varTokens = context.parseDelimited("`", "`", ",", context.getTokenThatSatisfiesPredicate.bind(context), (token) => token.type === constants.VARIABLE); const varNames = []; varTokens.map(varToken => { @@ -36,4 +35,4 @@ class KwNodeWoke extends BaseNode { } } -module.exports = new KwNodeWoke(); \ No newline at end of file +module.exports = new KwNodeWoke(); diff --git a/src/parsers/keywordnodes/kwnodeyi.js b/src/parsers/keywordnodes/kwnodeyi.js index 746f6be..61991fe 100644 --- a/src/parsers/keywordnodes/kwnodeyi.js +++ b/src/parsers/keywordnodes/kwnodeyi.js @@ -3,22 +3,21 @@ const BaseNode = require("../basenode.js"); const bracketExpressionNl = require("../nodeLiterals/bracketexpressionnl.js"); class KwNodeYi extends BaseNode { - - constructor() { - super() + constructor () { + super(); if (!(bracketExpressionNl instanceof BaseNode)) { throw new Error("Dependency brackExpressionNl must be of type BaseNode"); - } + } } - getNode() { + getNode () { const node = {}; node.operation = constants.KW.YI; this.pushToBlockTypeStack(constants.KW.YI); this.skipKeyword(constants.KW.YI); node.yivalue = bracketExpressionNl.getNode.call(this); this.skipPunctuation(constants.SYM.L_PAREN); - node.yibody = KwNodeYi.getYiBody(this); + node.yibody = KwNodeYi.getYiBody(this); node.padasi = KwNodeYi.getPadasi(this); this.skipPunctuation(constants.SYM.R_PAREN); this.popBlockTypeStack(); @@ -26,8 +25,8 @@ class KwNodeYi extends BaseNode { return node; } - static getYiBody(context) { - const yiBody = [], kwNodeIRU = new KwNodeIRU(); + static getYiBody (context) { + const yiBody = []; const kwNodeIRU = new KwNodeIRU(); while (KwNodeYi.isNextTokenIru(context)) { yiBody.push(kwNodeIRU.getNode.call(context)); @@ -36,11 +35,11 @@ class KwNodeYi extends BaseNode { return yiBody; } - static isNextTokenIru(context) { + static isNextTokenIru (context) { return context.isNotEndOfFile() && context.lexer().peek().value == constants.KW.IRU; } - static getPadasi(context) { + static getPadasi (context) { const padasi = []; if (context.isNextTokenKeyword(constants.KW.PADASI)) { @@ -57,34 +56,33 @@ class KwNodeYi extends BaseNode { } class KwNodeIRU extends BaseNode { - - getNode() { + getNode () { const node = {}; node.operation = constants.KW.IRU; this.skipKeyword(constants.KW.IRU); node.IRUvalue = this.parseExpression(); - this.skipPunctuation(constants.SYM.COLON); + this.skipPunctuation(constants.SYM.COLON); node.IRUbody = KwNodeIRU.getIRUBody(this); return node; } - static getIRUBody(context) { + static getIRUBody (context) { const IRUBody = []; while (KwNodeIRU.canParseIRUStatements(context)) { IRUBody.push(context.parseAst()); } - + return IRUBody; } - static canParseIRUStatements(context) { - return context.isNotEndOfFile() - && context.lexer().peek().value !== constants.KW.IRU - && context.lexer().peek().value !== constants.KW.PADASI - && context.lexer().peek().value !== constants.SYM.R_PAREN; + static canParseIRUStatements (context) { + return context.isNotEndOfFile() && + context.lexer().peek().value !== constants.KW.IRU && + context.lexer().peek().value !== constants.KW.PADASI && + context.lexer().peek().value !== constants.SYM.R_PAREN; } } -module.exports = new KwNodeYi(); \ No newline at end of file +module.exports = new KwNodeYi(); diff --git a/src/parsers/nodeLiterals/arraynl.js b/src/parsers/nodeLiterals/arraynl.js index 049f5c0..b3cc6d6 100644 --- a/src/parsers/nodeLiterals/arraynl.js +++ b/src/parsers/nodeLiterals/arraynl.js @@ -2,24 +2,23 @@ const BaseNode = require("../basenode.js"); const constants = require("../../constants.js"); class ArrayNl extends BaseNode { - - getNode(arrayNameToken) { + getNode (arrayNameToken) { return (arrayNameToken == undefined) ? ArrayNl.getParsedArrayLiteral(this) - : ArrayNl.getParsedArrayElement(this, arrayNameToken); + : ArrayNl.getParsedArrayElement(this, arrayNameToken); } - static getParsedArrayLiteral(context) { + static getParsedArrayLiteral (context) { const node = {}; node.operation = constants.ARRAY; - node.body = context.parseDelimited( - constants.SYM.L_SQ_BRACKET , constants.SYM.R_SQ_BRACKET, constants.SYM.COMMA, + node.body = context.parseDelimited( + constants.SYM.L_SQ_BRACKET, constants.SYM.R_SQ_BRACKET, constants.SYM.COMMA, context.parseExpression.bind(context), null ); return node; } - static getParsedArrayElement(context, arrayNameToken) { + static getParsedArrayElement (context, arrayNameToken) { const node = {}; node.operation = constants.ARRAY_ELEM; node.name = arrayNameToken.value; @@ -28,18 +27,18 @@ class ArrayNl extends BaseNode { return node; } - static getArrayElementIndexNodes(context) { - const indexNodes = [ArrayNl.getArrayElementIndexNode(context)]; + static getArrayElementIndexNodes (context) { + const indexNodes = [ArrayNl.getArrayElementIndexNode(context), ]; - while (context.isNextTokenPunctuation(constants.SYM.L_SQ_BRACKET)) { //handles multi-dimensional array element + while (context.isNextTokenPunctuation(constants.SYM.L_SQ_BRACKET)) { // handles multi-dimensional array element indexNodes.push(ArrayNl.getArrayElementIndexNode(context)); } return indexNodes; } - static getArrayElementIndexNode(context) { - let indexNode = { operation: null, right: null, left: null, value: "" }; + static getArrayElementIndexNode (context) { + let indexNode = { operation: null, right: null, left: null, value: "", }; context.skipPunctuation(constants.SYM.L_SQ_BRACKET); if (ArrayNl.isNotEmptyArrayIndex(context)) indexNode = context.parseExpression(); @@ -48,9 +47,9 @@ class ArrayNl extends BaseNode { return indexNode; } - static isNotEmptyArrayIndex(context) { + static isNotEmptyArrayIndex (context) { return context.lexer().peek().value != constants.SYM.R_SQ_BRACKET; } } -module.exports = new ArrayNl(); \ No newline at end of file +module.exports = new ArrayNl(); diff --git a/src/parsers/nodeLiterals/bracketexpressionnl.js b/src/parsers/nodeLiterals/bracketexpressionnl.js index ea913f4..a4b15a6 100644 --- a/src/parsers/nodeLiterals/bracketexpressionnl.js +++ b/src/parsers/nodeLiterals/bracketexpressionnl.js @@ -2,16 +2,15 @@ const BaseNode = require("../basenode.js"); const constants = require("../../constants.js"); class BracketExpressionNl extends BaseNode { - - getNode(isArithmetic = true, isBracketExpected = true) { + getNode (isArithmetic = true, isBracketExpected = true) { if (isBracketExpected) this.skipPunctuation(constants.SYM.L_BRACKET); this.setIsArithmeticExpression(isArithmetic); const node = this.parseExpression(); - this.setIsArithmeticExpression(true); //set back to default + this.setIsArithmeticExpression(true); // set back to default if (isBracketExpected) this.skipPunctuation(constants.SYM.R_BRACKET); - return node; + return node; } } -module.exports = new BracketExpressionNl(); \ No newline at end of file +module.exports = new BracketExpressionNl(); diff --git a/src/parsers/nodeLiterals/keywordnl.js b/src/parsers/nodeLiterals/keywordnl.js index a87a949..40d4389 100644 --- a/src/parsers/nodeLiterals/keywordnl.js +++ b/src/parsers/nodeLiterals/keywordnl.js @@ -3,25 +3,24 @@ const leafNl = require("./leafnl.js"); const BaseNode = require("../basenode.js"); class KeywordNl extends BaseNode { - - constructor() { - super() + constructor () { + super(); if (!(leafNl instanceof BaseNode)) { throw new Error("Dependency leafNl must be of type BaseNode"); - } + } } - getNode() { + getNode () { if (KeywordNl.isKeywordNl(this)) { return leafNl.getNode.call(this); } - + this.throwError(`Expecting yorlang keyword value e.g boolean(iró|òótó) but found ${token.value}`); } - static isKeywordNl(context) { - return [constants.KW.OOTO, constants.KW.IRO].indexOf(context.lexer().peek().value) >= 0 + static isKeywordNl (context) { + return [constants.KW.OOTO, constants.KW.IRO, ].indexOf(context.lexer().peek().value) >= 0; } } -module.exports = new KeywordNl(); \ No newline at end of file +module.exports = new KeywordNl(); diff --git a/src/parsers/nodeLiterals/leafnl.js b/src/parsers/nodeLiterals/leafnl.js index 075a5b5..5945b98 100644 --- a/src/parsers/nodeLiterals/leafnl.js +++ b/src/parsers/nodeLiterals/leafnl.js @@ -1,15 +1,14 @@ const BaseNode = require("../basenode.js"); -class LeafNl extends BaseNode{ - - getNode() { +class LeafNl extends BaseNode { + getNode () { return { value: this.lexer().next().value, left: null, right: null, - operation: null - } + operation: null, + }; } } -module.exports = new LeafNl(); \ No newline at end of file +module.exports = new LeafNl(); diff --git a/src/parsers/nodeLiterals/nodeliterals.js b/src/parsers/nodeLiterals/nodeliterals.js index 9315012..3b4a14b 100644 --- a/src/parsers/nodeLiterals/nodeliterals.js +++ b/src/parsers/nodeLiterals/nodeliterals.js @@ -12,4 +12,4 @@ nodeLiterals[constants.EXP_PUNC][constants.SYM.L_SQ_BRACKET] = require("./arrayn nodeLiterals[constants.EXP_PUNC][constants.SYM.L_BRACKET] = require("./bracketexpressionnl.js"); nodeLiterals[constants.EXP_PUNC][constants.SYM.EXCLAMATION_POINT] = require("./notoperatornl.js"); -module.exports = nodeLiterals; \ No newline at end of file +module.exports = nodeLiterals; diff --git a/src/parsers/nodeLiterals/notoperatornl.js b/src/parsers/nodeLiterals/notoperatornl.js index 806d1dc..3c9a73a 100644 --- a/src/parsers/nodeLiterals/notoperatornl.js +++ b/src/parsers/nodeLiterals/notoperatornl.js @@ -1,13 +1,12 @@ const BaseNode = require("../basenode.js"); class NotOperatorNl extends BaseNode { - - getNode() { + getNode () { return { operation: this.lexer().next().value, body: this.parseExpression(), - } + }; } } -module.exports = new NotOperatorNl(); \ No newline at end of file +module.exports = new NotOperatorNl(); diff --git a/src/parsers/nodeLiterals/variablenl.js b/src/parsers/nodeLiterals/variablenl.js index 466851a..e177398 100644 --- a/src/parsers/nodeLiterals/variablenl.js +++ b/src/parsers/nodeLiterals/variablenl.js @@ -3,8 +3,7 @@ const BaseNode = require("../basenode.js"); const variableNlTypes = require("./variablenltypes"); class VariableNl extends BaseNode { - - getNode() { + getNode () { const varNameToken = this.lexer().next(); const nextTokenValue = this.lexer().peek().value; @@ -16,9 +15,9 @@ class VariableNl extends BaseNode { return { operation: constants.GET_JEKI, - name: varNameToken.value + name: varNameToken.value, }; } } -module.exports = new VariableNl(); \ No newline at end of file +module.exports = new VariableNl(); diff --git a/src/parsers/nodeLiterals/variablenltypes.js b/src/parsers/nodeLiterals/variablenltypes.js index 1ef403d..655f10f 100644 --- a/src/parsers/nodeLiterals/variablenltypes.js +++ b/src/parsers/nodeLiterals/variablenltypes.js @@ -1,7 +1,7 @@ const constants = require("../../constants.js"); const variableNlTypes = {}; -variableNlTypes[constants.SYM.L_BRACKET] = require("./callIseNl.js"); //when current variable is a function call -variableNlTypes[constants.SYM.L_SQ_BRACKET] = require("./arraynl.js"); //when current variable is an array element +variableNlTypes[constants.SYM.L_BRACKET] = require("./callIseNl.js"); // when current variable is a function call +variableNlTypes[constants.SYM.L_SQ_BRACKET] = require("./arraynl.js"); // when current variable is an array element -module.exports = variableNlTypes; \ No newline at end of file +module.exports = variableNlTypes; diff --git a/src/parsers/parser.js b/src/parsers/parser.js index 05f7d39..96fe406 100644 --- a/src/parsers/parser.js +++ b/src/parsers/parser.js @@ -4,122 +4,121 @@ const nodeLiterals = require("./nodeLiterals/nodeliterals.js"); const BaseNode = require("./basenode.js"); class Parser { - - constructor(lexer) { + constructor (lexer) { this.lexer = () => lexer; this.initBlockTypeStack(); this.initIsArithmeticExpression(); } - initBlockTypeStack() { - //a work around for creating a private field with public accessors + initBlockTypeStack () { + // a work around for creating a private field with public accessors var _blockTypeStack = []; this.pushToBlockTypeStack = (blockName) => { _blockTypeStack.push(blockName); - } + }; this.popBlockTypeStack = () => _blockTypeStack.pop(); this.peekBlockTypeStack = () => _blockTypeStack[_blockTypeStack.length - 1]; - this.getBlockTypeStack = () => [..._blockTypeStack]; + this.getBlockTypeStack = () => [..._blockTypeStack, ]; } - initIsArithmeticExpression() { + initIsArithmeticExpression () { var _isArithmeticExpression = true; this.setIsArithmeticExpression = (isArithmetic) => { _isArithmeticExpression = isArithmetic; - } + }; this.isArithmeticExpression = () => _isArithmeticExpression; } - isNextTokenPunctuation(punc) { + isNextTokenPunctuation (punc) { const token = this.lexer().peek(); return token && token.type == constants.PUNCTUATION && (token.value == punc); } - isNextTokenOperator(op) { + isNextTokenOperator (op) { const token = this.lexer().peek(); return token && token.type == constants.OPERATOR && (token.value == op); } - isNextTokenKeyword(kw) { + isNextTokenKeyword (kw) { const token = this.lexer().peek(); return token && token.type == constants.KEYWORD && (token.value == kw); } - skipPunctuation(punc) { + skipPunctuation (punc) { if (this.isNextTokenPunctuation(punc)) this.lexer().next(); else this.throwError(this.getGenericErrorMsg(this.getCurrentTokenValue())); } - skipOperator(op) { + skipOperator (op) { if (this.isNextTokenOperator(op)) this.lexer().next(); else this.throwError(this.getGenericErrorMsg(this.getCurrentTokenValue())); } - skipKeyword(kw) { + skipKeyword (kw) { if (this.isNextTokenKeyword(kw)) this.lexer().next(); else this.throwError(this.getGenericErrorMsg(this.getCurrentTokenValue())); } - getCurrentTokenValue() { + getCurrentTokenValue () { return this.lexer().peek() ? this.lexer().peek().value : null; } - //Recursive descent parsing technique - //backtracking is used in handling operator precedence while parsing the expression - parseExpression() { - return this.parseAssign(); + // Recursive descent parsing technique + // backtracking is used in handling operator precedence while parsing the expression + parseExpression () { + return this.parseAssign(); } - parseAssign() { - return this.parseWhile([constants.SYM.ASSIGN], this.parseOr); + parseAssign () { + return this.parseWhile([constants.SYM.ASSIGN, ], this.parseOr); } - parseOr() { - return this.parseWhile([constants.SYM.OR], this.parseAnd); + parseOr () { + return this.parseWhile([constants.SYM.OR, ], this.parseAnd); } - parseAnd() { - return this.parseWhile([constants.SYM.AND], this.parseGreaterLesserEquality); + parseAnd () { + return this.parseWhile([constants.SYM.AND, ], this.parseGreaterLesserEquality); } - parseGreaterLesserEquality() { + parseGreaterLesserEquality () { const operatorList = [ - constants.SYM.L_THAN, constants.SYM.G_THAN, constants.SYM.G_THAN_OR_EQ, - constants.SYM.L_THAN_OR_EQ, constants.SYM.EQ, constants.SYM.NOT_EQ + constants.SYM.L_THAN, constants.SYM.G_THAN, constants.SYM.G_THAN_OR_EQ, + constants.SYM.L_THAN_OR_EQ, constants.SYM.EQ, constants.SYM.NOT_EQ, ]; if (this.isArithmeticExpression()) return this.parseWhile(operatorList, this.parsePlusMinus); - else return this.parseWhile(operatorList, this.parseNodeLiteral); //it is a boolean expression + else return this.parseWhile(operatorList, this.parseNodeLiteral); // it is a boolean expression } - parsePlusMinus() { - return this.parseWhile([constants.SYM.PLUS, constants.SYM.MINUS], this.parseMultiplyDivisionRemainder); + parsePlusMinus () { + return this.parseWhile([constants.SYM.PLUS, constants.SYM.MINUS, ], this.parseMultiplyDivisionRemainder); } - parseMultiplyDivisionRemainder() { - return this.parseWhile([constants.SYM.MULTIPLY, constants.SYM.DIVIDE, constants.SYM.REMAINDER], this.parseNodeLiteral); + parseMultiplyDivisionRemainder () { + return this.parseWhile([constants.SYM.MULTIPLY, constants.SYM.DIVIDE, constants.SYM.REMAINDER, ], this.parseNodeLiteral); } - parseWhile(operatorList, parseOperationWithLesserPrecedence) { + parseWhile (operatorList, parseOperationWithLesserPrecedence) { let node = parseOperationWithLesserPrecedence.bind(this)(); while (this.isNextTokenInOperatorList(operatorList)) { node = { - left : node, - operation : this.lexer().next().value, - right : parseOperationWithLesserPrecedence.bind(this)(), - value : null + left: node, + operation: this.lexer().next().value, + right: parseOperationWithLesserPrecedence.bind(this)(), + value: null, }; } return node; } - isNextTokenInOperatorList(operatorList) { + isNextTokenInOperatorList (operatorList) { return this.isNotEndOfFile() && (operatorList.indexOf(this.lexer().peek().value) >= 0); } - parseNodeLiteral() { + parseNodeLiteral () { const token = this.lexer().peek(); if (nodeLiterals[token.type] != undefined) { @@ -128,8 +127,8 @@ class Parser { else throw new Error(`${token.value} must be of type BaseNode`); } - //check if the token value is a punctuation that can be used in an expression e.g (, [ - if (nodeLiterals[constants.EXP_PUNC][token.value] != undefined) { + // check if the token value is a punctuation that can be used in an expression e.g (, [ + if (nodeLiterals[constants.EXP_PUNC][token.value] != undefined) { const nodeliteral = nodeLiterals[constants.EXP_PUNC][token.value]; if (nodeliteral instanceof BaseNode) return nodeliteral.getNode.call(this); else throw new Error(`${token.value} must be of type BaseNode`); @@ -138,10 +137,10 @@ class Parser { this.lexer().throwError(this.getGenericErrorMsg(token.value)); } - parseBlock(currentBlock) { + parseBlock (currentBlock) { this.pushToBlockTypeStack(currentBlock); this.skipPunctuation(constants.SYM.L_PAREN); - const block = []; + const block = []; while (this.isNotEndOfBlock()) { block.push(this.parseAst()); } @@ -151,24 +150,24 @@ class Parser { return block; } - isNotEndOfBlock() { + isNotEndOfBlock () { return this.isNotEndOfFile() && (this.lexer().peek().value != constants.SYM.R_PAREN); } - parseVarname() { - return ( this.lexer().peek().type == constants.VARIABLE ) - ? this.lexer().next().value - : this.lexer().throwError(this.getGenericErrorMsg(this.lexer().peek().value)); + parseVarname () { + return (this.lexer().peek().type == constants.VARIABLE) + ? this.lexer().next().value + : this.lexer().throwError(this.getGenericErrorMsg(this.lexer().peek().value)); } - parseDelimited(start, stop, separator, parser, predicate) { + parseDelimited (start, stop, separator, parser, predicate) { const varList = []; let firstVar = true; this.skipPunctuation(start); while (this.isNotEndOfFile()) { if (this.isNextTokenPunctuation(stop)) break; if (firstVar) firstVar = false; else this.skipPunctuation(separator); - if (this.isNextTokenPunctuation(stop)) break; //this is necessary for an optional last separator + if (this.isNextTokenPunctuation(stop)) break; // this is necessary for an optional last separator varList.push(parser(predicate)); } this.skipPunctuation(stop); @@ -176,27 +175,27 @@ class Parser { return varList; } - getTokenThatSatisfiesPredicate(predicate) { + getTokenThatSatisfiesPredicate (predicate) { var token = this.lexer().next(); if (predicate(token)) return token; this.throwError(this.getGenericErrorMsg(token.type)); } - getGenericErrorMsg(value) { + getGenericErrorMsg (value) { return `Cannot process unexpected token : ${value}`; } - parseAst() { + parseAst () { const token = this.lexer().peek(); if (kwnodes[token.value] != undefined) { const kwNode = kwnodes[token.value]; - if (kwNode instanceof BaseNode) return kwNode.getNode.call(this); //call the method getNode in kwNode object like an extension function to the Parser class + if (kwNode instanceof BaseNode) return kwNode.getNode.call(this); // call the method getNode in kwNode object like an extension function to the Parser class else throw new Error(`${kwNode} must be of type BaseNode`); } - if (token.type === constants.VARIABLE) { //then a function call is expected + if (token.type === constants.VARIABLE) { // then a function call is expected const callIseNodeLiteral = nodeLiterals[constants.CALL_ISE]; if (callIseNodeLiteral instanceof BaseNode) return callIseNodeLiteral.getNode.call(this); else throw new Error(`${callIseNodeLiteral} must be of type BaseNode`); @@ -205,13 +204,13 @@ class Parser { this.throwError(this.getGenericErrorMsg(token.value)); } - isNotEndOfFile() { + isNotEndOfFile () { return this.lexer().isNotEndOfFile(); } - throwError(msg) { + throwError (msg) { this.lexer().throwError(msg); } } -module.exports = Parser; \ No newline at end of file +module.exports = Parser; diff --git a/src/tests/helperise/array_helpers/ka.test.js b/src/tests/helperise/array_helpers/ka.test.js index ea66868..1a510a7 100644 --- a/src/tests/helperise/array_helpers/ka.test.js +++ b/src/tests/helperise/array_helpers/ka.test.js @@ -1,14 +1,13 @@ const ka = require("../../../helperise/array_helpers/ka.js"); describe("Ka Test suite", () => { - test("It should return the length of the array", () => { - const array = [[1,2,3]]; + const array = [[1, 2, 3, ], ]; expect(ka(array)).toBe(3); }); test("It should fail because ka expects a multidimensional array", () => { - const array = [1,2,3]; + const array = [1, 2, 3, ]; expect(() => ka(array)).toThrow(); }); @@ -16,4 +15,4 @@ describe("Ka Test suite", () => { const array = 2; expect(() => ka(array)).toThrow("Yorlang system error"); }); -}); \ No newline at end of file +}); diff --git a/src/tests/helperise/input_ouptut/tesibi.test.js b/src/tests/helperise/input_ouptut/tesibi.test.js index f10a29e..03d5853 100644 --- a/src/tests/helperise/input_ouptut/tesibi.test.js +++ b/src/tests/helperise/input_ouptut/tesibi.test.js @@ -1,28 +1,27 @@ -jest.mock('readline-sync', () => ({ - question: jest.fn() +jest.mock("readline-sync", () => ({ + question: jest.fn(), })); -const readlineSync = require('readline-sync'); +const readlineSync = require("readline-sync"); const teSibi = require("../../../helperise/input_output/tesibi.js"); describe("TeSibi Test suite", () => { - test("It should read user input as string", () => { readlineSync.question.mockReturnValueOnce("anu"); - const array = ["What is your name?"]; + const array = ["What is your name?", ]; expect(teSibi(array)).toBe("anu"); }); test("It should read user input as number", () => { readlineSync.question.mockReturnValueOnce("2"); - const array = ["What is your age?"]; + const array = ["What is your age?", ]; expect(teSibi(array)).toBe(2); }); test("It should fail to read user input", () => { - const array = [1]; + const array = [1, ]; expect(() => teSibi(array)).toThrow(); }); @@ -30,4 +29,4 @@ describe("TeSibi Test suite", () => { const array = 2; expect(() => teSibi(array)).toThrow("Yorlang system error"); }); -}); \ No newline at end of file +}); diff --git a/src/tests/helperise/string_helpers/si_leta_kekere.test.js b/src/tests/helperise/string_helpers/si_leta_kekere.test.js index 87e4fa6..f1db153 100644 --- a/src/tests/helperise/string_helpers/si_leta_kekere.test.js +++ b/src/tests/helperise/string_helpers/si_leta_kekere.test.js @@ -1,14 +1,13 @@ const siLetaKekere = require("../../../helperise/string_helpers/si_leta_kekere.js"); describe("SiLetaNla Test suite", () => { - test("It should return lowercase version of string", () => { - const array = ["ANU"]; + const array = ["ANU", ]; expect(siLetaKekere(array)).toBe("anu"); }); test("It should fail to convert invalid string to lowercase", () => { - const array = [1]; + const array = [1, ]; expect(() => siLetaKekere(array)).toThrow(); }); @@ -16,4 +15,4 @@ describe("SiLetaNla Test suite", () => { const array = 2; expect(() => siLetaKekere(array)).toThrow("Yorlang system error"); }); -}); \ No newline at end of file +}); diff --git a/src/tests/helperise/string_helpers/si_leta_nla.test.js b/src/tests/helperise/string_helpers/si_leta_nla.test.js index 541e0ee..f3540f4 100644 --- a/src/tests/helperise/string_helpers/si_leta_nla.test.js +++ b/src/tests/helperise/string_helpers/si_leta_nla.test.js @@ -1,14 +1,13 @@ const siLetaNla = require("../../../helperise/string_helpers/si_leta_nla.js"); describe("SiLetaNla Test suite", () => { - test("It should return uppercase version of string", () => { - const array = ["anu"]; + const array = ["anu", ]; expect(siLetaNla(array)).toBe("ANU"); }); test("It should fail to convert invalid string to upper case", () => { - const array = [1]; + const array = [1, ]; expect(() => siLetaNla(array)).toThrow(); }); @@ -16,4 +15,4 @@ describe("SiLetaNla Test suite", () => { const array = 2; expect(() => siLetaNla(array)).toThrow("Yorlang system error"); }); -}); \ No newline at end of file +}); diff --git a/src/tests/inputstream.test.js b/src/tests/inputstream.test.js index 4892ee8..c22b65f 100644 --- a/src/tests/inputstream.test.js +++ b/src/tests/inputstream.test.js @@ -1,5 +1,5 @@ -jest.mock('fs', () => ({ - readFileSync: jest.fn() +jest.mock("fs", () => ({ + readFileSync: jest.fn(), })); const InputStream = require("../inputstream.js"); @@ -27,7 +27,7 @@ describe("InputStream Tests", () => { test("ThrowError - It should throw an error message while specifying the location of the error accurately", () => { inputStream.code = `${constants.SYM.NEW_LINE}`; - inputStream.next(); //read in the new line character + inputStream.next(); // read in the new line character const errorMsg = "Testing error msg"; expect(() => { @@ -46,5 +46,4 @@ describe("InputStream Tests", () => { expect(inputStream.isEndOfFile()).toBe(true); }); - -}); \ No newline at end of file +}); diff --git a/src/tests/interpreters/inodeand.test.js b/src/tests/interpreters/inodeand.test.js index a0365f2..67c6c57 100644 --- a/src/tests/interpreters/inodeand.test.js +++ b/src/tests/interpreters/inodeand.test.js @@ -1,5 +1,5 @@ -jest.mock('fs', () => ({ - readFileSync: jest.fn() +jest.mock("fs", () => ({ + readFileSync: jest.fn(), })); const MainInterpreter = require("../../interpreters/maininterpreter.js"); @@ -40,4 +40,4 @@ describe("INodeAnd test suite", () => { mainInterpreter.interpreteProgram(); expect(mainInterpreter.environment().getJeki(mainInterpreter.getCurrentScope(), "b")).toEqual(constants.KW.IRO); }); -}); \ No newline at end of file +}); diff --git a/src/tests/interpreters/inodearray.test.js b/src/tests/interpreters/inodearray.test.js index 3b0cf90..37d0f39 100644 --- a/src/tests/interpreters/inodearray.test.js +++ b/src/tests/interpreters/inodearray.test.js @@ -1,5 +1,5 @@ -jest.mock('fs', () => ({ - readFileSync: jest.fn() +jest.mock("fs", () => ({ + readFileSync: jest.fn(), })); const MainInterpreter = require("../../interpreters/maininterpreter.js"); @@ -39,7 +39,7 @@ describe("INodeArray test suite", () => { `; mainInterpreter.interpreteProgram(); - expect(mainInterpreter.environment().getJeki(mainInterpreter.getCurrentScope(), "b")).toEqual([1,2,5]); + expect(mainInterpreter.environment().getJeki(mainInterpreter.getCurrentScope(), "b")).toEqual([1, 2, 5, ]); }); test("it should interprete expression that contains an array element reference", () => { @@ -49,7 +49,7 @@ describe("INodeArray test suite", () => { `; mainInterpreter.interpreteProgram(); - expect(mainInterpreter.environment().getJeki(mainInterpreter.getCurrentScope(), "b")).toEqual([1,2,3]); + expect(mainInterpreter.environment().getJeki(mainInterpreter.getCurrentScope(), "b")).toEqual([1, 2, 3, ]); }); test("it should interprete a multidimensional array", () => { @@ -59,7 +59,7 @@ describe("INodeArray test suite", () => { `; mainInterpreter.interpreteProgram(); - expect(mainInterpreter.environment().getJeki(mainInterpreter.getCurrentScope(), "b")).toEqual([[1,2],[3,4]]); + expect(mainInterpreter.environment().getJeki(mainInterpreter.getCurrentScope(), "b")).toEqual([[1, 2, ], [3, 4, ], ]); }); test("it should interprete a multidimensional array element", () => { @@ -82,4 +82,4 @@ describe("INodeArray test suite", () => { expect(() => mainInterpreter.interpreteProgram()).toThrow(); }); -}); \ No newline at end of file +}); diff --git a/src/tests/interpreters/inodecallise.test.js b/src/tests/interpreters/inodecallise.test.js index 6f3a3da..129e418 100644 --- a/src/tests/interpreters/inodecallise.test.js +++ b/src/tests/interpreters/inodecallise.test.js @@ -1,5 +1,5 @@ -jest.mock('fs', () => ({ - readFileSync: jest.fn() +jest.mock("fs", () => ({ + readFileSync: jest.fn(), })); const MainInterpreter = require("../../interpreters/maininterpreter.js"); @@ -86,7 +86,6 @@ describe("INodeCallIse test suite", () => { mainInterpreter.interpreteProgram(); expect(global.console.log).toHaveBeenCalledWith("karounwi femi"); expect(global.console.log).toHaveBeenCalledWith("karounwi femi 0812035532"); - }); test("it should call an ise function in a parent scope", () => { @@ -169,4 +168,4 @@ describe("INodeCallIse test suite", () => { mainInterpreter.interpreteProgram(); expect(global.console.log).toHaveBeenCalledWith(0); }); -}); \ No newline at end of file +}); diff --git a/src/tests/interpreters/inodedivide.test.js b/src/tests/interpreters/inodedivide.test.js index 1d6a2fe..c587b46 100644 --- a/src/tests/interpreters/inodedivide.test.js +++ b/src/tests/interpreters/inodedivide.test.js @@ -1,5 +1,5 @@ -jest.mock('fs', () => ({ - readFileSync: jest.fn() +jest.mock("fs", () => ({ + readFileSync: jest.fn(), })); const MainInterpreter = require("../../interpreters/maininterpreter.js"); @@ -11,7 +11,6 @@ const InputStream = require("../../inputstream.js"); const constants = require("../../constants.js"); describe("IDivide test suite", () => { - test("it should interprete a division operation", () => { let parser = new Parser(new Lexer(new InputStream())); parser.lexer().inputStream.code = `${constants.KW.JEKI} a = 15 / 5;`; @@ -25,4 +24,4 @@ describe("IDivide test suite", () => { const node = kwNodeTi.getNode.call(parser); expect(() => iDivide.interpreteNode.call(new MainInterpreter(), node.right)).toThrow(); }); -}); \ No newline at end of file +}); diff --git a/src/tests/interpreters/inodeequals.test.js b/src/tests/interpreters/inodeequals.test.js index cd41c0a..8d4c445 100644 --- a/src/tests/interpreters/inodeequals.test.js +++ b/src/tests/interpreters/inodeequals.test.js @@ -1,5 +1,5 @@ -jest.mock('fs', () => ({ - readFileSync: jest.fn() +jest.mock("fs", () => ({ + readFileSync: jest.fn(), })); const MainInterpreter = require("../../interpreters/maininterpreter.js"); @@ -40,4 +40,4 @@ describe("INodeEquals test suite", () => { mainInterpreter.interpreteProgram(); expect(mainInterpreter.environment().getJeki(mainInterpreter.getCurrentScope(), "b")).toEqual(constants.KW.OOTO); }); -}); \ No newline at end of file +}); diff --git a/src/tests/interpreters/inodefun.test.js b/src/tests/interpreters/inodefun.test.js index 711523f..5651428 100644 --- a/src/tests/interpreters/inodefun.test.js +++ b/src/tests/interpreters/inodefun.test.js @@ -1,5 +1,5 @@ -jest.mock('fs', () => ({ - readFileSync: jest.fn() +jest.mock("fs", () => ({ + readFileSync: jest.fn(), })); const MainInterpreter = require("../../interpreters/maininterpreter.js"); @@ -69,5 +69,4 @@ describe("INodeFun test suite", () => { mainInterpreter.interpreteProgram(); expect(global.console.log).toHaveBeenCalledTimes(6); }); - -}); \ No newline at end of file +}); diff --git a/src/tests/interpreters/inodegbewole.test.js b/src/tests/interpreters/inodegbewole.test.js index 8bbb1de..d00dedd 100644 --- a/src/tests/interpreters/inodegbewole.test.js +++ b/src/tests/interpreters/inodegbewole.test.js @@ -1,5 +1,5 @@ -jest.mock('fs', () => ({ - readFileSync: jest.fn() +jest.mock("fs", () => ({ + readFileSync: jest.fn(), })); const MainInterpreter = require("../../interpreters/maininterpreter.js"); @@ -11,7 +11,6 @@ const constants = require("../../constants.js"); const fs = require("fs"); describe("INodeGbeWole test suite", () => { - beforeEach(() => { global.console.log = jest.fn(); }); @@ -23,7 +22,7 @@ describe("INodeGbeWole test suite", () => { `).mockReturnValueOnce(`${constants.KW.ISE} isiro(a, b) { ${constants.KW.PADA} a * b; }`); - + const parser = new Parser(new Lexer(new InputStream())); const mainInterpreter = new MainInterpreter(new Environment(), parser); mainInterpreter.interpreteProgram(); @@ -35,10 +34,10 @@ describe("INodeGbeWole test suite", () => { ${constants.KW.JEKI} b = isiro(14, 2); ${constants.KW.SOPE} b; `); - + const parser = new Parser(new Lexer(new InputStream())); const mainInterpreter = new MainInterpreter(new Environment(), parser); - + expect(() => mainInterpreter.interpreteProgram()).toThrow(); }); -}); \ No newline at end of file +}); diff --git a/src/tests/interpreters/inodegetti.test.js b/src/tests/interpreters/inodegetti.test.js index 147ffc7..b73b7d7 100644 --- a/src/tests/interpreters/inodegetti.test.js +++ b/src/tests/interpreters/inodegetti.test.js @@ -1,5 +1,5 @@ -jest.mock('fs', () => ({ - readFileSync: jest.fn() +jest.mock("fs", () => ({ + readFileSync: jest.fn(), })); const MainInterpreter = require("../../interpreters/maininterpreter.js"); @@ -24,13 +24,13 @@ describe("INodegetJeki test suite", () => { parser.lexer().inputStream.code = `${constants.KW.JEKI} a = 15 / 5;`; const node = kwNodeTi.getNode.call(parser); iNodeTi.interpreteNode.call(mainInterpreter, node); - expect(iNodeGetJeki.interpreteNode.call(mainInterpreter, {name: "a"})).toBe(3); + expect(iNodeGetJeki.interpreteNode.call(mainInterpreter, { name: "a", })).toBe(3); }); test("it should throw an error when attempting to get the value of a non-existent variable within the current scope", () => { parser.lexer().inputStream.code = `${constants.KW.JEKI} a = 15 / 5;`; const node = kwNodeTi.getNode.call(parser); iNodeTi.interpreteNode.call(mainInterpreter, node); - expect(() => iNodeGetJeki.interpreteNode.call(mainInterpreter, {name: "b"})).toThrow(); + expect(() => iNodeGetJeki.interpreteNode.call(mainInterpreter, { name: "b", })).toThrow(); }); -}); \ No newline at end of file +}); diff --git a/src/tests/interpreters/inodegthan.test.js b/src/tests/interpreters/inodegthan.test.js index 623878f..6abd230 100644 --- a/src/tests/interpreters/inodegthan.test.js +++ b/src/tests/interpreters/inodegthan.test.js @@ -1,5 +1,5 @@ -jest.mock('fs', () => ({ - readFileSync: jest.fn() +jest.mock("fs", () => ({ + readFileSync: jest.fn(), })); const MainInterpreter = require("../../interpreters/maininterpreter.js"); @@ -46,4 +46,4 @@ describe("INodeGreaterThan test suite", () => { mainInterpreter.interpreteProgram(); expect(mainInterpreter.environment().getJeki(mainInterpreter.getCurrentScope(), "b")).toEqual(constants.KW.OOTO); }); -}); \ No newline at end of file +}); diff --git a/src/tests/interpreters/inodegthanoreq.test.js b/src/tests/interpreters/inodegthanoreq.test.js index 601c55d..ab573e7 100644 --- a/src/tests/interpreters/inodegthanoreq.test.js +++ b/src/tests/interpreters/inodegthanoreq.test.js @@ -1,5 +1,5 @@ -jest.mock('fs', () => ({ - readFileSync: jest.fn() +jest.mock("fs", () => ({ + readFileSync: jest.fn(), })); const MainInterpreter = require("../../interpreters/maininterpreter.js"); @@ -40,4 +40,4 @@ describe("INodeGreaterThanOrEqual test suite", () => { mainInterpreter.interpreteProgram(); expect(mainInterpreter.environment().getJeki(mainInterpreter.getCurrentScope(), "b")).toEqual(constants.KW.OOTO); }); -}); \ No newline at end of file +}); diff --git a/src/tests/interpreters/inodeise.test.js b/src/tests/interpreters/inodeise.test.js index 8a578dc..e38531c 100644 --- a/src/tests/interpreters/inodeise.test.js +++ b/src/tests/interpreters/inodeise.test.js @@ -1,5 +1,5 @@ -jest.mock('fs', () => ({ - readFileSync: jest.fn() +jest.mock("fs", () => ({ + readFileSync: jest.fn(), })); const MainInterpreter = require("../../interpreters/maininterpreter.js"); @@ -30,18 +30,18 @@ describe("INodeIse test suite", () => { operation: constants.KW.SOPE, body: { name: "fname", - operation: constants.GET_JEKI - } - }], - name: "teOruko", - operation: constants.KW.ISE, + operation: constants.GET_JEKI, + }, + }, ], + name: "teOruko", + operation: constants.KW.ISE, paramTokens: [ { - type: constants.VARIABLE, - value: "fname" - } - ] - } + type: constants.VARIABLE, + value: "fname", + }, + ], + }; mainInterpreter.interpreteProgram(); expect(mainInterpreter.environment().getIse(mainInterpreter.getCurrentScope(), "teOruko")).toEqual(expectedNode); @@ -74,5 +74,4 @@ describe("INodeIse test suite", () => { mainInterpreter.interpreteProgram(); expect(mainInterpreter.environment().getIse(mainInterpreter.getCurrentScope(), "teName")).toBeTruthy(); }); - -}); \ No newline at end of file +}); diff --git a/src/tests/interpreters/inodejeki.test.js b/src/tests/interpreters/inodejeki.test.js index 5cea450..03b032a 100644 --- a/src/tests/interpreters/inodejeki.test.js +++ b/src/tests/interpreters/inodejeki.test.js @@ -1,5 +1,5 @@ -jest.mock('fs', () => ({ - readFileSync: jest.fn() +jest.mock("fs", () => ({ + readFileSync: jest.fn(), })); const MainInterpreter = require("../../interpreters/maininterpreter.js"); @@ -44,7 +44,7 @@ describe("INodeJeki test suite", () => { parser.lexer().inputStream.code = `${constants.KW.JEKI} a = [1,2];`; const node = kwNodeTi.getNode.call(parser); iNodeTi.interpreteNode.call(mainInterpreter, node); - expect(mainInterpreter.environment().getJeki(mainInterpreter.getCurrentScope(), "a")).toEqual([1,2]); + expect(mainInterpreter.environment().getJeki(mainInterpreter.getCurrentScope(), "a")).toEqual([1, 2, ]); }); test("it should interprete expression that contains a variable reference", () => { @@ -64,7 +64,7 @@ describe("INodeJeki test suite", () => { `; mainInterpreter.interpreteProgram(); - expect(mainInterpreter.environment().getJeki(mainInterpreter.getCurrentScope(), "a")).toEqual(["funmi",2]); + expect(mainInterpreter.environment().getJeki(mainInterpreter.getCurrentScope(), "a")).toEqual(["funmi", 2, ]); }); test("it should assign value to the last position of an array element with empty index", () => { @@ -74,7 +74,7 @@ describe("INodeJeki test suite", () => { `; mainInterpreter.interpreteProgram(); - expect(mainInterpreter.environment().getJeki(mainInterpreter.getCurrentScope(), "a")).toEqual([1,2, "funmi"]); + expect(mainInterpreter.environment().getJeki(mainInterpreter.getCurrentScope(), "a")).toEqual([1, 2, "funmi", ]); }); test("it should assign value to the last position of a multidimensional array element with empty index", () => { @@ -84,7 +84,7 @@ describe("INodeJeki test suite", () => { `; mainInterpreter.interpreteProgram(); - expect(mainInterpreter.environment().getJeki(mainInterpreter.getCurrentScope(), "a")).toEqual( [1,[2, "funmi"]]); + expect(mainInterpreter.environment().getJeki(mainInterpreter.getCurrentScope(), "a")).toEqual([1, [2, "funmi", ], ]); }); test("it should assign value to a multi-dimensional array element", () => { @@ -94,7 +94,7 @@ describe("INodeJeki test suite", () => { `; mainInterpreter.interpreteProgram(); - expect(mainInterpreter.environment().getJeki(mainInterpreter.getCurrentScope(), "a")).toEqual([ [1,2], [["funmi",4],5] ]); + expect(mainInterpreter.environment().getJeki(mainInterpreter.getCurrentScope(), "a")).toEqual([ [1, 2, ], [["funmi", 4, ], 5, ], ]); }); test("it should fail to assign value to an invalid multi-dimensional array element", () => { @@ -125,7 +125,7 @@ describe("INodeJeki test suite", () => { `; mainInterpreter.interpreteProgram(); - expect(mainInterpreter.environment().getJeki(mainInterpreter.getCurrentScope(), "a")).toEqual([[1,2], "funmi", 5]); + expect(mainInterpreter.environment().getJeki(mainInterpreter.getCurrentScope(), "a")).toEqual([[1, 2, ], "funmi", 5, ]); }); test("it should assign transformed (uppercase) string to variablet", () => { @@ -145,4 +145,4 @@ describe("INodeJeki test suite", () => { mainInterpreter.interpreteProgram(); expect(mainInterpreter.environment().getJeki(mainInterpreter.getCurrentScope(), "a")).toBe("funmi"); }); -}); \ No newline at end of file +}); diff --git a/src/tests/interpreters/inodelthan.test.js b/src/tests/interpreters/inodelthan.test.js index 2d735f7..0d846e1 100644 --- a/src/tests/interpreters/inodelthan.test.js +++ b/src/tests/interpreters/inodelthan.test.js @@ -1,5 +1,5 @@ -jest.mock('fs', () => ({ - readFileSync: jest.fn() +jest.mock("fs", () => ({ + readFileSync: jest.fn(), })); const MainInterpreter = require("../../interpreters/maininterpreter.js"); @@ -40,4 +40,4 @@ describe("INodeLessThan test suite", () => { mainInterpreter.interpreteProgram(); expect(mainInterpreter.environment().getJeki(mainInterpreter.getCurrentScope(), "b")).toEqual(constants.KW.OOTO); }); -}); \ No newline at end of file +}); diff --git a/src/tests/interpreters/inodelthanoreq.test.js b/src/tests/interpreters/inodelthanoreq.test.js index ccb571e..2fdcdaa 100644 --- a/src/tests/interpreters/inodelthanoreq.test.js +++ b/src/tests/interpreters/inodelthanoreq.test.js @@ -1,5 +1,5 @@ -jest.mock('fs', () => ({ - readFileSync: jest.fn() +jest.mock("fs", () => ({ + readFileSync: jest.fn(), })); const MainInterpreter = require("../../interpreters/maininterpreter.js"); @@ -40,4 +40,4 @@ describe("INodeLessThanOrEqual test suite", () => { mainInterpreter.interpreteProgram(); expect(mainInterpreter.environment().getJeki(mainInterpreter.getCurrentScope(), "b")).toEqual(constants.KW.OOTO); }); -}); \ No newline at end of file +}); diff --git a/src/tests/interpreters/inodeminus.test.js b/src/tests/interpreters/inodeminus.test.js index db360f2..cf0215b 100644 --- a/src/tests/interpreters/inodeminus.test.js +++ b/src/tests/interpreters/inodeminus.test.js @@ -1,5 +1,5 @@ -jest.mock('fs', () => ({ - readFileSync: jest.fn() +jest.mock("fs", () => ({ + readFileSync: jest.fn(), })); const MainInterpreter = require("../../interpreters/maininterpreter.js"); @@ -11,11 +11,10 @@ const InputStream = require("../../inputstream.js"); const constants = require("../../constants.js"); describe("IMinus test suite", () => { - test("it should interprete a minus operation", () => { let parser = new Parser(new Lexer(new InputStream())); parser.lexer().inputStream.code = `${constants.KW.JEKI} a = 5 - 4;`; const node = kwNodeTi.getNode.call(parser); expect(iMinus.interpreteNode.call(new MainInterpreter(), node.right)).toBe(1); }); -}); \ No newline at end of file +}); diff --git a/src/tests/interpreters/inodemultiply.test.js b/src/tests/interpreters/inodemultiply.test.js index d2c66c0..992f326 100644 --- a/src/tests/interpreters/inodemultiply.test.js +++ b/src/tests/interpreters/inodemultiply.test.js @@ -1,5 +1,5 @@ -jest.mock('fs', () => ({ - readFileSync: jest.fn() +jest.mock("fs", () => ({ + readFileSync: jest.fn(), })); const MainInterpreter = require("../../interpreters/maininterpreter.js"); @@ -11,11 +11,10 @@ const InputStream = require("../../inputstream.js"); const constants = require("../../constants.js"); describe("IMultiply test suite", () => { - test("it should interprete a multiplication operation", () => { let parser = new Parser(new Lexer(new InputStream())); parser.lexer().inputStream.code = `${constants.KW.JEKI} a = 3 * 5;`; const node = kwNodeTi.getNode.call(parser); expect(iMultiply.interpreteNode.call(new MainInterpreter(), node.right)).toBe(15); }); -}); \ No newline at end of file +}); diff --git a/src/tests/interpreters/inodenigbati.test.js b/src/tests/interpreters/inodenigbati.test.js index 760f828..d2af24a 100644 --- a/src/tests/interpreters/inodenigbati.test.js +++ b/src/tests/interpreters/inodenigbati.test.js @@ -1,5 +1,5 @@ -jest.mock('fs', () => ({ - readFileSync: jest.fn() +jest.mock("fs", () => ({ + readFileSync: jest.fn(), })); const MainInterpreter = require("../../interpreters/maininterpreter.js"); @@ -68,4 +68,4 @@ describe("INodeNigbati test suite", () => { mainInterpreter.interpreteProgram(); expect(global.console.log).toHaveBeenCalledTimes(4); }); -}); \ No newline at end of file +}); diff --git a/src/tests/interpreters/inodenoteq.test.js b/src/tests/interpreters/inodenoteq.test.js index 0365d60..4e17306 100644 --- a/src/tests/interpreters/inodenoteq.test.js +++ b/src/tests/interpreters/inodenoteq.test.js @@ -1,5 +1,5 @@ -jest.mock('fs', () => ({ - readFileSync: jest.fn() +jest.mock("fs", () => ({ + readFileSync: jest.fn(), })); const MainInterpreter = require("../../interpreters/maininterpreter.js"); @@ -40,4 +40,4 @@ describe("INodeNotEqual test suite", () => { mainInterpreter.interpreteProgram(); expect(mainInterpreter.environment().getJeki(mainInterpreter.getCurrentScope(), "b")).toEqual(constants.KW.OOTO); }); -}); \ No newline at end of file +}); diff --git a/src/tests/interpreters/inodenotoperator.test.js b/src/tests/interpreters/inodenotoperator.test.js index 46f77ba..87c5e2d 100644 --- a/src/tests/interpreters/inodenotoperator.test.js +++ b/src/tests/interpreters/inodenotoperator.test.js @@ -1,5 +1,5 @@ -jest.mock('fs', () => ({ - readFileSync: jest.fn() +jest.mock("fs", () => ({ + readFileSync: jest.fn(), })); const MainInterpreter = require("../../interpreters/maininterpreter.js"); @@ -40,4 +40,4 @@ describe("INodeNotOperator test suite", () => { mainInterpreter.interpreteProgram(); expect(mainInterpreter.environment().getJeki(mainInterpreter.getCurrentScope(), "a")).toBe(constants.KW.IRO); }); -}); \ No newline at end of file +}); diff --git a/src/tests/interpreters/inodeor.test.js b/src/tests/interpreters/inodeor.test.js index fed12f9..5e8c8e3 100644 --- a/src/tests/interpreters/inodeor.test.js +++ b/src/tests/interpreters/inodeor.test.js @@ -1,5 +1,5 @@ -jest.mock('fs', () => ({ - readFileSync: jest.fn() +jest.mock("fs", () => ({ + readFileSync: jest.fn(), })); const MainInterpreter = require("../../interpreters/maininterpreter.js"); @@ -40,4 +40,4 @@ describe("INodeOr test suite", () => { mainInterpreter.interpreteProgram(); expect(mainInterpreter.environment().getJeki(mainInterpreter.getCurrentScope(), "b")).toEqual(constants.KW.IRO); }); -}); \ No newline at end of file +}); diff --git a/src/tests/interpreters/inodepada.test.js b/src/tests/interpreters/inodepada.test.js index 9bc9d3c..513597b 100644 --- a/src/tests/interpreters/inodepada.test.js +++ b/src/tests/interpreters/inodepada.test.js @@ -1,5 +1,5 @@ -jest.mock('fs', () => ({ - readFileSync: jest.fn() +jest.mock("fs", () => ({ + readFileSync: jest.fn(), })); const MainInterpreter = require("../../interpreters/maininterpreter.js"); @@ -46,6 +46,6 @@ describe("INodePada test suite", () => { parser.pushToBlockTypeStack(constants.KW.ISE); const node = kwNodePada.getNode.call(parser); - expect(iNodePada.interpreteNode.call(new MainInterpreter(), node)).toEqual([1,2]); + expect(iNodePada.interpreteNode.call(new MainInterpreter(), node)).toEqual([1, 2, ]); }); -}); \ No newline at end of file +}); diff --git a/src/tests/interpreters/inodeplus.test.js b/src/tests/interpreters/inodeplus.test.js index 2082151..b84da89 100644 --- a/src/tests/interpreters/inodeplus.test.js +++ b/src/tests/interpreters/inodeplus.test.js @@ -1,5 +1,5 @@ -jest.mock('fs', () => ({ - readFileSync: jest.fn() +jest.mock("fs", () => ({ + readFileSync: jest.fn(), })); const MainInterpreter = require("../../interpreters/maininterpreter.js"); @@ -11,11 +11,10 @@ const InputStream = require("../../inputstream.js"); const constants = require("../../constants.js"); describe("IPlus test suite", () => { - test("it should interprete a plus operation", () => { let parser = new Parser(new Lexer(new InputStream())); parser.lexer().inputStream.code = `${constants.KW.JEKI} a = 3 + 5;`; const node = kwNodeTi.getNode.call(parser); expect(iPlus.interpreteNode.call(new MainInterpreter(), node.right)).toBe(8); }); -}); \ No newline at end of file +}); diff --git a/src/tests/interpreters/inoderemainder.test.js b/src/tests/interpreters/inoderemainder.test.js index e8010ea..2d672b3 100644 --- a/src/tests/interpreters/inoderemainder.test.js +++ b/src/tests/interpreters/inoderemainder.test.js @@ -1,5 +1,5 @@ -jest.mock('fs', () => ({ - readFileSync: jest.fn() +jest.mock("fs", () => ({ + readFileSync: jest.fn(), })); const MainInterpreter = require("../../interpreters/maininterpreter.js"); @@ -11,11 +11,10 @@ const InputStream = require("../../inputstream.js"); const constants = require("../../constants.js"); describe("IRemainder test suite", () => { - test("it should interprete a remainder operation", () => { let parser = new Parser(new Lexer(new InputStream())); parser.lexer().inputStream.code = `${constants.KW.JEKI} a = 15 % 5;`; const node = kwNodeTi.getNode.call(parser); expect(iRemainder.interpreteNode.call(new MainInterpreter(), node.right)).toBe(0); }); -}); \ No newline at end of file +}); diff --git a/src/tests/interpreters/inodese.test.js b/src/tests/interpreters/inodese.test.js index b244048..cdf1e3f 100644 --- a/src/tests/interpreters/inodese.test.js +++ b/src/tests/interpreters/inodese.test.js @@ -1,5 +1,5 @@ -jest.mock('fs', () => ({ - readFileSync: jest.fn() +jest.mock("fs", () => ({ + readFileSync: jest.fn(), })); const MainInterpreter = require("../../interpreters/maininterpreter.js"); @@ -105,5 +105,4 @@ describe("INodeSe test suite", () => { mainInterpreter.interpreteProgram(); expect(global.console.log).toHaveBeenCalledWith(7); }); - -}); \ No newline at end of file +}); diff --git a/src/tests/interpreters/inodesope.test.js b/src/tests/interpreters/inodesope.test.js index c7bcea2..3c71325 100644 --- a/src/tests/interpreters/inodesope.test.js +++ b/src/tests/interpreters/inodesope.test.js @@ -1,5 +1,5 @@ -jest.mock('fs', () => ({ - readFileSync: jest.fn() +jest.mock("fs", () => ({ + readFileSync: jest.fn(), })); const MainInterpreter = require("../../interpreters/maininterpreter.js"); @@ -23,14 +23,14 @@ describe("INodeSope test suite", () => { test("it should print a string to the console", () => { parser.lexer().inputStream.code = `${constants.KW.SOPE} "femi";`; const node = kwNodeSope.getNode.call(parser); - iNodeSope.interpreteNode.call(mainInterpreter, node) + iNodeSope.interpreteNode.call(mainInterpreter, node); expect(global.console.log).toHaveBeenCalledWith("femi"); }); test("it should print a number to the console", () => { parser.lexer().inputStream.code = `${constants.KW.SOPE} 3;`; const node = kwNodeSope.getNode.call(parser); - iNodeSope.interpreteNode.call(mainInterpreter, node) + iNodeSope.interpreteNode.call(mainInterpreter, node); expect(global.console.log).toHaveBeenCalledWith(3); }); @@ -62,4 +62,4 @@ describe("INodeSope test suite", () => { mainInterpreter.interpreteProgram(); expect(global.console.log).toHaveBeenCalledWith(5); }); -}); \ No newline at end of file +}); diff --git a/src/tests/interpreters/inodewoke.test.js b/src/tests/interpreters/inodewoke.test.js index b53f248..0b3ddfe 100644 --- a/src/tests/interpreters/inodewoke.test.js +++ b/src/tests/interpreters/inodewoke.test.js @@ -1,5 +1,5 @@ -jest.mock('fs', () => ({ - readFileSync: jest.fn() +jest.mock("fs", () => ({ + readFileSync: jest.fn(), })); const MainInterpreter = require("../../interpreters/maininterpreter.js"); @@ -13,7 +13,7 @@ describe("INodeWoke test suite", () => { let mainInterpreter, parser; beforeEach(() => { - global.console.log = jest.fn() + global.console.log = jest.fn(); parser = new Parser(new lexer(new InputStream())); mainInterpreter = new MainInterpreter(new Environment(), parser); }); @@ -44,7 +44,7 @@ describe("INodeWoke test suite", () => { ${constants.KW.SOPE} count(); `; - mainInterpreter.interpreteProgram() + mainInterpreter.interpreteProgram(); expect(global.console.log).toHaveBeenCalledWith(16); expect(global.console.log).toHaveBeenCalledWith(14); expect(global.console.log).toHaveBeenCalledWith(15); @@ -76,7 +76,7 @@ describe("INodeWoke test suite", () => { count(); `; - mainInterpreter.interpreteProgram() + mainInterpreter.interpreteProgram(); expect(global.console.log).toHaveBeenCalledWith(18); }); -}); \ No newline at end of file +}); diff --git a/src/tests/interpreters/inodeyi.test.js b/src/tests/interpreters/inodeyi.test.js index fd44232..23fc18b 100644 --- a/src/tests/interpreters/inodeyi.test.js +++ b/src/tests/interpreters/inodeyi.test.js @@ -1,5 +1,5 @@ -jest.mock('fs', () => ({ - readFileSync: jest.fn() +jest.mock("fs", () => ({ + readFileSync: jest.fn(), })); const MainInterpreter = require("../../interpreters/maininterpreter.js"); @@ -71,5 +71,4 @@ describe("INodeFun test suite", () => { expect(global.console.log).toHaveBeenCalledWith("i don't know"); expect(global.console.log).toHaveBeenCalledWith("Yoruba - mi o mo"); }); - -}); \ No newline at end of file +}); diff --git a/src/tests/lexer.test.js b/src/tests/lexer.test.js index b1dab09..a624bbd 100644 --- a/src/tests/lexer.test.js +++ b/src/tests/lexer.test.js @@ -1,5 +1,5 @@ -jest.mock('fs', () => ({ - readFileSync: jest.fn() +jest.mock("fs", () => ({ + readFileSync: jest.fn(), })); const Lexer = require("../lexer.js"); @@ -10,11 +10,11 @@ describe("Lexer Tests", () => { let lexer; beforeEach(() => { - lexer = new Lexer(new InputStream()); + lexer = new Lexer(new InputStream()); }); test("IsWhiteSpace - it should confirm that they are whitespaces", () => { - constants.LIST.WHITESPACES.forEach((ws_char,i,a) => { + constants.LIST.WHITESPACES.forEach((ws_char, i, a) => { expect(lexer.isWhiteSpace(ws_char)).toBe(true); }); }); @@ -24,9 +24,9 @@ describe("Lexer Tests", () => { }); test("isPunctuation - it should confirm that they are punctuations", () => { - constants.LIST.PUNCTUATIONS.forEach((punc_char,i,a) => { + constants.LIST.PUNCTUATIONS.forEach((punc_char, i, a) => { expect(lexer.isPunctuation(punc_char)).toBe(true); - }); + }); }); test("isPunctuation - it should confirm that it is not a punctuation", () => { @@ -46,9 +46,9 @@ describe("Lexer Tests", () => { }); test("isOperator - it should confirm that they are operators", () => { - constants.LIST.OPERATORS.forEach((op_char,i,a) => { + constants.LIST.OPERATORS.forEach((op_char, i, a) => { expect(lexer.isOperator(op_char)).toBe(true); - }); + }); }); test("isOperator - it should confirm that it is not an operator", () => { @@ -56,9 +56,9 @@ describe("Lexer Tests", () => { }); test("isKeyword - it should confirm that they are keywords", () => { - constants.LIST.KEYWORDS.forEach((kw_char,i,a) => { + constants.LIST.KEYWORDS.forEach((kw_char, i, a) => { expect(lexer.isKeyword(kw_char)).toBe(true); - }); + }); }); test("isKeyword - it should confirm that it is not a keyword", () => { @@ -86,13 +86,13 @@ describe("Lexer Tests", () => { }); test("ReadString - it should identify a string literal, while stripping off the quote symbols, and return the string token", () => { - lexer.inputStream.code = `"a23"`; + lexer.inputStream.code = "\"a23\""; - expect(lexer.readString()).toEqual({ type: constants.STRING, value: "a23" }); + expect(lexer.readString()).toEqual({ type: constants.STRING, value: "a23", }); }); test("ReadString - it should identify an incomplete string literal, and throw an error msg ", () => { - lexer.inputStream.code = `"a23`; + lexer.inputStream.code = "\"a23"; expect(() => { lexer.readString(); @@ -102,25 +102,25 @@ describe("Lexer Tests", () => { test("ReadIdentifier - it should return an variable token", () => { lexer.inputStream.code = "name"; - expect(lexer.readIdentifier()).toEqual({type: constants.VARIABLE, value: "name"}); + expect(lexer.readIdentifier()).toEqual({ type: constants.VARIABLE, value: "name", }); }); test("ReadIdentifier - it should return a keyword token", () => { lexer.inputStream.code = `${constants.KW.JEKI}`; - expect(lexer.readIdentifier()).toEqual({type: constants.KEYWORD, value: `${constants.KW.JEKI}`}); + expect(lexer.readIdentifier()).toEqual({ type: constants.KEYWORD, value: `${constants.KW.JEKI}`, }); }); test("ReadNumber - it should return a number token", () => { lexer.inputStream.code = "50.32"; - expect(lexer.readNumber()).toEqual({type: constants.NUMBER, value: 50.32}); + expect(lexer.readNumber()).toEqual({ type: constants.NUMBER, value: 50.32, }); }); test("ReadNumber - it should return a number token with a single decimal points", () => { lexer.inputStream.code = "50.32.5"; - expect(lexer.readNumber()).toEqual({type: constants.NUMBER, value: 50.32}); + expect(lexer.readNumber()).toEqual({ type: constants.NUMBER, value: 50.32, }); }); test("SkipComments - it should skip all comments", () => { @@ -131,33 +131,33 @@ describe("Lexer Tests", () => { test("SkipWhiteSpaces - it should should skip whitespaces", () => { lexer.inputStream.code = ` \n\t${constants.KW.JEKI}`; - expect(lexer.next()).toEqual({type: constants.KEYWORD, value: `${constants.KW.JEKI}`}); + expect(lexer.next()).toEqual({ type: constants.KEYWORD, value: `${constants.KW.JEKI}`, }); }); test("ReadNext - it should return the next token", () => { lexer.inputStream.code = `${constants.KW.SOPE} 2`; - expect(lexer.readNext()).toEqual({type: constants.KEYWORD, value: `${constants.KW.SOPE}`}); + expect(lexer.readNext()).toEqual({ type: constants.KEYWORD, value: `${constants.KW.SOPE}`, }); }); test("ReadNext - it should throw an error when it can't recognize a token", () => { lexer.inputStream.code = "â"; expect(() => { - lexer.readNext() + lexer.readNext(); }).toThrow("Cant handle character 'â'"); }); test("Peek - it peek at the next token without discarding it", () => { lexer.inputStream.code = "name"; - expect(lexer.peek()).toEqual({type: constants.VARIABLE, value: "name"}); + expect(lexer.peek()).toEqual({ type: constants.VARIABLE, value: "name", }); }); test("Next - it peek at the next token and also discard it", () => { lexer.inputStream.code = "name"; - expect(lexer.next()).toEqual({type: constants.VARIABLE, value: "name"}); + expect(lexer.next()).toEqual({ type: constants.VARIABLE, value: "name", }); expect(lexer.next()).toBe(null); }); @@ -172,4 +172,4 @@ describe("Lexer Tests", () => { expect(lexer.isEndOfFile()).toBe(true); }); -}); \ No newline at end of file +}); diff --git a/src/tests/mocks/kwnode.mock.js b/src/tests/mocks/kwnode.mock.js index db79f4a..b4104fa 100644 --- a/src/tests/mocks/kwnode.mock.js +++ b/src/tests/mocks/kwnode.mock.js @@ -1,6 +1,6 @@ const BaseNode = require("../../parsers/basenode.js"); -//a mock class that does not override getNode -class KwNodeMock extends BaseNode { } +// a mock class that does not override getNode +class KwNodeMock extends BaseNode { } -module.exports = new KwNodeMock(); \ No newline at end of file +module.exports = new KwNodeMock(); diff --git a/src/tests/parsers/basenode.test.js b/src/tests/parsers/basenode.test.js index 127138a..b846bd8 100644 --- a/src/tests/parsers/basenode.test.js +++ b/src/tests/parsers/basenode.test.js @@ -1,5 +1,5 @@ -jest.mock('fs', () => ({ - readFileSync: jest.fn() +jest.mock("fs", () => ({ + readFileSync: jest.fn(), })); const BaseNode = require("../../parsers/basenode.js"); @@ -9,10 +9,9 @@ const Lexer = require("../../lexer.js"); const InputStream = require("../../inputstream.js"); describe("BaseNode test suite ", () => { - test("Constructor - it should throw error while attempting to instantiate constructor", () => { expect(() => { - new BaseNode() + new BaseNode(); }).toThrow("Cannot instantiate abstract class BaseNode"); }); @@ -23,4 +22,4 @@ describe("BaseNode test suite ", () => { kwNodeMock.getNode.call(this); }).toThrow("Class of type BaseNode must implement getNode()"); }); -}) \ No newline at end of file +}); diff --git a/src/tests/parsers/keywordnodes/kwnodefun.test.js b/src/tests/parsers/keywordnodes/kwnodefun.test.js index 7e2ae6f..1c9fda3 100644 --- a/src/tests/parsers/keywordnodes/kwnodefun.test.js +++ b/src/tests/parsers/keywordnodes/kwnodefun.test.js @@ -1,5 +1,5 @@ -jest.mock('fs', () => ({ - readFileSync: jest.fn() +jest.mock("fs", () => ({ + readFileSync: jest.fn(), })); const kwNodeFun = require("../../../parsers/keywordnodes/kwnodefun.js"); @@ -19,50 +19,50 @@ describe("KwNodeFun test suite", () => { parser.lexer().inputStream.code = `${constants.KW.FUN} (${constants.KW.JEKI} i =0; i < 10; ${constants.KW.JEKI} i = i + 1;) {}`; const expectedNode = { - body: [], + body: [], condition: { left: { - name: "i", - operation: constants.GET_JEKI - }, - operation: constants.SYM.L_THAN, + name: "i", + operation: constants.GET_JEKI, + }, + operation: constants.SYM.L_THAN, right: { - left: null, - operation: null, - right: null, - value: 10 - }, - value: null - }, + left: null, + operation: null, + right: null, + value: 10, + }, + value: null, + }, increment: { - left: "i", - operation: constants.SYM.ASSIGN, + left: "i", + operation: constants.SYM.ASSIGN, right: { left: { - name: "i", - operation: constants.GET_JEKI + name: "i", + operation: constants.GET_JEKI, }, - operation: constants.SYM.PLUS, + operation: constants.SYM.PLUS, right: { - left: null, - operation: null, - right: null, - value: 1 - }, - value: null - } - }, + left: null, + operation: null, + right: null, + value: 1, + }, + value: null, + }, + }, init: { - left: "i", - operation: constants.SYM.ASSIGN, + left: "i", + operation: constants.SYM.ASSIGN, right: { - left: null, - operation: null, - right: null, - value: 0 - } - }, - operation: constants.KW.FUN + left: null, + operation: null, + right: null, + value: 0, + }, + }, + operation: constants.KW.FUN, }; expect(kwNodeFun.getNode.call(parser)).toEqual(expectedNode); @@ -95,5 +95,4 @@ describe("KwNodeFun test suite", () => { kwNodeFun.getNode.call(parser); }).toThrow(); }); - -}); \ No newline at end of file +}); diff --git a/src/tests/parsers/keywordnodes/kwnodegbewole.test.js b/src/tests/parsers/keywordnodes/kwnodegbewole.test.js index 4ae0b6f..350e73f 100644 --- a/src/tests/parsers/keywordnodes/kwnodegbewole.test.js +++ b/src/tests/parsers/keywordnodes/kwnodegbewole.test.js @@ -1,5 +1,5 @@ -jest.mock('fs', () => ({ - readFileSync: jest.fn() +jest.mock("fs", () => ({ + readFileSync: jest.fn(), })); const KwNodeGbeWole = require("../../../parsers/keywordnodes/kwnodegbewole.js"); @@ -25,17 +25,17 @@ describe("KwNodeGbeWole test suite", () => { operation: null, right: null, value: "./test.yl", - } + }, }; expect(KwNodeGbeWole.getNode.call(parser)) .toEqual(expectedNode); }); - test("It should fail when gbewole is given invalid parameter", () => { + test("It should fail when gbewole is given invalid parameter", () => { parser.lexer().inputStream.code = ` ${constants.KW.GBE_WOLE} "./test.yal"; `; expect(() => KwNodeGbeWole.getNode.call(parser)).toThrow(); }); -}); \ No newline at end of file +}); diff --git a/src/tests/parsers/keywordnodes/kwnodeise.test.js b/src/tests/parsers/keywordnodes/kwnodeise.test.js index 54f1db5..e09cecf 100644 --- a/src/tests/parsers/keywordnodes/kwnodeise.test.js +++ b/src/tests/parsers/keywordnodes/kwnodeise.test.js @@ -1,5 +1,5 @@ -jest.mock('fs', () => ({ - readFileSync: jest.fn() +jest.mock("fs", () => ({ + readFileSync: jest.fn(), })); const kwNodeIse = require("../../../parsers/keywordnodes/kwnodeise.js"); @@ -19,20 +19,20 @@ describe("KwNodeIse test suite", () => { parser.lexer().inputStream.code = `${constants.KW.ISE} teOruko(a,b) {}`; const expectedNode = { - body: [], - name: "teOruko", - operation: constants.KW.ISE, + body: [], + name: "teOruko", + operation: constants.KW.ISE, paramTokens: [ { - type: constants.VARIABLE, - value: "a" - }, + type: constants.VARIABLE, + value: "a", + }, { - type: constants.VARIABLE, - value: "b" - } - ] - } + type: constants.VARIABLE, + value: "b", + }, + ], + }; expect(kwNodeIse.getNode.call(parser)).toEqual(expectedNode); }); @@ -77,7 +77,7 @@ describe("KwNodeIse test suite", () => { parser.lexer().inputStream.code = `${constants.KW.ISE} (teOruko(a,b) {}`; expect(() => { - kwNodeIse.getNode.call(parser) + kwNodeIse.getNode.call(parser); }).toThrow(); }); -}); \ No newline at end of file +}); diff --git a/src/tests/parsers/keywordnodes/kwnodekuro.test.js b/src/tests/parsers/keywordnodes/kwnodekuro.test.js index 569bfd2..3d4b207 100644 --- a/src/tests/parsers/keywordnodes/kwnodekuro.test.js +++ b/src/tests/parsers/keywordnodes/kwnodekuro.test.js @@ -1,5 +1,5 @@ -jest.mock('fs', () => ({ - readFileSync: jest.fn() +jest.mock("fs", () => ({ + readFileSync: jest.fn(), })); const kwNodeKuro = require("../../../parsers/keywordnodes/kwnodekuro.js"); @@ -18,7 +18,7 @@ describe("KwNodeKuro test suite", () => { }); test("It should return a kúrò node ast when kuro node is expected because it is within a loop", () => { - const expectedNode = {operation: constants.KW.KURO}; + const expectedNode = { operation: constants.KW.KURO, }; parser.pushToBlockTypeStack(constants.KW.NIGBATI); expect(kwNodeKuro.getNode.call(parser)) @@ -28,11 +28,11 @@ describe("KwNodeKuro test suite", () => { test("It should skip the semicolon after an expected keyword kúrò", () => { parser.pushToBlockTypeStack(constants.KW.NIGBATI); kwNodeKuro.getNode.call(parser); - + expect(parser.lexer().peek()).toBe(null); }); test("It should fail to return a kuro node because the kuro keyword is not within a loop", () => { expect(() => kwNodeKuro.getNode.call(parser)).toThrow(); }); -}); \ No newline at end of file +}); diff --git a/src/tests/parsers/keywordnodes/kwnodenigbati.test.js b/src/tests/parsers/keywordnodes/kwnodenigbati.test.js index 158c8b4..07dfffe 100644 --- a/src/tests/parsers/keywordnodes/kwnodenigbati.test.js +++ b/src/tests/parsers/keywordnodes/kwnodenigbati.test.js @@ -1,5 +1,5 @@ -jest.mock('fs', () => ({ - readFileSync: jest.fn() +jest.mock("fs", () => ({ + readFileSync: jest.fn(), })); const kwNodeNigbati = require("../../../parsers/keywordnodes/kwnodenigbati.js"); @@ -25,64 +25,64 @@ describe("KwNodeNigbati test suite", () => { body: [ { body: { - left: null, - operation: null, - right: null, - value: "a jura wa lo tijakadi ko" - }, - operation: constants.KW.SOPE - }, + left: null, + operation: null, + right: null, + value: "a jura wa lo tijakadi ko", + }, + operation: constants.KW.SOPE, + }, { - left: "ikeji", - operation: constants.SYM.ASSIGN, + left: "ikeji", + operation: constants.SYM.ASSIGN, right: { left: { - name: "ikeji", - operation: constants.GET_JEKI - }, - operation: "+", + name: "ikeji", + operation: constants.GET_JEKI, + }, + operation: "+", right: { - left: null, - operation:null, - right: null, - value: 1 - }, - value: null - } - } - ], + left: null, + operation: null, + right: null, + value: 1, + }, + value: null, + }, + }, + ], condition: { left: { left: { - name: "ikeji", - operation: constants.GET_JEKI - }, - operation: constants.SYM.L_THAN, + name: "ikeji", + operation: constants.GET_JEKI, + }, + operation: constants.SYM.L_THAN, right: { - name: "aropo", - operation: constants.GET_JEKI - }, - value: null - }, - operation: constants.SYM.AND, + name: "aropo", + operation: constants.GET_JEKI, + }, + value: null, + }, + operation: constants.SYM.AND, right: { left: { - name: "ikeji", - operation: constants.GET_JEKI - }, - operation: constants.SYM.G_THAN, + name: "ikeji", + operation: constants.GET_JEKI, + }, + operation: constants.SYM.G_THAN, right: { - left: null, - operation: null, - right: null, - value: 0 - }, - value: null - }, - value: null - }, - operation: constants.KW.NIGBATI - } + left: null, + operation: null, + right: null, + value: 0, + }, + value: null, + }, + value: null, + }, + operation: constants.KW.NIGBATI, + }; expect(kwNodeNigbati.getNode.call(parser)).toEqual(expectedNode); }); @@ -107,7 +107,7 @@ describe("KwNodeNigbati test suite", () => { }`; expect(() => { - kwNodeNigbati.getNode.call(parser) + kwNodeNigbati.getNode.call(parser); }).toThrow(); }); -}); \ No newline at end of file +}); diff --git a/src/tests/parsers/keywordnodes/kwnodepada.test.js b/src/tests/parsers/keywordnodes/kwnodepada.test.js index 88667f8..d7172e1 100644 --- a/src/tests/parsers/keywordnodes/kwnodepada.test.js +++ b/src/tests/parsers/keywordnodes/kwnodepada.test.js @@ -1,5 +1,5 @@ -jest.mock('fs', () => ({ - readFileSync: jest.fn() +jest.mock("fs", () => ({ + readFileSync: jest.fn(), })); const kwNodePada = require("../../../parsers/keywordnodes/kwnodepada.js"); @@ -25,8 +25,8 @@ describe("KwNodePada test suite", () => { value: 2, left: null, right: null, - operation: null - } + operation: null, + }, }; expect(kwNodePada.getNode.call(parser)).toEqual(expectedNode); @@ -42,8 +42,8 @@ describe("KwNodePada test suite", () => { value: "anu", left: null, right: null, - operation: null - } + operation: null, + }, }; expect(kwNodePada.getNode.call(parser)).toEqual(expectedNode); @@ -57,8 +57,8 @@ describe("KwNodePada test suite", () => { operation: constants.KW.PADA, body: { name: "sum", - operation: constants.GET_JEKI - } + operation: constants.GET_JEKI, + }, }; expect(kwNodePada.getNode.call(parser)).toEqual(expectedNode); @@ -74,10 +74,10 @@ describe("KwNodePada test suite", () => { operation: constants.CALL_ISE, name: "sum", paramValues: [ - {left: null, operation: null, right: null, value: 1}, - {name: "a", operation: constants.GET_JEKI} - ] - } + { left: null, operation: null, right: null, value: 1, }, + { name: "a", operation: constants.GET_JEKI, }, + ], + }, }; expect(kwNodePada.getNode.call(parser)).toEqual(expectedNode); @@ -92,8 +92,8 @@ describe("KwNodePada test suite", () => { body: { operation: constants.ARRAY_ELEM, name: "sum", - indexNodes: [{"left": null, "operation": null, "right": null, "value": 1}] - } + indexNodes: [{ "left": null, "operation": null, "right": null, "value": 1, }, ], + }, }; expect(kwNodePada.getNode.call(parser)).toEqual(expectedNode); @@ -109,8 +109,8 @@ describe("KwNodePada test suite", () => { value: `${constants.KW.IRO}`, left: null, right: null, - operation: null - } + operation: null, + }, }; expect(kwNodePada.getNode.call(parser)).toEqual(expectedNode); @@ -121,16 +121,16 @@ describe("KwNodePada test suite", () => { parser.pushToBlockTypeStack(constants.KW.ISE); const expectedNode = { - operation: constants.KW.PADA, - body: { - operation: constants.ARRAY, - body: [ - {left: null, operation: null, right: null, value: 1}, - {left: null, operation: null, right: null, value: 2}] - } - }; - - expect(kwNodePada.getNode.call(parser)).toEqual(expectedNode); + operation: constants.KW.PADA, + body: { + operation: constants.ARRAY, + body: [ + { left: null, operation: null, right: null, value: 1, }, + { left: null, operation: null, right: null, value: 2, }, ], + }, + }; + + expect(kwNodePada.getNode.call(parser)).toEqual(expectedNode); }); test("It should return node with body.operation 'array' when array is empty", () => { @@ -141,10 +141,10 @@ describe("KwNodePada test suite", () => { operation: constants.KW.PADA, body: { operation: constants.ARRAY, - body: [] - } + body: [], + }, }; - + expect(kwNodePada.getNode.call(parser)).toEqual(expectedNode); }); @@ -164,4 +164,4 @@ describe("KwNodePada test suite", () => { kwNodePada.getNode.call(parser); }).toThrow(); }); -}); \ No newline at end of file +}); diff --git a/src/tests/parsers/keywordnodes/kwnodese.test.js b/src/tests/parsers/keywordnodes/kwnodese.test.js index f113b63..64f7982 100644 --- a/src/tests/parsers/keywordnodes/kwnodese.test.js +++ b/src/tests/parsers/keywordnodes/kwnodese.test.js @@ -1,5 +1,5 @@ -jest.mock('fs', () => ({ - readFileSync: jest.fn() +jest.mock("fs", () => ({ + readFileSync: jest.fn(), })); const kwNodeSe = require("../../../parsers/keywordnodes/kwnodese.js"); @@ -22,22 +22,22 @@ describe("KwNodeSe test suite", () => { const expectedNode = { condition: { - name: "niOruko", - operation: constants.GET_JEKI - }, - operation: constants.KW.SE, + name: "niOruko", + operation: constants.GET_JEKI, + }, + operation: constants.KW.SE, then: [ { body: { - left: null, - operation: null, - right: null, - value: "o ni oruko" - }, - operation: constants.KW.SOPE - } - ] - } + left: null, + operation: null, + right: null, + value: "o ni oruko", + }, + operation: constants.KW.SOPE, + }, + ], + }; expect(kwNodeSe.getNode.call(parser)).toEqual(expectedNode); }); @@ -47,12 +47,12 @@ describe("KwNodeSe test suite", () => { const expectedNode = { condition: { - name: "niOruko", - operation: constants.GET_JEKI - }, - operation: constants.KW.SE, - then: [] - } + name: "niOruko", + operation: constants.GET_JEKI, + }, + operation: constants.KW.SE, + then: [], + }; expect(kwNodeSe.getNode.call(parser)).toEqual(expectedNode); }); @@ -71,21 +71,21 @@ describe("KwNodeSe test suite", () => { const expectedNode = { condition: { left: { - name: "aropo", - operation: constants.GET_JEKI - }, - operation: constants.SYM.AND, + name: "aropo", + operation: constants.GET_JEKI, + }, + operation: constants.SYM.AND, right: { - left: null, - operation: null, + left: null, + operation: null, right: null, - value: constants.KW.OOTO - }, - value: null - }, - else: [], - operation: constants.KW.SE, - then: [] + value: constants.KW.OOTO, + }, + value: null, + }, + else: [], + operation: constants.KW.SE, + then: [], }; expect(kwNodeSe.getNode.call(parser)).toEqual(expectedNode); @@ -111,41 +111,40 @@ describe("KwNodeSe test suite", () => { "condition": { "left": { "name": "aropo", - "operation": constants.GET_JEKI + "operation": constants.GET_JEKI, }, "operation": "&&", "right": { "left": null, "operation": null, "right": null, - "value": constants.KW.OOTO + "value": constants.KW.OOTO, }, - "value": null + "value": null, }, "else": { "condition": { "name": "niOruko", - "operation": constants.GET_JEKI + "operation": constants.GET_JEKI, }, "else": { "condition": { "left": null, "operation": null, "right": null, - "value": constants.KW.OOTO + "value": constants.KW.OOTO, }, "else": [], "operation": constants.KW.SE, - "then": [] + "then": [], }, "operation": constants.KW.SE, - "then": [] + "then": [], }, "operation": constants.KW.SE, - "then": [] - } + "then": [], + }; expect(kwNodeSe.getNode.call(parser)).toEqual(expectedNode); }); - -}); \ No newline at end of file +}); diff --git a/src/tests/parsers/keywordnodes/kwnodesope.test.js b/src/tests/parsers/keywordnodes/kwnodesope.test.js index 7c5411e..2dbc2c1 100644 --- a/src/tests/parsers/keywordnodes/kwnodesope.test.js +++ b/src/tests/parsers/keywordnodes/kwnodesope.test.js @@ -1,5 +1,5 @@ -jest.mock('fs', () => ({ - readFileSync: jest.fn() +jest.mock("fs", () => ({ + readFileSync: jest.fn(), })); const kwNodeSope = require("../../../parsers/keywordnodes/kwnodesope.js"); @@ -23,9 +23,9 @@ describe("KwNodeSope test suite", () => { value: 2, left: null, right: null, - operation: null - } - } + operation: null, + }, + }; expect(kwNodeSope.getNode.call(parser)).toEqual(expectedNode); }); @@ -38,9 +38,9 @@ describe("KwNodeSope test suite", () => { value: "beautiful", left: null, right: null, - operation: null - } - } + operation: null, + }, + }; expect(kwNodeSope.getNode.call(parser)).toEqual(expectedNode); }); @@ -51,9 +51,9 @@ describe("KwNodeSope test suite", () => { operation: constants.KW.SOPE, body: { name: "name", - operation: constants.GET_JEKI - } - } + operation: constants.GET_JEKI, + }, + }; expect(kwNodeSope.getNode.call(parser)).toEqual(expectedNode); }); @@ -65,9 +65,9 @@ describe("KwNodeSope test suite", () => { body: { operation: constants.CALL_ISE, name: "sum", - paramValues: [{left: null, operation: null, right: null, value: 1}, {left: null, operation: null, right: null, value: 2}] - } - } + paramValues: [{ left: null, operation: null, right: null, value: 1, }, { left: null, operation: null, right: null, value: 2, }, ], + }, + }; expect(kwNodeSope.getNode.call(parser)).toEqual(expectedNode); }); @@ -79,9 +79,9 @@ describe("KwNodeSope test suite", () => { body: { operation: constants.ARRAY_ELEM, name: "a", - indexNodes: [{"left": null, "operation": null, "right": null, "value": 1}] - } - } + indexNodes: [{ "left": null, "operation": null, "right": null, "value": 1, }, ], + }, + }; expect(kwNodeSope.getNode.call(parser)).toEqual(expectedNode); }); @@ -109,7 +109,7 @@ describe("KwNodeSope test suite", () => { parser.lexer().inputStream.code = `${constants.KW.SOPE} (2,3);`; expect(() => { - kwNodeSope.getNode.call(parser) + kwNodeSope.getNode.call(parser); }).toThrow(); }); -}); \ No newline at end of file +}); diff --git a/src/tests/parsers/keywordnodes/kwnodeti.test.js b/src/tests/parsers/keywordnodes/kwnodeti.test.js index 2d0a8c7..43a4b5a 100644 --- a/src/tests/parsers/keywordnodes/kwnodeti.test.js +++ b/src/tests/parsers/keywordnodes/kwnodeti.test.js @@ -1,5 +1,5 @@ -jest.mock('fs', () => ({ - readFileSync: jest.fn() +jest.mock("fs", () => ({ + readFileSync: jest.fn(), })); const kwNodeTi = require("../../../parsers/keywordnodes/kwnodejeki.js"); @@ -25,10 +25,10 @@ describe("KwNodeTi test suite", () => { value: 1, left: null, right: null, - operation: null - } - } - + operation: null, + }, + }; + expect(kwNodeTi.getNode.call(parser)).toEqual(expectedNode); }); @@ -37,15 +37,15 @@ describe("KwNodeTi test suite", () => { const expectedNode = { operation: constants.SYM.ASSIGN, - left: "a", + left: "a", right: { value: "blue", left: null, right: null, - operation: null - } - } - + operation: null, + }, + }; + expect(kwNodeTi.getNode.call(parser)).toEqual(expectedNode); }); @@ -57,10 +57,10 @@ describe("KwNodeTi test suite", () => { left: "a", right: { name: "b", - operation: constants.GET_JEKI - } - } - + operation: constants.GET_JEKI, + }, + }; + expect(kwNodeTi.getNode.call(parser)).toEqual(expectedNode); }); @@ -70,16 +70,16 @@ describe("KwNodeTi test suite", () => { const expectedNode = { operation: constants.SYM.ASSIGN, left: { - indexNodes: [{"left": null, "operation": null, "right": null, "value": 0}], - name: "a", - operation: constants.ARRAY_ELEM + indexNodes: [{ "left": null, "operation": null, "right": null, "value": 0, }, ], + name: "a", + operation: constants.ARRAY_ELEM, }, right: { name: "b", - operation: constants.GET_JEKI - } - } - + operation: constants.GET_JEKI, + }, + }; + expect(kwNodeTi.getNode.call(parser)).toEqual(expectedNode); }); @@ -92,15 +92,15 @@ describe("KwNodeTi test suite", () => { right: { operation: constants.ARRAY, body: [ - {left: null, operation: null, right: null, value: 1}, - {left: null, operation: null, right: null, value: "anu"}, - {name: "b", operation: constants.GET_JEKI}, - {indexNodes: [{"left": null, "operation": null, "right": null, "value": 0}], name: "c", operation: constants.ARRAY_ELEM}, - {body: [{left: null, operation: null, right: null, value: 1}, {left: null, operation: null, right: null, value: 2}], operation: constants.ARRAY} - ], - } - } - + { left: null, operation: null, right: null, value: 1, }, + { left: null, operation: null, right: null, value: "anu", }, + { name: "b", operation: constants.GET_JEKI, }, + { indexNodes: [{ "left": null, "operation": null, "right": null, "value": 0, }, ], name: "c", operation: constants.ARRAY_ELEM, }, + { body: [{ left: null, operation: null, right: null, value: 1, }, { left: null, operation: null, right: null, value: 2, }, ], operation: constants.ARRAY, }, + ], + }, + }; + expect(kwNodeTi.getNode.call(parser)).toEqual(expectedNode); }); @@ -112,12 +112,12 @@ describe("KwNodeTi test suite", () => { left: "a", right: { operation: constants.SYM.EQ, - right: {left: null, operation: null, right: null, value: 5}, - left: {left: null, operation: null, right: null, value: 5}, - value: null - } - } - + right: { left: null, operation: null, right: null, value: 5, }, + left: { left: null, operation: null, right: null, value: 5, }, + value: null, + }, + }; + expect(kwNodeTi.getNode.call(parser)).toEqual(expectedNode); }); @@ -125,62 +125,62 @@ describe("KwNodeTi test suite", () => { parser.lexer().inputStream.code = `${constants.KW.JEKI} a = (15 /3) + (3 * 2);`; const expectedNode = { - left: "a", - operation: constants.SYM.ASSIGN, + left: "a", + operation: constants.SYM.ASSIGN, right: { left: { left: { - left: null, - operation: null, - right: null, - value: 15 - }, - operation: "/", + left: null, + operation: null, + right: null, + value: 15, + }, + operation: "/", right: { - left: null, - operation: null, - right: null, - value: 3 - }, - value: null - }, - operation: "+", + left: null, + operation: null, + right: null, + value: 3, + }, + value: null, + }, + operation: "+", right: { left: { left: null, - operation: null, - right: null, - value: 3 - }, - operation: "*", + operation: null, + right: null, + value: 3, + }, + operation: "*", right: { - left: null, - operation: null, - right: null, - value: 2 - }, - value: null - }, - value: null - } - } - + left: null, + operation: null, + right: null, + value: 2, + }, + value: null, + }, + value: null, + }, + }; + expect(kwNodeTi.getNode.call(parser)).toEqual(expectedNode); }); test("it should throw an error when given invalid assignment operation", () => { parser.lexer().inputStream.code = `${constants.KW.JEKI} a = ;`; - + expect(() => { - kwNodeTi.getNode.call(parser) + kwNodeTi.getNode.call(parser); }).toThrow(); }); test("it should throw an error when variable is not initialized", () => { parser.lexer().inputStream.code = `${constants.KW.JEKI} a ;`; - + expect(() => { - kwNodeTi.getNode.call(parser) + kwNodeTi.getNode.call(parser); }).toThrow(); }); -}) \ No newline at end of file +}); diff --git a/src/tests/parsers/keywordnodes/kwnodewoke.test.js b/src/tests/parsers/keywordnodes/kwnodewoke.test.js index 2cdb210..e66bc12 100644 --- a/src/tests/parsers/keywordnodes/kwnodewoke.test.js +++ b/src/tests/parsers/keywordnodes/kwnodewoke.test.js @@ -1,5 +1,5 @@ -jest.mock('fs', () => ({ - readFileSync: jest.fn() +jest.mock("fs", () => ({ + readFileSync: jest.fn(), })); const kwNodeWoke = require("../../../parsers/keywordnodes/kwnodewoke.js"); @@ -20,7 +20,7 @@ describe("KwNodeWoke test suite", () => { const expectedNode = { operation: constants.KW.WOKE, - varNames: ["counter", "name"] + varNames: ["counter", "name", ], }; parser.pushToBlockTypeStack(constants.KW.ISE); @@ -40,4 +40,4 @@ describe("KwNodeWoke test suite", () => { expect(() => kwNodeWoke.getNode.call(parser)).toThrow(); }); -}); \ No newline at end of file +}); diff --git a/src/tests/parsers/keywordnodes/kwnodeyi.test.js b/src/tests/parsers/keywordnodes/kwnodeyi.test.js index cdff66f..9ebaca9 100644 --- a/src/tests/parsers/keywordnodes/kwnodeyi.test.js +++ b/src/tests/parsers/keywordnodes/kwnodeyi.test.js @@ -1,5 +1,5 @@ -jest.mock('fs', () => ({ - readFileSync: jest.fn() +jest.mock("fs", () => ({ + readFileSync: jest.fn(), })); const kwNodeYi = require("../../../parsers/keywordnodes/kwnodeyi.js"); @@ -31,59 +31,59 @@ describe("KwNodeYi test suite", () => { IRUbody: [ { body: { - left: null, - operation: null, - right: null, - value: "it is anu" - }, - operation: constants.KW.SOPE - } - ], + left: null, + operation: null, + right: null, + value: "it is anu", + }, + operation: constants.KW.SOPE, + }, + ], IRUvalue: { value: "anu", left: null, right: null, - operation: null - }, - operation: constants.KW.IRU - }, + operation: null, + }, + operation: constants.KW.IRU, + }, { IRUbody: [ { body: { - left: null, - operation: null, - right: null, - value: "it femi" - }, - operation: constants.KW.SOPE - } - ], + left: null, + operation: null, + right: null, + value: "it femi", + }, + operation: constants.KW.SOPE, + }, + ], IRUvalue: { value: "femi", left: null, right: null, - operation: null - }, - operation: constants.KW.IRU - } - ], - operation: constants.KW.YI, + operation: null, + }, + operation: constants.KW.IRU, + }, + ], + operation: constants.KW.YI, padasi: [ { body: { - left: null, - operation: null, - right: null, - value: "mi o mo" - }, - operation: constants.KW.SOPE - } - ], + left: null, + operation: null, + right: null, + value: "mi o mo", + }, + operation: constants.KW.SOPE, + }, + ], yivalue: { - name: "firstname", - operation: constants.GET_JEKI - } + name: "firstname", + operation: constants.GET_JEKI, + }, }; expect(kwNodeYi.getNode.call(parser)).toEqual(expectedNode); @@ -105,5 +105,4 @@ describe("KwNodeYi test suite", () => { kwNodeYi.getNode.call(parser); }).toThrow(); }); - -}); \ No newline at end of file +}); diff --git a/src/tests/parsers/nodeliterals/arraynl.test.js b/src/tests/parsers/nodeliterals/arraynl.test.js index bf2393b..df2ddf3 100644 --- a/src/tests/parsers/nodeliterals/arraynl.test.js +++ b/src/tests/parsers/nodeliterals/arraynl.test.js @@ -44,16 +44,15 @@ describe("ArrayNodeLiteral test suite", () => { }); test("It should parse array element with empty index", () => { - parser.lexer().inputStream.code = `a[]`; - const arrayNameToken = {value: parser.parseVarname()}; + parser.lexer().inputStream.code = "a[]"; + const arrayNameToken = { value: parser.parseVarname(), }; const expectedNode = { - indexNodes: [{"left": null, "operation": null, "right": null, "value": ""}], - name: "a", - operation: constants.ARRAY_ELEM + indexNodes: [{ "left": null, "operation": null, "right": null, "value": "", }, ], + name: "a", + operation: constants.ARRAY_ELEM, }; - expect(arrayNl.getNode.call(parser, arrayNameToken)).toEqual(expectedNode); }); diff --git a/src/tests/parsers/parser.test.js b/src/tests/parsers/parser.test.js index 528b021..4ba78ad 100644 --- a/src/tests/parsers/parser.test.js +++ b/src/tests/parsers/parser.test.js @@ -1,5 +1,5 @@ -jest.mock('fs', () => ({ - readFileSync: jest.fn() +jest.mock("fs", () => ({ + readFileSync: jest.fn(), })); const Parser = require("../../parsers/parser.js"); @@ -96,50 +96,50 @@ describe("Parser test suite", () => { }); test("ParseExpression - it should parse array elemement expression", () => { - parser.lexer().inputStream.code = `a = b[0] = 1`; - + parser.lexer().inputStream.code = "a = b[0] = 1"; + const expectedNode = { left: { left: { - name: "a", - operation: constants.GET_JEKI - }, - operation: constants.SYM.ASSIGN, + name: "a", + operation: constants.GET_JEKI, + }, + operation: constants.SYM.ASSIGN, right: { - indexNodes: [{"left": null, "operation": null, "right": null, "value": 0}], - name: "b", - operation: constants.ARRAY_ELEM - }, - value: null - }, - operation: constants.SYM.ASSIGN, + indexNodes: [{ "left": null, "operation": null, "right": null, "value": 0, }, ], + name: "b", + operation: constants.ARRAY_ELEM, + }, + value: null, + }, + operation: constants.SYM.ASSIGN, right: { - left: null, - operation: null, - right: null, - value: 1 - }, - value: null + left: null, + operation: null, + right: null, + value: 1, + }, + value: null, }; expect(parser.parseExpression()).toEqual(expectedNode); }); test("ParseAst - it should parse a function call in a program block", () => { - parser.lexer().inputStream.code = `koOruko();`; + parser.lexer().inputStream.code = "koOruko();"; const expectedNode = { - paramValues: [], - name: "koOruko", - operation: constants.CALL_ISE + paramValues: [], + name: "koOruko", + operation: constants.CALL_ISE, }; expect(parser.parseAst()).toEqual(expectedNode); }); test("ParseAst - it should fail to parse a non function call in a program block", () => { - parser.lexer().inputStream.code = `a[];`; + parser.lexer().inputStream.code = "a[];"; expect(() => parser.parseAst()).toThrow(); }); -}); \ No newline at end of file +});