Skip to content

Commit 3cd44f1

Browse files
authored
3.6 update
1 parent 4edc890 commit 3cd44f1

File tree

5 files changed

+128
-41
lines changed

5 files changed

+128
-41
lines changed

compiler.py

Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
indentation_required = 0
9898

9999
compiled_file = open(compiled_file_filename, "w", encoding="utf-8")
100-
compiled_file.write("# Compiled from ACPL programming language\n# Download from github : https://www.github.com/megat69/ACPL\n\nfrom time import sleep\nfrom random import randrange\n\n")
100+
compiled_file.write("# Compiled from ACPL programming language\n# Download from github : https://www.github.com/megat69/ACPL\n\nfrom time import sleep\nfrom random import randrange\nfrom math import *\n\n")
101101

102102
while line_numbers < len(code_lines):
103103
line = code_lines[line_numbers]
@@ -135,20 +135,11 @@
135135

136136
while "<" in line and ">" in line:
137137
equation = line[line.find("<") + 1:line.find(">")]
138-
while "{" in line and "}" in equation:
139-
variable = equation[equation.find("{") + 1:equation.find("}")]
140-
debug("other", lineno(), f"Variable {variable} found in print.")
141-
try:
142-
line = line.replace("{" + variable + "}", variable)
143-
except KeyError:
144-
error(line_numbers, "ArgumentError",
145-
f"The variable \"{variable}\" is not existing or has been declared later in the code.")
146-
debug("other", lineno(), f"Equation {equation} found.")
147-
try:
148-
line = line.replace(f"<{str(equation)}>", "{"+equation+"}")
149-
except KeyError:
150-
error(line_numbers, "ArgumentError",
151-
f"The equation \"{equation}\" is not existing or has been declared later in the code.")
138+
new_equation = line[line.find("<") + 1:line.find(">")]
139+
while "{" in new_equation and "}" in new_equation:
140+
variable = new_equation[new_equation.find("{") + 1:new_equation.find("}")]
141+
new_equation = new_equation.replace("{"+variable+"}", variable)
142+
line = line.replace("<"+equation+">", "{"+new_equation+"}")
152143

153144
if line.startswith("for"):
154145
indentation_required += 1
@@ -230,6 +221,8 @@
230221
elif line.startswith("var"):
231222
line = line.replace("var", "", 1)
232223
var_type = None
224+
var_action = None
225+
var_parameters = None
233226

234227
do_regroup = True
235228

@@ -241,10 +234,36 @@
241234
else:
242235
var_type = 'str'
243236
line = line.replace(":"+var_type, "", 1)
244-
line = line.replace(" ", "", 1)
237+
if line.startswith(" "):
238+
line = line.replace(" ", "", 1)
239+
240+
if line.startswith("--"):
241+
if line.startswith("--lowercase"):
242+
var_action = "lowercase"
243+
elif line.startswith("--uppercase"):
244+
var_action = "uppercase"
245+
elif line.startswith("--round:"):
246+
var_action = "round"
247+
var_parameters = [re.search('\-\-round\:\d*', line).group(0)]
248+
elif line.startswith("--ceil"):
249+
var_action = "ceil"
250+
if var_parameters is None:
251+
line = line.replace("--"+var_action, "", 1)
252+
else:
253+
var_parameters_to_str = ""
254+
for param in var_parameters:
255+
var_parameters_to_str += param
256+
line = line.replace("--" + var_action + ":" + var_parameters_to_str, "", 1)
257+
if line.startswith(" "):
258+
line = line.replace(" ", "", 1)
245259

246260
line = line.split(" ") # Result : [name, "=", content]
247261

262+
if var_parameters is not None:
263+
line.pop(0)
264+
if line[2].endswith("\n"):
265+
line[2] = line[2][:-1]
266+
248267
if str(line[2]).startswith("input"):
249268
line[2] = line[2].replace("input", "", 1)
250269
for i in range(3, len(line)):
@@ -280,13 +299,15 @@
280299

