diff --git a/.eslintignore b/.eslintignore index ba7d7e0..8f74907 100644 --- a/.eslintignore +++ b/.eslintignore @@ -2,3 +2,4 @@ .vscode .github /node_modules +/src/tests diff --git a/src/environment.js b/src/environment.js index 96a0ed1..e690480 100644 --- a/src/environment.js +++ b/src/environment.js @@ -7,7 +7,7 @@ class Environment { } setJeki (scope, name, value) { - if (this.vars[scope] == undefined) { + if (!this.vars[scope]) { this.vars[scope] = {}; } @@ -15,11 +15,11 @@ class Environment { } getJeki (scope, name) { - if (this.vars[scope] != undefined) { return this.vars[scope][name]; } + if (this.vars[scope]) { return this.vars[scope][name]; } } setIse (scope, iseName, iseNode) { - if (this.iseDeclarations[scope] == undefined) { + if (!this.iseDeclarations[scope]) { this.iseDeclarations[scope] = {}; } @@ -27,13 +27,13 @@ class Environment { } getIse (scope, iseName) { - if (this.iseDeclarations[scope] != undefined) { + if (this.iseDeclarations[scope]) { return this.iseDeclarations[scope][iseName]; } } isExistHelperIse (iseName) { - return helperIseDeclarations[iseName] != undefined; + return helperIseDeclarations[iseName] !== undefined; } runHelperIse (iseName, iseArgs) { diff --git a/src/helperise/array_helpers/ka.js b/src/helperise/array_helpers/ka.js index d967b3b..8e52904 100644 --- a/src/helperise/array_helpers/ka.js +++ b/src/helperise/array_helpers/ka.js @@ -1,7 +1,7 @@ // 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."); diff --git a/src/helperise/input_output/tesibi.js b/src/helperise/input_output/tesibi.js index 5f6d668..e5a9040 100644 --- a/src/helperise/input_output/tesibi.js +++ b/src/helperise/input_output/tesibi.js @@ -3,7 +3,7 @@ const readlineSync = require("readline-sync"); // Takes command line input function teSibi (args) { if (args instanceof Array) { - const [param, ] = args; + const [ param, ] = args; if (typeof param === "string") { const input = readlineSync.question(param); return parseFloat(input) || input; diff --git a/src/helperise/string_helpers/si_leta_kekere.js b/src/helperise/string_helpers/si_leta_kekere.js index 6ff2acf..3f877ec 100644 --- a/src/helperise/string_helpers/si_leta_kekere.js +++ b/src/helperise/string_helpers/si_leta_kekere.js @@ -1,7 +1,7 @@ // 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é."); diff --git a/src/helperise/string_helpers/si_leta_nla.js b/src/helperise/string_helpers/si_leta_nla.js index 020ec05..6ad8f4c 100644 --- a/src/helperise/string_helpers/si_leta_nla.js +++ b/src/helperise/string_helpers/si_leta_nla.js @@ -1,7 +1,7 @@ // 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á."); diff --git a/src/inputstream.js b/src/inputstream.js index 431eb0f..dcd9e92 100644 --- a/src/inputstream.js +++ b/src/inputstream.js @@ -41,11 +41,11 @@ class InputStream { } isEndOfFile () { - return this.peek() == ""; + return this.peek() === ""; } isNotEndOfFile () { - return this.peek() != ""; + return this.peek() !== ""; } } diff --git a/src/interpreters/helpers/woke_helper.js b/src/interpreters/helpers/woke_helper.js index 5af8ede..b4aa791 100644 --- a/src/interpreters/helpers/woke_helper.js +++ b/src/interpreters/helpers/woke_helper.js @@ -3,7 +3,7 @@ const constants = require("../../constants.js"); class WokeHelper { static isWokeVariable (context, tiName) { const wokeList = context.environment().getJeki(context.getCurrentScope(), constants.KW.WOKE); - return wokeList != undefined && wokeList.indexOf(tiName) != -1; + return wokeList && wokeList.indexOf(tiName) !== -1; } } diff --git a/src/interpreters/ibase.js b/src/interpreters/ibase.js index 2ce5ee3..310d049 100644 --- a/src/interpreters/ibase.js +++ b/src/interpreters/ibase.js @@ -1,6 +1,6 @@ class IBase { constructor () { - if (this.constructor == IBase) { + if (this.constructor === IBase) { throw new Error("Cannot instantiate abstract class IBase"); } } diff --git a/src/interpreters/inodearrayelem.js b/src/interpreters/inodearrayelem.js index 8ebab93..8ec7f97 100644 --- a/src/interpreters/inodearrayelem.js +++ b/src/interpreters/inodearrayelem.js @@ -23,7 +23,7 @@ class INodeArrayElement extends IBase { } }); - if (arrayElement == undefined) context.throwError(`Index given for array ${node.name} does not exist`); + if (!arrayElement) context.throwError(`Index given for array ${node.name} does not exist`); return arrayElement; } diff --git a/src/interpreters/inodecallise.js b/src/interpreters/inodecallise.js index 7bc4ff4..1959c11 100644 --- a/src/interpreters/inodecallise.js +++ b/src/interpreters/inodecallise.js @@ -1,5 +1,4 @@ const IBase = require("./ibase.js"); -const constants = require("../constants.js"); class INodeCallIse extends IBase { interpreteNode (node) { @@ -21,7 +20,7 @@ class INodeCallIse extends IBase { static getIseNode (context, iseName) { for (let index = context.scopeStack().length - 1; index >= 0; index--) { - if (context.environment().getIse(context.scopeStack()[index], iseName) != undefined) { + if (context.environment().getIse(context.scopeStack()[index], iseName) !== undefined) { return context.environment().getIse(context.scopeStack()[index], iseName); } } @@ -45,7 +44,7 @@ class INodeCallIse extends IBase { static runIseNodeBody (context, iseNodeBody) { for (let i = 0; i < iseNodeBody.length; i++) { const returnedValue = context.evaluateNode(iseNodeBody[i]); - if (returnedValue != undefined) return returnedValue; + if (returnedValue !== undefined) return returnedValue; } } } diff --git a/src/interpreters/inodefun.js b/src/interpreters/inodefun.js index ff68660..794ef53 100644 --- a/src/interpreters/inodefun.js +++ b/src/interpreters/inodefun.js @@ -9,7 +9,7 @@ class INodeFun extends IBase { 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; + if (returnedValue !== undefined) return returnedValue; } this.evaluateNode(node.increment); diff --git a/src/interpreters/inodegetjeki.js b/src/interpreters/inodegetjeki.js index 6660f3c..c3fa523 100644 --- a/src/interpreters/inodegetjeki.js +++ b/src/interpreters/inodegetjeki.js @@ -4,7 +4,7 @@ const WokeHelper = require("./helpers/woke_helper.js"); class INodeGetJeki extends IBase { interpreteNode (node) { for (let index = INodeGetJeki.getTopIndex(this, node.name); index >= 0; index--) { - if (this.environment().getJeki(this.scopeStack()[index], node.name) != undefined) { + if (this.environment().getJeki(this.scopeStack()[index], node.name) !== undefined) { return this.environment().getJeki(this.scopeStack()[index], node.name); } } diff --git a/src/interpreters/inodeise.js b/src/interpreters/inodeise.js index 1e0ad90..349634e 100644 --- a/src/interpreters/inodeise.js +++ b/src/interpreters/inodeise.js @@ -2,7 +2,7 @@ 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`); } + 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); } diff --git a/src/interpreters/inodejeki.js b/src/interpreters/inodejeki.js index bcc4089..3c976a7 100644 --- a/src/interpreters/inodejeki.js +++ b/src/interpreters/inodejeki.js @@ -21,7 +21,7 @@ class INodeJeki extends IBase { const topIndex = context.scopeStack().length - 2; for (let index = topIndex; index >= 0; index--) { - if (context.environment().getJeki(context.scopeStack()[index], node.left) != undefined) { + if (context.environment().getJeki(context.scopeStack()[index], node.left) !== undefined) { return context.environment().setJeki(context.scopeStack()[index], node.left, INodeJeki.getValue(context, node.right)); } } @@ -33,7 +33,7 @@ class INodeJeki extends IBase { 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) { + 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; @@ -64,7 +64,7 @@ class INodeJeki extends IBase { static getValue (context, node) { const value = context.evaluateNode(node); - if (value == undefined) context.throwError(`Cannot set value undefined to variable ${node.left}`); + if (value === undefined) context.throwError(`Cannot set value undefined to variable ${node.left}`); return value; } } diff --git a/src/interpreters/inodenigbati.js b/src/interpreters/inodenigbati.js index ac04b9f..881958f 100644 --- a/src/interpreters/inodenigbati.js +++ b/src/interpreters/inodenigbati.js @@ -7,7 +7,7 @@ class INodeNigbati extends IBase { 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; + if (returnedValue !== undefined) return returnedValue; } } } diff --git a/src/interpreters/inodese.js b/src/interpreters/inodese.js index 921afdd..1a94bbb 100644 --- a/src/interpreters/inodese.js +++ b/src/interpreters/inodese.js @@ -5,7 +5,7 @@ class INodeSe extends IBase { interpreteNode (node) { if (this.evaluateNode(node.condition) !== constants.KW.IRO) { return INodeSe.runBody(this, node.then); - } else if (node.else != undefined) { + } else if (node.else !== undefined) { return INodeSe.runBody(this, node.else); } } @@ -16,7 +16,7 @@ class INodeSe extends IBase { 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 } } } diff --git a/src/interpreters/inodewoke.js b/src/interpreters/inodewoke.js index d7c8354..182901d 100644 --- a/src/interpreters/inodewoke.js +++ b/src/interpreters/inodewoke.js @@ -5,7 +5,7 @@ class INodeWoke extends IBase { interpreteNode (node) { let woke = this.environment().getJeki(this.getCurrentScope(), constants.KW.WOKE); - if (woke == undefined) woke = node.varNames; + if (!woke) woke = node.varNames; else woke.push(...node.varNames); this.environment().setJeki(this.getCurrentScope(), constants.KW.WOKE, woke); diff --git a/src/interpreters/inodeyi.js b/src/interpreters/inodeyi.js index 98d8406..6783118 100644 --- a/src/interpreters/inodeyi.js +++ b/src/interpreters/inodeyi.js @@ -27,7 +27,7 @@ class INodeYi extends IBase { } static canRunPadasi (IRUIndex, node) { - return (IRUIndex === node.yibody.length - 1) && (node.padasi != undefined); + return (IRUIndex === node.yibody.length - 1) && (node.padasi !== undefined); } static runPadasi (context, padasi) { diff --git a/src/interpreters/maininterpreter.js b/src/interpreters/maininterpreter.js index 26692dd..db823e7 100644 --- a/src/interpreters/maininterpreter.js +++ b/src/interpreters/maininterpreter.js @@ -10,9 +10,9 @@ class MainInterpreter { } initScopeStack () { - const _scopeStack = ["global", ]; + 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(); } diff --git a/src/lexer.js b/src/lexer.js index b5b3231..522f609 100644 --- a/src/lexer.js +++ b/src/lexer.js @@ -44,10 +44,10 @@ class Lexer { const stringEnd = constants.SYM.STR_QUOTE; this.inputStream.next(); // needed to skip the opening quote symbol '"' const str = this.readWhile((ch) => { - return ch != stringEnd; + return ch !== stringEnd; }); - if (this.inputStream.peek() == stringEnd) { this.inputStream.next(); } // needed to skip the closing quote symbol '"' + 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, }; @@ -69,7 +69,7 @@ class Lexer { readNumber () { let hasDot = false; const num = this.readWhile((ch) => { - if (ch == constants.SYM.PERIOD) { + if (ch === constants.SYM.PERIOD) { if (hasDot) return false; hasDot = true; return true; @@ -82,7 +82,7 @@ class Lexer { skipComments () { this.readWhile((ch) => { - return ch != constants.SYM.NEW_LINE; + return ch !== constants.SYM.NEW_LINE; }); this.inputStream.next(); // skips the "\n" symbol } @@ -92,11 +92,11 @@ class Lexer { if (this.inputStream.isEndOfFile()) return null; const ch = this.inputStream.peek(); - if (ch == constants.SYM.COMMENT) { + if (ch === constants.SYM.COMMENT) { this.skipComments(); return this.readNext(); } - if (ch == constants.SYM.STR_QUOTE) return this.readString(); + 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(), }; diff --git a/src/parsers/basenode.js b/src/parsers/basenode.js index ba1fb93..88a56b6 100644 --- a/src/parsers/basenode.js +++ b/src/parsers/basenode.js @@ -1,7 +1,7 @@ class BaseNode { // Make BaseNode act like an interface. constructor () { - if (this.constructor == BaseNode) { + if (this.constructor === BaseNode) { throw new Error("Cannot instantiate abstract class BaseNode"); } } diff --git a/src/parsers/keywordnodes/kwnodefun.js b/src/parsers/keywordnodes/kwnodefun.js index bf4bfa9..1ec7a36 100644 --- a/src/parsers/keywordnodes/kwnodefun.js +++ b/src/parsers/keywordnodes/kwnodefun.js @@ -40,11 +40,11 @@ class KwNodeFun extends BaseNode { static isInValidFunIncrementStatement (funNode) { const incrementNode = funNode.increment.right; - if ([constants.SYM.PLUS, constants.SYM.MINUS, ].indexOf(incrementNode.operation) >= 0) { + if ([ constants.SYM.PLUS, constants.SYM.MINUS, ].indexOf(incrementNode.operation) >= 0) { // e.g fun (tí i =0; i < 10; tí i = i + 1;) // make sure there is variable 'i' in atleast one child of the incrementNode // i.e jeki i = i + 1 or jeki i = 1 + i or jeki i = i + i - if ([incrementNode.left.name, incrementNode.right.name, ].indexOf(funNode.init.left) >= 0) { + if ([ incrementNode.left.name, incrementNode.right.name, ].indexOf(funNode.init.left) >= 0) { return false; } } diff --git a/src/parsers/keywordnodes/kwnodegbewole.js b/src/parsers/keywordnodes/kwnodegbewole.js index 09b114f..52b93f2 100644 --- a/src/parsers/keywordnodes/kwnodegbewole.js +++ b/src/parsers/keywordnodes/kwnodegbewole.js @@ -9,9 +9,9 @@ class KwNodeGbeWole extends BaseNode { const node = {}; node.operation = constants.KW.GBE_WOLE; - if (this.lexer().peek().type == constants.STRING) { + 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; diff --git a/src/parsers/keywordnodes/kwnodeise.js b/src/parsers/keywordnodes/kwnodeise.js index aaaf665..bb2e379 100644 --- a/src/parsers/keywordnodes/kwnodeise.js +++ b/src/parsers/keywordnodes/kwnodeise.js @@ -11,7 +11,7 @@ class KwNodeIse extends BaseNode { } static isExpectedIseDeclaration (context) { - return context.getBlockTypeStack().length == 0 || context.peekBlockTypeStack() === constants.PROGRAM || + return context.getBlockTypeStack().length === 0 || context.peekBlockTypeStack() === constants.PROGRAM || context.peekBlockTypeStack() === constants.KW.ISE; } diff --git a/src/parsers/keywordnodes/kwnodeyi.js b/src/parsers/keywordnodes/kwnodeyi.js index 61991fe..47fdf6d 100644 --- a/src/parsers/keywordnodes/kwnodeyi.js +++ b/src/parsers/keywordnodes/kwnodeyi.js @@ -36,7 +36,7 @@ class KwNodeYi extends BaseNode { } static isNextTokenIru (context) { - return context.isNotEndOfFile() && context.lexer().peek().value == constants.KW.IRU; + return context.isNotEndOfFile() && context.lexer().peek().value === constants.KW.IRU; } static getPadasi (context) { diff --git a/src/parsers/nodeLiterals/arraynl.js b/src/parsers/nodeLiterals/arraynl.js index b3cc6d6..614f4a7 100644 --- a/src/parsers/nodeLiterals/arraynl.js +++ b/src/parsers/nodeLiterals/arraynl.js @@ -3,7 +3,7 @@ const constants = require("../../constants.js"); class ArrayNl extends BaseNode { getNode (arrayNameToken) { - return (arrayNameToken == undefined) ? ArrayNl.getParsedArrayLiteral(this) + return (!arrayNameToken) ? ArrayNl.getParsedArrayLiteral(this) : ArrayNl.getParsedArrayElement(this, arrayNameToken); } @@ -28,7 +28,7 @@ class ArrayNl extends BaseNode { } static getArrayElementIndexNodes (context) { - const indexNodes = [ArrayNl.getArrayElementIndexNode(context), ]; + const indexNodes = [ ArrayNl.getArrayElementIndexNode(context), ]; while (context.isNextTokenPunctuation(constants.SYM.L_SQ_BRACKET)) { // handles multi-dimensional array element indexNodes.push(ArrayNl.getArrayElementIndexNode(context)); @@ -48,7 +48,7 @@ class ArrayNl extends BaseNode { } static isNotEmptyArrayIndex (context) { - return context.lexer().peek().value != constants.SYM.R_SQ_BRACKET; + return context.lexer().peek().value !== constants.SYM.R_SQ_BRACKET; } } diff --git a/src/parsers/nodeLiterals/callIseNl.js b/src/parsers/nodeLiterals/callIseNl.js index d2d674b..e6d900a 100644 --- a/src/parsers/nodeLiterals/callIseNl.js +++ b/src/parsers/nodeLiterals/callIseNl.js @@ -20,7 +20,7 @@ class CallIseNl extends BaseNode { this.parseExpression.bind(this), null ); - if (iseNameToken.value == undefined) this.skipPunctuation(constants.SYM.STATEMENT_TERMINATOR); + if (iseNameToken.value === undefined) this.skipPunctuation(constants.SYM.STATEMENT_TERMINATOR); return node; } diff --git a/src/parsers/nodeLiterals/keywordnl.js b/src/parsers/nodeLiterals/keywordnl.js index 40d4389..853c578 100644 --- a/src/parsers/nodeLiterals/keywordnl.js +++ b/src/parsers/nodeLiterals/keywordnl.js @@ -15,11 +15,11 @@ class KeywordNl extends BaseNode { return leafNl.getNode.call(this); } - this.throwError(`Expecting yorlang keyword value e.g boolean(iró|òótó) but found ${token.value}`); + this.throwError("Expecting yorlang keyword value e.g boolean(iró|òótó)"); } static isKeywordNl (context) { - return [constants.KW.OOTO, constants.KW.IRO, ].indexOf(context.lexer().peek().value) >= 0; + return [ constants.KW.OOTO, constants.KW.IRO, ].indexOf(context.lexer().peek().value) >= 0; } } diff --git a/src/parsers/nodeLiterals/variablenl.js b/src/parsers/nodeLiterals/variablenl.js index e177398..cfced64 100644 --- a/src/parsers/nodeLiterals/variablenl.js +++ b/src/parsers/nodeLiterals/variablenl.js @@ -7,7 +7,7 @@ class VariableNl extends BaseNode { const varNameToken = this.lexer().next(); const nextTokenValue = this.lexer().peek().value; - if (variableNlTypes[nextTokenValue] != undefined) { + if (variableNlTypes[nextTokenValue]) { const variableNlType = variableNlTypes[nextTokenValue]; if (variableNlType instanceof BaseNode) return variableNlType.getNode.call(this, varNameToken); else throw new Error(`Dependency ${variableNlType} must be of type BaseNode`); diff --git a/src/parsers/parser.js b/src/parsers/parser.js index 96fe406..5e87d04 100644 --- a/src/parsers/parser.js +++ b/src/parsers/parser.js @@ -18,7 +18,7 @@ class Parser { }; this.popBlockTypeStack = () => _blockTypeStack.pop(); this.peekBlockTypeStack = () => _blockTypeStack[_blockTypeStack.length - 1]; - this.getBlockTypeStack = () => [..._blockTypeStack, ]; + this.getBlockTypeStack = () => [ ..._blockTypeStack, ]; } initIsArithmeticExpression () { @@ -31,17 +31,17 @@ class Parser { isNextTokenPunctuation (punc) { const token = this.lexer().peek(); - return token && token.type == constants.PUNCTUATION && (token.value == punc); + return token && token.type === constants.PUNCTUATION && (token.value === punc); } isNextTokenOperator (op) { const token = this.lexer().peek(); - return token && token.type == constants.OPERATOR && (token.value == op); + return token && token.type === constants.OPERATOR && (token.value === op); } isNextTokenKeyword (kw) { const token = this.lexer().peek(); - return token && token.type == constants.KEYWORD && (token.value == kw); + return token && token.type === constants.KEYWORD && (token.value === kw); } skipPunctuation (punc) { @@ -70,15 +70,15 @@ class Parser { } parseAssign () { - return this.parseWhile([constants.SYM.ASSIGN, ], this.parseOr); + return this.parseWhile([ constants.SYM.ASSIGN, ], this.parseOr); } parseOr () { - return this.parseWhile([constants.SYM.OR, ], this.parseAnd); + return this.parseWhile([ constants.SYM.OR, ], this.parseAnd); } parseAnd () { - return this.parseWhile([constants.SYM.AND, ], this.parseGreaterLesserEquality); + return this.parseWhile([ constants.SYM.AND, ], this.parseGreaterLesserEquality); } parseGreaterLesserEquality () { @@ -92,11 +92,11 @@ class Parser { } parsePlusMinus () { - return this.parseWhile([constants.SYM.PLUS, constants.SYM.MINUS, ], this.parseMultiplyDivisionRemainder); + 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); + return this.parseWhile([ constants.SYM.MULTIPLY, constants.SYM.DIVIDE, constants.SYM.REMAINDER, ], this.parseNodeLiteral); } parseWhile (operatorList, parseOperationWithLesserPrecedence) { @@ -121,14 +121,14 @@ class Parser { parseNodeLiteral () { const token = this.lexer().peek(); - if (nodeLiterals[token.type] != undefined) { + if (nodeLiterals[token.type]) { const nodeliteral = nodeLiterals[token.type]; if (nodeliteral instanceof BaseNode) return nodeliteral.getNode.call(this); 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) { + if (nodeLiterals[constants.EXP_PUNC][token.value]) { 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`); @@ -151,11 +151,11 @@ class Parser { } isNotEndOfBlock () { - return this.isNotEndOfFile() && (this.lexer().peek().value != constants.SYM.R_PAREN); + return this.isNotEndOfFile() && (this.lexer().peek().value !== constants.SYM.R_PAREN); } parseVarname () { - return (this.lexer().peek().type == constants.VARIABLE) + return (this.lexer().peek().type === constants.VARIABLE) ? this.lexer().next().value : this.lexer().throwError(this.getGenericErrorMsg(this.lexer().peek().value)); } @@ -189,7 +189,7 @@ class Parser { parseAst () { const token = this.lexer().peek(); - if (kwnodes[token.value] != undefined) { + if (kwnodes[token.value]) { 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 else throw new Error(`${kwNode} must be of type BaseNode`);