Skip to content

Commit 81d4ac4

Browse files
authored
3.8 update !
1 parent 39a13d5 commit 81d4ac4

File tree

8 files changed

+366
-38
lines changed

8 files changed

+366
-38
lines changed

compiler.py

Lines changed: 81 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,29 @@
135135

136136
while "<" in line and ">" in line:
137137
equation = line[line.find("<") + 1:line.find(">")]
138-
new_equation = line[line.find("<") + 1:line.find(">")]
138+
"""new_equation = line[line.find("<") + 1:line.find(">")]
139139
while "{" in new_equation and "}" in new_equation:
140140
variable = new_equation[new_equation.find("{") + 1:new_equation.find("}")]
141141
new_equation = new_equation.replace("{"+variable+"}", variable)
142+
line = line.replace("<"+equation+">", "{"+new_equation+"}")"""
143+
new_equation = equation.replace("{", "")
144+
new_equation = new_equation.replace("}", "")
142145
line = line.replace("<"+equation+">", "{"+new_equation+"}")
143146

147+
while len(re.findall("\{[a-zA-Z]*\[len\]\}", line)) > 0 and re.findall("\{[a-zA-Z]*\[len\]\}", line)[0] in line:
148+
variable = line[line.find("{") + 1:line.find("[")]
149+
full_var = re.findall("\{[a-zA-Z]*\[len\]\}", line)[0]
150+
line = line.replace(str(full_var), "{len("+variable+")}")
151+
while "[{" in line and "}]" in line:
152+
variable = line[line.find("[") + 1:line.find("]")]
153+
full_var = line[line.find("{") + 1:line.find("[")]
154+
variable = variable.replace("{", "", 1)
155+
variable = variable.replace("}", "", 1)
156+
if variable == "len":
157+
line = line.replace("{"+full_var+"[{"+variable+"}]}", "{len("+full_var+")}")
158+
else:
159+
line = line.replace("[{"+variable+"}]", "["+variable+"]", 1)
160+
144161
if line.startswith("for"):
145162
indentation_required += 1
146163
line = remove_from_string(line, ["{", "}"])
@@ -230,6 +247,8 @@
230247
var_type = 'int'
231248
elif line.startswith(":float"):
232249
var_type = 'float'
250+
elif line.startswith(":list"):
251+
var_type = 'list'
233252
else:
234253
var_type = 'str'
235254
line = line.replace(":"+var_type, "", 1)
@@ -256,7 +275,7 @@
256275
if line.startswith(" "):
257276
line = line.replace(" ", "", 1)
258277

259-
line = line.split(" ") # Result : [name, "=", content]
278+
line = line.split(" ") # Result : [name, var_operator, content]
260279

261280
if var_parameters is not None:
262281
line.pop(0)
@@ -294,6 +313,54 @@
294313
f"The variable \"{variable}\" is not existing or has been declared later in the code.")
295314
do_regroup = False
296315

316+
elif var_type == "list":
317+
# Recombination of line vars in a single line
318+
for i in range(3, len(line)):
319+
line[2] = line[2] + " " + line[i]
320+
321+
# Initializing list elements
322+
list_elements = []
323+
if "list." not in line[2]:
324+
while "[" in line[2] and "]" in line[2]:
325+
errors_count = 0
326+
variable = line[2][line[2].find("[") + 1:line[2].find("]")]
327+
debug("other", lineno(), f"List element {variable} found.")
328+
try:
329+
line[2] = line[2].replace("[" + variable + "]", "")
330+
except KeyError:
331+
error(line_numbers, "ArgumentError",
332+
f"An error occured while trying to parse the list \"{line[0]}\".")
333+
errors_count += 1
334+
if errors_count >= 10:
335+
print(
336+
f"\n\n{bcolors.FAIL}Debug has chosen to stop this program due to too many errors. Sorry for the inconvenicence.{bcolors.ENDC}")
337+
line_numbers = len(code_lines)
338+
break
339+
list_elements.append(variable)
340+
# Dememorizing 'variable'
341+
variable = None
342+
343+
line[2] = list_elements
344+
var_type = "list"
345+
do_regroup = False
346+
elif line[2].startswith("list.add"):
347+
line[2] = line[2].replace("list.add ", "", 1)
348+
line[2] = remove_suffix(line[2], line[2].endswith("\n"))
349+
line = line[0]+".append(f\""+line[2]+"\")"
350+
do_regroup = False
351+
elif line[2].startswith("list.insert"):
352+
line[2] = line[2].replace("list.insert ", "", 1)
353+
index = re.findall("\d*", str(line[2]))[0]
354+
line[2] = line[2].replace(index+" ", "", 1)
355+
line[2] = remove_suffix(line[2], line[2].endswith("\n"))
356+
line = line[0]+".insert("+index+", f\""+line[2]+"\")"
357+
do_regroup = False
358+
elif line[2].startswith("list.remove"):
359+
line[2] = line[2].replace("list.remove ", "", 1)
360+
index = re.findall("\d*", str(line[2]))[0]
361+
line = line[0]+".pop("+index+")"
362+
do_regroup = False
363+
297364
else:
298365
try:
299366
if "." not in str(line[2]):
@@ -306,11 +373,13 @@
306373
except ValueError:
307374
line[2] = str(line[2])
308375