281300
else:
282301
try:
283-
line[2] = eval(line[2])
284-
except SyntaxError:
285-
print(line[2])
286-
pass
287-
except NameError:
288-
print(line[2])
289-
pass
302+
if "." not in str(line[2]):
303+
line[2] = int(line[2])
304+
elif re.search("\d*", str(line[2]).replace(".", "")).group(0) == str(line[2]):
305+
line[2] = float(line[2])
306+
except ValueError:
307+
try:
308+
line[2] = float(line[2])
309+
except ValueError:
310+
line[2] = str(line[2])
290311

291312
if do_regroup:
292313
for i in range(3, len(line)):
@@ -311,6 +332,15 @@
311332
elif str(line[2]).lower() == "f\"false\"":
312333
line[2] = False
313334

335+
if var_action == "lowercase":
336+
line[2] = str(line[2]) + ".lower()"
337+
elif var_action == "uppercase":
338+
line[2] = str(line[2]) + ".upper()"
339+
elif var_action == "round":
340+
line[2] = f"round(float({line[2]}), {int(var_parameters[0].replace('--round:', ''))})"
341+
elif var_action == "ceil":
342+
line[2] = f"ceil({line[2]})"
343+
314344
if var_type is not None:
315345
line = line[0] + " = " + var_type + "(" + str(line[2]) + ")"
316346
else:

console.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@
166166
f"\t- 'compile' : Compiles an ACPL file to a Python file\n"
167167
f"\t- 'ini-content' : Displays the content of the ini file\n"
168168
f"\t- 'open' : Opens a specific file in its default program\n"
169-
f"\t- 'display' : Prints the content of a specified file.\n")
169+
f"\t- 'display' : Prints the content of a specified file.\n"
170+
f"\t- 'change-line'/'modify-line' : Modifies a specific line in a plain text file.\n")
170171

171172
elif user_input.lower() == "about":
172173
if language == "fr":
@@ -269,6 +270,18 @@
269270
ascii_art.close()
270271
print("\n\nMerci d'avoir jeté un coup d'oeil au code.")
271272

273+
elif user_input.startswith("change-line") or user_input.startswith("modify-line"): # change-line <file> <line_number> <new_text>
274+
user_input = user_input.replace("change-line ", "", 1)
275+
user_input = user_input.replace("modify-line ", "", 1)
276+
user_input = user_input.split(" ")
277+
for i in range(3, len(user_input)):
278+
user_input[2] += " " + user_input[i]
279+
while len(user_input) > 3:
280+
user_input.pop(3)
281+
replace_line(user_input[0], user_input[1], user_input[2])
282+
print(f"Line {user_input[1]} modified in {user_input[0]} with value :\n{user_input[2]}")
283+
284+
272285
else:
273286
output = texts.console["unknown-command"]
274287

main.py

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import os
1010
import msvcrt
1111
import timeit
12+
from math import *
1213

1314
time_launch = timeit.default_timer()
1415
final_filename = ""
@@ -227,24 +228,42 @@
227228
elif line.startswith("var"):
228229
line = line.replace("var", "", 1)
229230
var_type = None
231+
var_action = None
232+
var_parameters = None
230233

231234
if line.startswith(":"):
232235
if line.startswith(":int"):
233236
var_type = "int"
234-
elif line.startswith("float"):
237+
elif line.startswith(":float"):
235238
var_type = "float"
236239
else:
237240
var_type = "str"
238-
line = line.replace(":"+var_type, "", 1)
239-
line = line.replace(" ", "", 1)
241+
line = line.replace(":"+var_type, "", 1) # ERROR HERE !
242+
if line.startswith(" "):
243+
line = line.replace(" ", "", 1)
244+
245+
if line.startswith("--"):
246+
if line.startswith("--lowercase"):
247+
var_action = "lowercase"
248+
elif line.startswith("--uppercase"):
249+
var_action = "uppercase"
250+
elif line.startswith("--round:"):
251+
var_action = "round"
252+
var_parameters = [re.search('\-\-round\:\d*', line).group(0).replace("--round:", "")]
253+
elif line.startswith("--ceil"):
254+
var_action = "ceil"
255+
if var_parameters is None:
256+
line = line.replace("--" + var_action, "", 1)
257+
else:
258+
var_parameters_to_str = ""
259+
for param in var_parameters:
260+
var_parameters_to_str += param
261+
line = line.replace("--" + var_action + ":" + var_parameters_to_str, "", 1)
262+
if line.startswith(" "):
263+
line = line.replace(" ", "", 1)
240264

