Skip to content

Commit

Permalink
Feature- translated all error messages to yoruba
Browse files Browse the repository at this point in the history
  • Loading branch information
anoniscoding committed Dec 20, 2018
1 parent 114e26e commit a0d72b4
Show file tree
Hide file tree
Showing 22 changed files with 97 additions and 37 deletions.
27 changes: 18 additions & 9 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

const packageJson = require("./package.json");
const path = require("path");
const InputStream = require("./src/inputstream.js");
const Lexer = require("./src/lexer.js");
const Parser = require("./src/parsers/parser.js");
const Environment = require("./src/environment.js");
const MainInterpreter = require("./src/interpreters/maininterpreter.js");
const constants = require("./src/constants.js");
const commander = require("commander");

Expand All @@ -25,13 +20,27 @@ commander.arguments("[file]")
.option("-l, --lang [lang]", "Select language to use")
.action((file, options) => {
if (path.extname(file) === constants.YL_EXT) {
const lang = [ "english", "yoruba", ];
global.defaultLang = lang.includes(options.lang) ? options.lang : "english";
const parser = new Parser(new Lexer(new InputStream(file)));
new MainInterpreter(new Environment(), parser).interpreteProgram();
setGlobalVars(options);
startYorlangProcess(file);
} else {
throw new Error("Invalid Yorlang file. Expected a .yl file");
}
});

commander.parse(process.argv);

function setGlobalVars (options) {
const lang = [ "english", "yoruba", ];
global.defaultLang = lang.includes(options.lang) ? options.lang : "english";
}

function startYorlangProcess (file) {
const InputStream = require("./src/inputstream.js");
const Lexer = require("./src/lexer.js");
const Parser = require("./src/parsers/parser.js");
const Environment = require("./src/environment.js");
const MainInterpreter = require("./src/interpreters/maininterpreter.js");

const parser = new Parser(new Lexer(new InputStream(file)));
new MainInterpreter(new Environment(), parser).interpreteProgram();
}
29 changes: 28 additions & 1 deletion src/feedbackMessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,38 @@ const message = {
english: {
baseNodeType: (arg) => `${arg} must be of type BaseNode`,
genericErrorMsg: (arg) => `Cannot process unexpected token : ${arg}`,
funIncrementAndDecrementMsg: () => "Invalid yorlang decrement or increment operation",
invalidFileMsg: () => "Invalid yorlang file. Expected file with .yl extension",
invalidAssignment: () => "Cannot assign value to yorlang ise call",
invalidArrayIndexTypeMsg: (arg) => `Typeof index given for array ${arg} must be a number`,
arrayIndexDoesNotExistMsg: (arg) => `Index given for array ${arg} does not exist`,
varDoesNotExist: (type, name) => `${type} ${name} is undefined`,
iseAlreadyExist: (name, scope) => `Ise with name ${name} already exists within the ${scope} scope`,
expectStringMsg: (arg) => `${arg} expects a string`,
expectBooleanMsg: () => "Expecting yorlang keyword value e.g boolean(iró|òótó)",
unexpectedDeclaration: (arg) => `Yorlang ${arg} keyword not expected`,
yorlangArithmeticException: () => "YorlangArithmeticException - cannot divide by zero",
undefinedValueMsg: (arg) => `Cannot set value undefined to variable ${arg}`,
cannotNegateMsg: (arg) => `Cannot apply negation operator to the given expression: ${arg}`,

},

yoruba: {
baseNodeType: (arg) => `${arg} gbọdọ jẹ ti iru BaseNode`,
genericErrorMsg: (arg) => `kò lè ṣiṣẹ́ pẹlú ààmì ìfura tó yọjú láìròtẹ́lẹ : ${arg}`,
genericErrorMsg: (arg) => `Yorlang ò lè ṣiṣẹ́ pẹlú ààmì ìfura tó yọjú láìròtẹ́lẹ : ${arg}`,
funIncrementAndDecrementMsg: () => "Ilana ti ko dara ti yorlang nidi ise afikun tabi iyokuro ninu 'fun'",
invalidFileMsg: () => "Yorlang ko ri faili ti oruko re pari pelu .yl",
invalidAssignment: () => "Yorlang ko le fun ipe ise ni iye",
invalidArrayIndexTypeMsg: (arg) => `Atọka to je ti array ${arg} gbodo je nomba`,
arrayIndexDoesNotExistMsg: (arg) => `Atọka to je ti array ${arg} ko si ninu ibi itoju nkan pamo yorlang`,
varDoesNotExist: (type, name) => `${type} ${name} ko si ninu ibi itoju nkan pamo yorlang`,
iseAlreadyExist: (name, scope) => `Ise to ni oruko ${name} ti wa ninu odi ${scope} tẹ́lẹ`,
expectStringMsg: (arg) => `${arg} ti yorlang n reti string`,
expectBooleanMsg: (arg) => "Yorlang n reti ooto tabi iro",
unexpectedDeclaration: (arg) => `Yorlang ko reti '${arg}' ninu odi to ti yọjú`,
yorlangArithmeticException: () => "YorlangArithmeticException - yorlang ko le se isiro pipin nipase òdo",
undefinedValueMsg: (arg) => `Yorlang ko le fi ofifo sinu ${arg}`,
cannotNegateMsg: (arg) => `Yorlang ò le lo aami iyokuru pelu ${arg} `,
},
};

