Skip to content

Commit efb7a33

Browse files
LingDong-Lingdong Huang
authored andcommitted
nested comments
1 parent cee554c commit efb7a33

File tree

4 files changed

+216
-126
lines changed

4 files changed

+216
-126
lines changed

site/ide.html

Lines changed: 59 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -33124,15 +33124,15 @@
3312433124
};
3312533125

3312633126
var semantic = function(txt) {
33127-
var off = false;
33127+
var off = 0;
3312833128
var out = [];
3312933129
var i = 0;
3313033130
while (i < txt.length) {
3313133131
if (txt[i] == "「") {
33132-
off = true;
33132+
off ++;
3313333133
out.push("quot");
3313433134
} else if (txt[i] == "」") {
33135-
off = false;
33135+
off --;
3313633136
out.push("quot");
3313733137
} else {
3313833138
if (off) {
@@ -33455,28 +33455,40 @@
3345533455
if (idt || data) {
3345633456
tok += txt[i];
3345733457
}
33458-
} else if ((txt[i] == "「" && txt[i + 1] == "「") || txt[i]=="『") {
33459-
if (litlvl == 0){
33458+
} else if ((txt[i] == "「" && txt[i + 1] == "「") || txt[i] == "『") {
33459+
var is_sin = (txt[i] == "「")
33460+
if (litlvl == 0) {
3346033461
enddata();
3346133462
endnum();
3346233463
idt = true;
3346333464
tok = "";
33465+
}else{
33466+
tok += txt[i]
33467+
if (is_sin){
33468+
tok += txt[i+1]
33469+
}
3346433470
}
3346533471
litlvl++;
33466-
if (txt[i] == "「"){
33472+
if (is_sin) {
3346733473
i++;
3346833474
}
33469-
} else if (txt[i] == "」" && txt[i + 1] == "」" || txt[i]=="』") {
33470-
litlvl --;
33471-
if (litlvl == 0){
33475+
} else if ((txt[i] == "」" && txt[i + 1] == "」") || txt[i] == "』") {
33476+
var is_sin = (txt[i] == "」");
33477+
litlvl--;
33478+
if (litlvl == 0) {
3347233479
tokens.push(["lit", `"${tok}"`, i + 1]);
3347333480
idt = false;
3347433481
tok = "";
33482+
}else{
33483+
tok += txt[i]
33484+
if (is_sin){
33485+
tok += txt[i+1]
33486+
}
3347533487
}
33476-
if (txt[i] == "」"){
33488+
if (is_sin) {
3347733489
i++;
3347833490
}
33479-
} else if (litlvl > 0){
33491+
} else if (litlvl > 0) {
3348033492
tok += txt[i];
3348133493
} else {
3348233494
if (txt[i] == "「") {
@@ -33788,7 +33800,7 @@
3378833800
}
3378933801
asc.push(x);
3379033802
} else if (gettok(i, 0) == "call" && gettok(i, 1) == "r") {
33791-
var x = { op: "call", fun: tokens[i+1], args: [], pos };
33803+
var x = { op: "call", fun: tokens[i + 1], args: [], pos };
3379233804
i += 2;
3379333805
while (tokens[i] && gettok(i, 0) == "opord" && gettok(i, 1) == "r") {
3379433806
typeassert(i + 1, ["data", "num", "lit", "iden", "bool"]);
@@ -33797,14 +33809,14 @@
3379733809
}
3379833810
asc.push(x);
3379933811
} else if (gettok(i, 0) == "call" && gettok(i, 1) == "l") {
33800-
asc.push({ op: "call", pop: true, fun: tokens[i+1], pos });
33812+
asc.push({ op: "call", pop: true, fun: tokens[i + 1], pos });
3380133813
i += 2;
3380233814
} else if (gettok(i, 0) == "ctnr" && gettok(i, 1) == "push") {
3380333815
typeassert(i + 2, ["opord"]);
3380433816
assert(`<${cmd}> Only opord l allowed`, pos, gettok(i + 2, 1) == "l");
3380533817
var x = {
3380633818
op: "push",
33807-
container: tokens[i+1],
33819+
container: tokens[i + 1],
3380833820
values: [tokens[i + 3]],
3380933821
pos
3381033822
};
@@ -33823,7 +33835,7 @@
3382333835
typeassert(i + 1, ["iden", "lit"]);
3382433836
var x = {
3382533837
op: "subscript",
33826-
container: tokens[i+1],
33838+
container: tokens[i + 1],
3382733839
value: tokens[i + 3],
3382833840
pos
3382933841
};
@@ -33836,7 +33848,7 @@
3383633848
gettok(i + 2, 1) == "len"
3383733849
) {
3383833850
typeassert(i + 1, ["iden", "lit"]);
33839-
var x = { op: "length", container: tokens[i+1], pos };
33851+
var x = { op: "length", container: tokens[i + 1], pos };
3384033852
asc.push(x);
3384133853
i += 3;
3384233854
} else if (
@@ -33871,7 +33883,7 @@
3387133883
) {
3387233884
var x = {
3387333885
op: "for",
33874-
container: tokens[i+1],
33886+
container: tokens[i + 1],
3387533887
iterator: gettok(i + 3, 1),
3387633888
pos
3387733889
};
@@ -34068,7 +34080,7 @@
3406834080
var imports = [];
3406934081
var mwrapper = jsWrapModule;
3407034082
if (!compilers[lang]) {
34071-
console.log(compilers)
34083+
console.log(compilers);
3407234084
return logCallback("Target language not supported.");
3407334085
}
3407434086
var klass = compilers[lang];
@@ -34187,7 +34199,8 @@
3418734199
txt = txt.replace(/\n+/g, "");
3418834200
txt = txt.replace(/\t+/g, "");
3418934201
txt = txt.replace(/ +/g, "");
34190-
34202+
txt = txt.replace(/『/g, "「「");
34203+
txt = txt.replace(/』/g, "」」");
3419134204
// txt = txt + txt + txt;
3419234205

3419334206
var tokens = parser.wy2tokens(txt);
@@ -34365,7 +34378,7 @@
3436534378
var ky = PCT + CH / 2;
3436634379
var kx = Math.min(commentx, x + CO + CW / 2);
3436734380
for (var k = 0; k < cmt.length; k++) {
34368-
if (cmt[k] == "。") {
34381+
if (cmt[k] == "。" || cmt[k] == "、") {
3436934382
svg += `<circle cx="${kx + CW / 2 - CO}" cy="${ky -
3437034383
CH / 2}" r="${CH /
3437134384
12}" stroke="${RED}" fill="none" stroke-width="0.5"></circle>`;
@@ -34392,6 +34405,10 @@
3439234405
7}" stroke="${RED}" fill="none" stroke-width="1" wy-data="${
3439334406
txt[i]
3439434407
}"></circle>`;
34408+
} else if (txt[i] == "、" && !iden) {
34409+
svg += `<text x="${x + CW - 6}" y="${y -
34410+
CH +
34411+
PSH}" fill="${RED}" wy-data="${txt[i]}">、</text>`;
3439534412
} else if (txt[i] == "「") {
3439634413
iden = true;
3439734414
if (y > Y1) {
@@ -34459,7 +34476,7 @@
3445934476
function test_render() {
3446034477
var svgs = render(
3446134478
"圖靈機",
34462-
fs.readFileSync("../examples/turing.txt").toString()
34479+
fs.readFileSync("../examples/turing.wy").toString()
3446334480
);
3446434481
// var svgs = render("曼德博集",fs.readFileSync("../examples/mandelbrot.txt").toString(),{plotResult:true})
3446534482
// var svgs = render("春日宴",fs.readFileSync("../examples/beer.txt").toString(),{plotResult:false})
@@ -34717,7 +34734,9 @@
3471734734
");";
3471834735
strayvar.push(vname);
3471934736
} else if (a.op == "push") {
34720-
js += `${getval(a.container)}.push(${a.values.map(x => getval(x)).join(",")});`;
34737+
js += `${getval(a.container)}.push(${a.values
34738+
.map(x => getval(x))
34739+
.join(",")});`;
3472134740
} else if (a.op == "for") {
3472234741
js += `for (var ${a.iterator} of ${getval(a.container)}){`;
3472334742
curlvl++;
@@ -35001,7 +35020,9 @@
3500135020
strayvar.push(vname);
3500235021
} else {
3500335022
var vname = this.nextTmpVar();
35004-
py += `${vname}=${getval(a.fun)}(${a.args.map(x => getval(x)).join(")(")});`;
35023+
py += `${vname}=${getval(a.fun)}(${a.args
35024+
.map(x => getval(x))
35025+
.join(")(")});`;
3500535026
strayvar.push(vname);
3500635027
}
3500735028
} else if (a.op == "subscript") {
@@ -35163,11 +35184,9 @@
3516335184
} catch (e) {}
3516435185
class RBCompiler extends Base {
3516535186
rename(name) {
35166-
3516735187
return name && `${name.toLowerCase()}`;
3516835188
}
3516935189
lowerAllPinYinAndMakeItGlobal(asc) {
35170-
3517135190
for (let i = 0; i < asc.length; i++) {
3517235191
var item = asc[i];
3517335192
switch (item.op) {
@@ -35176,7 +35195,9 @@
3517635195
item.names = item.names.map(e => this.rename(e));
3517735196
break;
3517835197
case "call":
35179-
if (item.fun[0]=="iden") {item.fun[1] = this.rename(item.fun[1])};
35198+
if (item.fun[0] == "iden") {
35199+
item.fun[1] = this.rename(item.fun[1]);
35200+
}
3518035201
item.args = item.args.map(arg => {
3518135202
if (arg[0] == "iden") arg[1] = this.rename(arg[1]);
3518235203
return arg;
@@ -35196,15 +35217,21 @@
3519635217
item.containers = item.containers.map(e => this.rename(e));
3519735218
break;
3519835219
case "for":
35199-
if (item.container[0]=="iden") {item.container[1] = this.rename(item.container[1])}
35220+
if (item.container[0] == "iden") {
35221+
item.container[1] = this.rename(item.container[1]);
35222+
}
3520035223
item.iterator = this.rename(item.iterator);
3520135224
break;
3520235225
case "push":
3520335226
case "length":
35204-
if (item.container[0]=="iden") {item.container[1] = this.rename(item.container[1])}
35227+
if (item.container[0] == "iden") {
35228+
item.container[1] = this.rename(item.container[1]);
35229+
}
3520535230
break;
3520635231
case "subscript":
35207-
if (item.container[0]=="iden") {item.container[1] = this.rename(item.container[1])}
35232+
if (item.container[0] == "iden") {
35233+
item.container[1] = this.rename(item.container[1]);
35234+
}
3520835235
if (item.value[0] == "iden") this.rename(item.value[1]);
3520935236
break;
3521035237
case "if":
@@ -35396,7 +35423,9 @@
3539635423
strayvar.push(vname);
3539735424
} else {
3539835425
var vname = this.nextTmpVar();
35399-
rb += `${vname}=${getval(a.fun)}(${a.args.map(x => getval(x)).join(")(")});`;
35426+
rb += `${vname}=${getval(a.fun)}(${a.args
35427+
.map(x => getval(x))
35428+
.join(")(")});`;
3540035429
strayvar.push(vname);
3540135430
}
3540235431
} else if (a.op == "subscript") {

0 commit comments

Comments
 (0)