241265
if line.endswith("\n"):
242-
line = split(line)
243-
line.pop()
244-
temp_line = ""
245-
for char in line:
246-
temp_line += char
247-
line = temp_line
266+
line = line[:-1]
248267
line = line.replace("\\n", "\n")
249268

250269
line = line.split(" ") # Result : [name, "=", content]
@@ -254,6 +273,8 @@
254273
elif str(line[2]).lower() == "false":
255274
line[2] = False
256275

276+
recombine = True
277+
257278
if str(line[2]).startswith("input"):
258279
line[2] = line[2].replace("input", "", 1)
259280
line[2] = line[2].replace(" ", "", 1)
@@ -262,6 +283,12 @@
262283
while line[2].startswith(" "):
263284
line[2] = line[2].replace(" ", "", 1)
264285
line[2] = input(line[2])
286+
try:
287+
for i in range(3, len(line)):
288+
line.pop(i)
289+
except IndexError:
290+
pass
291+
recombine = False
265292

266293
if str(line[2]).startswith("random"):
267294
line[2] = line[2].replace("random", "", 1)
@@ -275,6 +302,11 @@
275302
rand_min = line[3].replace(",", "")
276303
rand_max = line[4]
277304
line[2] = randrange(int(rand_min), int(rand_max))
305+
recombine = False
306+
307+
if recombine:
308+
for i in range(3, len(line)):
309+
line[2] += " "+line[i]
278310

279311
try:
280312
line[2] = eval(line[2])
@@ -286,13 +318,25 @@
286318
line[2] = "\""+line[2]+"\""
287319

288320
try:
289-
line[2] = int(line[2])
321+
if "." not in str(line[2]):
322+
line[2] = int(line[2])
323+
elif re.search("\d*", str(line[2]).replace(".", "")).group(0) == str(line[2]):
324+
line[2] = float(line[2])
290325
except ValueError:
291326
try:
292327
line[2] = float(line[2])
293328
except ValueError:
294329
line[2] = str(line[2])
295330

331+
if var_action == "lowercase":
332+
line[2] = str(line[2]).lower()
333+
elif var_action == "uppercase":
334+
line[2] = str(line[2]).upper()
335+
elif var_action == "round":
336+
line[2] = round(float(str(line[2]).replace("= ", "", 1)), int(var_parameters[0].replace("--round:", "", 1)))
337+
elif var_action == "ceil":
338+
line[2] = ceil(float(str(line[2]).replace("= ", "", 1)))
339+
296340
if var_type is not None:
297341
if var_type == "int":
298342
variables_container[line[0]] = int(line[2])

recurrent_classes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def __str__(self):
106106

107107
def replace_line(file_name, line_num, text):
108108
lines = open(file_name, 'r').readlines()
109-
lines[line_num] = text
109+
lines[int(line_num)] = text
110110
out = open(file_name, 'w')
111111
out.writelines(lines)
112112
out.close()

startup.acpl-ini

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
filename: code_sample_ACPL_3.5
2-
lang: en
3-
version: 3.5.0
4-
current-version: Pre3.4.1c_A4
1+
filename: code
2+
lang: fr
3+
version: 3.6.0
4+
current-version: Pre3.6.0b_K10
55
debug-state: False
66
console-reloaded: False
77
use-colors: True
88
process-time-round-numbers: 6
9-
compiled-file-filename: code_sample_ACPL_3.5
9+
compiled-file-filename: code
1010
open-compiled-file: False
11-
leave-comments-at-compiling: False
11+
leave-comments-at-compiling: True
1212
startup-check-update: False
1313
compiling-style: compacted
1414
compile-ask-for-replace: True

0 commit comments

Comments
 (0)