Expand Down
5 changes: 3 additions & 2 deletions src/interpreters/inodearrayelem.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const IBase = require("./ibase.js");
const contansts = require("../constants.js");
const feedbackMessages = require("../feedbackMessages.js");

class INodeArrayElement extends IBase {
interpreteNode (node) {
Expand All @@ -19,11 +20,11 @@ class INodeArrayElement extends IBase {
arrayElement = (isOnedimensionalArray) ? arrayLiteral[index] : arrayElement[index];
isOnedimensionalArray = false;
} else {
context.throwError(`Typeof index given for array ${node.name} must be a number`);
context.throwError(feedbackMessages.invalidArrayIndexTypeMsg(node.name));
}
});

if (!arrayElement) context.throwError(`Index given for array ${node.name} does not exist`);
if (!arrayElement) context.throwError(feedbackMessages.arrayIndexDoesNotExistMsg(node.name));

return arrayElement;
}
Expand Down
4 changes: 3 additions & 1 deletion src/interpreters/inodecallise.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const IBase = require("./ibase.js");
const getFormattedReturnValue = require("./helpers/helper_ise_adapter");
const feedbackMessages = require("../feedbackMessages.js");
const constants = require("../constants.js");

class INodeCallIse extends IBase {
interpreteNode (node) {
Expand All @@ -10,7 +12,7 @@ class INodeCallIse extends IBase {
return getFormattedReturnValue(this.environment().runHelperIse(node.name, INodeCallIse.getIseHelperParams(this, node.paramValues)));
}

this.throwError(`Ise ${node.name} is undefined`);
this.throwError(feedbackMessages.varDoesNotExist(constants.KW.ISE, node.name));
}

return INodeCallIse.startNewScope(this, iseNode, INodeCallIse.getResolvedParameterValues(this, node.paramValues));
Expand Down
3 changes: 2 additions & 1 deletion src/interpreters/inodedivide.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const IBase = require("./ibase.js");
const feedbackMessages = require("../feedbackMessages.js");

class INodeDivide extends IBase {
interpreteNode (node) {
const leftNodeValue = this.evaluateNode(node.left);
const rightNodeValue = this.evaluateNode(node.right);
if (rightNodeValue === 0) this.throwError("YorlangArithmeticException - cannot divide by zero");
if (rightNodeValue === 0) this.throwError(feedbackMessages.yorlangArithmeticException());

return leftNodeValue / rightNodeValue;
}
Expand Down
4 changes: 3 additions & 1 deletion src/interpreters/inodegetjeki.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const IBase = require("./ibase.js");
const WokeHelper = require("./helpers/woke_helper.js");
const feedbackMessages = require("../feedbackMessages.js");
const constants = require("../constants.js");

class INodeGetJeki extends IBase {
interpreteNode (node) {
Expand All @@ -9,7 +11,7 @@ class INodeGetJeki extends IBase {
}
}

this.throwError(`Variable ${node.name} is undefined`);
this.throwError(feedbackMessages.varDoesNotExist(constants.VARIABLE, node.name));
}

static getTopIndex (context, jekiName) {
Expand Down
3 changes: 2 additions & 1 deletion src/interpreters/inodeise.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const IBase = require("./ibase.js");
const feedbackMessages = require("../feedbackMessages.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(feedbackMessages.iseAlreadyExist(node.name, this.getCurrentScope())); }

this.environment().setIse(this.getCurrentScope(), node.name, node);
}
Expand Down
7 changes: 4 additions & 3 deletions src/interpreters/inodejeki.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const IBase = require("./ibase.js");
const constants = require("../constants.js");
const WokeHelper = require("./helpers/woke_helper.js");
const feedbackMessages = require("../feedbackMessages.js");

class INodeJeki extends IBase {
interpreteNode (node) {
Expand Down Expand Up @@ -41,7 +42,7 @@ class INodeJeki extends IBase {

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}`);
context.throwError(feedbackMessages.arrayIndexDoesNotExistMsg(node.left.name));
}

if ((Array.isArray(arrayLiteral[arrayIndex])) && (i < node.left.indexNodes.length - 1)) {
Expand All @@ -52,7 +53,7 @@ class INodeJeki extends IBase {
arrayLiteral[arrayIndex] = context.evaluateNode(node.right);
}
} else {
context.throwError(`Typeof index given for array ${node.name} must be a number`);
context.throwError(feedbackMessages.invalidArrayIndexTypeMsg(node.name));
}
};
}
Expand All @@ -64,7 +65,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(feedbackMessages.undefinedValueMsg(node.left));
return value;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/interpreters/inodenegateexpression.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const IBase = require("./ibase.js");
const feedbackMessages = require("../feedbackMessages.js");

class INodeNegateExpression extends IBase {
interpreteNode (node) {
const expressionValue = this.evaluateNode(node.body);
if (typeof expressionValue === "number") return -parseFloat(expressionValue);

this.throwError("Cannot apply negation operator to the given expression");
this.throwError(feedbackMessages.cannotNegateMsg(expressionValue));
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/interpreters/maininterpreter.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
const registeredInterpreters = require("./interpreters.js");
const constants = require("../constants.js");
const IBase = require("./ibase.js");
const feedbackMessages = require("../feedbackMessages.js");

class MainInterpreter {
constructor (environment, parser) {
this.environment = () => environment;
this.parser = () => parser;
this.feedbackMessages = feedbackMessages;
this.initScopeStack();
}

Expand Down
5 changes: 3 additions & 2 deletions src/parsers/keywordnodes/kwnodefun.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
const constants = require("../../constants.js");
const BaseNode = require("../basenode.js");
const kwNodeJeki = require("./kwnodejeki.js");
const feedbackMessages = require("../../feedbackMessages.js");
const bracketExpressionNl = require("../nodeLiterals/bracketexpressionnl.js");

class KwNodeFun extends BaseNode {
constructor () {
super();
if (this.isDependenciesInValid()) {
throw new Error("Dependencies must be of type BaseNode");
throw new Error(feedbackMessages.baseNodeType("Dependencies"));
}
}

Expand All @@ -28,7 +29,7 @@ class KwNodeFun extends BaseNode {
node.increment = kwNodeJeki.getNode.call(this);

if (KwNodeFun.isInValidFunIncrementStatement(node)) {
this.throwError("Invalid yorlang decrement or increment operation");
this.throwError(feedbackMessages.funIncrementAndDecrementMsg());
}
this.skipPunctuation(constants.SYM.R_BRACKET);

Expand Down
5 changes: 3 additions & 2 deletions src/parsers/keywordnodes/kwnodegbewole.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const constants = require("../../constants.js");
const BaseNode = require("../basenode.js");
const leafnl = require("../nodeLiterals/leafnl.js");
const path = require("path");
const feedbackMessages = require("../../feedbackMessages.js");

class KwNodeGbeWole extends BaseNode {
getNode () {
Expand All @@ -11,13 +12,13 @@ class KwNodeGbeWole extends BaseNode {

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(feedbackMessages.invalidFileMsg()); }

this.skipPunctuation(constants.SYM.STATEMENT_TERMINATOR);
return node;
}

this.lexer().throwError(`${constants.KW.GBE_WOLE} expects a string.`);
this.lexer().throwError(feedbackMessages.expectStringMsg(constants.KW.GBE_WOLE));
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/parsers/keywordnodes/kwnodeise.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
const constants = require("../../constants.js");
const BaseNode = require("../basenode.js");
const feedbackMessages = require("../../feedbackMessages.js");

class KwNodeIse extends BaseNode {
getNode () {
if (KwNodeIse.isExpectedIseDeclaration(this)) {
return KwNodeIse.getParsedIseNode(this);
}

this.throwError("Cannot create a yorlang function within a non function block");
this.throwError(feedbackMessages.unexpectedDeclaration(constants.KW.ISE));
}

static isExpectedIseDeclaration (context) {
Expand Down
3 changes: 2 additions & 1 deletion src/parsers/keywordnodes/kwnodejeki.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const constants = require("../../constants.js");
const BaseNode = require("../basenode.js");
const variableNl = require("../nodeLiterals/variablenl.js");
const feedbackMessages = require("../../feedbackMessages.js");

class KwNodeJeki extends BaseNode {
getNode () {
Expand All @@ -9,7 +10,7 @@ class KwNodeJeki extends BaseNode {
const node = {};
node.operation = constants.SYM.ASSIGN;
const varNode = variableNl.getNode.call(this);
if (varNode.operation === constants.CALL_ISE) this.throwError("Cannot assign value to yorlang ise call");
if (varNode.operation === constants.CALL_ISE) this.throwError(feedbackMessages.invalidAssignment());
node.left = (varNode.operation === constants.GET_JEKI) ? varNode.name : varNode;
this.skipOperator(constants.SYM.ASSIGN);
node.right = this.parseExpression();
Expand Down
3 changes: 2 additions & 1 deletion src/parsers/keywordnodes/kwnodekuro.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
const constants = require("../../constants.js");
const BaseNode = require("../basenode.js");
const feedbackMessages = require("../../feedbackMessages.js");

class KwNodeKuro extends BaseNode {
getNode () {
if (KwNodeKuro.isExpectedKuroStatement(this)) {
return KwNodeKuro.getParsedKuroNode(this);
}

this.throwError("Yorlang Kuro keyword not expected");
this.throwError(feedbackMessages.unexpectedDeclaration(constants.KW.KURO));
}

static isExpectedKuroStatement (context) {
Expand Down
3 changes: 2 additions & 1 deletion src/parsers/keywordnodes/kwnodenigbati.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
const constants = require("../../constants.js");
const BaseNode = require("../basenode.js");
const bracketExpressionNl = require("../nodeLiterals/bracketexpressionnl.js");
const feedbackMessages = require("../../feedbackMessages.js");

class KwNodeNigbati extends BaseNode {
constructor () {
super();
if (!(bracketExpressionNl instanceof BaseNode)) {
throw new Error("Dependency bracketExpressionNl must be of type BaseNode");
throw new Error(feedbackMessages.baseNodeType("Dependencies bracketExpressionNl"));
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/parsers/keywordnodes/kwnodepada.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
const constants = require("../../constants.js");
const BaseNode = require("../basenode.js");
const feedbackMessages = require("../../feedbackMessages.js");

class KwNodePada extends BaseNode {
getNode () {
if (KwNodePada.isExpectedPadaStatement(this)) {
return KwNodePada.getParsedPadaNode(this);
}

this.throwError("Yorlang pada keyword not expected in a non function(ise) block");
this.throwError(feedbackMessages.unexpectedDeclaration(constants.KW.PADA));
}

static isExpectedPadaStatement (context) {
Expand Down
4 changes: 3 additions & 1 deletion src/parsers/keywordnodes/kwnodese.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
const constants = require("../../constants.js");
const BaseNode = require("../basenode.js");
const bracketExpressionNl = require("../nodeLiterals/bracketexpressionnl.js");
const feedbackMessages = require("../../feedbackMessages.js");

class KwNodeSe extends BaseNode {
constructor () {
super();
if (!(bracketExpressionNl instanceof BaseNode)) {
throw new Error("Dependency brackExpressionNl must be of type BaseNode");
throw new Error(feedbackMessages.baseNodeType("Dependency brackExpressionNl"));
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/parsers/keywordnodes/kwnodewoke.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
const constants = require("../../constants.js");
const BaseNode = require("../basenode.js");
const feedbackMessages = require("../../feedbackMessages.js");

class KwNodeWoke extends BaseNode {
getNode () {
if (KwNodeWoke.isExpectedWokeStatement(this)) {
return KwNodeWoke.getParsedWokeNode(this);
}

this.throwError("Yorlang woke keyword not expected in a non function(ise) block");
this.throwError(feedbackMessages.unexpectedDeclaration(constants.KW.WOKE));
}

static isExpectedWokeStatement (context) {
Expand Down
Loading

0 comments on commit a0d72b4

Please sign in to comment.