Не работает компилятор py-to-js
у меня есть компилятор
pyfile = open('testpy.py', 'r', encoding = 'UTF-8')
count = -1
with open('open.js', 'w', encoding = 'UTF-8') as f:
py = pyfile.readlines()
for num in py:
count += 1
# basic concepts
if '=' in num and not '==' in num:
name = num.replace('\n', '')
let = 'let '
if name.startswith('\t'):
name = name.replace('\t', '')
let = '\tlet '
f.write( let + f"{name}" + ';' + '\n')
elif 'if' in num:
condition = num.replace('\n', '').replace('if', '').replace(':', '')
if_ = 'if '
if condition.startswith('\t'):
condition = condition.replace('\t', '')
if_ = '\tif '
f.write( if_ + '(' + f'{condition}' + ' )' + ' {' + '\n')
if not '\t' in py[count + 1]:
f.write('}' + '\n')
# basic commands
elif 'print' in num:
command = num.replace('\n', '')
f.write(f'{command.replace("print", "console.log")}'+ ';' + '\n')
try:
if '\t' in py[count]:
if not '\t' in py[count + 1] and py[count + 1] != '\n':
f.write('}' + '\n' + '\n')
except:
f.write('}')
И впринципе он работает, но так получается что при вызове if в себя (if в if), ставится только одна кв.скобка:
if lol:
print('anything')
if pas:
print('tipidor')
if pas7:
pass
to
if ( lol ) {
console.log('anything');
if ( pas ) {
console.log('tipidor');
if ( pas7 ) {
}