Skip to content

Commit 3722cf0

Browse files
LingDong-Lingdong Huang
authored andcommitted
make py less broken
1 parent fb4b0e8 commit 3722cf0

File tree

2 files changed

+232
-5
lines changed

2 files changed

+232
-5
lines changed

tools/test_parser.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function readOtherExample(x) {
1414
function runExample(lang, name) {
1515
var txt = fs.readFileSync("../examples/" + name + ".wy").toString();
1616
var sourceCode = parser.compile(lang, txt, {
17-
romanizeIdentifiers: true,
17+
romanizeIdentifiers: "none", //true,
1818
lib: utils.loadlib(),
1919
reader: readOtherExample
2020
});
@@ -36,17 +36,21 @@ function runExample(lang, name) {
3636
}
3737
}
3838

39-
function runAll(lang) {
39+
function runAll(lang, skips = []) {
4040
var files = fs.readdirSync("../examples/").filter(x => x.endsWith(".wy"));
4141
console.log(files);
4242
for (var i = 0; i < files.length; i++) {
43+
if (skips.includes(files[i].split(".")[0])) {
44+
console.log("SKIPPED");
45+
continue;
46+
}
4347
console.log(`======= Progress ${i + 1}/${files.length} =======`);
4448
runExample(lang, files[i].split(".")[0]);
4549
}
4650
}
4751

48-
runExample("js", "tree");
49-
// runAll("js");
52+
// runExample("js", "tree");
53+
runAll("py", ["quine", "quine2", "tree", "tree2", "try"]);
5054

5155
// runExample("js", "../../../Downloads/local_test");
52-
// runExample("js", "import");
56+
// runExample("py", "draw_heart");

tools/tmp.py

Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
# -*- coding: utf-8 -*-
2+
class Ctnr:
3+
def __init__(self):self.dict = dict();self.length = 0;self.it = -1;
4+
def push(self,*args):
5+
for arg in args:
6+
self.dict[str(self.length)]=arg; self.length+=1
7+
def __getitem__(self,i):
8+
try: return self.dict[str(i)]
9+
except: return None
10+
def __setitem__(self,i,x):
11+
self.dict[str(i)]=x
12+
inti = None
13+
try:
14+
inti = int(i)
15+
if (abs(inti - float(i))>0.0001): inti=None
16+
except: pass
17+
if (inti != None):
18+
self.length=inti+1
19+
for j in range(0,self.length):
20+
try: self.dict[str(j)]
21+
except: self.dict[str(j)]=None
22+
def slice(self,i):
23+
ret = Ctnr();
24+
for i in range(i,self.length): ret.push(self[i])
25+
return ret
26+
def concat(self,other):
27+
ret = Ctnr();
28+
for i in range(0,self.length): ret.push(self[i])
29+
for i in range(0,other.length): ret.push(other[i])
30+
return ret
31+
def __str__(self):
32+
if (len(self.dict.keys())==self.length):
33+
ret = "["
34+
for k in range(0,self.length):
35+
v = self[k]
36+
if (isinstance(v,Ctnr)): ret += v.__str__()
37+
else: ret += str(v)
38+
ret+=","
39+
ret += "]"
40+
return ret;
41+
else:
42+
ret = "{"
43+
for k in self.dict.keys():
44+
ret += str(k)+":"
45+
v = self.dict[k]
46+
if (isinstance(v,Ctnr)): ret += v.__str__()
47+
else: ret += str(v)
48+
ret+=","
49+
ret += "}"
50+
return ret;
51+
def __repr__(self):
52+
return self.__str__()
53+
def __iter__(self):
54+
self.it = -1;
55+
return self
56+
def __next__(self):
57+
self.it += 1
58+
if (self.it >= self.length): raise StopIteration()
59+
return self[self.it]
60+
globals()['Ctnr']=Ctnr;
61+
class JSON:
62+
@staticmethod
63+
def stringify(x):
64+
return x;
65+
#####
66+
圖靈機=lambda _:0
67+
def 圖靈機 (諸律):
68+
def _rand1(始態):
69+
def _rand2(終態):
70+
nonlocal 諸律;
71+
nonlocal 始態;
72+
global 圖靈機;
73+
=Ctnr()
74+
.push("白")
75+
=1
76+
左疆=1
77+
右疆=1
78+
=始態
79+
圖靈機畫法=lambda _:0
80+
def 圖靈機畫法():
81+
global 圖靈機;
82+
nonlocal ;
83+
nonlocal ;
84+
nonlocal 左疆;
85+
nonlocal 右疆;
86+
nonlocal ;
87+
nonlocal 圖靈機畫法;
88+
畫帶=""
89+
=左疆
90+
while (True):
91+
92+
if >右疆:
93+
break
94+
95+
_ans1=[-1];
96+
97+
=_ans1;
98+
99+
if ==:
100+
_ans2="〔"+;
101+
_ans3=_ans2+"〕";
102+
103+
=_ans3;
104+
105+
else:
106+
_ans4="、"+;
107+
_ans5=_ans4+"、";
108+
109+
=_ans5;
110+
111+
_ans6=畫帶+;
112+
113+
畫帶=_ans6;
114+
_ans7=1+;
115+
116+
=_ans7;
117+
118+
_ans8=
119+
_ans9="《"
120+
_ans10=畫帶
121+
_ans11="》"
122+
print(_ans8,_ans9,_ans10,_ans11);
123+
124+
_ans12=圖靈機畫法();
125+
while (True):
126+
for in 諸律:
127+
_ans13=[1-1];
128+
129+
甲態=_ans13;
130+
_ans14=[2-1];
131+
132+
讀符=_ans14;
133+
_ans15=[3-1];
134+
135+
乙態=_ans15;
136+
_ans16=[4-1];
137+
138+
畫符=_ans16;
139+
_ans17=[5-1];
140+
141+
=_ans17;
142+
143+
if ==甲態:
144+
145+
if [-1]==讀符:
146+
147+
[-1]=畫符;
148+
149+
=乙態;
150+
151+
if =="左":
152+
_ans18=-1;
153+
154+
=_ans18;
155+
156+
157+
if =="右":
158+
_ans19=+1;
159+
160+
=_ans19;
161+
162+
break
163+
164+
165+
166+
167+
if <左疆:
168+
169+
[-1]="白";
170+
171+
左疆=;
172+
173+
174+
if >右疆:
175+
176+
[-1]="白";
177+
178+
右疆=;
179+
180+
_ans20=圖靈機畫法();
181+
182+
if ==終態:
183+
break
184+
185+
186+
return _rand2;
187+
return _rand1;
188+
189+
製律=lambda _:0
190+
def 製律 (諸律):
191+
def _rand3(甲態):
192+
def _rand4(讀符):
193+
def _rand5(乙態):
194+
def _rand6(畫符):
195+
def _rand7():
196+
nonlocal 諸律;
197+
nonlocal 甲態;
198+
nonlocal 讀符;
199+
nonlocal 乙態;
200+
nonlocal 畫符;
201+
global 圖靈機;
202+
global 製律;
203+
=Ctnr()
204+
.push(甲態,讀符,乙態,畫符,)
205+
諸律.push()
206+
return _rand7;
207+
return _rand6;
208+
return _rand5;
209+
return _rand4;
210+
return _rand3;
211+
212+
_ans21="營營河狸。止于樊。"
213+
print(_ans21);
214+
諸律=Ctnr()
215+
陽符="墨"
216+
陰符="白"
217+
_ans22=製律(諸律)("甲")(陰符)("乙")(陽符)("右");
218+
_ans23=製律(諸律)("甲")(陽符)("丙")(陽符)("左");
219+
_ans24=製律(諸律)("乙")(陰符)("甲")(陽符)("左");
220+
_ans25=製律(諸律)("乙")(陽符)("乙")(陽符)("右");
221+
_ans26=製律(諸律)("丙")(陰符)("乙")(陽符)("左");
222+
_ans27=製律(諸律)("丙")(陽符)("樊")(陽符)("中");
223+
_ans28=圖靈機(諸律)("甲")("樊");

0 commit comments

Comments
 (0)