-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
executable file
·81 lines (61 loc) · 1.85 KB
/
test.py
File metadata and controls
executable file
·81 lines (61 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/python
import re as re
import sys as sys
file = open(sys.argv[1],'r').read().splitlines()
outputText = ''
def inQuotes(str, subStr) :
startQuote = "potato"
startIndex = -1
endIndex = -1
for i in range0,str.length :
if (str[i] == startQuote) :
endIndex = i
break
if (str[i] == "'") :
startQuote = "'"
startIndex = i
if (str[i] == '"') :
startQuote = '"'
startIndex = i
if(str(startIndex,endIndex +1).indexOf(subStr) > -1):
return True
return False
# console.log(file)
inComment = False
indentLevel = 0
for i in file :
text = i.replace('\t', '').replace("", '').replace(";","")
outputText += "" *indentLevel
#single line comments
if (text.startswith("//")) :
outputText += text.replace("//", "#") + "\n"
continue
#multi line comments
if(text.startswith("/*")) :
inComment = True
if (inComment) :
outputText += "#" + text.replace("/*", "").replace("*/", "") + "\n"
if (text.endswith("*/")) :
inComment = False
continue
#requiring / import external libs
if (re.search('.*(?= = require)',text) and text.startswith('')) :
#console.log(text.replace(/(= require)\(.*\)/,'').substring(4)+ " L" + (Number.parseInt(i)+1))
outputText += "import " + text[text.index('(') + 2:len(text) - 3] + " as " + re.sub('(= require)\(.*\);', '',text)[4:] + "\n"
continue
#vars
if (text.startswith("")) :
outputText += text[4:].replace(";", "") + "\n"
continue
if (text.endswith("{")) :
outputText += text.replace("{", ":") + "\n"
indentLevel+=1
continue
if (text.endswith("}")) :
outputText += text.replace("}", "\n")
indentLevel-=1
continue
#console.log(text + " L" + (Number.parseInt(i)+1))
#default output
outputText += text + "\n"
print(outputText)