376+
309377
if do_regroup:
310378
for i in range(3, len(line)):
311379
line[2] += " "+line[i]
312380

313-
if not isinstance(line[2], bool):
381+
382+
if not isinstance(line[2], bool) and not isinstance(line[2], list):
314383
try:
315384
line[2] = int(line[2])
316385
except ValueError:
@@ -319,7 +388,8 @@
319388
except ValueError:
320389
pass
321390

322-
if isinstance(line[2], str) and not line[2].startswith("input") and not line[2].startswith("randint"):
391+
392+
if isinstance(line[2], str) and not line[2].startswith("input") and not line[2].startswith("randint") and not isinstance(line, str):
323393
line[2] = remove_suffix(line[2], line[2].endswith("\n"))
324394
line[2] = "f\""+line[2]+"\""
325395

@@ -337,10 +407,14 @@
337407
elif var_action == "ceil":
338408
line[2] = f"ceil({line[2]})"
339409

340-
if var_type is not None:
341-
line = line[0] + " = " + var_type + "(" + str(line[2]) + ")"
410+
if ("append" in line or "insert" in line or "pop" in line) and var_type == "list":
411+
line = line
412+
elif var_type == "list":
413+
line = line[0] + " " + line[1] + " " + str(line[2])
414+
elif var_type is not None:
415+
line = line[0] + " " + line[1] + " " + var_type + "(" + str(line[2]) + ")"
342416
else:
343-
line = line[0] + " = " + str(line[2])
417+
line = line[0] + " " + line[1] + " " + str(line[2])
344418

345419
elif line.startswith("pause"):
346420
line = line.replace("pause ", "", 1)

console.py

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import requests
77
import platform
88
import shlex
9+
import webbrowser
910

1011
running = True
1112
ini_file = "startup.acpl-ini"
@@ -77,19 +78,34 @@
7778

7879
debug("in", lineno(), user_input)
7980

81+
og_user_input = user_input
82+
83+
if user_input == "redo":
84+
user_input = last_user_input
85+
8086
if user_input.lower() == "end":
8187
print(f"{bcolors.OKBLUE}{texts.console['process-ended']}{bcolors.ENDC}")
8288
break
8389

8490
elif user_input.startswith("run"):
85-
user_input = user_input.replace("run ", "")
86-
replace_line('startup.acpl-ini', 0, 'filename: ' + user_input + "\n")
87-
if not user_input.endswith(".acpl"):
88-
user_input += ".acpl"
91+
if user_input == "run":
92+
user_input = open_file_dialog(extensions="acpl")
93+
if user_input is not None:
94+
replace_line('startup.acpl-ini', 0, 'filename: ' + user_input + "\n")
95+
else:
96+
print(f"{bcolors.FAIL}Cannot run this file.{bcolors.ENDC}")
97+
continue
98+
else:
99+
user_input = user_input.replace("run ", "")
100+
replace_line('startup.acpl-ini', 0, 'filename: ' + user_input + "\n")
101+
if not user_input.endswith(".acpl"):
102+
user_input += ".acpl"
103+
89104
print(f"{bcolors.OKBLUE}{texts.console['launch-code-file'].format(user_input)}{bcolors.ENDC}")
90105
sleep(1.7)
91106
os.system("python main.py")
92107

108+
93109
elif user_input.startswith("rerun"):
94110
print(f"{bcolors.OKBLUE}Running last file again...{bcolors.ENDC}")
95111
sleep(1.7)
@@ -163,6 +179,9 @@
163179
else:
164180
output = texts.console_modify_ini["unable-to-modify-option"]
165181

