fork download
  1. v = {}
  2.  
  3. waiting = False
  4.  
  5. def replace_low_and_cap(text, splitBy, joinBy):
  6. text = text.split(splitBy.lower())
  7. text = joinBy.join(text)
  8. text = text.split(splitBy.title())
  9. text = joinBy.join(text)
  10. return text
  11.  
  12. def replace_all(text, replaceWith, *splitList):
  13. text = replace_low_and_cap(text, replaceWith, replaceWith)
  14. for splitBy in splitList:
  15. text = replace_low_and_cap(text, splitBy, replaceWith)
  16. return text
  17.  
  18. def replace_all_dash(text, replaceWith, *splitList):
  19. text = replace_all(text, replaceWith, replaceWith)
  20. for splitBy in splitList:
  21. text = replace_all(text, replaceWith, "-"+splitBy)
  22. return text
  23.  
  24. def replace_first(text, replaceWith, spl):
  25. text = text.split(spl)
  26. if len(text) >= 2:
  27. text[0] += replaceWith+text.pop(1)
  28. text = spl.join(text)
  29. return text
  30.  
  31. def echo(l=""):
  32. print(l, end="")
  33. return l
  34.  
  35. def println(l=""):
  36. print(l)
  37. return l
  38.  
  39. def compileCode(inp):
  40. storeIn = None
  41. shouldEcho = None
  42. shouldPrint = None
  43. inp = replace_first(inp, '-r"', '"')
  44. inp = replace_all_dash(inp, "-r", "raw")
  45. inp = replace_all_dash(inp, "-a", "alias", "v", "var")
  46. inp = replace_all_dash(inp, "-e", "echo")
  47. inp = replace_all_dash(inp, "-p", "print", "println")
  48. inp = replace_all_dash(inp, "True", "yes", "positive")
  49. inp = replace_all_dash(inp, "False", "no", "negative")
  50. inp = replace_all_dash(inp, "None", "nothing", "empty", "undefined", "null")
  51. spl = inp.split("-e")
  52. if len(spl) >= 2:
  53. i = len(spl)-1
  54. del spl[i]
  55. shouldEcho = True
  56. spl = "-e".join(spl)
  57. spl = spl.split("-p")
  58. if len(spl) >= 2:
  59. i = len(spl)-1
  60. del spl[i]
  61. shouldPrint = True
  62. spl = "-p".join(spl)
  63. spl = spl.split("-ifvar")
  64. if len(spl) >= 2:
  65. i = len(spl)-1
  66. words = spl[i].split()
  67. varTxt = 'var['+words.pop(i)+']'
  68. cond = varTxt+'words'
  69. t = test(cond)
  70. if t != True:
  71. return
  72. spl = "-ifvar".join(spl)
  73. spl = spl.split("-if")
  74. if len(spl) >= 2:
  75. i = len(spl)-1
  76. cond = eval(spl.pop(i))
  77. t = test(cond)
  78. if t != True:
  79. return
  80. spl = "if".join(spl)
  81. spl = spl.split("-store in ")
  82. if len(spl) >= 2:
  83. i = len(spl) - 1
  84. storeIn = eval(spl.pop(i))
  85. spl = "-store in ".join(spl)
  86. spl = spl.split("-r")
  87. if len(spl) >= 2:
  88. cmd = ".".join(spl.pop(0).split())
  89. args = "-r".join(spl).split("-a")
  90. for i in range(len(args)):
  91. if i > 0:
  92. a = "v["+args[i]+"]"
  93. args[i] = a
  94. args = "".join(args)
  95. if shouldEcho:
  96. code = "{0}({1}, shouldEcho=True)".format(cmd, args)
  97. elif shouldPrint:
  98. code = "{}({}, shouldPrint=True)".format(cmd, args)
  99. else:
  100. code = "{0}({1})".format(cmd, args)
  101. else:
  102. spl = "".join(spl)
  103. spl = spl.split("-a")
  104. if len(spl) >= 2:
  105. cmd = ".".join(spl[0].split())
  106. for i in range(len(spl)):
  107. if i > 0:
  108. a = "v["+spl[i]+"]"
  109. spl[i] = a
  110. spl.pop(0)
  111. spl = "".join(spl)
  112. if shouldEcho:
  113. code = "{}({}, shouldEcho=True)".format(cmd, spl)
  114. elif shouldPrint:
  115. code = "{}({}, shouldPrint=True)".format(cmd, spl)
  116. else:
  117. code = "{}({})".format(cmd, spl)
  118. else:
  119. spl = "".join(spl)
  120. spl = spl.split("-f")
  121. if len(spl) >= 2:
  122. cmd = spl.pop(0)
  123. arg = spl.pop(0)
  124. cmd = "".join(cmd)
  125. cmd = ".".join(cmd.split())
  126. if shouldEcho:
  127. code = "{}({}(), shouldEcho=True)".format(cmd, arg)
  128. elif shouldPrint:
  129. code = "{}({}(), shouldPrint=True)".format(cmd, arg)
  130. else:
  131. code = "{}({}())".format(cmd, arg)
  132. else:
  133. spl = "".join(spl)
  134. spl = ".".join(spl.split())
  135.  
  136. if shouldEcho:
  137. code = "{}(shouldEcho=True)".format(spl)
  138. elif shouldPrint:
  139. code = "{}(shouldPrint=True)".format(spl)
  140. else:
  141. code = "{}()".format(spl)
  142. if type(storeIn) == str:
  143. code = """temp = {}
  144. v["{}"] = temp""".format(code, storeIn)
  145. return code
  146. def runCode(inp):
  147. code = compileCode(inp)
  148. eval(code)
  149. waiting = False
  150.  
  151. def q(shouldPrint=False, shouldEcho=False):
  152. if shouldEcho:
  153. return echo("Quitting ...")
  154. if shouldPrint:
  155. return println("Quitting ...")
  156. exit()
  157. raise Exception("Error exiting app")
  158.  
  159. def printAliases():
  160. for var in v:
  161. val = v[var]
  162. if type(val) == str:
  163. val = "\""+val+"\""
  164. print(var+": "+str(val))
  165.  
  166. def getAliases():
  167. return v
  168.  
  169. def amountOfAliases():
  170. return len(v)
  171.  
  172. def alias(var, i=None, shouldPrint=False, shouleEcho=False):
  173. if i != None:
  174. v[var] = i
  175. if shouldEcho:
  176. echo(var+":",v[var])
  177. if shouldPrint:
  178. println(var+":",v[var])
  179. return v[var]
  180.  
  181. class error:
  182. def __init__(self, e="", fatal=False, shouldPrint=False, shouldEcho=False):
  183. if fatal == False:
  184. self.txt = "Error"
  185. else:
  186. self.txt = "Fatal error"
  187. if e != "":
  188. self.txt += ": "+e
  189. if shouldPrint:
  190. println(str(self))
  191. if shouldEcho:
  192. echo(str(self))
  193.  
  194. @staticmethod
  195. def fatal(e="", shouldPrint=False, shouldEcho=False):
  196. err = error(e, True, shouldPrint=shouldPrint, shouldEcho=shouldEcho)
  197. q(shouldPrint, shouldEcho)
  198. return err
  199.  
  200. @staticmethod
  201. def makeFatal(self, shouldPrint=False, sholdEcho=False):
  202. e = "".join(self.txt.split("Error: "))
  203. return type(self).fatal(e, shouldPrint, shouldEcho)
  204.  
  205. def __str__(self):
  206. return self.txt
  207.  
  208. def python(c):
  209. eval(c)
  210.  
  211. class ui:
  212. @staticmethod
  213. def userinput(prompt):
  214. pauseLoop()
  215. inp = input(prompt)
  216. print()
  217. return(inp)
  218.  
  219. def test(cond, shouldEcho=False, shouldPrint=False):
  220. if type(cond) == bool:
  221. if shouldEcho:
  222. echo(cond)
  223. if shouldPrint:
  224. println(cond)
  225. return cond
  226. else:
  227. error.fatal("Condition is invalid.")
  228.  
  229. def testcond(cond):
  230. pauseLoop()
  231. quit = False
  232. cond = str(cond)
  233. while not quit:
  234. test = input("if the condition is:\n$ ")
  235. println(test)
  236. if test == "exit":
  237. quit = True
  238. ifTrue = input("Do:\n$ ")
  239. println(ifTrue)
  240. if test == "other":
  241. quit = True
  242. condtest = "True"
  243. else:
  244. condtest = cond+test
  245. if eval(condtest):
  246. quit = True
  247. runCode(ifTrue)
  248. playLoop()
  249.  
  250. def mainLoop():
  251. print("Mainloop")
  252. while waiting == False:
  253. inp = input("\n$ ")
  254. println(inp)
  255. runCode(inp)
  256. for var in v:
  257. print(var)
  258. print("")
  259.  
  260. def pauseLoop():
  261. waiting = True
  262.  
  263. def playLoop():
  264. waiting = False
  265. mainLoop()
  266.  
  267. playLoop()
Runtime error #stdin #stdout #stderr 0.02s 27696KB
stdin
echo "Hello, world!" -store in "a"
printAliases
q
stdout
Mainloop

$ echo "Hello, world!" -store in "cond"
stderr
Traceback (most recent call last):
  File "./prog.py", line 267, in <module>
  File "./prog.py", line 265, in playLoop
  File "./prog.py", line 255, in mainLoop
  File "./prog.py", line 148, in runCode
  File "<string>", line 1
    temp = echo("Hello, world!" )
         ^
SyntaxError: invalid syntax