Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added naqsh function representing the map function #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/editor/mode/urduscript/urduscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
"rakho": kw("var"), "likho": A, "pucho": A,
"sahi": atom, "galat": atom, "ghalat": atom, "khali": atom, "khaali": atom,
"kaam": kw("function"), "har": kw("for"), "k": A, "per": A, "pe": A,
"bhejo": C, "rukjao": C
"bhejo": C, "rukjao": C, "naqsh":C
};

// Extend the 'normal' keywords with the TypeScript language extensions
Expand Down Expand Up @@ -821,4 +821,4 @@ CodeMirror.defineMIME("application/ld+json", {name: "javascript", jsonld: true})
CodeMirror.defineMIME("text/typescript", { name: "javascript", typescript: true });
CodeMirror.defineMIME("application/typescript", { name: "javascript", typescript: true });

});
});
33 changes: 24 additions & 9 deletions docs/editor/scripts/urdujs/keywords.js.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ export syntax ghalat = ctx => #`false`

// if
export syntax agar = function (ctx) {

let ifparam = ctx.next().value
let ifblock = ctx.next().value;
let warnas = ctx.next();
let ctxCounter = 3;
let result = #`if ${ifparam} ${ifblock}`;
while(!warnas.done){
var isWarna = false;


if (warnas.value.value.token.value === "warna"){
let elseblock = ctx.next().value;
Expand All @@ -36,7 +36,7 @@ export syntax agar = function (ctx) {
ctxCounter += 2
result = result.concat(#`else if ${elseifparam} ${elseifblock}`)
isWarna = true;

}

if (!isWarna) {
Expand All @@ -45,15 +45,15 @@ export syntax agar = function (ctx) {
while (--ctxCounter){
ctx.next()
}

return result;
}

warnas = ctx.next();
ctxCounter++;
}
//console.log("warnas",warnas.value.token.value)

return result
//return #`if ${ifparam} ${ifblock}`;
}
Expand Down Expand Up @@ -88,15 +88,15 @@ export syntax kaam = function (ctx) {
// for and foreach loop
export syntax har = function (ctx) {
let fparam = ctx.next().value

if (fparam.type==="RawSyntax"){
//foreach
let fparamk = ctx.next().value;
let fparamvar = ctx.next().value;
let fblock = ctx.next().value;

//ignore 'per' or 'pe' if present
if (fblock.type==="RawSyntax"
if (fblock.type==="RawSyntax"
&& (fblock.value.token.value==="per" || fblock.value.token.value==="pe")
){
fblock = ctx.next().value;
Expand Down Expand Up @@ -127,9 +127,24 @@ export syntax karo = function(ctx) {
} else {
return #`console.log("galti: karo ke liye jabtak hona lazmi hai!")`;
}



}

// break
export syntax rukjao = (ctx) => #`break`;

//maps a number from one range to another
//map(value, currentMinRange, currentMaxRange, targetMinRange, targetMaxRange)
export syntax naqsh = function(ctx){
let bodyCtx = ctx.contextify(ctx.next().value);
let val = bodyCtx.next().value;
bodyCtx.next(); // eat ,
let currentMinRange = bodyCtx.next().value;
bodyCtx.next(); // eat ,
let currentMaxRange = bodyCtx.next().value;
bodyCtx.next(); // eat ,
let targetMinRange = bodyCtx.next().value;
bodyCtx.next(); // eat ,
let targetMaxRange = bodyCtx.next().value;
return #`((${val} - ${currentMinRange}) / (${currentMaxRange} - ${currentMinRange}))*(${targetMaxRange} - ${targetMinRange})+${targetMinRange}`;
}
30 changes: 23 additions & 7 deletions src/keywords.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ export syntax ghalat = ctx => #`false`

// if
export syntax agar = function (ctx) {

let ifparam = ctx.next().value
let ifblock = ctx.next().value;
let warnas = ctx.next();
let ctxCounter = 3;
let result = #`if ${ifparam} ${ifblock}`;
while(!warnas.done){
var isWarna = false;


if (warnas.value.value.token.value === "warna"){
let elseblock = ctx.next().value;
Expand All @@ -36,7 +36,7 @@ export syntax agar = function (ctx) {
ctxCounter += 2
result = result.concat(#`else if ${elseifparam} ${elseifblock}`)
isWarna = true;

}

if (!isWarna) {
Expand All @@ -45,15 +45,15 @@ export syntax agar = function (ctx) {
while (--ctxCounter){
ctx.next()
}

return result;
}

warnas = ctx.next();
ctxCounter++;
}
//console.log("warnas",warnas.value.token.value)

return result
//return #`if ${ifparam} ${ifblock}`;
}
Expand Down Expand Up @@ -88,15 +88,15 @@ export syntax kaam = function (ctx) {
// for and foreach loop
export syntax har = function (ctx) {
let fparam = ctx.next().value

if (fparam.type==="RawSyntax"){
//foreach
let fparamk = ctx.next().value;
let fparamvar = ctx.next().value;
let fblock = ctx.next().value;

//ignore 'per' or 'pe' if present
if (fblock.type==="RawSyntax"
if (fblock.type==="RawSyntax"
&& (fblock.value.token.value==="per" || fblock.value.token.value==="pe")
){
fblock = ctx.next().value;
Expand Down Expand Up @@ -132,3 +132,19 @@ export syntax karo = function(ctx) {

// break
export syntax rukjao = (ctx) => #`break`;

//maps a number from one range to another
//map(value, currentMinRange, currentMaxRange, targetMinRange, targetMaxRange)
export syntax naqsh = function(ctx){
let bodyCtx = ctx.contextify(ctx.next().value);
let val = bodyCtx.next().value;
bodyCtx.next(); // eat ,
let currentMinRange = bodyCtx.next().value;
bodyCtx.next(); // eat ,
let currentMaxRange = bodyCtx.next().value;
bodyCtx.next(); // eat ,
let targetMinRange = bodyCtx.next().value;
bodyCtx.next(); // eat ,
let targetMaxRange = bodyCtx.next().value;
return #`((${val} - ${currentMinRange}) / (${currentMaxRange} - ${currentMinRange}))*(${targetMaxRange} - ${targetMinRange})+${targetMinRange}`;
}