182+
elif user_input.lower().startswith("doc"):
183+
webbrowser.open("https://github.com/megat69/ACPL/blob/master/README.md")
184+
166185
elif user_input.lower() == "help":
167186
print(texts.console_help["available-commands"] + " :")
168187
print(f"\t- 'end' : {texts.console_help['end']}\n"
@@ -226,12 +245,22 @@
226245
raise CriticError
227246

228247
elif user_input.startswith("compile"):
229-
user_input = user_input.replace("compile ", "", 1)
230-
user_input = user_input.split(" ")
231-
if len(user_input) == 1:
232-
user_input.append(user_input[0]+".py")
233-
if not user_input[0].endswith(".acpl"):
234-
user_input[0] += ".acpl"
248+
if user_input == "compile":
249+
user_input = open_file_dialog(extensions="acpl")
250+
if user_input is not None:
251+
user_input = [user_input, user_input]
252+
else:
253+
continue
254+
else:
255+
user_input = user_input.replace("compile ", "", 1)
256+
user_input = user_input.split(" ")
257+
if len(user_input) == 1:
258+
user_input = [user_input[0], user_input[0]]
259+
if not user_input[0].endswith(".acpl"):
260+
user_input[0] += ".acpl"
261+
if ("." in user_input[0] and not user_input[0].endswith(".acpl")) or ("." in user_input[1] and not user_input[1].endswith(".acpl")):
262+
print(f"{bcolors.FAIL}Unable to compile that kind of file (extension '.{user_input[0].split('.')[1]}').")
263+
continue
235264
replace_line('startup.acpl-ini', 0, 'filename: '+user_input[0]+"\n")
236265
replace_line("startup.acpl-ini", 8, "compiled-file-filename: "+user_input[1]+"\n")
237266
os.system("python compiler.py")
@@ -300,6 +329,7 @@
300329

301330
else:
302331
output = texts.console["unknown-command"]
332+
last_user_input = og_user_input
303333

304334
if output is not None:
305335
print(f"{bcolors.WARNING}{texts.console['output'].upper()} :{bcolors.ENDC}\n{output}")

ide.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,14 @@ def trigger_autocomplete():
8080

8181
print(f"{bcolors.OKBLUE}ACPL IDE successfully opened.{bcolors.ENDC}")
8282

83+
# Part removed on 29/11/2020
84+
# Action : File opening in command line.
85+
# Replaced by dialog box.
86+
"""
8387
code_file_filename = input(f"{bcolors.OKBLUE}Enter code file filename : {bcolors.ENDC}")
8488
if not code_file_filename.endswith(".acpl") and "." not in code_file_filename:
8589
code_file_filename += ".acpl"
90+
8691
if code_file_filename.startswith("ACPL_IDE_NEW "):
8792
user_input = code_file_filename.replace("ACPL_IDE_NEW ", "", 1)
8893
if os.path.exists(user_input):
@@ -105,6 +110,8 @@ def trigger_autocomplete():
105110
code_file_filename = input(f"{bcolors.FAIL}Sorry, this file ({code_file_filename}) doesn't exist. Can you retry ?\nEnter the code file filename : {bcolors.ENDC}")
106111
if not code_file_filename.endswith(".acpl"):
107112
code_file_filename += ".acpl"
113+
"""
114+
code_file_filename = open_file_dialog()
108115

109116
print("\n\n")
110117

@@ -197,6 +204,8 @@ def trigger_autocomplete():
197204
displayed_lines[i] += bcolors.ENDC
198205
print(displayed_lines[i])
199206

207+
if loop_times[1] > 10:
208+
loop_times[1] = 10
200209
print(f"{bcolors.OKBLUE}{loop_times[1]} lines displayed out of {len(lines)}.{bcolors.ENDC}")
201210

202211
# Collect events until released
@@ -213,6 +222,12 @@ def trigger_autocomplete():
213222
except IndexError:
214223
temp_line = [""]
215224
temp_line.insert(current_cursor_position, pressed_key)
225+
if pressed_key == "{":
226+
temp_line.insert(current_cursor_position+1, "}")
227+
elif pressed_key == "<":
228+
temp_line.insert(current_cursor_position+1, ">")
229+
elif pressed_key == "[":
230+
temp_line.insert(current_cursor_position + 1, "]")
216231
try:
217232
lines[current_line] = ""
218233
except IndexError:

0 commit comments

Comments
 (0)