Skip to content
This repository was archived by the owner on Sep 24, 2022. It is now read-only.

Commit aaba9f2

Browse files
More bug fixes
1 parent af7353d commit aaba9f2

3 files changed

Lines changed: 15 additions & 3 deletions

File tree

src/langParser.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import mathParser.values
55
import executor
66
from typing import Any
7+
import mathParser.values
78

89

910
# Constants
@@ -70,6 +71,10 @@ def parse_type_from_value(value) -> Types:
7071
return Types.Array
7172
if isinstance(value, LambdaExpr):
7273
return Types.Action
74+
if isinstance(value, mathParser.values.Number):
75+
if executor.check_is_float(repr(value)):
76+
return Types.Float
77+
return Types.Integer
7378
if value in {None, "null"}:
7479
return Types.Void
7580
if not isinstance(value, str):
@@ -86,10 +91,11 @@ def parse_type_from_value(value) -> Types:
8691
if value.startswith("new Dynamic"):
8792
return Types.Dynamic
8893

89-
is_float = executor.check_is_float(value)
9094
if value.startswith('"') or value.endswith('"'):
9195
return Types.String
9296

97+
is_float = executor.check_is_float(value)
98+
9399
if is_float:
94100
return Types.Float
95101
if not is_float:

src/lexer.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,10 @@ def handle_base_keywords(self, tc: list, original_text: str) -> tuple:
545545
elif i == ")":
546546
in_arguments_list = False
547547
elif in_arguments_list:
548+
if is_found_equal_sign:
549+
arguments += "="
548550
arguments += i
551+
is_found_equal_sign = False
549552

550553
existing_arguments: set = set()
551554
def parse_function_argument(arg):
@@ -859,10 +862,11 @@ def analyse_command(self, tc: list, original_text: str = None) -> tuple:
859862
argpos += 1
860863

861864
flex = Lexer(custom_symbol_table, self.parser)
862-
print(function_object.function_body)
863865
res, error = flex.analyse_command(function_object.function_body.split(), original_text=function_object.function_body)
864866
for name in function_object.arguments:
865867
custom_symbol_table.DeleteVariable(name[1])
868+
if error:
869+
return res, error
866870
valtype = self.parser.parse_type_from_value(res)
867871
if valtype != function_object.return_type:
868872
return f"InvalidTypeException: Return value mismatched. Expected {function_object.return_type.value}, found {valtype.value}.", Exceptions.InvalidTypeException

src/tests.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,12 @@ def test_array(self):
233233
self.assertTrue((processor.execute("arr").data == np.array([0, 2, 3, 0, 0])).all())
234234

235235
def test_lambda(self):
236+
self.assertEqual(processor.execute("int num = 7"), None)
236237
self.assertEqual(processor.execute("Action add = lambda int (int one, int two) => one + two"), None)
237-
self.assertEqual(processor.execute("Action nothing = lambda void () => print(\"this does something\")"), None)
238+
self.assertEqual(processor.execute("Action nothing = lambda void () => num = 25"), None)
238239
self.assertEqual(processor.execute("add(2, 5)"), 7)
239240
self.assertEqual(processor.execute("nothing()"), None)
241+
self.assertEqual(processor.execute("num"), 25)
240242

241243

242244
if __name__ == "__main__":

0 commit comments

Comments
 (0)