Skip to content

Commit 0e43c90

Browse files
author
ETHproductions
committed
Add newvars(), fix S.r() bug
- S.r() now accepts an empty string as an argument, making the replacement non-global. - Leading ; resets the vars like so: A = [], B = "ABCDEFGHIJKLMNOPQRSTUVWXYZ", C = "abcdefghijklmnopqrstuvwxyz", D = "QWERTYUIOP\nASDFGHJKL\nZXCVBNM", E = "[a-z]", F = "[A-Za-z]", G = 36, H = 65, I = 91, J = ",", L = ".".
1 parent 913ef13 commit 0e43c90

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/japt-interpreter.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ df(String,'n',function(x){x=x||10;if(x==10)return parseFloat(this);else return p
122122
df(String,'o',function(x){return this.replace(new RegExp('[^'+x+']','gi'),"")}); // Removes all but specified characters. Similar to TeaScript's O function
123123
df(String,'p',function(x){return this.repeat(x)});
124124
df(String,'q',function(x){return this.split(x||"")});
125-
df(String,'r',function(x,y,z){return this.replace(x instanceof RegExp?x:RegExp(x,(z||"")+"g"),y||"")});
125+
df(String,'r',function(x,y,z){return this.replace(x instanceof RegExp?x:RegExp(x,z==""?"":(z||"")+"g"),y||"")});
126126
df(String,'s',function(x,y){y=fb(y,this.length);if(y<0)y+=this.length;return this.substring(x,y)});
127127
df(String,'t',function(x,y){y=fb(y,this.length);return this.substr(x,y)});
128128
df(String,'u',function(){return this.toUpperCase()});
@@ -403,6 +403,20 @@ function run() {
403403
document.getElementById("timeout").disabled = false;
404404
}
405405

406+
function newvars() {
407+
A = [],
408+
B = "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
409+
C = "abcdefghijklmnopqrstuvwxyz",
410+
D = "QWERTYUIOP\nASDFGHJKL\nZXCVBNM",
411+
E = "[a-z]",
412+
F = "[A-Za-z]",
413+
G = 36,
414+
H = 65,
415+
I = 91,
416+
J = ",",
417+
L = ".";
418+
}
419+
406420
function subparen(code) {
407421
var level = 0, min = 0;
408422
for(var i=0;i<code.length;i++) {
@@ -486,7 +500,8 @@ function transpile(code) {
486500

487501
for (i = 0; i < code.length; i++) {
488502
var char = code[i];
489-
if (isChar(char, "`'\"A-Z0-9\\(\\[{") && isChar(outp.slice(-1), "`\"A-Z0-9\\)\\]}")
503+
if (char === ";" && i === 0) { outp += "newvars();"; }
504+
else if (isChar(char, "`'\"A-Z0-9\\(\\[{") && isChar(outp.slice(-1), "`\"A-Z0-9\\)\\]}")
490505
&& !(isChar(char,"0-9") && isChar(outp.slice(-1),"0-9"))) {
491506
outp += ",";
492507
}

0 commit comments

Comments
 (0)