@@ -33124,15 +33124,15 @@
33124
33124
};
33125
33125
33126
33126
var semantic = function(txt) {
33127
- var off = false ;
33127
+ var off = 0 ;
33128
33128
var out = [];
33129
33129
var i = 0;
33130
33130
while (i < txt.length) {
33131
33131
if (txt[i] == "「") {
33132
- off = true ;
33132
+ off ++ ;
33133
33133
out.push("quot");
33134
33134
} else if (txt[i] == "」") {
33135
- off = false ;
33135
+ off -- ;
33136
33136
out.push("quot");
33137
33137
} else {
33138
33138
if (off) {
@@ -33455,28 +33455,40 @@
33455
33455
if (idt || data) {
33456
33456
tok += txt[i];
33457
33457
}
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) {
33460
33461
enddata();
33461
33462
endnum();
33462
33463
idt = true;
33463
33464
tok = "";
33465
+ }else{
33466
+ tok += txt[i]
33467
+ if (is_sin){
33468
+ tok += txt[i+1]
33469
+ }
33464
33470
}
33465
33471
litlvl++;
33466
- if (txt[i] == "「") {
33472
+ if (is_sin) {
33467
33473
i++;
33468
33474
}
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) {
33472
33479
tokens.push(["lit", `"${tok}"`, i + 1]);
33473
33480
idt = false;
33474
33481
tok = "";
33482
+ }else{
33483
+ tok += txt[i]
33484
+ if (is_sin){
33485
+ tok += txt[i+1]
33486
+ }
33475
33487
}
33476
- if (txt[i] == "」") {
33488
+ if (is_sin) {
33477
33489
i++;
33478
33490
}
33479
- } else if (litlvl > 0){
33491
+ } else if (litlvl > 0) {
33480
33492
tok += txt[i];
33481
33493
} else {
33482
33494
if (txt[i] == "「") {
33788
33800
}
33789
33801
asc.push(x);
33790
33802
} 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 };
33792
33804
i += 2;
33793
33805
while (tokens[i] && gettok(i, 0) == "opord" && gettok(i, 1) == "r") {
33794
33806
typeassert(i + 1, ["data", "num", "lit", "iden", "bool"]);
@@ -33797,14 +33809,14 @@
33797
33809
}
33798
33810
asc.push(x);
33799
33811
} 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 });
33801
33813
i += 2;
33802
33814
} else if (gettok(i, 0) == "ctnr" && gettok(i, 1) == "push") {
33803
33815
typeassert(i + 2, ["opord"]);
33804
33816
assert(`<${cmd}> Only opord l allowed`, pos, gettok(i + 2, 1) == "l");
33805
33817
var x = {
33806
33818
op: "push",
33807
- container: tokens[i+ 1],
33819
+ container: tokens[i + 1],
33808
33820
values: [tokens[i + 3]],
33809
33821
pos
33810
33822
};
33823
33835
typeassert(i + 1, ["iden", "lit"]);
33824
33836
var x = {
33825
33837
op: "subscript",
33826
- container: tokens[i+ 1],
33838
+ container: tokens[i + 1],
33827
33839
value: tokens[i + 3],
33828
33840
pos
33829
33841
};
33836
33848
gettok(i + 2, 1) == "len"
33837
33849
) {
33838
33850
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 };
33840
33852
asc.push(x);
33841
33853
i += 3;
33842
33854
} else if (
33871
33883
) {
33872
33884
var x = {
33873
33885
op: "for",
33874
- container: tokens[i+ 1],
33886
+ container: tokens[i + 1],
33875
33887
iterator: gettok(i + 3, 1),
33876
33888
pos
33877
33889
};
34068
34080
var imports = [];
34069
34081
var mwrapper = jsWrapModule;
34070
34082
if (!compilers[lang]) {
34071
- console.log(compilers)
34083
+ console.log(compilers);
34072
34084
return logCallback("Target language not supported.");
34073
34085
}
34074
34086
var klass = compilers[lang];
34187
34199
txt = txt.replace(/\n+/g, "");
34188
34200
txt = txt.replace(/\t+/g, "");
34189
34201
txt = txt.replace(/ +/g, "");
34190
-
34202
+ txt = txt.replace(/『/g, "「「");
34203
+ txt = txt.replace(/』/g, "」」");
34191
34204
// txt = txt + txt + txt;
34192
34205
34193
34206
var tokens = parser.wy2tokens(txt);
34365
34378
var ky = PCT + CH / 2;
34366
34379
var kx = Math.min(commentx, x + CO + CW / 2);
34367
34380
for (var k = 0; k < cmt.length; k++) {
34368
- if (cmt[k] == "。") {
34381
+ if (cmt[k] == "。" || cmt[k] == "、" ) {
34369
34382
svg += `<circle cx="${kx + CW / 2 - CO}" cy="${ky -
34370
34383
CH / 2}" r="${CH /
34371
34384
12}" stroke="${RED}" fill="none" stroke-width="0.5"></circle>`;
34392
34405
7}" stroke="${RED}" fill="none" stroke-width="1" wy-data="${
34393
34406
txt[i]
34394
34407
}"></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>`;
34395
34412
} else if (txt[i] == "「") {
34396
34413
iden = true;
34397
34414
if (y > Y1) {
34459
34476
function test_render() {
34460
34477
var svgs = render(
34461
34478
"圖靈機",
34462
- fs.readFileSync("../examples/turing.txt ").toString()
34479
+ fs.readFileSync("../examples/turing.wy ").toString()
34463
34480
);
34464
34481
// var svgs = render("曼德博集",fs.readFileSync("../examples/mandelbrot.txt").toString(),{plotResult:true})
34465
34482
// var svgs = render("春日宴",fs.readFileSync("../examples/beer.txt").toString(),{plotResult:false})
34717
34734
");";
34718
34735
strayvar.push(vname);
34719
34736
} 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(",")});`;
34721
34740
} else if (a.op == "for") {
34722
34741
js += `for (var ${a.iterator} of ${getval(a.container)}){`;
34723
34742
curlvl++;
35001
35020
strayvar.push(vname);
35002
35021
} else {
35003
35022
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(")(")});`;
35005
35026
strayvar.push(vname);
35006
35027
}
35007
35028
} else if (a.op == "subscript") {
35163
35184
} catch (e) {}
35164
35185
class RBCompiler extends Base {
35165
35186
rename(name) {
35166
-
35167
35187
return name && `${name.toLowerCase()}`;
35168
35188
}
35169
35189
lowerAllPinYinAndMakeItGlobal(asc) {
35170
-
35171
35190
for (let i = 0; i < asc.length; i++) {
35172
35191
var item = asc[i];
35173
35192
switch (item.op) {
35176
35195
item.names = item.names.map(e => this.rename(e));
35177
35196
break;
35178
35197
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
+ }
35180
35201
item.args = item.args.map(arg => {
35181
35202
if (arg[0] == "iden") arg[1] = this.rename(arg[1]);
35182
35203
return arg;
@@ -35196,15 +35217,21 @@
35196
35217
item.containers = item.containers.map(e => this.rename(e));
35197
35218
break;
35198
35219
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
+ }
35200
35223
item.iterator = this.rename(item.iterator);
35201
35224
break;
35202
35225
case "push":
35203
35226
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
+ }
35205
35230
break;
35206
35231
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
+ }
35208
35235
if (item.value[0] == "iden") this.rename(item.value[1]);
35209
35236
break;
35210
35237
case "if":
35396
35423
strayvar.push(vname);
35397
35424
} else {
35398
35425
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(")(")});`;
35400
35429
strayvar.push(vname);
35401
35430
}
35402
35431
} else if (a.op == "subscript") {
0 commit comments