-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpepper
More file actions
executable file
·109 lines (94 loc) · 4.52 KB
/
Copy pathpepper
File metadata and controls
executable file
·109 lines (94 loc) · 4.52 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#! /usr/bin/env python3
import sys, os
# Converts custom syntax to python syntax. Takes a string as input.
def pepper_convert(code):
includes = []
def convert_line(subject):
if subject.find("add players from") != -1:
includes.append(subject.replace("add players from", "").strip())
return ""
if subject.find("player") != -1:
subject = subject.replace("starter", "__init__")
if subject.find("takes") == -1:
subject = subject.replace("player", "def").replace(":", "") + "():"
else:
subject = subject.replace("player", "def").replace("takes", "")
if subject.find("if") != -1 or subject.find("while") != -1:
subject = subject.replace("greater than or equal to", ">=").replace("less than or equal to", "<=").replace("greater than", ">").replace("less than", "<").replace("not equal to", "!=").replace("not equal", "!=").replace("not equals", "!=").replace("equals", "==").replace("equal", "==")
subject = subject.replace("new", "")
subject = subject.replace("with", "")
subject = subject.replace("is the same as", "is")
subject = subject.replace("is not the same as", "is not")
subject = subject.replace("equals", "=")
subject = subject.replace("else if", "elif")
subject = subject.replace("`quote", "\"")
subject = subject.replace("bump", "return")
return subject
def process_line(subject):
if subject.find("pass") != -1 and not(subject.find("\"") != -1 and subject.find("pass") > subject.find("\"")):
end_index = subject.find("pass")
subject = subject.replace("pass ", "", 1)
arg_open_index = subject.find("(")
if arg_open_index != -1:
arg_closed_index = subject.find(")")
args = subject[arg_open_index+1:arg_closed_index]
else:
args = ""
function_name_index = subject.rfind(" to ")
function_name_index = function_name_index + 3
function_name = subject[function_name_index + 1:]
if function_name.find(" of ") != -1:
function = function_name[:function_name.find(" of ")]
team = function_name[function_name.find(" of "):].replace(" of ", "")
function_name = team + "." + function
subject = subject[:end_index].replace("equals", "=") + function_name + "(" + args + ")"
subject = subject.replace("`quote", "\\\"")
return subject
if subject.find("volley") != -1 and not (subject.find("\"") != -1 and subject.find("volley") > subject.find("\"")):
subject = subject.replace("volley", "raise Exception(")
subject = subject + ")"
return subject
if subject.find("team ") != -1 and not (subject.find("\"") != -1 and subject.find("team") > subject.find("\"")):
subject = subject.replace("team", "class")
if subject.find("improves off") != -1:
subject = subject.replace("improves off", "(")
subject = subject.replace(":", "") + "):"
return subject
clean = subject.split("\"")
index = 0
while index < len(clean):
clean[index] = convert_line(clean[index])
index += 2
index = 1
result = ""
while index < len(clean):
result = result + "\""+ clean[index]
index += 1
result = clean[0] + result
return result
instructions = code.split("\n")
includes = []
for i in range(len(instructions)):
instructions[i] = process_line(instructions[i])
instructions[i] = instructions[i] + "\n"
for i in range(len(includes)):
new_instructions = [pepper_convert(open(includes[i], "r").read())]
new_instructions.extend(instructions)
instructions = new_instructions
return "".join(instructions)
args = sys.argv
keep_output = False
if len(args) == 3 and args[2] == "python":
keep_output = True
print("Pepper Runtime Environment")
if len(args) == 1:
print("\nError: no input file")
else:
open(args[1].replace("pepper", "py"), "w").write(pepper_convert(open(args[1], "r").read()))
print("\nOutput: " + args[1].replace("pepper", "py"))
print("OK")
print("Program output:")
print()
os.system("python3 " + args[1].replace("pepper", "py"))
if not keep_output:
os.system("rm " + args[1].replace("pepper", "py"))